aboutsummaryrefslogtreecommitdiff
path: root/Source/Initialization/CustomDensityProb.H
diff options
context:
space:
mode:
authorGravatar Remi Lehe <remi.lehe@normalesup.org> 2019-08-19 15:34:52 -0700
committerGravatar Remi Lehe <remi.lehe@normalesup.org> 2019-08-19 15:34:52 -0700
commit863ff56254f5cc93e7030fa0c35481db42aabe2c (patch)
treec45e3cf99053c15a8a3e784bfd45a11fffc63852 /Source/Initialization/CustomDensityProb.H
parent9409e1b12c78442323c7181417c811b262d4a694 (diff)
parentc023286720c7ae8aa2913efc461240a81e8b2bd9 (diff)
downloadWarpX-863ff56254f5cc93e7030fa0c35481db42aabe2c.tar.gz
WarpX-863ff56254f5cc93e7030fa0c35481db42aabe2c.tar.zst
WarpX-863ff56254f5cc93e7030fa0c35481db42aabe2c.zip
Merge branch 'dev' into select_fields_in_tests
Diffstat (limited to 'Source/Initialization/CustomDensityProb.H')
-rw-r--r--Source/Initialization/CustomDensityProb.H49
1 files changed, 49 insertions, 0 deletions
diff --git a/Source/Initialization/CustomDensityProb.H b/Source/Initialization/CustomDensityProb.H
new file mode 100644
index 000000000..b00830e6c
--- /dev/null
+++ b/Source/Initialization/CustomDensityProb.H
@@ -0,0 +1,49 @@
+#ifndef CUSTOM_DENSITY_PROB_H_
+#define CUSTOM_DENSITY_PROB_H_
+
+#include <AMReX_ParmParse.H>
+#include <AMReX_Arena.H>
+#include <AMReX_Gpu.H>
+#include <AMReX_Dim3.H>
+
+// An example of Custom Density Profile
+
+// struct whose getDensity returns density at a given position computed from
+// a custom function, with runtime input parameters.
+struct InjectorDensityCustom
+{
+ InjectorDensityCustom (std::string const& species_name)
+ : p(nullptr)
+ {
+ // Read parameters for custom density profile from file, and
+ // store them in managed memory.
+ amrex::ParmParse pp(species_name);
+ std::vector<amrex::Real> v;
+ pp.getarr("custom_profile_params", v);
+ p = static_cast<amrex::Real*>
+ (amrex::The_Managed_Arena()->alloc(sizeof(amrex::Real)*v.size()));
+ for (int i = 0; i < static_cast<int>(v.size()); ++i) {
+ p[i] = v[i];
+ }
+ }
+
+ // Return density at given position, using user-defined parameters
+ // stored in p.
+ AMREX_GPU_HOST_DEVICE
+ amrex::Real
+ getDensity (amrex::Real, amrex::Real, amrex::Real) const noexcept
+ {
+ return p[0];
+ }
+
+ // Note that we are not allowed to have non-trivial destructor.
+ // So we rely on clear() to free memory.
+ void clear () {
+ amrex::The_Managed_Arena()->free(p);
+ }
+
+private:
+ amrex::Real* p;
+};
+
+#endif