Skip to content

Commit

Permalink
Add user-defined ("custom") temperature sources (#1407)
Browse files Browse the repository at this point in the history
* Implement stub for update_rhotheta_sources

* Initialize sources and add calls to update function

* Copy to device in update function

* Pass source pointer to slow RHS update functions

* Add custom source term within the RHS update

* Make a copy of the ABL problem

* Override Problem::update_rhotheta_sources()

* Fix sign error

* Add test problem inputs

* Add missing file

* Add option to have source terms correspond to prim vars

* Document custom forcing
  • Loading branch information
ewquon authored Jan 31, 2024
1 parent 390c052 commit 62ffc78
Show file tree
Hide file tree
Showing 19 changed files with 528 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Docs/sphinx_doc/Inputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,30 @@ List of Parameters
| | Rayleigh damping | | |
+----------------------------------+-------------------+-------------------+-------------+

In addition, custom forcings or tendencies may be defined on a problem-specific
basis. This affords additional flexibility in defining the RHS source term as
a function of time and/or height. Implementation entails modifying problem
source code inside the Exec directory and overriding the ``update_*_sources()``
function(s).

+--------------------------------------------+-------------------+-------------------+-------------+
| Parameter | Definition | Acceptable | Default |
| | | Values | |
+============================================+===================+===================+=============+
| **erf.custom_forcing_uses_primitive_vars** | User-defined | true or false | false |
| | source terms set | | |
| | the tendency of | | |
| | primitive | | |
| | variables instead | | |
| | of conserved | | |
| | quantities | | |
| | (rho*prim_var) | | |
+--------------------------------------------+-------------------+-------------------+-------------+
| **erf.add_custom_rhotheta_forcing** | Apply the | true or false | false |
| | user-defined | | |
| | temperature source| | |
| | term | | |
+--------------------------------------------+-------------------+-------------------+-------------+

Initialization
==============
Expand Down
1 change: 1 addition & 0 deletions Exec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ else ()
add_subdirectory(DevTests/ParticlesOverWoA)
add_subdirectory(DevTests/MiguelDev)
add_subdirectory(DevTests/MetGrid)
add_subdirectory(DevTests/TemperatureSource)
endif()
12 changes: 12 additions & 0 deletions Exec/DevTests/TemperatureSource/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(erf_exe_name erf_abl_with_temperature_source)

add_executable(${erf_exe_name} "")
target_sources(${erf_exe_name}
PRIVATE
prob.cpp
)

target_include_directories(${erf_exe_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

include(${CMAKE_SOURCE_DIR}/CMake/BuildERFExe.cmake)
build_erf_exe(${erf_exe_name})
34 changes: 34 additions & 0 deletions Exec/DevTests/TemperatureSource/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# AMReX
COMP = gnu
PRECISION = DOUBLE

# Profiling
PROFILE = FALSE
TINY_PROFILE = TRUE
COMM_PROFILE = FALSE
TRACE_PROFILE = FALSE
MEM_PROFILE = FALSE
USE_GPROF = FALSE

# Performance
USE_MPI = TRUE
USE_OMP = FALSE

USE_CUDA = FALSE
USE_HIP = FALSE
USE_SYCL = FALSE

# Debugging
DEBUG = FALSE

TEST = TRUE
USE_ASSERTION = TRUE

#USE_POISSON_SOLVE = TRUE

# GNU Make
Bpack := ./Make.package
Blocs := .
ERF_HOME := ../..
ERF_PROBLEM_DIR = $(ERF_HOME)/Exec/DevTests/TemperatureSource
include $(ERF_HOME)/Exec/Make.ERF
2 changes: 2 additions & 0 deletions Exec/DevTests/TemperatureSource/Make.package
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CEXE_headers += prob.H
CEXE_sources += prob.cpp
1 change: 1 addition & 0 deletions Exec/DevTests/TemperatureSource/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a copy of the ABL problem, but with update_rhotheta_sources defined
3 changes: 3 additions & 0 deletions Exec/DevTests/TemperatureSource/input_sounding
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1000.0 300.0 0.0
0.0 300.0 0.0 10.0 0.0
1000.0 300.0 0.0 10.0 0.0
50 changes: 50 additions & 0 deletions Exec/DevTests/TemperatureSource/neutral_column.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ------------------ INPUTS TO MAIN PROGRAM -------------------
stop_time = 999.9
max_step = 20

amrex.fpe_trap_invalid = 1

fabarray.mfiter_tile_size = 1024 1024 1024

# PROBLEM SIZE & GEOMETRY
geometry.prob_extent = 40. 40. 640.
amr.n_cell = 4 4 64

geometry.is_periodic = 1 1 0

zlo.type = "SlipWall"
zhi.type = "SlipWall"

# INITIALIZATION
erf.init_type = input_sounding
erf.init_sounding_ideal = true

# TIME STEP CONTROL
erf.fixed_dt = 0.1

# DIAGNOSTICS & VERBOSITY
amr.v = 1 # verbosity in Amr.cpp
erf.v = 1 # verbosity in ERF.cpp -- needs to be 1 to write out data_log files
erf.sum_interval = 1 # timesteps between computing mass

# REFINEMENT / REGRIDDING
amr.max_level = 0 # maximum level number allowed

# CHECKPOINT FILES
erf.check_file = chk # root name of checkpoint file
erf.check_int = -1 # number of timesteps between checkpoints

# PLOTFILES
erf.plot_file_1 = plt # prefix of plotfile name
erf.plot_int_1 = 5 # number of timesteps between plotfiles (DEBUG)
erf.plot_vars_1 = density x_velocity y_velocity z_velocity pressure theta

# SOLVER CHOICES
erf.use_gravity = true
erf.use_coriolis = false

erf.molec_diff_type = "None"
erf.les_type = "None"

erf.add_custom_rhotheta_forcing = true
erf.custom_forcing_uses_primitive_vars = true
85 changes: 85 additions & 0 deletions Exec/DevTests/TemperatureSource/prob.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef _PROB_H_
#define _PROB_H_

#include <string>

#include "AMReX_REAL.H"

#include "prob_common.H"

struct ProbParm : ProbParmDefaults {
amrex::Real rho_0 = 0.0;
amrex::Real T_0 = 0.0;
amrex::Real A_0 = 1.0;
amrex::Real QKE_0 = 0.1;

amrex::Real U_0 = 0.0;
amrex::Real V_0 = 0.0;
amrex::Real W_0 = 0.0;

// random initial perturbations (legacy code)
amrex::Real U_0_Pert_Mag = 0.0;
amrex::Real V_0_Pert_Mag = 0.0;
amrex::Real W_0_Pert_Mag = 0.0;
amrex::Real T_0_Pert_Mag = 0.0; // perturbation to rho*Theta

// divergence-free initial perturbations
amrex::Real pert_deltaU = 0.0;
amrex::Real pert_deltaV = 0.0;
amrex::Real pert_periods_U = 5.0;
amrex::Real pert_periods_V = 5.0;
amrex::Real pert_ref_height = 100.0;

// rayleigh damping
amrex::Real dampcoef = 0.2; // inverse time scale [1/s]
amrex::Real zdamp = 500.0; // damping depth [m] from model top

// helper vars
amrex::Real aval;
amrex::Real bval;
amrex::Real ufac;
amrex::Real vfac;
}; // namespace ProbParm

class Problem : public ProblemBase
{
public:
Problem(const amrex::Real* problo, const amrex::Real* probhi);

#include "Prob/init_constant_density_hse.H"
#include "Prob/init_rayleigh_damping.H"

void init_custom_pert (
const amrex::Box& bx,
const amrex::Box& xbx,
const amrex::Box& ybx,
const amrex::Box& zbx,
amrex::Array4<amrex::Real > const& state,
amrex::Array4<amrex::Real > const& x_vel,
amrex::Array4<amrex::Real > const& y_vel,
amrex::Array4<amrex::Real > const& z_vel,
amrex::Array4<amrex::Real > const& r_hse,
amrex::Array4<amrex::Real > const& p_hse,
amrex::Array4<amrex::Real const> const& z_nd,
amrex::Array4<amrex::Real const> const& z_cc,
amrex::GeometryData const& geomdata,
amrex::Array4<amrex::Real const> const& mf_m,
amrex::Array4<amrex::Real const> const& mf_u,
amrex::Array4<amrex::Real const> const& mf_v,
const SolverChoice& sc) override;

void update_rhotheta_sources (
const amrex::Real& time,
amrex::Vector<amrex::Real>& src,
amrex::Gpu::DeviceVector<amrex::Real>& d_src,
const amrex::Geometry& geom,
std::unique_ptr<amrex::MultiFab>& z_phys_cc) override;

protected:
std::string name() override { return "ABL"; }

private:
ProbParm parms;
};

#endif
Loading

0 comments on commit 62ffc78

Please sign in to comment.