Skip to content

Commit e12d19c

Browse files
authored
Merge pull request #4 from pkjha-aero/main
Fix tutorials under Basic and Amr
2 parents 3205650 + 9c415b7 commit e12d19c

File tree

16 files changed

+62
-34
lines changed

16 files changed

+62
-34
lines changed

Amr/Advection_AmrCore/Exec/Make.Adv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AMREX_HOME = ../../../../amrex
1+
AMREX_HOME ?= ../../../../amrex
22
ADV_DIR = ../
33

44
TOP := $(ADV_DIR)

Amr/Advection_AmrLevel/Exec/SingleVortex/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AMREX_HOME = ../../../../../amrex
1+
AMREX_HOME ?= ../../../../../amrex
22
USE_EB = FALSE
33
PRECISION = DOUBLE
44
PROFILE = FALSE

Amr/Advection_AmrLevel/Exec/UniformVelocity/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AMREX_HOME = ../../../../../amrex
1+
AMREX_HOME ?= ../../../../../amrex
22
USE_EB =FALSE
33
PRECISION = DOUBLE
44
PROFILE = FALSE

Basic/HeatEquation_EX1_C/Exec/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AMREX_HOME defines the directory in which we will find all the AMReX code.
2-
AMREX_HOME = ../../../../amrex
2+
AMREX_HOME ?= ../../../../
33

44
DEBUG = FALSE
55
USE_MPI = FALSE

Basic/HeatEquation_EX1_C/Source/mykernel.H

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ void init_phi (int i, int j, int k,
1515
Real y = prob_lo[1] + (j+Real(0.5)) * dx[1];
1616
#if (AMREX_SPACEDIM > 2)
1717
Real z = prob_lo[2] + (k+Real(0.5)) * dx[2];
18+
Real r2 = ((x-Real(0.25))*(x-Real(0.25))+(y-Real(0.25))*(y-Real(0.25))+(z-Real(0.25))*(z-Real(0.25)))/Real(0.01);
1819
#else
1920
Real z = Real(0.);
21+
Real r2 = ((x-Real(0.25))*(x-Real(0.25))+(y-Real(0.25))*(y-Real(0.25)))/Real(0.01);
2022
#endif
21-
Real r2 = ((x-Real(0.25))*(x-Real(0.25))+(y-Real(0.25))*(y-Real(0.25))+(z-Real(0.25))*(z-Real(0.25)))/Real(0.01);
2223
phi(i,j,k) = Real(1.) + std::exp(-r2);
2324
}
2425

Basic/HeatEquation_EX1_CF/Exec/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AMREX_HOME defines the directory in which we will find all the AMReX code.
2-
AMREX_HOME = ../../../../amrex
2+
AMREX_HOME ?= ../../../../amrex
33

44
DEBUG = FALSE
55
USE_MPI = FALSE

Basic/HeatEquation_EX1_F/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AMREX_HOME defines the directory in which we will find all the AMReX code
2-
AMREX_HOME = ../../../amrex
2+
AMREX_HOME ?= ../../../amrex
33

44
DEBUG = TRUE
55

Basic/HeatEquation_EX2_C/Exec/GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AMREX_HOME defines the directory in which we will find all the AMReX code.
2-
AMREX_HOME = ../../../../amrex
2+
AMREX_HOME ?= ../../../../amrex
33

44
DEBUG = FALSE
55
USE_MPI = TRUE

