Skip to content

Commit 531fda2

Browse files
committed
Changed timestepping to be one indexed so initial condition is not overwritten. Added solution verification using AMReX tool fcompare.
1 parent e701731 commit 531fda2

File tree

6 files changed

+82
-25
lines changed

6 files changed

+82
-25
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ The same mini-app is written in multiple programming languages systems.
55
TODO: Add overview of mini-app.
66

77
## Versions
8-
9-
TODO: Create valid links to files / directories.
108
- [C](swm_c)
119
- [Plain C](/swm_c/shallow_swap.c)
1210
- OpenACC
1311
- [swap](/swm_c/shallow_swap.acc.c)
1412
- [tile](/swm_c/shallow_swap.acc.Tile.c)
13+
- C++
14+
- [ARMeX](/swm_AMReX)
1515
- [Python](swm_python)
1616
- numpy
1717
- gt4py

swm_AMReX/GNUmakefile

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ USE_OMP = FALSE
88
COMP = gnu
99
DIM = 2
1010

11+
#USE_HDF5=TRUE
12+
#HDF5_HOME=/home/lalo/spack/opt/spack/linux-ubuntu24.04-skylake/gcc-13.3.0/hdf5-1.14.5-vm6rifl2savzhynhyx56ayutfhmycs3s/
13+
1114
CXXSTD = c++20
1215

1316
include $(AMREX_HOME)/Tools/GNUMake/Make.defs

