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

Add ML options to flame problem #370

Open
wants to merge 44 commits into
base: development
Choose a base branch
from
Open
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
4604a84
add option for Strang to save input & output reactions data in plotfi…
dwillcox May 19, 2021
79bb3dd
Merge remote-tracking branch 'upstream_don/save_reactions' into ML_save
Jun 21, 2021
eba157d
Store timestep information in time in plot file. Change output to sta…
Jun 21, 2021
218dbc0
Merge branch 'development' into ML_save
ajnonaka Sep 17, 2021
d0e277c
switch to aprox13 and comment out the actual_rhs_module
ajnonaka Sep 17, 2021
a8ed220
use fixed dt
ajnonaka Sep 17, 2021
1c3e449
500 time steps with fixed_dt=2.4e-8
ajnonaka Sep 21, 2021
7e6e0e6
Merge branch 'ML_save_ajn' of https://github.com/AMReX-Astro/MAESTROe…
ajnonaka Sep 21, 2021
0b04ebb
add option for Strang to save input & output reactions data in plotfi…
dwillcox May 19, 2021
d8b2692
Store timestep information in time in plot file. Change output to sta…
Jun 21, 2021
176b27c
save rhs into output plotfile for ML
dwillcox Jul 17, 2021
0823049
If we are using CXX_REACTIONS or CXX_EOS, then do not compile the For…
dwillcox Jul 17, 2021
bed351e
Merge branch 'development' into ML_save_ajn
doreenfan Oct 5, 2021
44bca35
Merge branch 'development' into ML_save_ajn
ajnonaka Oct 6, 2021
88b13b5
Merge branch 'ML_save_ajn' of https://github.com/AMReX-Astro/MAESTROe…
doreenfan Oct 12, 2021
70fec26
Merge branch 'development' into ML_save_ajn
doreenfan Nov 2, 2021
15a72b6
Add perturbations to mass fractions to generate varied input/output f…
doreenfan Nov 4, 2021
693d60c
Add density and temperature perturbations
doreenfan Nov 4, 2021
721e595
Change minimum istep to 1
doreenfan Nov 4, 2021
f57cdb0
tabs/whitespace
ajnonaka Nov 4, 2021
459348b
Perturb all trace species mass fractions instead of just one
doreenfan Nov 4, 2021
df1bec0
Merge branch 'ML_save_perturb' of https://github.com/AMReX-Astro/MAES…
doreenfan Nov 4, 2021
5bfd619
Change log base to 10
doreenfan Nov 4, 2021
13a578b
Merge branch 'development' into ML_save_perturb
doreenfan Jan 6, 2022
1f27a32
Change perturbation of density and temperature to much smaller values
doreenfan Jan 14, 2022
fb1f0e4
Remove perturbation limit of 10^-4
doreenfan Jan 15, 2022
692320f
Revert "Change perturbation of density and temperature to much smalle…
doreenfan Jan 19, 2022
c3eec05
Add perturbations for ignition_simple network
doreenfan Jan 20, 2022
2f7d302
Merge branch 'development' into ML_save_perturb
doreenfan Jan 28, 2022
abc553e
Add ML option to evaluate ignition_simple network
doreenfan Feb 1, 2022
57019e1
Change perturbation to 10% of smaller mass fraction
doreenfan Feb 25, 2022
ec6ad18
Change ML model to use only 2 species (C12, Mg24)
doreenfan Feb 25, 2022
5d4455a
Merge branch 'development' into add_pytorch_model_igsimple
doreenfan Mar 2, 2022
cb83a74
Generalize random perturbation when generating training data
doreenfan Mar 3, 2022
fa70af9
Use ML model and write react data plotfiles starting at step 1
doreenfan Mar 3, 2022
0f1b284
Add ML capabilities to reacting_bubble problem
doreenfan Mar 3, 2022
fad7ca4
Merge branch 'development' into add_pytorch_model_igsimple
doreenfan May 5, 2022
28716cc
Fix CUDA compilation
WeiqunZhang Jun 29, 2022
dac5009
Merge branch 'development' into add_pytorch_model_igsimple
doreenfan Mar 20, 2023
b31f848
Add README containing instructions on how to run an ML problem.
doreenfan Mar 20, 2023
345f943
Revert some non-ML problems back
doreenfan Mar 20, 2023
8f009e9
Update README to include flame_ml problem description
doreenfan Mar 20, 2023
81618fa
Update defines to include ML options in CI workflow
doreenfan Mar 20, 2023
8b1ee81
Merge branch 'development' into add_pytorch_model_igsimple
zingale Apr 13, 2023
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
2 changes: 2 additions & 0 deletions .github/workflows/good_defines.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ AMREX_SPACEDIM
AMREX_USE_CUDA
AMREX_USE_GPU
DO_PROBLEM_POST_TIMESTEP
ML
NAUX_NET
AUX_THERMO
ROTATION
SDC
_ML_LIB
_OPENMP
__cplusplus
38 changes: 38 additions & 0 deletions Exec/Make.Maestro
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ BL_NO_FORT ?= TRUE
# Require C++17
CXXSTD := c++17