Basic/HeatEquation_EX2_C/Source/myfunc.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void advance (MultiFab& phi_old,
1515
// Fill the ghost cells of each grid from the other grids
1616
// includes periodic domain boundaries
1717
phi_old.FillBoundary(geom.periodicity());
18-
18+
// There are physical boundaries to fill.
1919
FillDomainBoundary(phi_old, geom, BoundaryCondition);
2020

2121
const BCRec& bc = BoundaryCondition[0];
@@ -27,13 +27,15 @@ void advance (MultiFab& phi_old,
2727
//
2828
// =======================================================
2929

30-
const Real dxinv = geom.InvCellSize(0);
31-
const Real dyinv = geom.InvCellSize(1);
32-
const Real dzinv = geom.InvCellSize(2);
30+
// This example supports both 2D and 3D. Otherwise,
31+
// we would not need to use AMREX_D_TERM.
32+
AMREX_D_TERM(const Real dxinv = geom.InvCellSize(0);,
33+
const Real dyinv = geom.InvCellSize(1);,
34+
const Real dzinv = geom.InvCellSize(2););
3335

3436
const Box& domain_bx = geom.Domain();
35-
const Dim3 dom_lo = lbound(domain_bx);
36-
const Dim3 dom_hi = ubound(domain_bx);
37+
const auto dom_lo = lbound(domain_bx);
38+
const auto dom_hi = ubound(domain_bx);
3739

3840
// Compute fluxes one grid at a time
3941
for ( MFIter mfi(phi_old); mfi.isValid(); ++mfi )
@@ -47,8 +49,8 @@ void advance (MultiFab& phi_old,
4749
auto const& fluxz = flux[2].array(mfi);
4850
#endif
4951
const Box& bx = mfi.validbox();
50-
const Dim3 lo = lbound(bx);
51-
const Dim3 hi = ubound(bx);
52+
const auto lo = lbound(bx);
53+
const auto hi = ubound(bx);
5254

5355
auto const& phi = phi_old.array(mfi);
5456

@@ -81,14 +83,19 @@ void advance (MultiFab& phi_old,
8183
const Box& vbx = mfi.validbox();
8284
auto const& fluxx = flux[0].array(mfi);
8385
auto const& fluxy = flux[1].array(mfi);
86+
#if (AMREX_SPACEDIM > 2)
8487
auto const& fluxz = flux[2].array(mfi);
88+
#endif
8589
auto const& phiOld = phi_old.array(mfi);
8690
auto const& phiNew = phi_new.array(mfi);
8791

8892
amrex::ParallelFor(vbx,
8993
[=] AMREX_GPU_DEVICE (int i, int j, int k)
9094
{
91-
update_phi(i,j,k,phiOld,phiNew,fluxx,fluxy,fluxz,dt,dxinv,dyinv,dzinv);
95+
update_phi(i,j,k,phiOld,phiNew,
96+
AMREX_D_DECL(fluxx,fluxy,fluxz),
97+
dt,
98+
AMREX_D_DECL(dxinv,dyinv,dzinv));
9299
});
93100
}
94101
}
@@ -104,7 +111,8 @@ void init_phi(amrex::MultiFab& phi_new, amrex::Geometry const& geom){
104111
{
105112
const Box& vbx = mfi.validbox();
106113
auto const& phiNew = phi_new.array(mfi);
107-
AMREX_FOR_3D ( vbx, i, j, k,
114+
amrex::ParallelFor(vbx,
115+
[=] AMREX_GPU_DEVICE(int i, int j, int k)
108116
{
109117
init_phi(i,j,k,phiNew,dx,prob_lo);
110118
});

Basic/HeatEquation_EX2_C/Source/mykernel.H

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ void init_phi (int i, int j, int k,
99
GpuArray<amrex::Real,AMREX_SPACEDIM> const& dx,
1010
GpuArray<amrex::Real,AMREX_SPACEDIM> const& prob_lo)
1111
{
12-
amrex::Real x = prob_lo[0] + (i+0.5) * dx[0];
13-
amrex::Real y = prob_lo[1] + (j+0.5) * dx[1];
14-
amrex::Real z = prob_lo[2] + (k+0.5) * dx[2];
15-
amrex::Real r2 = ((x-0.25)*(x-0.25)+(y-0.25)*(y-0.25)+(z-0.25)*(z-0.25))/0.01;
16-
phi(i,j,k) = 1. + std::exp(-r2);
12+
using amrex::Real;;
13+
14+
Real x = prob_lo[0] + (i+Real(0.5)) * dx[0];
15+
Real y = prob_lo[1] + (j+Real(0.5)) * dx[1];
16+
#if (AMREX_SPACEDIM > 2)
17+
Real z = prob_lo[2] + (k+Real(0.5)) * dx[2];
18+
Real r2 = ((x-Real(0.25))*(x-Real(0.25))+(y-Real(0.25))*(y-Real(0.25))+(z-Real(0.25))*(z-Real(0.25)))/Real(0.01);
19+
#else
20+
Real z = Real(0.);
21+
Real r2 = ((x-Real(0.25))*(x-Real(0.25))+(y-Real(0.25))*(y-Real(0.25)))/Real(0.01);
22+
#endif
23+
phi(i,j,k) = Real(1.) + std::exp(-r2);
1724
}
1825

1926

@@ -93,6 +100,8 @@ void compute_flux_y (int i, int j, int k,
93100
}
94101
}
95102

103+
104+
#if (AMREX_SPACEDIM > 2)
96105
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
97106
void compute_flux_z (int i, int j, int k,
98107
amrex::Array4<amrex::Real> const& fluxz,
@@ -130,18 +139,28 @@ void compute_flux_z (int i, int j, int k,
130139
fluxz(i,j,k) = (phi(i,j,k)-phi(i,j,k-1)) * dzinv;
131140
}
132141
}
142+
#endif
133143

134144
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
135145
void update_phi (int i, int j, int k,
136146
amrex::Array4<amrex::Real const> const& phiold,
137147
amrex::Array4<amrex::Real > const& phinew,
138-
amrex::Array4<amrex::Real const> const& fluxx,
139-
amrex::Array4<amrex::Real const> const& fluxy,
140-
amrex::Array4<amrex::Real const> const& fluxz,
148+
AMREX_D_DECL(amrex::Array4<amrex::Real const> const& fluxx,
149+
amrex::Array4<amrex::Real const> const& fluxy,
150+
amrex::Array4<amrex::Real const> const& fluxz),
141151
amrex::Real dt,
142-
amrex::Real dxinv, amrex::Real dyinv, amrex::Real dzinv)
152+
AMREX_D_DECL(amrex::Real dxinv,
153+
amrex::Real dyinv,
154+
amrex::Real dzinv))
143155
{
144-
phinew(i,j,k) = phiold(i,j,k) + dt * dxinv * (fluxx(i+1,j ,k ) - fluxx(i,j,k)) + dt * dyinv * (fluxy(i ,j+1,k ) - fluxy(i,j,k)) + dt * dzinv * (fluxz(i ,j ,k+1) - fluxz(i,j,k));
156+
phinew(i,j,k) = phiold(i,j,k)
157+
+ dt * dxinv * (fluxx(i+1,j ,k ) - fluxx(i,j,k))
158+
+ dt * dyinv * (fluxy(i ,j+1,k ) - fluxy(i,j,k))
159+
#if (AMREX_SPACEDIM > 2)
160+
+ dt * dzinv * (fluxz(i ,j ,k+1) - fluxz(i,j,k));
161+
#else
162+
;
163+
#endif
145164
}
146165

147166
#endif

0 commit comments

Comments
 (0)