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 "Utils/WarpXUtil.H"
11 
12 #include <AMReX_Arena.H>
13 #include <AMReX_Dim3.H>
14 #include <AMReX_Gpu.H>
15 #include <AMReX_ParmParse.H>
16 
17 // An example of Custom Density Profile
18 
19 // struct whose getDensity returns density at a given position computed from
20 // a custom function, with runtime input parameters.
22 {
23  InjectorDensityCustom (std::string const& species_name)
24  {
25  // Read parameters for custom density profile from file
26  amrex::ParmParse pp_species_name(species_name);
27  std::vector<amrex::Real> v;
28  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(v.size() <= 6,
29  "Too many parameters for InjectorDensityCustom");
30  getArrWithParser(pp_species_name, "custom_profile_params", v);
31  for (int i = 0; i < static_cast<int>(v.size()); ++i) {
32  p[i] = v[i];
33  }
34  }
35 
36  // Return density at given position, using user-defined parameters
37  // stored in p.
38  AMREX_GPU_HOST_DEVICE
39  amrex::Real
40  getDensity (amrex::Real, amrex::Real, amrex::Real) const noexcept
41  {
42  return p[0];
43  }
44 
45  // Note that we are not allowed to have non-trivial destructor.
46  // So we rely on clear() to free memory if needed.
47  void clear () {}
48 
49 private:
50  amrex::GpuArray<amrex::Real,6> p;
51 };
52 
53 #endif
void clear()
Definition: CustomDensityProb.H:47
void getArrWithParser(const amrex::ParmParse &a_pp, char const *const str, std::vector< amrex::Real > &val)
Definition: WarpXUtil.cpp:426
InjectorDensityCustom(std::string const &species_name)
Definition: CustomDensityProb.H:23
amrex::GpuArray< amrex::Real, 6 > p
Definition: CustomDensityProb.H:50
Definition: CustomDensityProb.H:21
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:40