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

NREL / SolTrace / 18544749821

15 Oct 2025 10:47PM UTC coverage: 89.946% (+45.8%) from 44.166%
18544749821

push

github

web-flow
Restructured backend for SolTrace (#63)

* Initial API for refactored SolTrace

* Updates to various APIs; first pass at element/ray source container implementation

* Use existing matrix-vector code as backend for matrix and vector classes; start implementing APIs

* Created new test on power tower example file with 50000 rays. Changed CMake to use cpp 17.

* Added ground results csv to new folder in google-tests directory

* Removed register prefix from variables in mtrand.h. More errors to come.

* Removed lines in CMakeLists causing linux failure, fixed bug in power tower test

* Created parabola.stinput test and a test using powertower optimization on the powertower sample

* Commented out parabola test for now, added nonexistent branch to CI to see how it runs

* Fixed syntax error

* Changed tests based on PR feedback

* Fixed error in CMakeLists that caused failure on windows

* Removed output messages from st_sim_run_test

* Fixed silly mistake in previous commit

* Added comments and removed unused libraries

* Changed naming conventions of tests

* Added high flux solar furnace test changes, changed parabola test file name

* Fixed typo

* Move refactored data to its own directory; add to refactored classes to build

* Add missed files

* Add unit tests for basic linear algebra and container template

* More tests; Start implementation of composite element

* Add more unit tests on element

* Add missed headers

* Remove target from cmake build command in CI

* Initial virtual element implementation; smoke test for virtual element

* Correct aperture spelling; add tests for virtual elements

* Add some unit tests for simulation data

* Move to static library for simulation data (temporary); update cmake files to get correct mac architecture

* Attempt to fix coverage failure

* Attempt to capture inline functions in code coverage; add a few more explicit tests

* Fix build

* Separate storage of CompositeElement and SingleElement; update te... (continued)

4357 of 4844 new or added lines in 62 files covered. (89.95%)

4357 of 4844 relevant lines covered (89.95%)

8565975.82 hits per line

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

88.89
/coretrace/simulation_data/simulation_data.cpp
1
#include "simulation_data.hpp"
2

3
#include <cassert>
4

5
#include "composite_element.hpp"
6
#include "simdata_io.hpp"
7

8
namespace SolTrace::Data {
9

10
SimulationData::SimulationData() : number_of_elements(0),
29✔
11
                                   my_elements(1),
29✔
12
                                   my_sources(0)
29✔
13
{
14
    return;
29✔
15
}
16

17
SimulationData::~SimulationData()
29✔
18
{
19
    return;
29✔
20
}
29✔
21

22
element_id SimulationData::add_element(element_ptr el)
8,646✔
23
{
24
    element_id id = ELEMENT_ERROR;
8,646✔
25

26
    if (el->get_id() != ELEMENT_ID_UNASSIGNED)
8,646✔
27
    {
28
        id = ELEMENT_ALREADY_REGISTERED;
1✔
29
    }
30
    else
31
    {
32
        id = this->my_elements.add_item(el);
8,645✔
33
        if (Element::is_success(id))
8,645✔
34
        {
35
            // Check that all fields required from the user have been specified
36
            el->enforce_user_fields_set();
8,645✔
37
            // Make sure coordinate stuff has been computed
38
            el->compute_coordinate_rotations();
8,641✔
39
            el->set_id(id);
8,641✔
40
            if (el->is_composite())
8,641✔
41
            {
42
                // The CompositeElement itself does not count toward the
43
                // number of elements since it does not impact the ray
44
                // tracing computation. So we do not increment the
45
                // number of elements here.
46
                uint_fast64_t n = this->add_subelements(el);
270✔
47
                assert(n == el->get_number_of_elements());
270✔
48
            }
49
            else
50
            {
51
                this->number_of_elements++;
8,371✔
52
            }
53
        }
54
        else
55
        {
56
            // TODO: Throw an error here
57
        }
58
    }
59

60
    return id;
8,642✔
61
}
62

63
// void SimulationData::add_single_element(element_id key,
64
//                                         element_ptr el)
65
// {
66
//     SingleElementMap::value_type to_insert(key, el);
67
//     auto result = this->my_elements.insert(to_insert);
68
//     assert(result.second);
69
//     return;
70
// }
71

72
uint_fast64_t SimulationData::add_subelements(element_ptr el)
272✔
73
{
74
    // CompositeElementMap::value_type to_insert(key, el);
75
    // auto result = this->composite_elements.insert(to_insert);
76
    // assert(result.second);
77

78
    composite_element_ptr cptr =
79
        std::dynamic_pointer_cast<CompositeElement>(el);
272✔
80
    assert(cptr != nullptr);
272✔
81

82
    uint_fast64_t nadded = cptr->get_number_of_elements();
272✔
83

84
    auto iter = cptr->get_const_iterator();
272✔
85
    while (!cptr->is_at_end(iter))
8,871✔
86
    {
87
        auto id = this->add_element(iter->second);
8,599✔
88
        assert(Element::is_success(id));
8,599✔
89
        // // Make sure coordinate stuff has been computed
90
        // iter->second->compute_coordinate_rotations();
91
        ++iter;
8,599✔
92
    }
93

94
    return nadded;
272✔
95
}
272✔
96

97
bool SimulationData::replace_element(element_id id, element_ptr el)
5✔
98
{
99
    bool success = false;
5✔
100
    assert(el->get_id() == ELEMENT_ID_UNASSIGNED);
5✔
101
    element_ptr old_el = this->get_element(id);
5✔
102
    if (old_el != nullptr)
5✔
103
    {
104
        success = this->my_elements.replace_item(id, el);
4✔
105
        if (success)
4✔
106
        {
107
            old_el->set_id(ELEMENT_ID_UNASSIGNED);
4✔
108
            if (old_el->is_composite())
4✔
109
            {
110
                this->remove_subelements(old_el);
2✔
111
            }
112
            else
113
            {
114
                this->number_of_elements--;
2✔
115
            }
116
            // Make sure coordinate stuff has been computed
117
            el->compute_coordinate_rotations();
4✔
118
            el->set_id(id);
4✔
119
            if (el->is_composite())
4✔
120
            {
121
                this->add_subelements(el);
2✔
122
            }
123
            else
124
            {
125
                this->number_of_elements++;
2✔
126
            }
127
            // this->number_of_elements -= old_el->get_number_of_elements();
128
            // this->number_of_elements += el->get_number_of_elements();
129
        }
130
    }
131

132
    return success;
5✔
133
}
5✔
134

135
element_ptr SimulationData::get_element(element_id id) const
13,176✔
136
{
137
    return this->my_elements.get_item(id);
13,176✔
138
    // element_ptr retval = nullptr;
139
    // auto iter1 = this->my_elements.find(id);
140
    // auto iter2 = this->composite_elements.find(id);
141
    // if (iter1 != this->my_elements.end())
142
    // {
143
    //     retval = iter1->second;
144
    // }
145
    // else if (iter2 != this->composite_elements.end())
146
    // {
147
    //     retval = iter2->second;
148
    // }
149
    // else
150
    // {
151
    //     // Intentional no-op
152
    // }
153
    // return retval;
154
}
155

156
uint_fast64_t SimulationData::remove_element(element_id id)
10✔
157
{
158

159
    uint_fast64_t nremoved = 0;
10✔
160
    element_ptr el = this->my_elements.get_item(id);
10✔
161

162
    if (el != nullptr)
10✔
163
    {
164
        this->my_elements.remove_item(id);
9✔
165
        el->set_id(ELEMENT_ID_UNASSIGNED);
9✔
166
        if (el->is_composite())
9✔
167
        {
168
            // The CompositeElement itself does not count toward the number
169
            // of elements since it does not impact the ray tracing computation.
170
            // So we do not decrement the number of elements here.
171
            nremoved = this->remove_subelements(el);
1✔
172
            assert(nremoved == el->get_number_of_elements());
1✔
173
        }
174
        else
175
        {
176
            this->number_of_elements--;
8✔
177
            nremoved = 1;
8✔
178
        }
179
    }
180

181
    return nremoved;
10✔
182

183
    // auto iter2 = this->composite_elements.find(id);
184
    // if (iter1 != this->my_elements.end())
185
    // {
186
    //     retval = remove_single_element(iter1);
187
    // }
188
    // else if (iter2 != this->composite_elements.end())
189
    // {
190
    //     retval = remove_composite_element(iter2);
191
    // }
192
    // else
193
    // {
194
    //     // Intentional no-op
195
    // }
196
    // return retval;
197
}
10✔
198

199
// uint_fast64_t SimulationData::remove_single_element(
200
//     SingleElementMap::iterator iter)
201
// {
202
//     iter->second->set_id(ELEMENT_ID_UNASSIGNED);
203
//     this->my_elements.erase(iter);
204
//     return 1;
205
// }
206

207
// uint_fast64_t SimulationData::remove_composite_element(element_ptr el)
208
// {
209
//     composite_element_ptr cptr = iter->second;
210
//     iter->second->set_id(ELEMENT_ID_UNASSIGNED);
211
//     this->composite_elements.erase(iter);
212
//     return this->remove_subelements(cptr);
213
// }
214

215
uint_fast64_t SimulationData::remove_subelements(element_ptr el)
3✔
216
{
217
    uint_fast64_t retval = 0;
3✔
218

219
    composite_element_ptr cptr =
220
        std::dynamic_pointer_cast<CompositeElement>(el);
3✔
221
    assert(cptr != nullptr);
3✔
222

223
    element_ptr ptr = nullptr;
3✔
224
    for (auto iter = cptr->get_iterator(); !cptr->is_at_end(iter); ++iter)
10✔
225
    {
226
        ptr = iter->second;
7✔
227
        retval += this->remove_element(ptr->get_id());
7✔
228
    }
229

230
    assert(retval == cptr->get_number_of_elements());
3✔
231

232
    return retval;
3✔
233
}
3✔
234

NEW
235
int SimulationData::update_simulation_positions()
×
236
{
NEW
237
    int sts = 0;
×
238
    // TODO: Implement this
NEW
239
    return sts;
×
240
}
241

NEW
242
int SimulationData::update_simulation_positions(const Time &t)
×
243
{
244
    this->my_parameters.sim_dt.my_time = t;
NEW
245
    return this->update_simulation_positions();
×
246
}
247

NEW
248
int SimulationData::update_simulation_positions(const Date &d)
×
249
{
250
    this->my_parameters.sim_dt.my_date = d;
NEW
251
    return this->update_simulation_positions();
×
252
}
253

NEW
254
int SimulationData::update_simulation_positions(const DateTime &dt)
×
255
{
NEW
256
    this->my_parameters.sim_dt.set(dt);
×
NEW
257
    return this->update_simulation_positions();
×
258
}
259

260
int SimulationData::import_from_file(const char *file_name)
3✔
261
{
262
    return load_stinput_file(*this, file_name);
6✔
263
}
264

265
int SimulationData::import_from_file(const std::string file_name)
3✔
266
{
267
    return this->import_from_file(file_name.c_str());
3✔
268
}
269

270
} // namespace SolTrace::Data
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