Hipace
GetInitialDensity.H
Go to the documentation of this file.
1 /* Copyright 2020
2  *
3  * This file is part of HiPACE++.
4  *
5  * Authors: MaxThevenet, Severin Diederichs
6  * License: BSD-3-Clause-LBNL
7  */
8 #ifndef GETINTIALDENSITY_H_
9 #define GETINTIALDENSITY_H_
10 
11 #include <AMReX.H>
12 #include <AMReX_REAL.H>
13 #include <AMReX_RealVect.H>
14 #include "utils/Parser.H"
15 
18 
22 {
25  GetInitialDensity () = default;
26  GetInitialDensity (const std::string& name, amrex::Parser& parser);
27 
34  amrex::Real operator() (const amrex::Real x, const amrex::Real y, const amrex::Real z) const
35  {
36  using namespace amrex::literals;
37  amrex::Real density = 0._rt;
39  amrex::Real delta_x = (x - m_position_mean[0]) / m_position_std[0];
40  amrex::Real delta_y = (y - m_position_mean[1]) / m_position_std[1];
41  amrex::Real delta_z = (z - m_position_mean[2]) / m_position_std[2];
42  density = m_density * exp( -0.5_rt*delta_x*delta_x )
43  * exp( -0.5_rt*delta_y*delta_y )
44  * exp( -0.5_rt*delta_z*delta_z );
45  } else if (m_profile == BeamProfileType::Flattop) {
46  density = m_density;
47  } else if (m_profile == BeamProfileType::Parsed) {
48  density = m_density_func(x, y, z);
49  }
50  return density;
51  }
52  amrex::RealVect m_position_mean {0.,0.,0.}; /* mean in case of a Gaussian density distribution. */
53  amrex::RealVect m_position_std {0.,0.,0.}; /* rms standard deviation in case of a Gaussian density distribution */
54  BeamProfileType m_profile; /* beam profile type, e.g. BeamProfileType::Flattop or BeamProfileType::Gaussian*/
55  amrex::Real m_density;
57 };
58 
59 #endif // GETINTIALDENSITY_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
BeamProfileType
Beam profile type, currently only Gaussian or Flattop or Parsed.
Definition: GetInitialDensity.H:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > exp(const GpuComplex< T > &a_z) noexcept
parser
Definition: checksumAPI.py:104
Functor gets the initial density for beam particles for a given position.
Definition: GetInitialDensity.H:22
amrex::RealVect m_position_std
Definition: GetInitialDensity.H:53
GetInitialDensity()=default
BeamProfileType m_profile
Definition: GetInitialDensity.H:54
amrex::Real m_density
Definition: GetInitialDensity.H:55
amrex::ParserExecutor< 3 > m_density_func
Definition: GetInitialDensity.H:56
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real operator()(const amrex::Real x, const amrex::Real y, const amrex::Real z) const
returns the density for a beam particle at a given position
Definition: GetInitialDensity.H:34
amrex::RealVect m_position_mean
Definition: GetInitialDensity.H:52