Skip to content

Commit 88c0891

Browse files
committed
Initial commit of AMReX version of SWM mini-app.
1 parent 7c738be commit 88c0891

10 files changed

+993
-0
lines changed

swm_AMReX/GNUmakefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# AMREX_HOME defines the directory in which we will find all the AMReX code.
2+
# I recommend adding this to your environment before running make. However if it is not defined then it will get set here:
3+
AMREX_HOME ?= PROVIDE_YOUR_OWN_PATH_TO_AMREX_HERE
4+
5+
DEBUG = FALSE
6+
USE_MPI = FALSE
7+
USE_OMP = FALSE
8+
COMP = gnu
9+
DIM = 2
10+
11+
CXXSTD = c++20
12+
13+
include $(AMREX_HOME)/Tools/GNUMake/Make.defs
14+
15+
include ./Make.package
16+
17+
include $(AMREX_HOME)/Src/Base/Make.package
18+
19+
include $(AMREX_HOME)/Tools/GNUMake/Make.rules

swm_AMReX/Make.package

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CEXE_sources += main.cpp swm_mini_app_utils.cpp
2+
CEXE_headers += swm_mini_app_utils.h
3+

swm_AMReX/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# AMReX Shallow Water Equations Mini-App
2+
3+
Based on the NCAR SWM mini-app found [here](https://github.com/NCAR/SWM).
4+
5+
## Prerequisites
6+
- g++ (a version with support for c++20)
7+
- Other compilers should also work fine but I have been using gcc/g++ for testing so far.
8+
- make
9+
- [AMReX](https://github.com/AMReX-Codes/amrex)
10+
- [yt](https://yt-project.org/) (Only needed if you want to run the postprocessing script [plot_with_yt.py](plot_with_yt.py))
11+
12+
## Build
13+
14+
- Set AMREX_HOME
15+
- The make file requires this environment variable to be set. It should point to the directory where you pulled [AMReX](https://github.com/AMReX-Codes/amrex). I set mine in my shell startup script. You can also set it at the top of this file: [GNUmakefile](./GNUmakefile).
16+
17+
- make
18+
- If AMREX_HOME is set correctly then make should just work. This will produce and executable with a name similar to, main2d.gnu.ex . The exact name will vary depending on compile time options (compiler, MPI usage, openMP usage, Debugging options, etc.)
19+
20+
## Run
21+
- Note that you need to supply [inputs](./inputs) file on command line when running the executable. For example:
22+
- ./main2d.gnu.ex inputs
23+
24+
25+
## Postprocess
26+
- python plot.py
27+
- 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).
28+
29+
30+
## Convenience Script
31+
- [run_local.sh](./run_local.sh)
32+
- The environment variable SWM_AMREX_ROOT must be set to use this script. It should point to the top level of this directoy. This script will:
33+
- Build.
34+
- Create a subdirectory called SWM_AMREX_ROOT/run_dir if it does not already exist.
35+
- Run and postprocess in that subdirectory.

swm_AMReX/doc/figure_labels.tex

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
\documentclass{article}
2+
3+
\usepackage[dvipsnames]{xcolor}
4+
5+
\begin{document}
6+
7+
% Only use these colors for labels.
8+
\definecolor{cell_centered_color}{named}{Orange}
9+
\definecolor{node_color}{named}{Red}
10+
\definecolor{x_face_color}{named}{OliveGreen}
11+
\definecolor{y_face_color}{named}{Blue}
12+
13+
\newcommand{\nodecolor}[1]{\textcolor{node_color}{#1}}
14+
\newcommand{\cellcolor}[1]{\textcolor{cell_centered_color}{#1}}
15+
\newcommand{\xfacecolor}[1]{\textcolor{x_face_color}{#1}}
16+
\newcommand{\yfacecolor}[1]{\textcolor{y_face_color}{#1}}
17+
18+
\begin{Huge}
19+
20+
Legend:
21+
\begin{tabular}{ c l }
22+
\color{cell_centered_color}{$\bullet$} & \color{cell_centered_color}{Cell Centered} \\
23+
\color{node_color}{$\bullet$} & \color{node_color}{Node} \\
24+
\color{x_face_color}{$\bullet$} & \color{x_face_color}{X Face} \\
25+
\color{y_face_color}{$\bullet$} & \color{y_face_color}{Y Face}
26+
\end{tabular}
27+
28+
\begin{tabular}{ c l }
29+
\color{cell_centered_color}{} & \color{cell_centered_color}{Cell Centered} \\
30+
\color{node_color}{} & \color{node_color}{Node} \\
31+
\color{x_face_color}{} & \color{x_face_color}{X Face} \\
32+
\color{y_face_color}{} & \color{y_face_color}{Y Face}
33+
\end{tabular}
34+
35+
\vspace{1in}
36+
Cell Center Values:
37+
\color{cell_centered_color}{
38+
$$ \psi_{i,j} $$
39+
$$ \psi_{i+1,j} $$
40+
$$ \psi_{i,j+1} $$
41+
$$ \psi_{i+1,j+1} $$
42+
$$ \psi_{i-1,j} $$
43+
$$ \psi_{i,j-1} $$
44+
$$ \psi_{i-1,j-1} $$
45+
46+
$$ \eta_{i,j}$$
47+
48+
$$ z $$
49+
}
50+
51+
\color{node_color}{
52+
$$ p_{i,j} $$
53+
$$ p_{i+1,j} $$
54+
$$ p_{i,j+1} $$
55+
$$ p_{i+1,j+1} $$
56+
57+
$$ h $$
58+
$$ h_{i,j} $$
59+
}
60+
61+
62+
\color{y_face_color}{
63+
$$ u_{i,j} $$
64+
$$ u_{i,j+1} $$
65+
$$ u_{i-1,j} $$
66+
67+
$$ cu $$
68+
}
69+
70+
71+
\color{x_face_color}{
72+
$$ v_{i,j} $$
73+
$$ v_{i+1,j} $$
74+
$$ v_{i,j-} $$
75+
76+
$$ cv $$
77+
}
78+
79+
\color{black}{
80+
Initial Conditions:
81+
$$\vec{V}_0$$
82+
$$P_0$$
83+
84+
Mesh: \\
85+
Nx \\
86+
Ny \\
87+
dx \\
88+
dy \\
89+
dx = dy = 10,000 \\
90+
N$_\mathrm{ghost}$ = 1 \\
91+
N$_\mathrm{grow}$ = 1 \\
92+
}
93+
94+
95+
96+
\end{Huge}
97+
98+
The shallow water equations are:
99+
$$ \frac{\partial{\vec{V}}}{\partial t} + \eta \hat{N} \times P \vec{V} + \nabla \left( P + \frac{1}{2}\vec{V} \cdot \vec{V} \right) = 0$$
100+
101+
$$ \frac{\partial{P}}{\partial t} + \nabla \cdot \left( P \vec{V} \right) = 0$$
102+
103+
where:
104+
105+
$$ \eta = \frac{\nabla \times \vec{V}}{P} $$
106+
107+
Where in component form we get:
108+
109+
110+
$$ \textcolor{y_face_color}{ \frac{\partial u}{\partial t} }= \eta P v - \frac{\partial}{\partial x} \left( P + \frac{1}{2} (u^2 + v^2) \right)$$
111+
112+
113+
114+
$$ \textcolor{x_face_color}{ \frac{\partial v}{\partial t} } = -\eta P u - \frac{\partial}{\partial y} \left( P + \frac{1}{2} (u^2 + v^2) \right)$$
115+
116+
117+
$$ \nodecolor{ \frac{\partial P}{\partial t} } = -\frac{\partial}{\partial x}\left(Pu\right) - \frac{\partial}{\partial y} (Pv) $$
118+
119+
$$ \textcolor{cell_centered_color}{\eta} = \frac{ \frac{\partial v}{\partial x} + \frac{\partial u}{\partial y} }{P} $$
120+
121+
$$ \textcolor{node_color}{h_{i,j}} = \textcolor{node_color}{P_{i,j}} + \frac{1}{2} \left( \frac{\textcolor{y_face_color}{u_{i-1,j}}^2 + \textcolor{y_face_color}{u_{i,j}}^2}{2} + \frac{\textcolor{x_face_color}{v_{i,j-1}}^2 + \textcolor{x_face_color}{v_{i,j}}^2}{2} \right) $$
122+
123+
124+
$$ \textcolor{y_face_color}{[Pu]_{i,j}} = \frac{ \textcolor{node_color}{P_{i,j}} + \textcolor{node_color}{P_{i+1,j}} }{2} \textcolor{y_face_color}{u_{i,j}} $$
125+
126+
127+
$$ \textcolor{x_face_color}{[Pv]_{i,j}} = \frac{\textcolor{node_color}{P_{i,j}} + \textcolor{node_color}{P_{i,j+1}}}{2} \textcolor{x_face_color}{v_{i,j}}$$
128+
129+
$$ \textcolor{cell_centered_color}{\eta_{i,j}} = \frac{ \frac{ \textcolor{x_face_color}{v_{i+1,j}} - \textcolor{x_face_color}{v_{i,j}}}{dx} + \frac{ \textcolor{y_face_color}{u_{i,j+1}} - \textcolor{y_face_color}{u_{i,j}} }{dy} }{\frac{ \textcolor{node_color}{P_{i,j}} + \textcolor{node_color}{P_{i+1,j}} + \textcolor{node_color}{P_{i,j+1}} + \textcolor{node_color}{P_{i+1,j+1}} }{4} } $$
130+
131+
$$ \frac{\partial \yfacecolor{u_{i,j}}}{\partial t} = \left( \frac{ \cellcolor{\eta_{i,j-1}} + \cellcolor{\eta_{i,j}} }{2} \right) \left( \frac{ \xfacecolor{[P v]_{i,j-1}} + \xfacecolor{[P v]_{i,j}} + \xfacecolor{[P v]_{i+1,j-1}} + \xfacecolor{[P v]_{i+1,j}} }{4} \right) - \left(\frac{ \nodecolor{ h_{i+1,j} } - \nodecolor{ h_{i,j} } }{dx} \right) $$
132+
133+
$$ \frac{\partial \xfacecolor{v_{i,j}}}{\partial t} = \left( \frac{ \textcolor{cell_centered_color}{\eta_{i-1,j}} + \textcolor{cell_centered_color}{\eta_{i,j}} }{2} \right) \left( \frac{ \yfacecolor{[P u]_{i-1,j}} + \yfacecolor{[P u]_{i-1,j+1}} + \yfacecolor{[P u]_{i,j}} + \yfacecolor{[P u]_{i,j+1}} }{4} \right) - \left( \frac{ \nodecolor{h_{i,j+1}} - \nodecolor{h_{i,j}} }{dy} \right) $$
134+
135+
$$ \frac{\partial \nodecolor{P_{i,j}}}{\partial t} = - \left( \frac{ \yfacecolor{[Pu]_{i,j}} - \yfacecolor{[Pu]_{i-1,j}} }{dx} \right) - \left( \frac{ \xfacecolor{[Pv]_{i,j}} - \xfacecolor{[Pu]_{i,j-1}}}{dy} \right) $$
136+
137+
\end{document}

swm_AMReX/inputs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
nx = 64
2+
ny = 64
3+
4+
dx = 100000
5+
dy = 100000
6+
7+
max_chunk_size = 100000
8+
9+
n_time_steps = 4000
10+
11+
dt = 90
12+
13+
plot_interval = 100

0 commit comments

Comments
 (0)