# default is to not compile with ML (PyTorch)
USE_ML ?= FALSE

# Check to make sure that Microphysics actually exists,
# using an arbitrary file that must exist to check.
# Throw an error if we don't have Microphysics.
Expand All @@ -49,6 +52,10 @@ ifeq ($(USE_SDC), TRUE)
USERSuffix = .SDC
endif

ifeq ($(USE_ML), TRUE)
USERSuffix = .ML
endif

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

MAESTROEX_AUTO_SOURCE_DIR := $(TmpBuildDir)/maestroex_sources/$(optionsSuffix).EXE
Expand Down Expand Up @@ -143,6 +150,37 @@ Blocs += $(foreach dir, $(EXTERN_CORE), $(dir))
# external libraries
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# PyTorch
#------------------------------------------------------------------------------

# Torch directories -- note the Make.package for these adds these
# directories into INCLUDE_LOCATIONS and LIBRARY_LOCATIONS for us,
# so we don't need to do it here
ifeq ($(USE_ML), TRUE)
PYTORCH_ROOT := $(TOP)/external/libtorch

TORCH_LIBPATH = $(PYTORCH_ROOT)/lib

ifeq ($(USE_CUDA),TRUE)
TORCH_LIBS = -ltorch -ltorch_cpu -lc10 -lc10_cuda -lcuda # -lcaffe2 -lcaffe2_gpu
else
TORCH_LIBS = -ltorch -ltorch_cpu -lc10 # -lcaffe2
endif

INCLUDE_LOCATIONS += $(PYTORCH_ROOT)/include \
$(PYTORCH_ROOT)/include/torch/csrc/api/include
LIBRARY_LOCATIONS += $(TORCH_LIBPATH)

DEFINES += -DML -D_GLIBCXX_USE_CXX11_ABI=1

ifeq ($(USE_CUDA), TRUE)
LDFLAGS += -Xlinker '--no-as-needed,-rpath $(TORCH_LIBPATH) $(TORCH_LIBS)'
else
LDFLAGS += -Wl,--no-as-needed,-rpath=$(TORCH_LIBPATH) $(TORCH_LIBS)
endif
endif

#------------------------------------------------------------------------------
# include all of the necessary directories
#------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions Exec/science/README
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ flame/
the SNe code show that SDC can overcome these problems.


flame_ml/

The same combustion-mode problem as in flame/ but using ML model to
replace the reaction kernel of the solver.

sub_chandra/

Surpise! We're modelling convection. This time in 3D spherical
Expand Down
29 changes: 29 additions & 0 deletions Exec/science/flame_ml/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
DEBUG = FALSE
DIM = 2
COMP = gnu
USE_MPI = TRUE
USE_OMP = FALSE
USE_REACT = TRUE
USE_ML = TRUE

TINY_PROFILE = FALSE
PROFILE = FALSE # TRUE overrides TINY_PROFILE


# define the location of the MAESTROEX home directory
MAESTROEX_HOME := ../../..


# Set the EOS, conductivity, and network directories
# We first check if these exist in $(MAESTROEX_HOME)/Microphysics/(EOS/conductivity/networks)
# If not we use the version in $(MICROPHYSICS_HOME)/Microphysics/(EOS/conductivity/networks)
EOS_DIR := helmholtz
CONDUCTIVITY_DIR := stellar
NETWORK_DIR := ignition_simple
INTEGRATOR_DIR := VODE

Bpack := ./Make.package
Blocs := .
PROBIN_PARAMETER_DIRS := .

include $(MAESTROEX_HOME)/Exec/Make.Maestro
259 changes: 259 additions & 0 deletions Exec/science/flame_ml/MaestroBCFill.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@

#include <Maestro.H>
#include <Maestro_F.H>

#include <MaestroInletBCs.H>

using namespace amrex;
using namespace InletBCs;

void Maestro::ScalarFill(const Array4<Real>& scal, const Box& bx,
const Box& domainBox, const Real* dx, const BCRec bcs,
const Real* gridlo, const int comp) {
// timer for profiling
BL_PROFILE_VAR("Maestro::ScalarFill()", ScalarFill);

fab_filcc(bx, scal, 1, domainBox, dx, gridlo, &bcs);

FillExtBC(scal, bx, domainBox, dx, bcs, comp, false);
}

void Maestro::VelFill(const Array4<Real>& vel, const Box& bx,
const Box& domainBox, const Real* dx, const BCRec bcs,
const Real* gridlo, const int comp) {
// timer for profiling
BL_PROFILE_VAR("Maestro::VelFill()", VelFill);

fab_filcc(bx, vel, 1, domainBox, dx, gridlo, &bcs);

FillExtBC(vel, bx, domainBox, dx, bcs, comp, true);
}

void Maestro::FillExtBC(const Array4<Real>& q, const Box& bx,
const Box& domainBox, const Real* dx, const BCRec bcs,
const int comp, const bool is_vel) {
// timer for profiling
BL_PROFILE_VAR("Maestro::FillExtBC()", FillExtBC);

// do nothing if there are no exterior boundaries
bool found_ext_boundary = false;
for (auto i = 0; i < AMREX_SPACEDIM; ++i) {
if (bcs.lo(i) == BCType::ext_dir || bcs.hi(i) == BCType::ext_dir) {
found_ext_boundary = true;
break;
}
}
if (!found_ext_boundary) return;

// get parameters for EXT_DIR bcs
const Real INLET_RHO_l = INLET_RHO;
const Real INLET_RHOH_l = INLET_RHOH;
const Real INLET_TEMP_l = INLET_TEMP;
RealVector INLET_RHOX_l(NumSpec);
for (int i = 0; i < NumSpec; ++i) INLET_RHOX_l[i] = INLET_RHOX[i];
const Real INLET_VEL_l = INLET_VEL;

const auto domlo = domainBox.loVect3d();
const auto domhi = domainBox.hiVect3d();

const auto lo = bx.loVect3d();
const auto hi = bx.hiVect3d();

if (lo[0] < domlo[0]) {
auto imax = domlo[0];

if (bcs.lo(0) == BCType::ext_dir) {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (i < imax) {
q(i, j, k) = 1.0;
}
});
Gpu::synchronize();
}
}

if (hi[0] > domhi[0]) {
auto imin = domhi[0];

if (bcs.hi(0) == BCType::ext_dir) {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (i > imin) {
q(i, j, k) = 1.0;
}
});
Gpu::synchronize();
}
}

if (lo[1] < domlo[1]) {
auto jmax = domlo[1];

if (bcs.lo(1) == BCType::ext_dir) {
if (is_vel) {
if (comp == 0) {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j < jmax) {
q(i, j, k) = 0.0;
}
});
} else if (comp == 1) {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j < jmax) {
q(i, j, k) = INLET_VEL_l;
}
});
}
Gpu::synchronize();
} else {
if (INLET_VEL != 0.0) {
if (comp == Rho) {
ParallelFor(bx,
[=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j < jmax) {
q(i, j, k) = INLET_RHO_l;
}
});
} else if (comp == RhoH) {
ParallelFor(bx,
[=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j < jmax) {
q(i, j, k) = INLET_RHOH_l;
}
});
} else if (comp >= FirstSpec &&
comp < FirstSpec + NumSpec) {
Real* AMREX_RESTRICT INLET_RHOX_p =
INLET_RHOX.dataPtr();
ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j < jmax) {
q(i, j, k) = INLET_RHOX_p[comp - FirstSpec];
}
});
} else if (comp == Temp) {
ParallelFor(bx,
[=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j < jmax) {
q(i, j, k) = INLET_TEMP_l;
}
});
} else {
ParallelFor(bx,
[=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j < jmax) {
q(i, j, k) = 0.0;
}
});
}
} else {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j < jmax) {
q(i, j, k) = 0.0;
}
});
}
Gpu::synchronize();
} // end if is_vel
}
}

if (hi[1] > domhi[1]) {
auto jmin = domhi[1];

if (bcs.hi(1) == BCType::ext_dir) {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (j > jmin) {
q(i, j, k) = 1.0;
}
});
}
Gpu::synchronize();
}

#if AMREX_SPACEDIM == 3

if (lo[2] < domlo[2]) {
auto kmax = domlo[2];

if (bcs.lo(2) == BCType::ext_dir) {
if (is_vel) {
if (comp == 0 || comp == 1) {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k < kmax) {
q(i, j, k) = 0.0;
}
});
} else if (comp == 2) {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k < kmax) {
q(i, j, k) = INLET_VEL_l;
}
});
}
} else {
if (INLET_VEL != 0.0) {
if (comp == Rho) {
ParallelFor(bx,
[=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k < kmax) {
q(i, j, k) = INLET_RHO_l;
}
});
} else if (comp == RhoH) {
ParallelFor(bx,
[=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k < kmax) {
q(i, j, k) = INLET_RHOH_l;
}
});
} else if (comp >= FirstSpec &&
comp < FirstSpec + NumSpec) {
Real* AMREX_RESTRICT INLET_RHOX_p =
INLET_RHOX.dataPtr();
ParallelFor(
bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k < kmax) {
q(i, j, k) = INLET_RHOX_p[comp - FirstSpec];
}
});
} else if (comp == Temp) {
ParallelFor(bx,
[=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k < kmax) {
q(i, j, k) = INLET_TEMP_l;
}
});
} else {
ParallelFor(bx,
[=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k < kmax) {
q(i, j, k) = 0.0;
}
});
}
} else {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k < kmax) {
q(i, j, k) = 0.0;
}
});
}
} // end if is_vel
Gpu::synchronize();
}
}

if (hi[2] > domhi[2]) {
auto kmin = domhi[2];

if (bcs.hi(2) == BCType::ext_dir) {
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
if (k > kmin) {
q(i, j, k) = 0.0;
}
});
}
Gpu::synchronize();
}
#endif
}
Loading