Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
832841e
changed printing behavior of optix runner
nickmedwards Apr 8, 2026
6c16f46
print stuff
nickmedwards Apr 10, 2026
855f4fc
disable stages for embree in simdriver
nickmedwards Apr 16, 2026
89d07db
track number of loops for optix simulation
nickmedwards Apr 29, 2026
1b80cce
clean up old prints
nickmedwards May 5, 2026
a6c700d
work on element groups
nickmedwards May 7, 2026
22df451
finished group tests
nickmedwards May 8, 2026
0489cc8
added tag for verbose to simdriver main
nickmedwards May 10, 2026
d5d811d
wrote group result struct and test to get into report_simulation
nickmedwards May 11, 2026
c8a3a9e
added counters for group result
nickmedwards May 12, 2026
94bac64
wrote test for counters
nickmedwards May 12, 2026
bb41fd4
write group results as json
nickmedwards May 12, 2026
6337194
added cli arg --level to simdriver main
nickmedwards May 12, 2026
7ccc049
added writing code to simdriver/main
nickmedwards May 12, 2026
0fbdd62
formatting and checking groups size before fetching
nickmedwards May 13, 2026
d8d31df
asked to remove in pr comment
nickmedwards May 14, 2026
5f50b64
asked to manage group virtually above single element
nickmedwards May 14, 2026
dc59186
asked to manage group virtually, actually removed from ElementBase
nickmedwards May 14, 2026
0114cc4
asked to make groups 32 bit
nickmedwards May 14, 2026
03ffd6a
asked to change destructor
nickmedwards May 14, 2026
de613b3
removed dangling includes
nickmedwards May 14, 2026
73b9a7c
asked to change write_json_file to write_group_json_file
nickmedwards May 14, 2026
a4e7b99
asked to change call signature for get_groups, forgot to change funct…
nickmedwards May 15, 2026
533d187
convert to std::set
nickmedwards Jun 9, 2026
8beb0bb
addressed pr comments about group membership to optix runner, work on…
nickmedwards Jun 10, 2026
794207f
friend access to test without adding gtest to prod build
nickmedwards Jun 11, 2026
6c2fbee
remove dead code
nickmedwards Jun 11, 2026
b11d317
finished grouped results counts test, makes sure json write doesn't t…
nickmedwards Jun 11, 2026
9fa16a2
added level to simdriver/main.cpp
nickmedwards Jun 11, 2026
eb63797
updated test jsons for grouped optical properities changes
nickmedwards Jun 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

74 changes: 62 additions & 12 deletions coretrace/simdriver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ using SolTrace::Runner::RunnerStatus;
static void print_usage(const char *prog)
{
std::cerr
<< "Usage: " << prog << " <input.json|input.stinput> [<output.csv>] [options]\n"
<< "Usage: " << prog << " <input.json|input.stinput> [<output_filename>] [options]\n"
<< "Please include the .json extension for the input.json argument, while"
<< " excluding a file extension for the output filename. The output file "
<< "extension will be determined based on the level specified (see below).\n"
<< "\n"
<< "Options:\n"
<< " --threads <n> Number of threads (default: 1)\n"
Expand All @@ -61,6 +64,7 @@ static void print_usage(const char *prog)
<< " (output file argument not required with this flag)\n"
<< " --no-csv Retrieve results but skip writing the CSV file\n"
<< " (output file argument not required with this flag)\n"
<< " --level <n> Runner reporting level (default: 0, see SolTrace::Runner::RunnerStatistics for available levels)\n"
#ifdef SOLTRACE_EMBREE_SUPPORT
<< " --embree Use Embree runner instead of the native runner\n"
<< " (requires SOLTRACE_BUILD_EMBREE_SUPPORT=ON at build time)\n"
Expand All @@ -69,13 +73,15 @@ static void print_usage(const char *prog)
<< " --optix Use OptiX runner instead of the native runner\n"
<< " (requires SOLTRACE_BUILD_OPTIX_SUPPORT=ON at build time)\n"
#endif
<< " --verbose Enable verbose logging in the OptiX runner\n"
<< " -v, --verbose Enable verbose logging in the OptiX runner\n"
;
}