swm_AMReX/README.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,23 @@ Based on the NCAR SWM mini-app found [here](https://github.com/NCAR/SWM).
2323

2424

2525
## Postprocess
26+
- Solution Verification
27+
- One time setup for building AMReX provided tool to diff plotfiles (fcompare). Full instructions on how to build AMReX postprocessing tools [here](https://amrex-codes.github.io/amrex/docs_html/Post_Processing.html).
28+
- cd $AMREX_HOME/Tools/Plotfile/
29+
- make
30+
- This should produce an executable:
31+
- $AMREX_HOME/Tools/Plotfile/fcompare.gnu.ex
32+
- Note the exact name will vary depending on the compiler you used. The above example is when gcc was used.
33+
- Now you can diff two plot files using the fcompare tool:
34+
- $AMREX_HOME/Tools/Plotfile/fcompare.gnu.ex plotfile1 plotfile2
35+
2636
- python plot.py
2737
- Currently just generates images of plots the x velocity (u), y velocity (v), and pressure (p) for first and last time step. TODO - add check against the output from the other versions of the [mini-app](https://github.com/NCAR/SWM).
2838

29-
3039
## Convenience Script
3140
- [run_local.sh](./run_local.sh)
32-
- The environment variable SWM_AMREX_ROOT must be set to use this script. It should point to this directoy. This script will:
41+
- The environment variable SWM_AMREX_ROOT must be set to use this script. It should point to this directory. This script will:
3342
- Build.
3443
- Create a subdirectory called SWM_AMREX_ROOT/run_dir if it does not already exist.
35-
- Run and postprocess in that subdirectory.
44+
- Run in that subdirectory.
45+
- Verify the solution matches a reference solution.

swm_AMReX/main.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ int main (int argc, char* argv[])
7171

7272
InitializeVariables(geom, psi, p, u, v);
7373

74-
amrex::Print() << "Initial: " << std::endl;
75-
amrex::Print() << "psi max: " << psi.max(0) << std::endl;
76-
amrex::Print() << "psi min: " << psi.min(0) << std::endl;
77-
amrex::Print() << "p max: " << p.max(0) << std::endl;
78-
amrex::Print() << "p min: " << p.min(0) << std::endl;
79-
amrex::Print() << "u max: " << u.max(0) << std::endl;
80-
amrex::Print() << "u min: " << u.min(0) << std::endl;
81-
amrex::Print() << "v max: " << v.max(0) << std::endl;
82-
amrex::Print() << "v min: " << v.min(0) << std::endl;
74+
//amrex::Print() << "Initial: " << std::endl;
75+
//amrex::Print() << "psi max: " << psi.max(0) << std::endl;
76+
//amrex::Print() << "psi min: " << psi.min(0) << std::endl;
77+
//amrex::Print() << "p max: " << p.max(0) << std::endl;
78+
//amrex::Print() << "p min: " << p.min(0) << std::endl;
79+
//amrex::Print() << "u max: " << u.max(0) << std::endl;
80+
//amrex::Print() << "u min: " << u.min(0) << std::endl;
81+
//amrex::Print() << "v max: " << v.max(0) << std::endl;
82+
//amrex::Print() << "v min: " << v.min(0) << std::endl;
8383

8484
// **********************************
8585
// Write initial plot file
@@ -139,7 +139,7 @@ int main (int argc, char* argv[])
139139
double tdt = dt;
140140
const double alpha = 0.001;
141141

142-
for (int time_step = 0; time_step < n_time_steps; ++time_step)
142+
for (int time_step = 1; time_step <= n_time_steps; ++time_step)
143143
{
144144
// Sets: cu, cv, h, z
145145
UpdateIntermediateVariables(fsdx, fsdy, geom,
@@ -176,13 +176,13 @@ int main (int argc, char* argv[])
176176

177177
}
178178

179-
amrex::Print() << "Final: " << std::endl;
180-
amrex::Print() << "p max: " << p.max(0) << std::endl;
181-
amrex::Print() << "p min: " << p.min(0) << std::endl;
182-
amrex::Print() << "u max: " << u.max(0) << std::endl;
183-
amrex::Print() << "u min: " << u.min(0) << std::endl;
184-
amrex::Print() << "v max: " << v.max(0) << std::endl;
185-
amrex::Print() << "v min: " << v.min(0) << std::endl;
179+
//amrex::Print() << "Final: " << std::endl;
180+
//amrex::Print() << "p max: " << p.max(0) << std::endl;
181+
//amrex::Print() << "p min: " << p.min(0) << std::endl;
182+
//amrex::Print() << "u max: " << u.max(0) << std::endl;
183+
//amrex::Print() << "u min: " << u.min(0) << std::endl;
184+
//amrex::Print() << "v max: " << v.max(0) << std::endl;
185+
//amrex::Print() << "v min: " << v.min(0) << std::endl;
186186

187187
}
188188
amrex::Finalize();

swm_AMReX/run_local.sh

+43-3
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,71 @@
66
set -e
77
set -u
88

9+
# Convenience function to print 80 character wide banners with centered text
10+
print_banner() {
11+
local message="$1"
12+
local border_char="#"
13+
local width=80
14+
local padding=$(( (width - ${#message} - 2) / 2 ))
15+
local border=$(printf "%-${width}s" | tr ' ' "$border_char")
16+
17+
echo -e "\n$border"
18+
printf "%*s %s %*s\n" $padding "" "$message" $padding ""
19+
echo -e "$border\n"
20+
}
21+
922
# Will put you back in this directory after script is finished
1023
dir_backup=$(pwd)
1124

1225
##############################################################################
1326
# Build
1427
##############################################################################
28+
print_banner "Build"
1529
cd "$SWM_AMREX_ROOT"
1630
make
1731

1832
##############################################################################
1933
# Run
2034
##############################################################################
35+
print_banner "Run"
36+
2137
run_dir="$SWM_AMREX_ROOT"/run_dir
2238
mkdir -p "$run_dir"
2339
cd "$run_dir"
2440

41+
# TODO: Make the executable name a variable so that we can run the MPI, OpenMP, and Cuda versions with the same script
2542
"$SWM_AMREX_ROOT"/main2d.gnu.ex "$SWM_AMREX_ROOT"/inputs
43+
#"$SWM_AMREX_ROOT"/main2d.gnu.MPI.ex "$SWM_AMREX_ROOT"/inputs
2644

2745
##############################################################################
28-
# Postprocess
46+
# Solution Verification
2947
##############################################################################
30-
python "$SWM_AMREX_ROOT"/plot_with_yt.py
48+
print_banner "Solution Verification"
49+
50+
# Turn off exit on error for this one command since we want to check the return value
51+
set +e
52+
53+
# TODO: Make the plotfile name a so it automatically finds the plotfile for the last time step
54+
# TODO: Do a check to see if the corresponding reference plotfile exists step
55+
$AMREX_HOME/Tools/Plotfile/fcompare.gnu.ex plt00000 "$SWM_AMREX_ROOT"/plt04000_reference
3156

57+
if [ $? -eq 0 ]; then
58+
echo -e "\nSolution Verification: PASS"
59+
else
60+
echo -e "\nSolution Verification: FAIL"
61+
exit 1
62+
fi
63+
64+
# Turn exit on error back on
65+
set -e
66+
67+
##############################################################################
68+
# Plotting
69+
##############################################################################
70+
#print_banner "Plotting"
71+
#python "$SWM_AMREX_ROOT"/plot_with_yt.py
3272

3373
##############################################################################
3474
# Clean Up
3575
##############################################################################
36-
cd "$dir_backup"
76+
cd "$dir_backup"

swm_AMReX/swm_mini_app_utils.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <AMReX_ParmParse.H>
66
#include <AMReX_PlotFileUtil.H>
77
#include <AMReX_MultiFab.H>
8+
#include <AMReX_Array.H>
89

910
#include "swm_mini_app_utils.h"
1011

@@ -300,6 +301,9 @@ void WriteOutput(const amrex::MultiFab & psi,
300301
int min_digits = 5;
301302
const std::string& pltfile = amrex::Concatenate("plt", time_step, min_digits);
302303
amrex::WriteSingleLevelPlotfile(pltfile, output_values, {"psi", "p", "u", "v"}, geom, time, time_step);
304+
//amrex::WriteSingleLevelPlotfileHDF5(pltfile, output_values, {"psi", "p", "u", "v"}, geom, time, time_step);
305+
//amrex::WriteSingleLevelPlotfileHDF5MultiDset(pltfile, output_values, {"psi", "p", "u", "v"}, geom, time, time_step);
306+
303307

304308
return;
305309
}

0 commit comments

Comments
 (0)