Skip to content

Commit 91b775a

Browse files
committed
First draft unifying WeylExtraction and particles
The following logic is enforced in this commit: - Particle interpolator is stored in BHAMR (as well as particles are populated once) - Particle interpolator is also now templated over the number of components - We ask for Redistribute() of particles after regrid - GRAMR contains a very short function to post-process the MultiFabs of derived variables into the correct format for interpolation - GRAMR contains some virtual function to be overriden by BHAMR in order to set up query and populate the particles only once - Handling for parity of derived vars is implemented. Parity handling for both state and derived is to be tested! - Weyl4 is computed in the post-processing step for now; to be addressed later but is needed for WeylExtraction testing
1 parent 6a451db commit 91b775a

19 files changed

+1485
-52
lines changed

Examples/BinaryBH/BinaryBHLevel.cpp

Lines changed: 101 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#include "PunctureTagger.hpp"
1313
#include "PunctureTracker.hpp"
1414
// xxxxx #include "SixthOrderDerivatives.hpp"
15-
#include "CustomExtraction.hpp"
15+
// #include "CustomExtraction.hpp"
1616
#include "TraceARemoval.hpp"
1717
#include "TwoPuncturesInitialData.hpp"
1818
#include "Weyl4.hpp"
19-
// #include "WeylExtraction.hpp"
19+
#include "WeylExtractionParticle.hpp"
2020

