-
Notifications
You must be signed in to change notification settings - Fork 51
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
Move turb inflow helpers from PeleLMeX and add documentation #489
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cab4bc0
Bring turbulent inflow generation stuff from PeleLMeX
baperry2 9f2e720
some progress on documentation
baperry2 0dad956
more progress on turbinflow documentation
baperry2 4e7da6e
add option for size of wavenumber space in turbulence generation
baperry2 73f9f12
make multiple turbinflows additive rather than replacing each other
baperry2 e5b11b4
Merge branch 'development' into turb-inflow
baperry2 87a6245
Merge branch 'turb-inflow' of github.com:baperry2/PelePhysics into tu…
baperry2 6b232c5
fix typo and math format
baperry2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
.. highlight:: rst | ||
|
||
.. _sec:Support: | ||
|
||
******* | ||
Support | ||
******* | ||
|
||
The main purpose of PelePhysics is to contain a library of routines for shared use by the other Pele codes, | ||
which are contained in the ``Source`` directory. In the ``Support`` directory, PelePhysics also contains | ||
several stand-alone tools and scripts that are used to generate data and source code that support these purposes. | ||
These tools include: | ||
|
||
* ``ceptr``: Chemistry Evaluation for Pele Through Recasting, machine generation of mechanism code | ||
* ``TurbFileHIT``: Isotropic turbulence initial conditions and inflows | ||
* ``MechanismPAH``: Append PAH module to chemical mechanism data | ||
* ``liquidProp``: Fits to NIST data for condensed phase species | ||
|
||
ceptr | ||
===== | ||
|
||
CEPTR is used to generate the C++ mechanism files from Cantera-format mechanism data for all the chemical | ||
mechanisms in the ``Mechanisms/`` directory. For a full description of CEPTR and how to use it, see the | ||
:ref:`CEPTR subsection <sec:ceptr>` of the Chemistry section of this documentation. | ||
|
||
.. _sec_turbfile: | ||
|
||
TurbFileHIT | ||
=========== | ||
|
||
This support code contains two separate pieces: a python script that generates a synthetic 3D isotropic turbulence velocity field and | ||
an AMReX-based C++ code that converts that data into a format that can be used by the PelePhysics :ref:`TurbInflow Utility <sec_turbinflow>` | ||
to provide turbulent inflow boundary conditions in either PeleC or PeleLMeX. | ||
|
||
Generating an HIT File | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The ``gen_hit_ic.py`` python script creates a synthetic isotropic turbulence velocity field based on the methodology described | ||
in the appendix of `Johnsen et al. (2010) J. Comp Phys. <http://dx.doi.org/10.1016/j.jcp.2009.10.028>`_. The resulting velocity | ||
field is stored in files with names following the pattern ``hit_ic_k0_N.dat``, where ``k0`` is the most | ||
energetic wave number and ``N`` is the size of the grid. The initial | ||
condition for a grid of size N^3 is generated as follows: | ||
|
||
1. velocity fluctuations generated on a 512^3 grid in wavenumber space | ||
2. Coefficients associated to wavenumbers that cannot be represented on the desired grid are set to 0 (sharp wavenumber cutoff) | ||
3. inverse Fourier transform of the velocity fluctuations (512^3 grid) | ||
4. velocity fluctuations resampled on the desired grid (N^3) | ||
|
||
This script accepts the following options: :: | ||
|
||
./gen_hit_ic.py --help | ||
usage: gen_hit_ic.py [-h] [-k0 K0] [-N N] [-Nk NK] [-s SEED] [-p] | ||
|
||
Generate the velocity fluctuations for the HIT IC | ||
|
||
options: | ||
-h, --help show this help message and exit | ||
-k0 K0 Wave number containing highest energy | ||
-N N Resolution | ||
-Nk NK Resolution in wavenumber space for intermediate step | ||
-s SEED, --seed SEED Random number generator seed | ||
-p, --plot Save a plot of the x-velocity | ||
|
||
Generating an initial condition file is as easy as: :: | ||
|
||
./gen_hit_ic.py -N 16 | ||
|
||
.. Note:: | ||
|
||
This script utilizes standard python libraries such as SciPy and Matplotlib. If you'd like to ensure that you are using appropriate | ||
versions of the dependencies, follow the :ref:`CEPTR instructions <sec_ceptr_software>` for setting up ``poetry`` to manage | ||
dependencies, then run the script using ``poetry run -C ../ceptr/ python gen_hit_ic.py -N 16``. | ||
|
||
Generating Inflow Files | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The ``TurbFileHIT`` directory also contains C++ source code for a small program that reads the ``.dat`` files created using the python script | ||
above and saves them as AMReX data structures that can be read by the TurbInflow utility, which uses Taylor's hypothesis to provide | ||
temporally varying boundary data by marching through the 3rd dimension of the HIT files at a constant velocity. | ||
|
||
Build options can be specified in the ``GNUmakefile``. Notably, if you did not recursively clone PelePhysics with the AMReX submodule, you | ||
will need to specify a path to AMReX (``AMREX_HOME``). But in most cases, you should be able to directly build the utility simply by running: :: | ||
|
||
make -j | ||
|
||
Then run the resulting executable using the provided input file: :: | ||
|
||
./PeleTurb3d.gnu.ex input | ||
|
||
Adjust the ``hit_file`` and ``input_ncell`` parameters in the input file to match the file name and number of cells from the previous step. | ||
The ``urms0`` parameter is a scale factor to rescale the velocity fluctuations. ``TurbFile`` specified the name of the directory where the | ||
output files will be saved. After successful execution, the output directory should contain two files: ``HDR`` and ``DAT``. | ||
|
||
|
||
MechanismPAH | ||
============ | ||
|
||
This functionality takes an existing set of mechanism, transport, and thermodynamic data files in Chemkin format and attempts to add a PAH module to it. It checks if any species are duplicated by comparing the atomic composition and the enthalpy curves. It check if any reactions are duplicated. If any species or reactions are duplicated, these are skipped. Once the new yaml file is created, ignition delay time at 1 and 20 atm is compared between the original and new mechanism to see what impact the PAH module has on the mechanism. Plot files of these values are created for you to decide if the differences are significant. | ||
|
||
Usage | ||
~~~~~ | ||
|
||
You need to have the NumPy, Cantera, and MatPlotLib python modules. In order to run, use the following :: | ||
|
||
python addPAHmech.py --mech origmech.inp --transport origtrans.dat --thermo origthermo.dat --fuelname NC10H22 | ||
|
||
where ``origmech.inp``, ``origthermo.dat``, and ``origtrans.dat`` are the initial mechanism, thermodynamic, | ||
and transport files to have the PAH module amended to. | ||
|
||
Disclaimer | ||
~~~~~~~~~~ | ||
|
||
The resulting IDT should be studied to determine if the new mechanism is now compromised with the addition of the PAH module. This is left up to the user's discretion. This has only been tested on a few mechanisms and might have bugs. | ||
|
||
liquidProp | ||
========== | ||
|
||
This is a python script that reads in an NIST property file for a condensed or saturated phase of a species. | ||
Files for rho, mu, and lambda (thermal conductivity) should be provided in a single directory and | ||
named ``rho.dat``, ``mu.dat``, and ``lambda.dat``. The usage for this script is:: | ||
|
||
$ python propcoeff.py -h | ||
|
||
usage: propcoeff.py [-h] --species NC10H22 [--file_loc FILE_LOC] [--units UNITS] [--vars VARS [VARS ...]] | ||
|
||
options: | ||
-h, --help show this help message and exit | ||
--species NC10H22 Species name | ||
--file_loc FILE_LOC Location of data files. Files should be called rho.dat, mu.dat, and/or lambda.dat | ||
--units UNITS Units, either MKS or CGS | ||
--vars VARS [VARS ...] | ||
Which variables to fit, ex. mu lambda rho |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
AMREX_HOME ?= ../../Submodules/amrex | ||
|
||
# Local | ||
EBASE = PeleTurb | ||
|
||
# AMReX | ||
DIM = 3 | ||
DEBUG = FALSE | ||
PRECISION = DOUBLE | ||
TINY_PROFILE = FALSE | ||
|
||
# Compilation | ||
COMP = gnu | ||
USE_MPI = FALSE | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.defs | ||
|
||
Bpack += ./Make.package | ||
|
||
Pdirs := Base Boundary | ||
Bpack += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)/Make.package) | ||
Blocs += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)) | ||
include $(Bpack) | ||
INCLUDE_LOCATIONS += $(Blocs) | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef HITDATA_H | ||
#define HITDATA_H | ||
|
||
#include <AMReX_REAL.H> | ||
#include <AMReX_GpuMemory.H> | ||
|
||
struct HITData | ||
{ | ||
int input_ncell = 0; | ||
amrex::Real urms0 = 1.0; | ||
amrex::Real uin_norm = 1.0; | ||
|
||
amrex::Real Linput = 0.0; | ||
|
||
amrex::Real* d_uinput = nullptr; | ||
amrex::Real* d_vinput = nullptr; | ||
amrex::Real* d_winput = nullptr; | ||
amrex::Real* d_xarray = nullptr; | ||
amrex::Real* d_xdiff = nullptr; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CEXE_headers += HITData.H main_K.H Utilities.H | ||
CEXE_sources += main.cpp Utilities.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
This code enable generating synthetic HIT files usable with PelePhysics | ||
TurbInflow capabilities. | ||
|
||
First generate the data using the python script: | ||
./gen_hit_ic.py -k0 4 -N 128 | ||
|
||
To generate a synthetic HIT field discretized with 128 cells and most energetic eddies | ||
at a wave number of 4. | ||
|
||
Then compile the C++ executable (AMReX needed): | ||
make | ||
|
||
And the executable to generature the turbfile (adapt the input file to your needs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generature -> generate |
||
./PeleTurb3d.gnu.ex input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef _UTILITIES_H | ||
#define _UTILITIES_H | ||
|
||
#include <AMReX_FArrayBox.H> | ||
|
||
AMREX_FORCE_INLINE | ||
std::string | ||
read_file(std::ifstream& in) | ||
{ | ||
return static_cast<std::stringstream const&>( | ||
std::stringstream() << in.rdbuf()) | ||
.str(); | ||
} | ||
|
||
void read_binary( | ||
const std::string& iname, | ||
const size_t nx, | ||
const size_t ny, | ||
const size_t nz, | ||
const size_t ncol, | ||
amrex::Vector<amrex::Real>& data); | ||
|
||
void read_csv( | ||
const std::string& iname, | ||
const size_t nx, | ||
const size_t ny, | ||
const size_t nz, | ||
amrex::Vector<amrex::Real>& data); | ||
|
||
// ----------------------------------------------------------- | ||
// Search for the closest index in an array to a given value | ||
// using the bisection technique. | ||
// INPUTS/OUTPUTS: | ||
// xtable(0:n-1) => array to search in (ascending order) | ||
// n => array size | ||
// x => x location | ||
// idxlo <=> output st. xtable(idxlo) <= x < xtable(idxlo+1) | ||
// ----------------------------------------------------------- | ||
AMREX_GPU_DEVICE | ||
AMREX_FORCE_INLINE | ||
void | ||
locate(const amrex::Real* xtable, const int n, const amrex::Real& x, int& idxlo) | ||
{ | ||
// If x is out of bounds, return boundary index | ||
if (x >= xtable[n - 1]) { | ||
idxlo = n - 1; | ||
return; | ||
} | ||
if (x <= xtable[0]) { | ||
idxlo = 0; | ||
return; | ||
} | ||
|
||
// Do the bisection | ||
idxlo = 0; | ||
int idxhi = n - 1; | ||
bool notdone = true; | ||
while (notdone) { | ||
if (idxhi - idxlo <= 1) { | ||
notdone = false; | ||
} else { | ||
const int idxmid = (idxhi + idxlo) / 2; | ||
if (x >= xtable[idxmid]) { | ||
idxlo = idxmid; | ||
} else { | ||
idxhi = idxmid; | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can
math
the N^3 and other such math expressions below