• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NREL / SolTrace / 18889752882

28 Oct 2025 09:28PM UTC coverage: 89.87% (-0.08%) from 89.946%
18889752882

Pull #76

github

web-flow
Merge e6c58895d into f6f121007
Pull Request #76: Fix NativeRunner ray tracing failure for parabola surface

944 of 994 new or added lines in 28 files covered. (94.97%)

2 existing lines in 1 file now uncovered.

4418 of 4916 relevant lines covered (89.87%)

10138914.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.61
/coretrace/simulation_results/simulation_result.cpp
1
#include "simulation_result.hpp"
2

3
#include <fstream>
4
#include <iomanip>
5
#include <iostream>
6
#include <sstream>
7
#include <stdexcept>
8
#include <string>
9

10
#include "element.hpp"
11
#include "vector3d.hpp"
12

13
namespace SolTrace::Result
14
{
15

16
    using element_id = SolTrace::Data::element_id;
17
    using Vector3d = SolTrace::Data::Vector3d;
18

19
    const std::string &ray_event_string(const RayEvent rev)
146,416✔
20
    {
21
        auto item = REV_TO_STR.find(rev);
146,416✔
22
        if (item != REV_TO_STR.cend())
146,416✔
23
        {
24
            return item->second;
146,416✔
25
        }
26
        else
27
        {
28
            return REV_TO_STR.find(RayEvent::UNKNOWN)->second;
×
29
        }
30
    }
31

32
    InteractionRecord::InteractionRecord(
208,606✔
33
        element_id el,
34
        RayEvent rev,
35
        const Vector3d &location,
36
        const Vector3d &direction)
208,606✔
37
        // : index(-1),
38
        : element(el),
208,606✔
39
          event(rev),
208,606✔
40
          location(location),
208,606✔
41
          direction(direction)
208,606✔
42
    {
43
    }
208,606✔
44

45
    InteractionRecord::InteractionRecord(
1✔
46
        element_id el,
47
        RayEvent rev,
48
        double px,
49
        double py,
50
        double pz,
51
        double dx,
52
        double dy,
53
        double dz)
1✔
54
        : element(el),
1✔
55
          event(rev),
1✔
56
          location(px, py, pz),
1✔
57
          direction(dx, dy, dz)
1✔
58
    {
59
    }
1✔
60

61
    InteractionRecord::~InteractionRecord()
208,607✔
62
    {
63
    }
208,607✔
64

65
    std::ostream &operator<<(std::ostream &os, const InteractionRecord &rec)
21✔
66
    {
67
        os << "Element: " << rec.element
21✔
68
           << " Location: " << rec.location
21✔
69
           << " Direction: " << rec.direction
21✔
70
           << " Event: " << ray_event_string(rec.event);
21✔
71
        return os;
21✔
72
    }
73

74
    RayRecord::RayRecord(ray_id id) : id(id)
70,018✔
75
    {
76
    }
70,018✔
77

78
    RayRecord::~RayRecord()
70,018✔
79
    {
80
        this->interactions.clear();
70,018✔
81
        return;
70,018✔
82
    }
70,018✔
83

84
    void RayRecord::add_interaction_record(interaction_ptr ip)
208,604✔
85
    {
86
        // ip->index = this->interactions.size();
87
        this->interactions.push_back(ip);
208,604✔
88
        return;
208,604✔
89
    }
90

91
    void RayRecord::get_position(const interaction_ptr ip, Vector3d &pos)
106,817✔
92
    {
93
        pos = ip->location;
106,817✔
94
        return;
106,817✔
95
    }
96

97
    void RayRecord::get_position(int_fast64_t idx, Vector3d &pos)
106,812✔
98
    {
99
        const interaction_ptr ip0 = this->interactions[idx];
106,812✔
100
        return this->get_position(ip0, pos);
213,624✔
101
    }
106,812✔
102

103
    void RayRecord::get_direction(const interaction_ptr ip,
106,817✔
104
                                  Vector3d &cos)
105
    {
106
        cos = ip->direction;
106,817✔
107
        make_unit_vector(cos);
106,817✔
108
        return;
106,817✔
109
    }
110

111
    void RayRecord::get_direction(int_fast64_t idx,
106,812✔
112
                                  Vector3d &cos)
113
    {
114
        const interaction_ptr ip0 = this->interactions[idx];
106,812✔
115
        this->get_direction(ip0, cos);
106,812✔
116
        return;
213,624✔
117
    }
106,812✔
118

119
    const interaction_ptr &RayRecord::operator[](int_fast64_t idx) const
5✔
120
    {
121
        if (idx < 0 || idx >= this->interactions.size())
5✔
122
        {
123
            std::stringstream ss;
×
124
            ss << "RayRecord: Index " << idx
×
125
               << " is out of bounds [0, " << this->interactions.size()
×
126
               << "].";
×
127
            throw std::invalid_argument(ss.str());
×
128
        }
×
129
        return this->interactions[idx];
5✔
130
    }
131

132
    std::ostream &operator<<(std::ostream &os, const RayRecord &rec)
4✔
133
    {
134
        os << "Ray: " << rec.id
4✔
135
           << "\nInteractions:\n";
4✔
136
        for (uint_fast64_t k = 0; k < rec.interactions.size(); ++k)
24✔
137
        {
138
            os << k << " " << *rec.interactions[k] << "\n";
20✔
139
        }
140
        // os << "Last Cosines: " << rec.cos_last << "\n";
141
        return os;
4✔
142
    }
143

144
    SimulationResult::SimulationResult()
6✔
145
    {
146
        return;
6✔
147
    }
148

149
    SimulationResult::~SimulationResult()
6✔
150
    {
151
        this->ray_history.clear();
6✔
152
        return;
6✔
153
    }
6✔
154

155
    void SimulationResult::add_ray_record(ray_record_ptr rp)
70,016✔
156
    {
157
        this->ray_history.push_back(rp);
70,016✔
158
        return;
70,016✔
159
    }
160

NEW
161
    void SimulationResult::write_csv_file(std::string csv_name,
×
162
                                          int precision)
163
    {
NEW
164
        return this->write_csv_file(csv_name.c_str(), precision);
×
165
    }
166

167
    void SimulationResult::write_csv_file(const char *csv_name,
1✔
168
                                          int precision)
169
    {
170
        std::ofstream csv(csv_name);
1✔
171
        csv.precision(precision);
1✔
172
        csv << "Ray Number,Pos X,Pos Y,Pos Z,"
173
            << "Cos X,Cos Y,Cos Z,Element,Event\n";
1✔
174
        for (auto srit : this->ray_history)
50,001✔
175
        {
176
            for (auto cit : srit->interactions)
196,320✔
177
            {
178
                csv << srit->id << ","
146,320✔
179
                    << cit->location[0] << ","
146,320✔
180
                    << cit->location[1] << ","
146,320✔
181
                    << cit->location[2] << ","
146,320✔
182
                    << cit->direction[0] << ","
146,320✔
183
                    << cit->direction[1] << ","
146,320✔
184
                    << cit->direction[2] << ","
146,320✔
185
                    << cit->element << ","
146,320✔
186
                    << ray_event_string(cit->event) << "\n";
146,320✔
187
            }
146,320✔
188
        }
50,000✔
189
        csv.close();
1✔
190
        return;
2✔
191
    }
1✔
192

193
    const ray_record_ptr &SimulationResult::operator[](int_fast64_t idx) const
223,179✔
194
    {
195
        if (idx < 0 || idx >= this->ray_history.size())
223,179✔
196
        {
197
            std::stringstream ss;
×
198
            ss << "SimulationResult: Index " << idx
×
NEW
199
               << " is out of bounds [0, " << this->ray_history.size() - 1
×
200
               << "].";
×
201
            throw std::invalid_argument(ss.str());
×
202
        }
×
203
        return this->ray_history[idx];
223,179✔
204
    }
205

206
    // ray_record_ptr &SimulationResult::operator[](int_fast64_t idx)
207
    // {
208
    //     // TODO: Probably should do bounds checking...
209
    //     return this->ray_history[idx];
210
    // }
211

212
    std::ostream &operator<<(std::ostream &os, const SimulationResult &simres)
1✔
213
    {
214
        os << "Simulation Results -- " << simres.ray_history.size() << " Rays\n";
1✔
215
        for (uint_fast64_t k = 0; k < simres.ray_history.size(); ++k)
4✔
216
        {
217
            // os << "Ray: " << k << "\n"
218
            //    << *simres.ray_history[k];
219
            os << *simres.ray_history[k];
3✔
220
        }
221
        return os;
1✔
222
    }
223

224
} // namespace SolTrace::Result
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc