WarpX
CustomDensityProb.H
Go to the documentation of this file.
1 /* Copyright 2019 Maxence Thevenet, Weiqun Zhang
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef CUSTOM_DENSITY_PROB_H_
8 #define CUSTOM_DENSITY_PROB_H_
9 
10 #include <AMReX_ParmParse.H>
11 #include <AMReX_Arena.H>
12 #include <AMReX_Gpu.H>
13 #include <AMReX_Dim3.H>
14 
15 // An example of Custom Density Profile
16 
17 // struct whose getDensity returns density at a given position computed from
18 // a custom function, with runtime input parameters.
20 {
21  InjectorDensityCustom (std::string const& species_name)
22  {
23  // Read parameters for custom density profile from file
24  amrex::ParmParse pp(species_name);
25  std::vector<amrex::Real> v;
26  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(v.size() <= 6,
27  "Too many parameters for InjectorDensityCustom");
28  pp.getarr("custom_profile_params", v);
29  for (int i = 0; i < static_cast<int>(v.size()); ++i) {
30  p[i] = v[i];
31  }
32  }
33 
34  // Return density at given position, using user-defined parameters
35  // stored in p.
36  AMREX_GPU_HOST_DEVICE
37  amrex::Real
38  getDensity (amrex::Real, amrex::Real, amrex::Real) const noexcept
39  {
40  return p[0];
41  }
42 
43  // Note that we are not allowed to have non-trivial destructor.
44  // So we rely on clear() to free memory if needed.
45  void clear () {}
46 
47 private:
48  amrex::GpuArray<amrex::Real,6> p;
49 };
50 
51 #endif
void clear()
Definition: CustomDensityProb.H:45
InjectorDensityCustom(std::string const &species_name)
Definition: CustomDensityProb.H:21
amrex::GpuArray< amrex::Real, 6 > p
Definition: CustomDensityProb.H:48
Definition: CustomDensityProb.H:19
i
Definition: check_interp_points_and_weights.py:171
AMREX_GPU_HOST_DEVICE amrex::Real getDensity(amrex::Real, amrex::Real, amrex::Real) const noexcept
Definition: CustomDensityProb.H:38