Skip to content
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

Black Holes: Port puncture tracking and enable tagging around the punctures #89

Draft
wants to merge 25 commits into
base: develop
Choose a base branch
from

Conversation

mirenradia
Copy link
Member

This long-awaited PR ports the puncture tracking capabilities from GRChombo to GRTeclyn. Here, we leverage AMReX's particle capabilities and the particles are moved around the grid as particles. This simplifies working out what box/grid they reside in as we can instead just make AMReX redistribute them.

The main things introduced/changed by this PR are described below

Parameters

The parameters have been renamed to

  • puncture_tracking.enabled = false (default) or true
  • puncture_tracking.level = 0 (default), ..., max_level

PunctureTracker class

This is now derived from amrex::ParticleContainer<AMREX_SPACEDIM, 0> and is templated over num_punctures (which will probably be 2). The member functions have been renamed from the ones in PunctureTracking in GRChombo.

For the actual tracking, we essentially copy what AMReX's TracerParticleContainer::AdvectWithUcc does except we advect in the reverse direction to the shift. This uses the midpoint method with linear interpolation (which means we only need to fill 1 ghost cell).

Note that we also store the coordinates in PunctureTracker::m_puncture_coords variable which is set and broadcast to all MPI processes in PunctureTracker::update_puncture_coords.

BHAMR changes

This is now also templated over num_punctures so it can store a puncture tracker with the correct number of punctures! Its constructor initialises the PunctureTracker if puncture_tracking.enabled == true.

New GRAMRLevel hooks

I have added some hooks for examples to do things post init, post restart, pre checkpoint and post checkpoint. I should make the formatting of these hooks more consistent...

PunctureTagger class

Rather than having a combined ChiPunctureExtractionTaggingCriterion class as before, we switch to using the existing ChiExtractionTagger class and then using a separate PunctureTracker class which just does the tagging around the punctures.

This resolves #15.

I'll open this as a draft for now as I still need to make a few minor changes and fix the linter errors but I think it should be close enough to finish for you to test, @KAClough.

mirenradia and others added 25 commits February 7, 2025 17:02
Also move initialization of particles to set_initial_punctures.
* pre checkpoint
* post checkpoint
* post init
* post restart

Also add some problem specific hooks too.
This example builds fine but there are still problems with some failed
assertions in the puncture tracking.

[skip ci]
We know we want to switch to tagging cells based on the puncture
locations but for now this is making debugging the punctures annoying.
MPI_AllGather doesn't like the send and receive buffers being the same
and we need to redistribute particles before writing to a checkpoint as
they might have moved to a different process.
This seems to work unlike invoking linear_interpolate_to_particle
directly.
CUDA doesn't allow device lambdas in class member functions that are
private.
This means we only have to do MPI collectives at the end of
execute_tracking rather than in redistribute to figure out which
process has the punctures.
This removes the need to convert between a 2-index object and a linear
object in the PunctureTracker.

Also remove the tracking of which process has each puncture. We don't
need this info as we set the puncture coords to 0 by default and then
sum reduce over all procs.
This is in an effort to make member functions single-purpose and remove
redundant variables.
These changes include
* Making PunctureTracker a template class with the template parameter
  being the number of punctures. This allows us to make
  m_puncture_coords a fixed size array.
* Moving the setting of initial_puncture_coords to
  start_from_initial_punctures() rather than initialize() as it's
  irrelevant in the restart case.
* Making PunctureTracker obtain the restart_time from it's GRAMR pointer
  rather than it being needed to be passed to track().
* Moving the updating of m_puncture_coords from the particle locations
  to a separate function which we now also call after restarting from
  the checkpoint file.
* Other minor changes
Also get the filename and output path from the ParmParse table directly
(in a more AMReX-like way) rather than requiring it to be passed in the
constructor to PunctureTracker.

Move the initialization of PunctureTracker to the BHAMR constructor.
Also make m_puncture_tracker a private member of BHAMR.
Following AMReX-Codes/amrex#4098 we no longer need to make an alias
MultiFab and use cic_interpolate.
This requires moving around some of the initialization of the
PunctureTracker class. Also, rather than having a combined
ChiPunctureExtractionTaggingCriterion class, we switch to using the
existing ChiExtractionTaggingCriterion class and then using a separate
PunctureTracker class.
@mirenradia mirenradia added the enhancement New feature or request label Feb 7, 2025
@mirenradia mirenradia self-assigned this Feb 7, 2025
Copy link

github-actions bot commented Feb 7, 2025

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

Source/BlackHoles/PunctureTracker.impl.hpp

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

Copy link

github-actions bot commented Feb 7, 2025

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v19.1.1) reports: 2 file(s) not formatted
  • Source/BlackHoles/PunctureTracker.impl.hpp
  • Source/Tagging/PunctureTagger.hpp
