-
Notifications
You must be signed in to change notification settings - Fork 213
Add python test function for boundary corrections #2700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add python test function for boundary corrections #2700
Conversation
|
|
||
| namespace { | ||
| struct VolumeDouble { | ||
| double t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps value as the member name?
| /*mesh_velocity*/, | ||
| const boost::optional<Scalar<DataVector>>& normal_dot_mesh_velocity, | ||
| const double volume_double) const noexcept { | ||
| const VolumeDoubleType volume_double_in) const noexcept { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure this will be clearer in the documentation for the specific boundary corrections when you start putting them in, but for my understanding, can you explain the role of this volume_double in these packaging functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just to test that quantities from the volume (i.e. DataBox) can be passed in. A practical example is needing the equation of state (which can't be projected onto the boundary) in order to calculate the speed of sound, which is needed to compute the characteristic speeds. The Newtonian Euler system uses this pattern, for example.
| template <size_t Dim> | ||
| struct Correction { | ||
| template <size_t Dim, typename VolumeDoubleType> | ||
| struct Correction final { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Correction object is just for the test helper, but presumably its interface will be the same as the forthcoming individual boundary correction structs -- will the boundary corrections need to store member data? If not, can their functions be made static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some boundary corrections (not ones we are using) exist that have parameters that would be reasonable to tune in an input file. I think it's easier to have all the functions be non-static for uniformity and ease-of-understanding for new users. There are also classes of boundary corrections like HLL, HLLE, HLLEM, HLLC, etc. (there's something like 5-8 of these that I know of, but I'm sure there are even more) that could reasonably all be one class with an input file option for which one to use. This helps keep down the amount of boiler plate code (class, inheritence, function declarations, files, etc.) to support many different forms of nearly identical boundary corrects.
| CAPTURE(python_module); | ||
| CAPTURE( | ||
| gsl::at(python_dg_package_data_functions, function_name_index)); | ||
| const auto cxx_result = pypp::call<ResultType, ConversionClassList>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems slightly misleading to call this cxx_result as it's the thing that results from calling the python functions and then converting them to c++ objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, should be named python_result!
| const auto cxx_result = pypp::call<ResultType, ConversionClassList>( | ||
| python_module, | ||
| gsl::at(python_dg_package_data_functions, function_name_index), | ||
| get<FaceTags>(fields_on_face)..., unit_normal_covector, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface to the python function seems potentially confusing -- the ordering of the arguments is not quite what I would expect (same order, but variables pack-expanded).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean. In the C++ code the Variables classes are also expanded before being passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I think I was just mistaken with my previous comment -- what I was saying was that I would expect the same order but pack-expanded, but thought that you were passing in a different order. I think I just misunderstood what FaceTags would hold, so I'm now happy with this as-is
| * You can convert custom types using the `ConversionClassList` template | ||
| * parameter, which is then passed to `pypp::call()`. This allows you to, e.g., | ||
| * convert an equation of state into an array locally in a test file. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to add notes about the assumed relationship between python functions and the package functions tag list, and the System:variables_tag tag list - In particular, you require that there be a python function for each packaged field, and one for each tag in the system variables. The interface of the python function should also be specified -- the order of arguments and relationships to the tag collections where the Variables need to be pack-expanded.
4c194d3 to
60035cc
Compare
|
I've pushed a fixup and rebased on develop. Please let me know if I've missed or misunderstood any comments (or anything else!). |
fmahebert
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once @moxcodes gives okay to squash, you can also squash these small things in
| * in `dg_package_field_tags` | ||
| * - There must be one python function to compute the boundary correction for | ||
| * each tag in `System::variables_tag` | ||
| * - The arguments to the python functions for computing the packaged data is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is -> are
| make_not_null(&gen), make_not_null(&dist), used_for_size); | ||
| const auto unit_normal_covector = make_with_random_values< | ||
| tnsr::i<DataVector, FaceDim + 1, Frame::Inertial>>( | ||
| make_not_null(&gen), make_not_null(&dist), used_for_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You call this a unit normal, but as far as I can tell it has a random magnitude (including, rarely, 0 — should this be checked against too?). Please either normalize the vector, rename the variable, or add a comment.
|
looks good -- go ahead and squash. |
60035cc to
3db3111
Compare
|
Rebased on develop and squashed, including @fmahebert's requested changes. (I decided to just normalize the vector) |
3db3111 to
bd58e69
Compare
|
Rebased again and squashed in |
Proposed changes
Add a generic function that does a random value test of the boundary corrections for DG. This means that the actual tests for boundary corrections are quite short. For example, the Rusanov solver for Burgers is:
Most work/code comes in from the python implementations. There's a bit more needed if an equation of state (or some other non-DataVector-wrapping class) needs to be converted. Here's Newtonian Euler as an example:
Upgrade instructions
Code review checklist
make docto generate the documentation locally intoBUILD_DIR/docs/html.Then open
index.html.code review guide.
bugfixormajor new featureif appropriate.Further comments