Skip to content

Commit dbfa94a

Browse files
authored
Merge pull request #221 from solidsgroup/feature/timeintegrator
Migrate Hydro and HeatConduction to using amrex::TimeIntegrator
2 parents 6b8fc61 + 064c205 commit dbfa94a

File tree

9 files changed

+143
-304
lines changed

9 files changed

+143
-304
lines changed

src/IO/ParmParse.H

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,10 @@ public:
340340
// First value is accepted by default...
341341

342342
// set default value
343-
value = possibleintvals[0];
343+
if (!contains(name.c_str()))
344+
{
345+
add(name.c_str(), possibleintvals[0]);
346+
}
344347

345348
// get the read value (if it exists)
346349
int retval = query(name.c_str(),value);
@@ -380,14 +383,17 @@ public:
380383
// if not using default values, then the input must be specified
381384
if (!firstbydefault)
382385
{
383-
if (!contains(name.c_str()))
386+
if (!amrex::ParmParse::contains(name.c_str()))
384387
{
385388
Util::ParmParseException(INFO,full(name),"required value for ",full(name)," missing");
386389
}
387390
}
388391

389392
// set default value
390-
value = std::string(possiblecharvals[0]);
393+
if (!amrex::ParmParse::contains(name.c_str()))
394+
{
395+
add(name.c_str(), std::string(possiblecharvals[0]));
396+
}
391397

392398
// get the read value (if it exists)
393399
int retval = amrex::ParmParse::query(name.c_str(),value);

src/Integrator/HeatConduction.H

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <AMReX.H>
2323
#include <AMReX_ParallelDescriptor.H>
2424
#include <AMReX_ParmParse.H>
25+
#include <AMReX_TimeIntegrator.H>
2526
#ifdef ALAMO_FFT
2627
#include <AMReX_FFT.H>
2728
#endif
@@ -131,28 +132,47 @@ protected:
131132
// the new one.
132133
std::swap(*temp_mf[lev], *temp_old_mf[lev]);
133134

134-
// Get the cell size corresponding to this level
135-
const Set::Scalar* DX = geom[lev].CellSize();
136-
137-
// Iterate over all of the patches on this level
138-
for (amrex::MFIter mfi(*temp_mf[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
135+
// Create the time integrator object
136+
amrex::TimeIntegrator timeintegrator(*temp_old_mf[lev], time);
137+
138+
// Calculate the "RHS" of the function.
139+
// If using forward Euler, the RHS would be
140+
// T_new = T_old + dt * RHS
141+
timeintegrator.set_rhs([&](amrex::MultiFab & rhs_mf, amrex::MultiFab & temp_mf, const Set::Scalar /*time*/)
139142
{
140-
// Get the box (index dimensions) for this patch
141-
const amrex::Box &bx = mfi.tilebox();
142-
143-
// Get an array-accessible handle to the data on this patch.
144-
Set::Patch<const Set::Scalar> temp_old = temp_old_mf.Patch(lev,mfi);
145-
Set::Patch<Set::Scalar> temp = temp_mf.Patch(lev,mfi);
143+
// Get the cell size corresponding to this level
144+
const Set::Scalar* DX = geom[lev].CellSize();
146145

147-
// Iterate over the grid on this patch
148-
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
146+
// Iterate over all of the patches on this level
147+
for (amrex::MFIter mfi(temp_mf, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
149148
{
150-
// Do the physics!
151-
// Note that Numeric::Laplacian is an inlined function so there is no overhead.
152-
// You can calculate the derivatives yourself if you want.
153-
temp(i, j, k) = temp_old(i, j, k) + dt * alpha * Numeric::Laplacian(temp_old, i, j, k, 0, DX);
154-
});
155-
}
149+
// Get the box (index dimensions) for this patch
150+
const amrex::Box &bx = mfi.tilebox();
151+
152+
// Get an array-accessible handle to the data on this patch.
153+
Set::Patch<const Set::Scalar> temp = temp_mf.array(mfi);
154+
Set::Patch<Set::Scalar> rhs = rhs_mf.array(mfi);
155+
156+
// Iterate over the grid on this patch
157+
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
158+
{
159+
// Do the physics!
160+
// Note that Numeric::Laplacian is an inlined function so there is no overhead.
161+
// You can calculate the derivatives yourself if you want.
162+
rhs(i, j, k) = alpha * Numeric::Laplacian(temp, i, j, k, 0, DX);
163+
});
164+
}
165+
});
166+
167+
// We must update the boundaries here and apply boundary conditions
168+
timeintegrator.set_post_stage_action([&](amrex::MultiFab & stage_mf, Set::Scalar time)
169+
{
170+
bc->FillBoundary(stage_mf,0,1,time,0);
171+
stage_mf.FillBoundary(true);
172+
});
173+
174+
// Do the update
175+
timeintegrator.advance(*temp_old_mf[lev], *temp_mf[lev], time, dt);
156176
}
157177

158178

src/Integrator/Hydro.H

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ private:
138138

139139
Solver::Local::Riemann::Riemann *riemannsolver = nullptr;
140140

141-
enum IntegrationScheme {
142-
ForwardEuler, SSPRK3, RK4
143-
};
144-
IntegrationScheme scheme;
145-
146141
};
147142
}
148143

0 commit comments

Comments
 (0)