int main(int argc, char *argv[])
{
if (argc < 2)
using SolTrace::Runner::RunnerStatistics;
// double check that this works with no-output/no-csv flags
if (argc < 3)
{
print_usage(argv[0]);
return EXIT_FAILURE;
Expand Down Expand Up @@ -112,6 +118,7 @@ int main(int argc, char *argv[])

int num_threads = 1;
long long num_rays_override = -1; // -1 means use what the JSON specifies
int level = 0;
bool use_embree = false;
bool use_optix = false;
bool verbose = false;
Expand Down Expand Up @@ -167,6 +174,28 @@ int main(int argc, char *argv[])
{
// already handled in pre-scan; skip here
}
else if (arg == "--level")
{
if (i + 1 >= argc)
{
std::cerr << "Error: --level requires an argument\n";
return EXIT_FAILURE;
}
try
{
level = std::stoi(argv[++i]);
}
catch (...)
{
std::cerr << "Error: invalid level '" << argv[i] << "'\n";
return EXIT_FAILURE;
}
if (level < RunnerStatistics::RAY_RECORDS || level > RunnerStatistics::ALL)
{
std::cerr << "Error: level must map to SolTrace::Runner::RunnerStatistics\n";
return EXIT_FAILURE;
}
}
else if (arg == "--embree")
{
use_embree = true;
Expand All @@ -175,7 +204,7 @@ int main(int argc, char *argv[])
{
use_optix = true;
}
else if (arg == "--verbose")
else if (arg == "-v" || arg == "--verbose")
{
verbose = true;
}
Expand Down Expand Up @@ -271,6 +300,7 @@ int main(int argc, char *argv[])

std::cout << "Setting up simulation...\n";
auto t_setup_start = std::chrono::steady_clock::now();
runner.disable_stages();
sts = runner.setup_simulation(&simData);
auto t_setup_end = std::chrono::steady_clock::now();
if (sts != RunnerStatus::SUCCESS)
Expand Down Expand Up @@ -365,9 +395,9 @@ int main(int argc, char *argv[])

if (!skip_output)
{
std::cout << "Retrieving results...\n";
std::cout << "Retrieving results at level " << level << "...\n";
auto t_report_start = std::chrono::steady_clock::now();
sts = runner.report_simulation(&result, 0);
sts = runner.report_simulation(&result, level);
auto t_report_end = std::chrono::steady_clock::now();
if (sts != RunnerStatus::SUCCESS)
{
Expand Down Expand Up @@ -468,16 +498,16 @@ int main(int argc, char *argv[])
}

// -------------------------------------------------------------------------
// Write results to CSV
// Write results to CSV / JSON
// -------------------------------------------------------------------------
if (!skip_output && !skip_csv)
if (!skip_csv && (level == RunnerStatistics::RAY_RECORDS || level == RunnerStatistics::ALL))
{
std::cout << "Writing " << result.get_number_of_records()
<< " ray records to: " << output_file << "...\n";
<< " ray records to: " << output_file << ".csv ...\n";
try
{
auto t_write_start = std::chrono::steady_clock::now();
result.write_csv_file(output_file);
result.write_csv_file(output_file + ".csv");
auto t_write_end = std::chrono::steady_clock::now();
std::cout << " Written in "
<< std::chrono::duration<double>(t_write_end - t_write_start).count()
Expand All @@ -493,11 +523,31 @@ int main(int argc, char *argv[])
{
std::cout << "Skipping CSV output (--no-csv).\n";
}
else

if (!skip_output && (level == RunnerStatistics::GROUPED_COUNTS || level == RunnerStatistics::ALL))
{
std::cout << "Writing " << result.get_number_of_groups()
<< " group results to: " << output_file << ".json ...\n";
try
{
auto t_write_start = std::chrono::steady_clock::now();
result.write_group_json_file(output_file + ".json");
auto t_write_end = std::chrono::steady_clock::now();
std::cout << " Written in "
<< std::chrono::duration<double>(t_write_end - t_write_start).count()
<< " s\n";
}
catch (const std::exception &e)
{
std::cerr << "Error writing JSON file: " << e.what() << "\n";
return EXIT_FAILURE;
}
}
else if (skip_output)
{
std::cout << "Skipping CSV output (--no-output).\n";
}

std::cout << "Done.\n";
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions coretrace/simulation_data/composite_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ namespace SolTrace::Data
{
return this->my_elements.is_at_end(citer);
}

// only single elements have groups
virtual int32_t get_group() const override { return -2; }

virtual void enforce_user_fields_set() const override;

Expand Down
4 changes: 4 additions & 0 deletions coretrace/simulation_data/element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class Element
/// @return id if registered with SimulationData, ELEMENT_ID_UNASSIGNED if not
virtual element_id get_id() const = 0;

/// @brief Get the group number this element belongs to
/// @return Group number
virtual int32_t get_group() const = 0;

/**
* @brief Get the stage number this element belongs to
* @return Stage number
Expand Down
20 changes: 20 additions & 0 deletions coretrace/simulation_data/simulation_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SimulationData::SimulationData() : number_of_elements(0),

SimulationData::~SimulationData()
{
this->clear(true);
return;
}

Expand Down Expand Up @@ -51,6 +52,24 @@ element_id SimulationData::add_element(element_ptr el)
else
{
this->number_of_elements++;

Comment thread
jmaack24 marked this conversation as resolved.
// only check groups on single elements
int32_t group = el->get_group();

if (group > -1)
{
// ensure that group index exists by adding empty groups if necessary
size_t my_groups_size = this->my_groups.size();
if (group >= my_groups_size)
{
for (size_t i = my_groups_size; i <= (size_t)group; ++i)
{
this->my_groups.push_back(std::set<uint_fast64_t>());
}
}

this->my_groups[group].insert(id);
}
}
}
else
Expand Down Expand Up @@ -331,6 +350,7 @@ void SimulationData::clear(bool reset_parameters)
{
this->my_elements.clear();
this->my_sources.clear();
this->my_groups.clear();
this->number_of_elements = 0;

this->my_optical_property_sets.reset(0);
Expand Down
10 changes: 10 additions & 0 deletions coretrace/simulation_data/simulation_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <map>
#include <memory>
#include <string>
#include <set>
#include <vector>

#include "container.hpp"
#include "element.hpp"
Expand Down Expand Up @@ -294,6 +296,11 @@ class SimulationData
return this->my_parameters;
}

const std::vector<std::set<uint_fast64_t>>& get_groups() const
{
return this->my_groups;
}

int update_simulation_positions();
int update_simulation_positions(const Time &);
int update_simulation_positions(const Date &);
Expand Down Expand Up @@ -323,6 +330,9 @@ class SimulationData
// mutable element_id next_element_id;

uint_fast64_t number_of_elements;
// index is the group number and the value is the first id of that group in my_elements
// if groups are used they must be added after all ungrouped elements
std::vector<std::set<uint_fast64_t>> my_groups;

ElementContainer my_elements;
RaySourceContainer my_sources;
Expand Down
11 changes: 10 additions & 1 deletion coretrace/simulation_data/single_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@ SingleElement::SingleElement(const nlohmann::ordered_json& jnode,
const OpticalPropertySetResolver& resolve_optics) : ElementBase(jnode),
aperture(nullptr),
surface(nullptr),
opt_id(OPTICS_ID_UNASSIGNED)
opt_id(OPTICS_ID_UNASSIGNED),
group(-1)
{
this->set_aperture(Aperture::make_aperture_from_json(jnode.at("aperture")));
this->set_surface(make_surface_from_json(jnode.at("surface")));

const optics_id opt_id = jnode.at("opt_id").get<optics_id>();
this->set_optical_property_set(resolve_optics(opt_id));

// don't need to require every element have a group
if (jnode.contains("group"))
{
this->group = jnode.at("group").get<int32_t>();
} else {
this->group = -1;
}
}

SingleElement::~SingleElement()
Expand Down
8 changes: 8 additions & 0 deletions coretrace/simulation_data/single_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class SingleElement : public ElementBase
this->optics_back = op;
}*/

virtual int32_t get_group() const override { return this->group; }

virtual void enforce_user_fields_set() const override;

virtual void write_json(nlohmann::ordered_json& jnode) const override;
Expand All @@ -107,6 +109,12 @@ class SingleElement : public ElementBase

optics_id opt_id = OPTICS_ID_UNASSIGNED;
std::weak_ptr<const OpticalPropertySet> optical_property_set;

// group number of element.
// -2 is an element that does not interact with the trace, ie stage or composite elements.
// -1 is an ungrouped element, assigned explicitly or if "group" key is missing from JSON.
// 0 and above are grouped elements.
int32_t group;
};

using single_element_ptr = typename std::shared_ptr<SingleElement>;
Expand Down
2 changes: 2 additions & 0 deletions coretrace/simulation_results/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ include_directories(

set(SIMRES_SRC
records.cpp
group_result.cpp
simulation_result.cpp
)

set(SIMRES_HDRS
records.hpp
group_result.hpp
simulation_result.hpp
simulation_result_api.hpp
simulation_result_export.hpp
Expand Down
49 changes: 49 additions & 0 deletions coretrace/simulation_results/group_result.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <cstdint>
#include <map>
#include <string>
#include <vector>

// #include "element.hpp"

// #include <../../hpvm.h>

// SimulationResult headers
#include "group_result.hpp"

namespace SolTrace::Result
{
GroupResult::GroupResult(int32_t group_id, size_t n_groups) :
group_id(group_id),
absorb_count(0),
reflect_count(0),
transmit_count(0),
virtual_count(0),
absorb_sun_previous(0),
reflect_sun_previous(0),
transmit_sun_previous(0),
virtual_sun_previous(0)
{
// need extra spots in the vectors for ungrouped elements and the sun.
absorb_previous_group.resize(n_groups);
reflect_previous_group.resize(n_groups);
transmit_previous_group.resize(n_groups);
virtual_previous_group.resize(n_groups);
}

void GroupResult::write_json(nlohmann::ordered_json &jnode) const
{
jnode["group_id"] = group_id;
jnode["absorb_count"] = absorb_count;
jnode["reflect_count"] = reflect_count;
jnode["transmit_count"] = transmit_count;
jnode["virtual_count"] = virtual_count;
jnode["absorb_sun_previous"] = absorb_sun_previous;
jnode["reflect_sun_previous"] = reflect_sun_previous;
jnode["transmit_sun_previous"] = transmit_sun_previous;
jnode["virtual_sun_previous"] = virtual_sun_previous;
jnode["absorb_previous_group"] = absorb_previous_group;
jnode["reflect_previous_group"] = reflect_previous_group;
jnode["transmit_previous_group"] = transmit_previous_group;
jnode["virtual_previous_group"] = virtual_previous_group;
}
}
Loading