clang-tidy (v19.1.1) reports: 9 concern(s)
  • Examples/BinaryBH/BinaryBHLevel.cpp:225:29: warning: [bugprone-implicit-widening-of-multiplication-result]

    performing an implicit widening conversion to type 'std::size_t' (aka 'unsigned long') of a multiplication performed in type 'int'

      225 |     std::array<amrex::Real, AMREX_SPACEDIM * num_punctures> puncture_coords{};
          |                             ^
    note: expanded from macro 'AMREX_SPACEDIM'
    BinaryBHLevel.cpp:225:29: note: make conversion explicit to silence this warning
      225 |     std::array<amrex::Real, AMREX_SPACEDIM * num_punctures> puncture_coords{};
          |                             ^                             
          |                             static_cast<std::size_t>(     )
    note: expanded from macro 'AMREX_SPACEDIM'
    BinaryBHLevel.cpp:225:29: note: perform multiplication in a wider type
      225 |     std::array<amrex::Real, AMREX_SPACEDIM * num_punctures> puncture_coords{};
          |                             ^
          |                             static_cast<long>( )
    note: expanded from macro 'AMREX_SPACEDIM'
  • Source/BlackHoles/PunctureTracker.hpp:81:16: warning: [bugprone-misplaced-widening-cast]

    either cast from 'int' to 'size_t' (aka 'unsigned long') is ineffective, or there is loss of precision before the conversion

       81 |         return static_cast<size_t>(ipuncture * AMREX_SPACEDIM + idir);
          |                ^
  • Source/BlackHoles/PunctureTracker.hpp:84:3: warning: [readability-redundant-access-specifiers]

    redundant access specifier has the same accessibility as the previous access specifier

       84 |   private:
          |   ^~~~~~~~
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/BlackHoles/PunctureTracker.hpp:67:3: note: previously declared here
       67 |   private: // CUDA doesn't allow lambdas in private functions
          |   ^
  • Source/Tagging/PunctureTagger.hpp:25:29: warning: [bugprone-implicit-widening-of-multiplication-result]

    performing an implicit widening conversion to type 'std::size_t' (aka 'unsigned long') of a multiplication performed in type 'unsigned int'

       25 |     std::array<amrex::Real, AMREX_SPACEDIM * num_punctures> m_puncture_coords;
          |                             ^
    note: expanded from macro 'AMREX_SPACEDIM'
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:25:29: note: make conversion explicit to silence this warning
       25 |     std::array<amrex::Real, AMREX_SPACEDIM * num_punctures> m_puncture_coords;
          |                             ^                             
          |                             static_cast<std::size_t>(     )
    note: expanded from macro 'AMREX_SPACEDIM'
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:25:29: note: perform multiplication in a wider type
       25 |     std::array<amrex::Real, AMREX_SPACEDIM * num_punctures> m_puncture_coords;
          |                             ^
          |                             static_cast<std::size_t>( )
    note: expanded from macro 'AMREX_SPACEDIM'
  • Source/Tagging/PunctureTagger.hpp:31:9: warning: [bugprone-easily-swappable-parameters]

    3 adjacent parameters of 'PunctureTagger<num_punctures>' of convertible types are easily swapped by mistake

       31 |         const amrex::Real a_dx, const int a_level, const int a_max_level,
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:31:27: note: the first parameter in the range is 'a_dx'
       31 |         const amrex::Real a_dx, const int a_level, const int a_max_level,
          |                           ^~~~
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:31:62: note: the last parameter in the range is 'a_max_level'
       31 |         const amrex::Real a_dx, const int a_level, const int a_max_level,
          |                                                              ^~~~~~~~~~~
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:31:9: note: 
       31 |         const amrex::Real a_dx, const int a_level, const int a_max_level,
          |         ^
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:31:33: note: 'const amrex::Real' and 'const int' may be implicitly converted: 'const amrex::Real' (as 'double') -> 'const int' (as 'int'), 'const int' (as 'int') -> 'const amrex::Real' (as 'double')
       31 |         const amrex::Real a_dx, const int a_level, const int a_max_level,
          |                                 ^
  • Source/Tagging/PunctureTagger.hpp:32:39: warning: [bugprone-implicit-widening-of-multiplication-result]

    performing an implicit widening conversion to type 'std::size_t' (aka 'unsigned long') of a multiplication performed in type 'unsigned int'

       32 |         const std::array<amrex::Real, AMREX_SPACEDIM * num_punctures>
          |                                       ^
    note: expanded from macro 'AMREX_SPACEDIM'
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:32:39: note: make conversion explicit to silence this warning
       32 |         const std::array<amrex::Real, AMREX_SPACEDIM * num_punctures>
          |                                       ^                             
          |                                       static_cast<std::size_t>(     )
    note: expanded from macro 'AMREX_SPACEDIM'
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:32:39: note: perform multiplication in a wider type
       32 |         const std::array<amrex::Real, AMREX_SPACEDIM * num_punctures>
          |                                       ^
          |                                       static_cast<std::size_t>( )
    note: expanded from macro 'AMREX_SPACEDIM'
  • Source/Tagging/PunctureTagger.hpp:40:30: warning: [bugprone-easily-swappable-parameters]

    2 adjacent parameters of 'operator()' of similar type are easily swapped by mistake

       40 |     operator()(int i, int j, int k,
          |                              ^~~~~~
       41 |                const amrex::Array4<amrex::TagBox::TagType> &tags) const
          |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:40:34: note: the first parameter in the range is 'k'
       40 |     operator()(int i, int j, int k,
          |                                  ^
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:41:61: note: the last parameter in the range is 'tags'
       41 |                const amrex::Array4<amrex::TagBox::TagType> &tags) const
          |                                                             ^~~~
    /home/runner/work/GRTeclyn/GRTeclyn/GRTeclyn/Source/Tagging/PunctureTagger.hpp:41:16: note: 'int' and 'const int &' parameters accept and bind the same kind of values
       41 |                const amrex::Array4<amrex::TagBox::TagType> &tags) const
          |                ^
  • Source/Tagging/PunctureTagger.hpp:41:43: error: [clang-diagnostic-error]

    no member named 'TagBox' in namespace 'amrex'

       41 |                const amrex::Array4<amrex::TagBox::TagType> &tags) const
          |                                    ~~~~~~~^
  • Source/Tagging/PunctureTagger.hpp:72:45: error: [clang-diagnostic-error]

    no member named 'TagBox' in namespace 'amrex'

       72 |                 tags(current_cell) = amrex::TagBox::SET;
          |                                      ~~~~~~~^

Have any feedback or feature suggestions? Share it here.

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 puncture tracker
2 participants