Skip to content

Conversation

@jmaack24
Copy link
Member

@jmaack24 jmaack24 commented Apr 17, 2025

Work in progress:

  • Simulation data structure implementation
  • Simulation runner implementation for existing CPU SolTrace backend
  • Validation and regression tests for native runner
  • Simulation result implementation for native runner

jmaack24 and others added 25 commits February 27, 2025 15:21
@jmaack24 jmaack24 self-assigned this Apr 17, 2025
@jmaack24 jmaack24 marked this pull request as draft April 17, 2025 15:52
@jmaack24 jmaack24 marked this pull request as ready for review October 1, 2025 15:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 124 out of 147 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (2)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +3 to +9
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

using namespace std;
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using 'using namespace std;' in header files or at global scope. It pollutes the global namespace and can cause naming conflicts. Use specific using declarations or fully qualified names instead.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The using statement is in a .cpp file. Probably not something that needs to be addressed.

Comment on lines 9 to +12
MTRand myrng(1);
double random_number = myrng.rand();

EXPECT_NEAR(random_number, 0.13387664401253274, 0.0000001);
EXPECT_NEAR(random_number, 0.13387664401253274, 1e-7);
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a named constant for the expected value and tolerance to improve readability and maintainability. Magic numbers make the test harder to understand and modify.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test for the legacy code and will likely be deprecated at some point.

Comment on lines +48 to +60
goto Label_9;
}
else
{
Euler[0] = PI / 2.0;
goto Label_8;
}
}

Euler[0] = atan2(CosIn[0], CosIn[2]);
Label_8:
Euler[1] = atan2(CosIn[1], sqrt(CosIn[0] * CosIn[0] + CosIn[2] * CosIn[2]));
Label_9:
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of goto statements makes code harder to read and maintain. Consider refactoring this logic using structured control flow (if/else, functions, or early returns) instead.

Suggested change
goto Label_9;
}
else
{
Euler[0] = PI / 2.0;
goto Label_8;
}
}
Euler[0] = atan2(CosIn[0], CosIn[2]);
Label_8:
Euler[1] = atan2(CosIn[1], sqrt(CosIn[0] * CosIn[0] + CosIn[2] * CosIn[2]));
Label_9:
}
else
{
Euler[0] = PI / 2.0;
Euler[1] = atan2(CosIn[1], sqrt(CosIn[0] * CosIn[0] + CosIn[2] * CosIn[2]));
}
}
else
{
Euler[0] = atan2(CosIn[0], CosIn[2]);
Euler[1] = atan2(CosIn[1], sqrt(CosIn[0] * CosIn[0] + CosIn[2] * CosIn[2]));
}

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted in #71 and to be addressed in a future PR.

Comment on lines +176 to +177
NIter = 10;
Epsilon = 0.000005;
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These appear to be magic numbers that should be defined as named constants at the top of the file or as class members to improve maintainability and make their purpose clear.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@taylorbrown75 taylorbrown75 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Legacy SolTrace GUI and coretrace can be built by setting CMakelist variables to ON. Legacy sample files run, tests pass on my machine.

on:
push:
branches: [ develop, trace_refactor ]
branches: [ develop, trace_refactor, jm-dev-tmb ]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove trace_refactor on both push and PRs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returned to just develop

return;
}

void Heliostat::enforce_user_fields_set() const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing some of the class user set fields here, e.g., gap_x.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your checking them as they are set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should still get checked by the enforce_user_fields_set function. I will add it.

{
if (this->initialized)
{
CompositeElement::enforce_user_fields_set();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, I believe this will always be skipped. The template only calls this function if initialized is False.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enforce_user_fields_set function gets called when the element is added to a SimulationData object as well, at which point it is initialized and this will get called.

elem->set_aperture(ap);

// // TODO: Is this the correct thing to do here?
// vector_add(1.0, this->focal_point, -1.0, origin, aim);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the focal_point? Should this and the other code referring to it be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something from when I was trying to implement it. I will remove it.

if (this->focal_length_x <= 0.0 && this->focal_length_y <= 0.0)
{
surf = make_surface<Flat>();
// Vector3d khat(0.0, 0.0, 1.0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.

0.0);

elem->set_front_optical_properties(this->optics_mirror);
elem->set_back_optical_properties(this->optics_mirror);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make the back surface properties different. Either fixed to some default "absorber" or provide access to customize.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a TODO about this.

It was while doing these templates that I realized we should rework the optical properties to have be a single object with a front and back so we can do error checking make it a bit easier to create elements (less verbose).

Copy link
Collaborator

@qualand qualand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start. I think we have a lot of loose ends to build out in the coming months.


sun_position_vector_degrees(this->sun_position, azimuth, elevation);
Vector3d target_dir;
vector_add(1.0, this->target_pos,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a check target_set before these calculations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets checked by the enforce_user_fields_set function which is called at the top of the initialize function.

throw std::invalid_argument(ss.str());
}

this->coordinates_initialized = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a check on this->initialized? that either calls create_geometry or throws an error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Added a check and an error throw.

return;
}

void Heliostat::enforce_user_fields_set() const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your checking them as they are set.

REFRACTION
};

// enum DistributionType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

optics_front(),
optics_back()
{
// TODO: Do we want a default aperture and surface? What about default
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would set the default to a flat rectangle (1x1) set to a perfect absorber.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aperture and surface have checks to make sure they get set. I updated the optics to default to ideal absorber.


namespace SolTrace::Data {

StageElement::StageElement(int_fast64_t stage) : CompositeElement()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this how you envision Stages being handled? Will this implementation run into issues when the added element is a compositeElement, e.g., a CST template.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a composite element to a stage is allowed so you can add a CST template to a stage. But this should work to handle stages since they are largely a way for users to define a local coordinate system.

@qualand qualand merged commit 814815a into develop Oct 15, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants