Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactDiff #165

Merged
merged 44 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fba95df
reactDiff shell
ajnonaka Aug 21, 2024
1533f0f
Merge branch 'main' into reactDiff
ajnonaka Aug 21, 2024
c8befe2
build chemistry namespace
ajnonaka Aug 21, 2024
4e59a7a
chemistry functions
ajnonaka Aug 22, 2024
92cad71
namelist
ajnonaka Aug 22, 2024
1e2cc29
reactDiff namespace
ajnonaka Aug 22, 2024
9576543
setup preliminaries
ajnonaka Aug 23, 2024
9bf6d2c
diffusion outline
ajnonaka Aug 23, 2024
3f4d752
build diffusion operator for explicit
ajnonaka Aug 24, 2024
fcbe57b
more work
ajnonaka Aug 26, 2024
497c984
more work
ajnonaka Aug 26, 2024
99f5b28
Merge branch 'main' into reactDiff
ajnonaka Aug 26, 2024
ff6d8e1
lots of more work
ajnonaka Aug 26, 2024
9c3c7fe
outline for reactions
ajnonaka Aug 26, 2024
62f6d3d
more chemistry routines
ajnonaka Aug 27, 2024
1e9b93d
more chemistry routines
ajnonaka Aug 27, 2024
01194aa
starting the testing/debugging
ajnonaka Aug 27, 2024
5dcd786
more debugging
ajnonaka Aug 27, 2024
a3d7bb2
bugfix
ajnonaka Aug 27, 2024
786028e
chemistry loop bugfix
ajnonaka Aug 27, 2024
09f563c
sign fix
ajnonaka Aug 27, 2024
020e76e
cleanup, added several reactDiff_diffusion_types
ajnonaka Aug 28, 2024
0b86555
second-order split scheme chemistry
ajnonaka Aug 28, 2024
828da13
implemented both strang splitting schemes
ajnonaka Aug 28, 2024
efcd081
incorporate include_discrete_LMA_correction option
ajnonaka Aug 28, 2024
17be21c
stochastic diffusion work
ajnonaka Aug 29, 2024
1193194
unsplit integrator shell
ajnonaka Aug 29, 2024
1c46839
fix first order unsplit integrator
ajnonaka Aug 29, 2024
ce9414b
diffusive noise
ajnonaka Aug 29, 2024
67ea8d5
paper setup
ajnonaka Aug 29, 2024
c9076f3
paper setups
ajnonaka Sep 4, 2024
a018d36
fine tuning of 3d setup. still needs work for larger time steps
ajnonaka Sep 4, 2024
4468fb4
implicit diffusion module, incorporated crank-nicolson strang option
ajnonaka Sep 4, 2024
8b6539d
add integer populations option
ajnonaka Sep 4, 2024
5aad360
CLE and tau leaping implemented
ajnonaka Sep 5, 2024
93bc070
implement midpoint_stoch_flux_type for split integrators
ajnonaka Sep 6, 2024
b13a58e
split out GenerateStochasticFluxdivCorrector for split and unsplit al…
ajnonaka Sep 6, 2024
8ae192d
explicit midpoint (non-SSA) written
ajnonaka Sep 6, 2024
eb8b966
implicit midpoint (non-SSA) unsplit
ajnonaka Sep 7, 2024
b249fcc
match paper
ajnonaka Sep 7, 2024
32f6395
SSA attempt
ajnonaka Sep 9, 2024
fb97cf3
ssa bugfix
ajnonaka Sep 9, 2024
e95745c
unsplit SSA schemes
ajnonaka Sep 9, 2024
ddcf0bf
structure factor implemented
ajnonaka Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions exec/reactDiff/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# AMREX_HOME defines the directory in which we will find all the AMReX code.
# If you set AMREX_HOME as an environment variable, this line will be ignored
AMREX_HOME ?= ../../../amrex/

DEBUG = FALSE
USE_MPI = TRUE
USE_OMP = FALSE
USE_CUDA = FALSE
COMP = gnu
DIM = 2
MAX_SPEC = 8
MAX_REAC = 7

TINY_PROFILE = FALSE

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

# add this back on if we add any local files
#include ./Make.package
#VPATH_LOCATIONS += .
#INCLUDE_LOCATIONS += .

include ../../src_reactDiff/Make.package
VPATH_LOCATIONS += ../../src_reactDiff/
INCLUDE_LOCATIONS += ../../src_reactDiff/

include ../../src_chemistry/Make.package
VPATH_LOCATIONS += ../../src_chemistry/
INCLUDE_LOCATIONS += ../../src_chemistry/

include ../../src_analysis/Make.package
VPATH_LOCATIONS += ../../src_analysis/
INCLUDE_LOCATIONS += ../../src_analysis/

include ../../src_rng/Make.package
VPATH_LOCATIONS += ../../src_rng/
INCLUDE_LOCATIONS += ../../src_rng/

include ../../src_common/Make.package
VPATH_LOCATIONS += ../../src_common/
INCLUDE_LOCATIONS += ../../src_common/