2121
BHAMR<BinaryBHLevel::num_punctures> *BinaryBHLevel::get_bhamr_ptr()
2222
{
@@ -252,6 +252,25 @@ void BinaryBHLevel::tag_cells(amrex::TagBoxArray &a_tag_box_array,
252252
amrex::Gpu::streamSynchronize();
253253
}
254254

255+
// This is called by amrex on every level after regridding. After regrid we
256+
// should redistribute the particles again if BoxArrays or DistributionMappings
257+
// have changed, for example?
258+
void BinaryBHLevel::specific_post_regrid(int a_lbase, int a_new_finest)
259+
{
260+
amrex::Print() << "BinaryBHLevel::specific_post_regrid() on level "
261+
<< Level() << "\n";
262+
if (get_gramr_ptr()->cumTime() > 0.0)
263+
{
264+
if (auto *bh = get_bhamr_ptr())
265+
{
266+
if (bh->m_weyl_interpolator)
267+
{
268+
bh->m_weyl_interpolator->force_redistribute(true);
269+
}
270+
}
271+
}
272+
}
273+
255274
void BinaryBHLevel::specific_post_init()
256275
{
257276
BL_PROFILE("BinaryBHLevel::specific_post_init()");
@@ -295,32 +314,91 @@ void BinaryBHLevel::specific_post_checkpoint(const std::string &a_chk_dir,
295314

296315
void BinaryBHLevel::specificPostTimeStep()
297316
{
298-
299-
// Custon extraction
317+
// std::cout << "BinaryBHLevel::specificPostTimeStep() on level " << Level()
318+
// << std::endl;
300319
bool first_step = (parent->levelSteps(0) == 0);
301320

302-
if (Level() == 1)
321+
if (Level() == 0)
303322
{
304-
// set the interpolator
305-
ParticleInterpolators<1> interpolator(simParams().boundary_params,
306-
c_chi);
307-
interpolator.set_gramr_ptr(get_gramr_ptr());
308-
309-
// set up the query and execute it
310-
std::array<double, AMREX_SPACEDIM> extraction_origin = {
311-
0.0, simParams().L / 2, -4.0};
312-
313-
double m_time = get_state_data(State_Type).curTime();
314-
double m_dt = get_gramr_ptr()->dtLevel(Level());
315-
double restart_time = get_gramr_ptr()->get_restart_time();
316-
317-
// a random chi lineout
318-
CustomExtraction chi_extraction(c_chi, 1, 15, simParams().L / 2.,
319-
extraction_origin, m_dt, m_time,
320-
restart_time, first_step);
321-
chi_extraction.execute_query(interpolator, "chi_lineout");
323+
// Weyl extraction
324+
const int finest = get_gramr_ptr()->finestLevel();
325+
amrex::Vector<std::unique_ptr<amrex::MultiFab>> out_weyl(finest + 1);
326+
327+
// get all the derived info on Weyl
328+
auto &lst = amrex::AmrLevel::get_derive_lst();
329+
const auto *rec = lst.get("Weyl4");
330+
int state_index = -1, scomp = -1, ncomp_in = -1;
331+
rec->getRange(
332+
0, state_index, scomp,
333+
ncomp_in); // here scomp indicated the starting comp in the state
334+
// (needed to calculate the derived var); similarly
335+
// ncomp_in is the overall number of state comps needed.
336+
// Currently Weyl4 fills all CCZ4 vars, which may be
337+
// problematic.
338+
339+
// std::cout << "Number of components in Weyl query " << ncomp_in <<
340+
// std::endl; std::cout << "Starting component " << scomp << std::endl;
341+
// std::cout << "Number of components in Weyl derive " <<
342+
// rec->numDerive() << std::endl;
343+
344+
const int ngrow = 2;
345+
const int nout = rec->numDerive();
346+
347+
for (int lev = 0; lev <= finest; ++lev)
348+
{
349+
auto &L = get_gramr_ptr()->getLevel(lev);
350+
const auto &geom = L.Geom();
351+
const auto &state = L.get_new_data(state_index);
352+
353+
out_weyl[lev] = std::make_unique<amrex::MultiFab>(
354+
state.boxArray(), state.DistributionMap(), nout, ngrow);
355+
356+
// fill ghosts
357+
amrex::MultiFab src(state.boxArray(), state.DistributionMap(),
358+
ncomp_in, ngrow);
359+
amrex::Copy(src, state, /*scomp=*/scomp, /*dcomp=*/0,
360+
/*ncomp=*/ncomp_in, /*nghost=*/ngrow);
361+
src.FillBoundary(geom.periodicity());
362+
363+
Weyl4::compute_mf(*out_weyl[lev], /*dcomp=*/0, /*ncomp=*/nout, src,
364+
geom, /*time=*/0.0, /*bcrec=*/nullptr,
365+
/*level=*/lev);
366+
}
367+
368+
amrex::Vector<const amrex::MultiFab *> fields;
369+
get_gramr_ptr()->convert_derived_multifabs(out_weyl, fields);
370+
371+
// Perform extraction
372+
double m_time = get_state_data(State_Type).curTime();
373+
double m_dt = get_gramr_ptr()->dtLevel(Level());
374+
double m_restart_time = get_gramr_ptr()->get_restart_time();
375+
376+
WeylExtractionParticle my_extraction(simParams().extraction_params,
377+
m_dt, m_time, first_step,
378+
m_restart_time);
379+
my_extraction.execute_query(get_bhamr_ptr()->m_weyl_interpolator,
380+
fields);
322381
}
323382

383+
// Custom extraction
384+
// if (Level() == 1)
385+
// {
386+
// // set up the query and execute it
387+
// std::array<double, AMREX_SPACEDIM> extraction_origin = {
388+
// 0.0, simParams().L / 2, -4.0};
389+
390+
// double m_time = get_state_data(State_Type).curTime();
391+
// double m_dt = get_gramr_ptr()->dtLevel(Level());
392+
// double restart_time = get_gramr_ptr()->get_restart_time();
393+
394+
// // a random chi lineout
395+
// CustomExtraction chi_extraction(c_chi, 1, 15, simParams().L / 2.,
396+
// extraction_origin, m_dt, m_time,
397+
// restart_time, first_step);
398+
// chi_extraction.execute_query(*get_bhamr_ptr()->m_weyl_interpolator,
399+
// "chi_lineout");
400+
// }
401+
324402
// do puncture tracking on requested level
325403
if (simParams().puncture_tracking_enabled &&
326404
Level() == simParams().puncture_tracking_level)

Examples/BinaryBH/BinaryBHLevel.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class BinaryBHLevel : public GRAMRLevel
5050
void tag_cells(amrex::TagBoxArray &a_tag_box_array,
5151
amrex::Real a_regrid_threshold) final;
5252

53+
/// Things to do after regrid
54+
void specific_post_regrid(int a_lbase, int a_new_finest) override;
55+
5356
//! Things to do after a restart
5457
void specific_post_restart() override;
5558

Examples/BinaryBH/Main_BinaryBH.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// Problem specific includes:
1616
#include "BinaryBHLevel.hpp"
1717

18+
#include "ParticleInterpolators.hpp"
19+
1820
// System includes
1921
#include <chrono>
2022
#include <iostream>
@@ -35,7 +37,6 @@ int runGRTeclyn(int /*argc*/, char * /*argv*/[])
3537
}
3638

3739
GRAMR::set_simulation_parameters(sim_params);
38-
3940
DefaultLevelFactory<BinaryBHLevel> bh_level_bld;
4041

4142
#ifdef USE_TWOPUNCTURES
@@ -49,6 +50,12 @@ int runGRTeclyn(int /*argc*/, char * /*argv*/[])
4950

5051
bh_amr.init(0., sim_params.stop_time);
5152

53+
// Hand the interpolation pointer to BHAMR
54+
ParticleInterpolators<2> weyl_interpolator(
55+
sim_params.boundary_params,
56+
0); // the derived component usually starts from 0
57+
bh_amr.set_interpolator(&weyl_interpolator);
58+
5259
while (
5360
(bh_amr.okToContinue() != 0) &&
5461
(bh_amr.levelSteps(0) < sim_params.max_steps ||

Examples/BinaryBH/params_new.txt

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# GRAMReX BinaryBH parameter file for GitHub Action regression test
2+
3+
#################################################
4+
# Filesystem parameters
5+
6+
verbosity = 1
7+
8+
output_path = .
9+
# amr.check_file = chk
10+
# amr.plot_file = plt
11+
# amr.restart = chk00000
12+
# amr.file_name_digits = 5
13+
14+
amr.check_int = 0
15+
checkpoint_interval = 0
16+
amr.plot_int = 8
17+
plot_interval = 8
18+
amr.derive_plot_vars = ALL
19+
20+
#################################################
21+
# BH Initial Data parameters
22+
23+
massA = 0.5
24+
massB = 0.5
25+
26+
offsetA = -10 0 0
27+
offsetB = 10 0 0
28+
29+
momentumA = 0.0 -0.1 0.0
30+
momentumB = 0.0 0.1 0.0
31+
32+
#################################################
33+
# Grid parameters
34+
35+
N_full = 128
36+
L_full = 64
37+
38+
max_level = 1 # There are (max_level+1) levels
39+
40+
regrid_interval = -1 -1 # no point regridding with no AMR
41+
42+
max_grid_size = 16
43+
block_factor = 16
44+
45+
# tag_buffer_size = 3
46+
# num_ghosts = 3
47+
# center = 8 8 8 # defaults to center of the grid
48+
49+
#################################################
50+
# Boundary Conditions parameters
51+
52+
# Periodic directions - 0 = false, 1 = true
53+
isPeriodic = 0 0 0
54+
# if not periodic, then specify the boundary type
55+
# 0 = static, 1 = sommerfeld, 2 = reflective
56+
# (see BoundaryConditions.hpp for details)
57+
hi_boundary = 1 1 1
58+
lo_boundary = 1 1 1
59+
60+
# if sommerfeld boundaries selected, must select
61+
# non zero asymptotic values
62+
nonzero_asymptotic_vars = chi h11 h22 h33 lapse
63+
nonzero_asymptotic_values = 1.0 1.0 1.0 1.0 1.0
64+
65+
# if you are using extrapolating BC:
66+
# extrapolation_order = 1
67+
68+
# extrapolating_vars =
69+
70+
#################################################
71+
# Evolution parameters
72+
73+
# dt will be dx*dt_multiplier on each grid level
74+
dt_multiplier = 0.25
75+
# stop_time = 1.0
76+
max_steps = 3
77+
78+
# max_spatial_derivative_order = 4 # only 4 implemented at the moment
79+
80+
# nan_check = true
81+
82+
# Lapse evolution
83+
lapse_advec_coeff = 1.0
84+
lapse_coeff = 2.0
85+
lapse_power = 1.0
86+
87+
# Shift evolution
88+
shift_advec_coeff = 1.0
89+
shift_Gamma_coeff = 0.75
90+
eta = 1.0
91+
92+
# CCZ4 parameters
93+
formulation = 0 # 1 for BSSN, 0 for CCZ4
94+
kappa1 = 0.1
95+
kappa2 = 0.
96+
kappa3 = 1.
97+
covariantZ4 = 1 # 0: keep kappa1; 1 [default]: replace kappa1 -> kappa1/lapse
98+
99+
# coefficient for KO numerical dissipation
100+
sigma = 0.5
101+
102+
# min_chi = 1.e-4
103+
# min_lapse = 1.e-4
104+
105+
#################################################
106+
# Extraction parameters
107+
108+
# extraction_center = 4 4 0 # defaults to center
109+
activate_extraction = true
110+
num_extraction_radii = 1
111+
extraction_radii = 30.0
112+
extraction_levels = 0
113+
num_points_phi = 24
114+
num_points_theta = 37
115+
num_modes = 3
116+
modes = 2 0 2 1 2 2
117+
118+
#################################################
119+
# Puncture Tracking parameters
120+
121+
puncture_tracking.enabled = 1
122+
puncture_tracking.level = 0

Source/BlackHoles/BHAMR.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#define BHAMR_HPP_
88

99
#include "GRAMR.hpp"
10+
#include "InterpolationQueryParticle.hpp"
11+
#include "ParticleInterpolators.hpp"
1012
#include "PunctureTracker.hpp"
1113

1214
#include <AMReX_ParmParse.H>
@@ -21,8 +23,18 @@ template <int num_punctures> class BHAMR : public GRAMR
2123
{
2224
private:
2325
PunctureTracker<num_punctures> m_puncture_tracker;
26+
InterpolationQueryParticle *m_query =
27+
nullptr; // query used for interpolation
28+
bool m_query_populated =
29+
false; // flag to identify whether the query has been populated: for
30+
// particles that will be fixed we want to do this only once
31+
// here!
2432

2533
public:
34+
35+
ParticleInterpolators<2> *m_weyl_interpolator =
36+
nullptr; // weyl interpolator
37+
2638
BHAMR(amrex::LevelBld *a_levelbld) : GRAMR(a_levelbld)
2739
{
2840
amrex::ParmParse puncture_tracking_pp("puncture_tracking");
@@ -39,6 +51,42 @@ template <int num_punctures> class BHAMR : public GRAMR
3951
{
4052
return m_puncture_tracker;
4153
}
54+
55+
// set weyl interpolator
56+
void set_interpolator(ParticleInterpolators<2> *a_interpolator)
57+
{
58+
AMREX_ASSERT(a_interpolator != nullptr);
59+
60+
m_weyl_interpolator = a_interpolator;
61+
m_weyl_interpolator->set_gramr_ptr(this);
62+
}
63+
64+
// set query
65+
void set_query(InterpolationQueryParticle &q) override
66+
{
67+
if (m_query != &q)
68+
{ // only if the query object changed
69+
m_query = &q;
70+
m_query_populated = false;
71+
}
72+
}
73+
74+
// populate only once
75+
void ensure_query_populated() override
76+
{
77+
AMREX_ASSERT(m_query);
78+
if (!m_query_populated)
79+
{
80+
m_weyl_interpolator->populate_from_query(*m_query);
81+
m_query_populated = true;
82+
}
83+
}
84+
85+
// access to a cached query
86+
InterpolationQueryParticle *query() override
87+
{
88+
return m_query ? &*m_query : nullptr;
89+
}
4290
};
4391

4492
#endif /* BHAMR_HPP_ */

0 commit comments

Comments
 (0)