Skip to content

Commit d897279

Browse files
committed
error WIP, needs periodic wrap
1 parent fa80775 commit d897279

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

ExampleCodes/SUNDIALS/AdvDiff-HyprePrecon/Source/main.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void main_main ()
149149
// **********************************
150150
// INITIALIZE DATA
151151

152-
InitializeData(phi,dx,prob_lo);
152+
InitializeData(phi,dx,prob_lo,prob_hi,time,advCoeffx,advCoeffy);
153153

154154
// Write a plotfile of the initial data if plot_int > 0
155155
if (plot_int > 0)
@@ -230,11 +230,32 @@ void main_main ()
230230
Real evolution_stop_time = ParallelDescriptor::second() - evolution_start_time;
231231
ParallelDescriptor::ReduceRealMax(evolution_stop_time);
232232
amrex::Print() << "Total evolution time = " << evolution_stop_time << " seconds\n";
233+
234+
// exact solution
235+
MultiFab phi_exact(ba, dm, Ncomp, 0);
236+
InitializeData(phi_exact,dx,prob_lo,prob_hi,time,advCoeffx,advCoeffy);
237+
const std::string& pltfile = amrex::Concatenate("exact",nsteps,5);
238+
WriteSingleLevelPlotfile(pltfile, phi_exact, {"phi"}, geom, time, nsteps);
239+
240+
241+
MultiFab::Subtract(phi_exact,phi,0,0,1,0);
242+
Real error = phi_exact.norm1(0,geom.periodicity());
243+
244+
amrex::Print() << "L1 error = " << error << std::endl;
233245
}
234246

235247
void InitializeData(MultiFab& phi,
236248
const GpuArray<Real,AMREX_SPACEDIM> dx,
237-
const GpuArray<Real,AMREX_SPACEDIM> prob_lo) {
249+
const GpuArray<Real,AMREX_SPACEDIM> prob_lo,
250+
const GpuArray<Real,AMREX_SPACEDIM> prob_hi,
251+
const Real& time,
252+
const Real& Ax,
253+
const Real& Ay) {
254+
255+
GpuArray<Real,AMREX_SPACEDIM> L;
256+
for (int d=0; d<AMREX_SPACEDIM; ++d) {
257+
L[d] = prob_hi[d] - prob_lo[d];
258+
}
238259

239260
// loop over boxes
240261
for (MFIter mfi(phi); mfi.isValid(); ++mfi)
@@ -245,15 +266,16 @@ void InitializeData(MultiFab& phi,
245266
Real sigma = 0.1;
246267
Real a = 1.0/(sigma*sqrt(2*M_PI));
247268
Real b = -0.5/(sigma*sigma);
248-
269+
249270
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
250271
{
251-
Real y = prob_lo[1] + (((Real) j) + 0.5) * dx[1];
252272
Real x = prob_lo[0] + (((Real) i) + 0.5) * dx[0];
253-
Real r = x * x + y * y;
273+
Real y = prob_lo[1] + (((Real) j) + 0.5) * dx[1];
274+
Real r = (x-Ax*time) * (x-Ax*time) + (y-Ay*time) * (y-Ay*time);
254275
phi_array(i,j,k) = a * std::exp(b * r);
255276
});
256277
}
278+
257279
}
258280

259281
void ComputeDiffusion(MultiFab& S_rhs,

ExampleCodes/SUNDIALS/AdvDiff-HyprePrecon/Source/myfunc.H

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ void main_main ();
99

1010
void InitializeData(MultiFab& phi,
1111
const GpuArray<Real,AMREX_SPACEDIM> dx,
12-
const GpuArray<Real,AMREX_SPACEDIM> prob_lo);
12+
const GpuArray<Real,AMREX_SPACEDIM> prob_lo,
13+
const GpuArray<Real,AMREX_SPACEDIM> prob_hi,
14+
const Real& time,
15+
const Real& Ax,
16+
const Real& Ay);
1317

1418
void ComputeDiffusion(MultiFab& S_rhs,
1519
MultiFab& S_data,

0 commit comments

Comments
 (0)