include $(AMREX_HOME)/Src/Base/Make.package
include $(AMREX_HOME)/Src/Boundary/Make.package
include $(AMREX_HOME)/Src/LinearSolvers/MLMG/Make.package

include $(AMREX_HOME)/Tools/GNUMake/Make.rules

ifeq ($(findstring cgpu, $(HOST)), cgpu)
CXXFLAGS += $(FFTW)
endif

ifeq ($(USE_CUDA),TRUE)
LIBRARIES += -lcufft
else
LIBRARIES += -L$(FFTW_DIR) -lfftw3_mpi -lfftw3
endif

MAXSPECIES := $(strip $(MAX_SPEC))
DEFINES += -DMAX_SPECIES=$(MAXSPECIES)

MAXREACTION := $(strip $(MAX_REAC))
DEFINES += -DMAX_REACTION=$(MAXREACTION)

121 changes: 121 additions & 0 deletions exec/reactDiff/inputs_paper_BPM_2d
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# This inputs file is used for generating
# - Figures 5, 6, 7 (Section V.B)
# in Paper by C. Kim et al. "Stochastic simulation of reaction-diffusion
# systems: A fluctuating-hydrodynamics approach"
# J. Chem. Phys. 146, 124110 (2017).
# You can change some relevant parameters such as
# - cell_depth
# - n_cells (64^2 or 256^2) and max_grid_size
# - fixed_dt, max_step
# - plot_int (plot files)
# - temporal_integrator, reaction_type (numerical scheme)
# and run this inputs file.

# Problem specification
prob_lo = 0.0 0.0 # physical lo coordinate
prob_hi = 32.0 32.0 # physical hi coordinate

# number of cells in domain and maximum number of cells in a box
n_cells = 64 64
max_grid_size = 32 32

# to compute cell volume in 2D problems
cell_depth = 10.

# Time-step control
fixed_dt = 0.5

# Controls for number of steps between actions
max_step = 20000
plot_int = 200
struct_fact_int = -1
n_steps_skip = 2000

seed = 1

nspecies = 3
nreaction = 7

prob_type = 0

n_init_in_1 = 1685.8 533.5 56.38 # Start on the limit cycle

integer_populations = 1

# 0=D+R (first-order splitting)
# 1=(1/2)R + D + (1/2)R (Strang option 1)
# 2=(1/2)D + R + (1/2)D (Strang option 2)
# -1=unsplit forward Euler
# -2=unsplit explicit midpoint
# -3=unsplit multinomial diffusion
# -4=unsplit implicit midpoint
temporal_integrator = -4

# only used for split schemes (temporal_integrator>=0)
# 0=explicit trapezoidal predictor/corrector
# 1=Crank-Nicolson semi-implicit
# 2=explicit midpoint
# 3=multinomial diffusion
# 4=forward Euler
reactDiff_diffusion_type = 4

# Fickian diffusion coeffs
D_Fick = 0.1 0.01 0.01

variance_coef_mass = 1.
initial_variance_mass = 1.

# how to compute n on faces for stochastic weighting
# 1=arithmetic (with C0-Heaviside), 2=geometric, 3=harmonic
# 10=arithmetic average with discontinuous Heaviside function
# 11=arithmetic average with C1-smoothed Heaviside function
# 12=arithmetic average with C2-smoothed Heaviside function
avg_type = 1

# only used for split schemes (temporal_integrator>=0)
# 0=first-order (deterministic, tau leaping, CLE, or SSA)
# 1=second-order (determinisitc, tau leaping, or CLE only)
reactDiff_reaction_type = 0

# 0=deterministic; 1=CLE; 2=SSA; 3=tau leap
reaction_type = 3

# BPM model is:
# (1) U + W --> V + W
# (2) V + V --> W
# (3) W --> V + V
# (4) V --> 0
# (5) 0 --> V
# (6) U --> 0
# (7) 0 --> U
stoich_1R = 1 0 1
stoich_1P = 0 1 1
stoich_2R = 0 2 0
stoich_2P = 0 0 1
stoich_3R = 0 0 1
stoich_3P = 0 2 0
stoich_4R = 0 1 0
stoich_4P = 0 0 0
stoich_5R = 0 0 0
stoich_5P = 0 1 0
stoich_6R = 1 0 0
stoich_6P = 0 0 0
stoich_7R = 0 0 0
stoich_7P = 1 0 0

# reaction rate constant for each reaction (assuming Law of Mass Action holds)
# using rate_multiplier, reaction rates can be changed by the same factor
# if include_discrete_LMA_correction, n^2 and n^3 in rate expressions become
# n*(n-1/dv) and n*(n-1/dv)*(n-2/dv).
rate_const = 0.0002 0.0002 1. 0.03666663 4.44444555555 0.00333333 16.66665
rate_multiplier = 1.
include_discrete_LMA_correction = 1

