Skip to content

Matter: Port Matter classes (with unit tests) #94

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

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from

Conversation

julianakwan
Copy link
Contributor

This PR completes my port of the Matter classes and closes #10 . It includes:

  • Porting MatterCCZ4
  • Porting the ScalarField and DefaultPotential classes
  • Porting the calculation of Weyl4_Re and Weyl4_Im for a Matter class
  • Porting the calculation of the energy density, the momentum density and the spatial stress energy density for Matter classes
  • Porting the calculation of the relaxation of chi (I didn't know it was going to be depreciated!)
  • Unit tests for the above
  • Renaming NewMatterConstraints to just MatterConstraints.
  • The removal of the Matter directory from the list of ignored files in .lint_ignore

@julianakwan julianakwan added the enhancement New feature or request label Mar 1, 2025
@julianakwan julianakwan self-assigned this Mar 1, 2025
Copy link

github-actions bot commented Mar 1, 2025

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/ChiRelaxation.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/MatterCCZ4RHS.impl.hpp
Source/Matter/MatterConstraints.impl.hpp
Source/Matter/MatterWeyl4.impl.hpp
Source/Matter/ScalarField.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@julianakwan julianakwan changed the title Enhancement/matter class fix Matter: Port Matter classes (with unit tests) Mar 3, 2025
Copy link

github-actions bot commented Mar 4, 2025

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/ChiRelaxation.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/MatterCCZ4RHS.impl.hpp
Source/Matter/MatterConstraints.impl.hpp
Source/Matter/MatterWeyl4.impl.hpp
Source/Matter/ScalarField.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

Copy link
Member

@mirenradia mirenradia left a comment

Choose a reason for hiding this comment

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

Thanks for this PR Juliana.

It looks pretty good but I have some comments. I know there are a fair few of them but I think most of them should be easy to resolve and the more complicated ones I will try and look at myself.

For the GRChombo HDF5 files you have generated for the tests, where is the code you used to create them? I couldn't find a relevant branch in the GRChombo repo.

I don't think the Tests/MatterWeyl4Test/GRChomboEMTensorTest.h5 file is needed/used so could you remove it as well?

Would you also be able to fix the commit history by applying the fixups?

/// 3 components for the momentum density: m_11, m_22, m_33
/// 6 components for the stress energy tensor (symmetric): s_11, s_12 etc.
static inline const amrex::Vector<std::string> extra_var_names = {
"m_11, m_22, m_33, s_11, s_12, s_13, s_22, s_23, s_33"};
Copy link
Member

Choose a reason for hiding this comment

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

Yes. We have always used Si and Sij but here that naming might be confusing. We could use J instead, so then it would be J1,J2,J3, S11, S12 etc. Maybe let's leave this for the naming tidy up as it would be best to be consistent throughout the code.

Copy link
Member

Choose a reason for hiding this comment

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

This would be good. I always found the passing of intervals in the constructor a bit ugly and confusing.

class [[deprecated("Use new MatterConstraints class in "
"NewMatterConstraints.hpp")]] MatterConstraints
: public Constraints
template <class matter_t> class MatterConstraints : public Constraints
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it is nicer for this to be called ConstraintsWithMatter, and similarly CCZ4RHSWithMatter, Weyl4WithMatter etc but we can do this in the tidy up if it is controversial. The advantage is that the files don't then all start with Matter, which is a bit annoying for tab complete. I also find it more readable.

Copy link
Member

Choose a reason for hiding this comment

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

I would be fine with this change so long as it is done consistently. We might as well do it now given this whole PR is about matter.

@julianakwan julianakwan force-pushed the enhancement/matter_class_fix branch from 5e527e5 to 2b7a3ce Compare March 19, 2025 22:19
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ChiRelaxation.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@julianakwan julianakwan force-pushed the enhancement/matter_class_fix branch 2 times, most recently from 1c36aac to a44ef5d Compare April 9, 2025 13:51
Copy link

github-actions bot commented Apr 9, 2025

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ChiRelaxation.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

1 similar comment
Copy link

github-actions bot commented Apr 9, 2025

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ChiRelaxation.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@julianakwan julianakwan force-pushed the enhancement/matter_class_fix branch from 50c4e2b to dcf4ae8 Compare April 9, 2025 15:13
Copy link

github-actions bot commented Apr 9, 2025

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ChiRelaxation.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

Copy link

github-actions bot commented Apr 9, 2025

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@julianakwan
Copy link
Contributor Author

julianakwan commented Apr 9, 2025

Hi all - I think I have addressed everyone's comments now (and the lint checks have finally passed). Could you please review this PR again and double check that you are happy with everything?

Main changes are:

  • ChiRelaxation has been moved to a new branch enhancement/chi_relaxation
  • Names starting with Matter have been moved to ...WithMatter e.g. MatterCCZ4RHS is now CCZ4RHSWithMatter
  • Constructor classes involving the Matter object no longer require the Matter object to be passed as an argument because the object is now default constructed from the templated type.
  • Tests/Common/InitialData.hpp now has a function to initialize test scalar field and conjugate momentum values
  • I have applied the bugfix from GRChombo to the MovingPunctureGauge. Because it is a matter thing only, it is stored in it's own matter file MovingPunctureGaugeWithMatter.hpp

Copy link
Member

@mirenradia mirenradia left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes, Juliana. Just a couple more minor changes.

Comment on lines 37 to 39
static inline const amrex::Vector<std::string> extra_var_names = {
"Sij_11, Sij_22, Sij_33, Sij_11, Sij_12, Sij_13, Sij_22, Sij_23, "
"Sij_33"};
Copy link
Member

Choose a reason for hiding this comment

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

I think we've agreed on the following names.

Suggested change
static inline const amrex::Vector<std::string> extra_var_names = {
"Sij_11, Sij_22, Sij_33, Sij_11, Sij_12, Sij_13, Sij_22, Sij_23, "
"Sij_33"};
static inline const amrex::Vector<std::string> extra_var_names = {
"j_1, j_2, j_3, S_11, S_12, S_13, S_22, S_23, S_33"};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on this comment:

We should make sure our var names are consistent with the emtensor_t struct.

I thought we had decided to make them consistent with the existing names without matter? If you prefer the j's, I can open a pull request to change them both?

Copy link
Member

Choose a reason for hiding this comment

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

Let's just change it to my suggestion in the emtensor_t struct in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Could you change the emtensor_t struct in CCZ4Geometry.hpp to

template <class data_t> struct emtensor_t
{
    Tensor<2, data_t> S;  //!< S_ij = T_ij
    Tensor<1, data_t> j;  //!< j_i = T_ia_n^a
    data_t trS;           //!< trS = S^i_i
    data_t rho;           //!< rho = T_ab n^a n^b
};

and modify where this struct appears accordingly?

Copy link
Contributor Author

@julianakwan julianakwan Apr 16, 2025

Choose a reason for hiding this comment

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

I opened a new PR for this (#117) because CCZ4Geometry.hpp wasn't part of this original PR. I will change in this PR once that has been accepted and merged.

@julianakwan julianakwan force-pushed the enhancement/matter_class_fix branch from da3ee70 to 47a3a61 Compare April 15, 2025 11:53
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@julianakwan julianakwan force-pushed the enhancement/matter_class_fix branch from 47a3a61 to 20562ea Compare April 15, 2025 12:14
@julianakwan julianakwan requested a review from mirenradia April 15, 2025 12:36
@julianakwan
Copy link
Contributor Author

Hi @mirenradia - I believe I have addressed all your comments now. Can you please take another look at this PR? Thanks!

This will also modify the current implementation of Weyl4::set_up and
Weyl4::calculate_mf to be inline (so header can be included with
MatterWeyl4 without multiple definitions). It also changes the
private members of Weyl4 to be protected, so that MatterWeyl4 can
access the derivatives and epsilon3_U_LL and EB fields calculated by
Weyl4.
This test will check the calculation of Ham and Mom against a previously
calculated set in GRChombo. It will also change the private class members
of Constraints to protected and inline the Constraints::set_up and
Constraints::calculate_mf so they can be inherited by the matter versions.
Previously, the HDF5 files were written in serial so the CI runs
with MPI would fail. Also added MatterWeyl4::set_up and
MatterWeyl4::compute_mf functions.
- Calculate MatterWeyl4 and EMTensor by adding these to derive_lst
using new MultiFab version of looping over the calculate function
- Add set_up function to MatterWeyl4 to set up derive_lst
- Add default constructor to ScalarField class
There were some leftover GRChombo characteristics in the calls to
Cell in the compute function so I've cleaned these up in this commit.
I also fixed a bug where I had mixed up the rhs as Vars and the
rhs as an Array4.
This commit adds:
  - a set_up function to add the energy density, momemtum density
    and spatial stress-energy tensor as components of derive_lst
  - compute_mf a wrapper to the compute function which is called
    by AMReX whenever a derived variable needs to be calculated.
This commit will:
  - introduce a set_up function that adds "Weyl4_Re" and "Weyl4_Im"
    to the derive_lst for matter classes.
  - wrap the compute function inside compute_mf which is called by
    AMReX whenever the derived variable are needed.
This commit will:
  - introduce a set_up function for adding "Ham", "Mom1", "Mom2",
    and "Mom3" (or alternatively "Ham" and "Mom" normalized) to
    the derive_lst
  - introduce a compute_mf wrapper that will calculate the above
    whenever required by AMReX.
This commit will:
  - Call compute_mf to calculate derived varables
  - Refactor the HDF5 output to be consistent with the other unit
    tests (and update the relevent HDF5 files).
This commit will:
  - Pull out the test for rho from the MatterWeyl4 unit test into
    its own test case
  - Test the outputted values of rho calculated by EMTensor
    against values calculated by GRChombo
  - Test the outputted values of chi calculated by ChiRelaxation
    against values calculated by GRChombo
  - Add the GRChombo .h5 files for comparison
  - Add these two new test cases to the list in TestCases.hpp
This commit will:
  - Add an #if statement around HDF5 parts so they are not
    compiled if USE_HDF5=FALSE
  - Also, fix Lint errors
This commit will:
  - fix the bug in GRChombo with the gauge calculation in
    MatterCCZ4
This commit will:
  - Add the definition of phi and Pi to the common header file
  - Refactor the tests to use these definitions. I noticed that
    the BSSN Matter test and the chi relaxation test were using
    different initial conditions from the other so I had to
    update the HDF5 file outputs as well.
This commit will also:
  - Rename G_newton to G_Newton in the BSSN Matter test
This commit will:
  - Switch ordering of naming convention, so MatterCCZ4RHS becomes
    CCZ4RHSWithMatter, MatterConstraints becomes
    ConstraintsWithMatter, MatterWeyl4 becomes Weyl4WithMatter

Matter: Remove matter object from constructor

I forgot to remove the matter object in the constructor for
CCZ4RHSWithMatter!
There is now a separate branch for the ChiRelaxation class
This will update the naming convention of emtensor_t:
  - The trace of the spatial stress energy tensor is now trS
  - The spatial stress energy tensor itself is now S
  - The momentum vector is now j
@julianakwan julianakwan force-pushed the enhancement/matter_class_fix branch from 20562ea to 8c30fcb Compare April 17, 2025 12:44
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

Copy link
Member

@KAClough KAClough left a comment

Choose a reason for hiding this comment

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

I am happy with this PR, I made two minor suggestions for you to consider @julianakwan but I don't feel strongly about them, so whatever you think! Let's get this merged and do the tidy up!

/// This class adds the matter terms to the RHS of the gauge equation
/// for the moving puncture gauge

class MovingPunctureGaugeWithMatter : public MovingPunctureGauge
Copy link
Member

Choose a reason for hiding this comment

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

In the original code, we just added this function into the MovingPunctureGauge class, and didn't inherit to a matter version... I can see it is a bit inconsistent with the structure of the CCZ4/CCZ4Matter classes, but it means fewer files and I don't think it should cause issues, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this because I thought it was tidier to have everything to do with matter in the Source/Matter directory. It doesn't cause any issues otherwise, it was just an issue of consistency so non-matter people can freely ignore the matter stuff if they choose to :)

@@ -107,7 +109,8 @@ template <class potential_t>
template <class data_t, template <typename> class vars_t,
template <typename> class diff2_vars_t,
template <typename> class rhs_vars_t>
void ScalarField<potential_t>::matter_rhs_excl_potential(
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void
ScalarField<potential_t>::matter_rhs_excl_potential(
Copy link
Member

Choose a reason for hiding this comment

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

I know that I did this - separating out the rhs and emtensor with and without potential - but now I can't remember why! I think it was to enable doing complex fields, but now we do that without any inheritance from the real fields, which is tidier. This just adds another long function definition that doesn't do much in the body of the function and that makes the code messier. Maybe we should just combine them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port Matter classes
3 participants