-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactor derived variables #63
Conversation
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.
Nice - the proposed changes work well! I agree that the stateVariableSetUp should be a part of GRAMRLevel that each PhysicsLevel::variableSetUp can call, since not all applications need the extra CCZ4/BSSN variables.
I tested this pull request by merging this branch with the scalar field example that I'm working on. I found a few minor quibbles (so I'll mark it as 'request changes'. Note that I would be happy to leave these as future work on a separate pull request if you would like to merge this branch into develop immediately.)
- It's a bit cumbersome to have to set the parity for all variables even though reflective boundary conditions are not used. It would be nice if there was a separate option that checked for the type of BCs and then if some of them are reflective, look for the parities.
- Consider changing the definition of variables as enums to be a vector of strings like what AMReX requires when interfacing with plotMultiFab, derive.lst etc. I find myself making a separate vector of strings that just goes over the enums so I can pass variable names to AMReX functions.
- I think some of the code in PhysicsLevel::derive() can be placed in GRAMRLevel and then called by PhysicsLevel like stateVariableSetUp. For example the Hamiltonian and momentum calculations would be common to any GR application and so will be copied in each GR physics example and this is probably a point of failure (if we update the calculations later on).
I guess my question was whether we wanted to make
This is a good idea. Let me look at setting some kind of default so that the user doesn't need to set this if they never intend to use reflective BCs.
I presume you mean
We don't want to include the constraint code in |
I also forgot to mention: some of the 'old' files in the test directory e.g. |
I just had a look at the changes in these files and it's just coming from the renaming |
17b7305
to
985b883
Compare
985b883
to
3b869a9
Compare
This PR modifies the following files which are ignored by .lint-ignore:
Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted. |
4047f30
to
4b9b121
Compare
I should add that 8bd6e68 means that we now use |
The variableSetupUp() should be defined in the specific example level class as it needs to be static and it sets up the derived variables.
Move the setting up of state variables from BinaryBHLevel::variableSetUp() to here. The state variables are inferred from the examples UserVariables.hpp.
This test writes the computed values to an HDF5 file which is then compared with the GRChombo equivalent using h5diff. Note that this test is skipped if built without HDF5.
This is to make them more consistent with AMReX terms.
Derived variables are instead defined in the examples PhysicsLevel::variableSetUp function. MultiFabs are instantiated as required to store them and the component numbers are not fixed.
Also add some minor refactoring of the load_vars_to_vector and load_values_to_array functions.
Like the Weyl4 test, this produces an HDF5 file which is then compared with one produced similarly from GRChombo using the h5diff tool. If built without HDF5, the test is skipped.
The "New" was just a GRChombo relic for backwards compatibility. We can get rid of that now.
Also add assertion for undefined parities which should only trigger if reflective BCs are used.
This will allow a valid but undefined StateVariables::parities to be constructed with an empty initializer list: {}.
Even though it may be less performant as we know the size of the container at compile time, it is more consistent with AMReX.
This is only valid for std::vectors and derived classes such as amrex::Vector since it relies on there being a constructor with the size being passed as the first and only argument.
Unfortunately, this adds a dependency of Constraints and Weyl4 on AMReX's Amr component which means adding this to the tests (which we will have to do at some point anyway).
The addition of this new type of derive function in AMReX-Codes/amrex#3990 means we can store the derive function to calculate the relevant derived quantity in the derive_lst. This means we can rely on AmrLevel::derive() for our needs and we can remove our overrides of this function in GRAMRLevel and BinaryBHLevel. The Weyl4 and Constaints tests have been modified to use the new DeriveFuncMF functions.
These have all not been ported yet or are old files we don't want to lint.
It is needed by utils/StateVariablesParmParse.hpp.
4b9b121
to
285b685
Compare
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.
Thanks so much for changing the variable names to be vectors - I think that was a really handy addition. Also the new set_up
and compute_mf
functions are nice.
I ran into a few issues running the BinaryBH example though:
- I can't seem to get the derived variables to print out in the plot files. I'm using
inputs.test
as the parameter file which contains the lines:
amr.plot_vars = chi # The default is to plot all state variables
amr.derive_plot_vars = Ham Mom # The default is none for derived variables.`
I also added calculate_constraint_norms = true
I think it would be nice if inputs.test
(or some other input file) could be modified to contained a working example with the derived variables outputted.
- A separate issue is if I do
amr.derive_plot_vars = ALL
then the code exits with a segmentation fault when writing the plot files. It happens in the Weyl4 calculation (I've saved the Backtrace.* files if you want to see?) I think it is because the default value forcalculate_constraint_norms
is false butALL
makes it calculate everything anyway and there are now too many components inderiv_lst
- if I setcalculate_constraint_norms = true
andamr.derive_plot_vars = ALL
then I get every derived variable exceptMom
.
I think this could be fixed by adding an if
statement to SimulationParameters.hpp
to check if ALL
is set then automatically set calculate_constraint_norms = true
as well. I'm not sure about the missing Mom
though...
For this parameter, you need to use the
This parameter currently doesn't do anything. Previously, in GRChombo it would calculate the L2 norm of the constraint variables and write them to a file (see here). We can now re-implement this but given how long it has taken to merge this PR, I suggest creating an issue (about AMR reductions) and deferring it to a later PR. I presume you thought this would change what is passed to the
I already added
I was able to reproduce this. I think the problem comes from saying that |
We can't load more variables than we claim to depend on.
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.
Thanks! I did a fresh pull from the repo and confirmed that my problems had been fixed.
I presume you thought this would change what is passed to the a_calc_mom_norm argument in Constraints::set_up()?
Yeah, this is exactly what I thought was going on! I agree implementing calculate_constraint_norms
should be a separate issue.
Thanks for updating inputs.test
also - I think some other parameter files might also have the "old" style of specifying constraint parameters but this should be a separate issue also.
This PR resolves #41 by moving the variable setup and
derive()
function into the specific level class (well justBinaryBHLevel
for now) rather thanGRAMRLevel
.It also does the following
GRAMRLevel::stateVariableSetUp()
. This needs to be called byPhysicsLevel::variableSetUp()
. We could instead not require this and callstateVariableSetUp()
directly inDefaultLevelFactory::variableSetUp()
?AMREX_USE_HDF5
since we now use HDF5.derive()
to calculate derived quantites on multifabs with ghost cells (which we will need for Port AMRInterpolator #2). Previously, for GRChombo we used to fill these ghost cells (using BCs as appropriate) but this would have been very complicated so now we just fill a source multifab with extra ghost cells.vars_parity
andvars_parity_diagnostic
parameters.PhysicsLevel::variableSetUp()
function. MultiFabs are instantiated asrequired to store them and the component numbers are not fixed.
UserVariables
toStateVariables
again for consistency with AMReX.Constraints.[impl.].hpp
and renamesNewConstraints.hpp
toConstraints.hpp
. The former was only kept in GRChombo for backwards compatibility reasons.I still need to make some changes to resolve some of the clang-tidy warnings but, given the size of this PR, I thought I would create it now so that you can start reviewing next week, @julianakwan.