# Boundary conditions
# ----------------------
# BC specifications:
# -1 = periodic
# 1 = wall (Neumann)
# 2 = reservoir (Dirichlet)
bc_mass_lo = -1 -1
bc_mass_hi = -1 -1
109 changes: 109 additions & 0 deletions exec/reactDiff/inputs_paper_Lemarchand_3d
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# This inputs file is used for generating
# - Figure 8 (Section V.C)
# in Paper by C. Kim et al. "Stochastic simulation of reaction-diffusion
# systems: A fluctuating-hydrodynamics approach"
# J. Chem. Phys. 146, 124110 (2017).
# You can change some relevant parameters such as
# - initial_variance_mass: 0 (smooth initial condition) 1 (with fluctuations):
# - variance_coef_mass: 0 (deterministic diffusion) 1 (stochastic)
# - reaction_type: 0=deterministic; 1=CLE; 2=SSA; 3=tau leap
# and run this inputs file.

# Problem specification
prob_lo = 0.0 0.0 0.0 # physical lo coordinate
prob_hi = 512.0 512.0 512.0 # physical hi coordinate

# number of cells in domain and maximum number of cells in a box
n_cells = 256 256 256
max_grid_size = 256 256 256

# volume scale factor in 3D problems
cell_depth = 1000.

# Time-step control
fixed_dt = 0.25

# Controls for number of steps between actions
max_step = 800
plot_int = 10
struct_fact_int = -1
n_steps_skip = 200

seed = 1

nspecies = 2
nreaction = 4

prob_type = 5
perturb_width = 16. # scale factor for perturbed part in initial profile (for prob_type=4,5)
smoothing_width = 1. # scale factor for smoothing initial profile (for prob_type=4,5)

n_init_in_1 = 2.16245 1.35018
n_init_in_2 = 0. 10.

# 0=D+R (first-order splitting)
# 1=(1/2)R + D + (1/2)R (Strang option 1)
# 2=(1/2)D + R + (1/2)D (Strang option 2)
# -1=unsplit forward Euler
# -2=unsplit explicit midpoint
# -3=unsplit multinomial diffusion
# -4=unsplit implicit midpoint
temporal_integrator = -4

# only used for split schemes (temporal_integrator>=0)
# 0=explicit trapezoidal predictor/corrector
# 1=Crank-Nicolson semi-implicit
# 2=explicit midpoint
# 3=multinomial diffusion
# 4=forward Euler
reactDiff_diffusion_type = 4

# Fickian diffusion coeffs
D_Fick = 1. 10.

variance_coef_mass = 1.

# how to compute n on faces for stochastic weighting
# 1=arithmetic (with C0-Heaviside), 2=geometric, 3=harmonic
# 10=arithmetic average with discontinuous Heaviside function
# 11=arithmetic average with C1-smoothed Heaviside function
# 12=arithmetic average with C2-smoothed Heaviside function
avg_type = 1

# only used for split schemes (temporal_integrator>=0)
# 0=first-order (deterministic, tau leaping, CLE, or SSA)
# 1=second-order (determinisitc, tau leaping, or CLE only)
reactDiff_reaction_type = 0

# 0=deterministic; 1=CLE; 2=SSA; 3=tau leap
reaction_type = 3

# (1) A -> 0
# (2) 2A + B --> 3A
# (3) B --> 0
# (4) 0 --> B
stoich_1R = 1 0
stoich_1P = 0 0
stoich_2R = 2 1
stoich_2P = 3 0
stoich_3R = 0 1
stoich_3P = 0 0
stoich_4R = 0 0
stoich_4P = 0 1

# reaction rate constant for each reaction (assuming Law of Mass Action holds)
# using rate_multiplier, reaction rates can be changed by the same factor
# if include_discrete_LMA_correction, n^2 and n^3 in rate expressions become
# n*(n-1/dv) and n*(n-1/dv)*(n-2/dv).
rate_const = 4. 1.37 1. 10.
rate_multiplier = 0.1
include_discrete_LMA_correction = 1

# Boundary conditions
# ----------------------
# BC specifications:
# -1 = periodic
# 1 = wall (Neumann)
# 2 = reservoir (Dirichlet)
bc_mass_lo = -1 -1 -1
bc_mass_hi = -1 -1 -1
12 changes: 12 additions & 0 deletions src_chemistry/chemistry_functions.H
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@ void InitializeChemistryNamespace();
// used in compressible code only
void compute_compressible_chemistry_source_CLE(amrex::Real dt, amrex::Real dV,
MultiFab& prim, MultiFab& source, MultiFab& ranchem);

void ChemicalRates(const MultiFab& n_cc, MultiFab& chem_rate, const amrex::Geometry& geom, const amrex::Real& dt,
const MultiFab& n_interm, Vector<Real>& lin_comb_coef_in, Real volume_factor_in=1.);

AMREX_GPU_HOST_DEVICE void compute_reaction_rates(GpuArray<Real,MAX_SPECIES>& n_in,
GpuArray<Real,MAX_REACTION>& reaction_rates,
const amrex::Real& dv);

AMREX_GPU_HOST_DEVICE void sample_num_reactions(GpuArray<Real,MAX_SPECIES>& n_in,
GpuArray<Real,MAX_REACTION>& num_reactions,
GpuArray<Real,MAX_REACTION>& avg_num_reactions,
const amrex::RandomEngine& engine);
#endif
Loading
Loading