1#ifndef IPPL_LANDAU_DAMPING_MANAGER_H
2#define IPPL_LANDAU_DAMPING_MANAGER_H
22 KOKKOS_INLINE_FUNCTION
double operator()(
double x,
unsigned int d,
23 const double* params_p)
const {
25 + (params_p[d * 2 + 0] / params_p[d * 2 + 1])
26 * Kokkos::sin(params_p[d * 2 + 1] * x);
31 KOKKOS_INLINE_FUNCTION
double operator()(
double x,
unsigned int d,
32 double const* params_p)
const {
33 return 1.0 + params_p[d * 2 + 0] * Kokkos::cos(params_p[d * 2 + 1] * x);
38 KOKKOS_INLINE_FUNCTION
double operator()(
double u,
unsigned int d,
39 double const* params_p)
const {
40 return u + params_p[d] * 0.;
45template <
typename T,
unsigned Dim>
54 std::string& solver_, std::string& stepMethod_)
58 std::string& solver_, std::string& stepMethod_,
59 std::vector<std::string> preconditioner_params_)
61 preconditioner_params_) {}
68 const double pi = Kokkos::numbers::pi_v<T>;
72 "Open boundaries solver incompatible with this simulation!");
75 for (
unsigned i = 0; i <
Dim; i++) {
88 std::reduce(this->
rmax_m.begin(), this->rmax_m.end(), -1., std::multiplies<double>());
90 this->
dt_m = std::min(.05, 0.5 * *std::min_element(this->
hr_m.begin(), this->hr_m.end()));
94 m <<
"Discretization:" <<
endl
104 this->
fcontainer_m->getMesh(), this->fcontainer_m->getFL()));
111 &this->fcontainer_m->getPhi(), this->preconditioner_params_m));
115 &this->fcontainer_m->getPhi()));
151 Inform m(
"Initialize Particles");
157 double parR[2 *
Dim];
158 for (
unsigned int i = 0; i <
Dim; i++) {
160 parR[i * 2 + 1] = this->
kw_m[i];
169 m <<
"Starting first repartition" <<
endl;
173 const int nghost = this->
fcontainer_m->getRho().getNghost();
178 "Assign initial rho based on PDF",
180 KOKKOS_LAMBDA(
const index_array_type& args) {
186 ippl::apply(rhoview, args) = distR.getFullPdf(xvec);
206 Kokkos::Random_XorShift64_Pool<> rand_pool64((
size_type)(seed + 100 *
ippl::Comm->rank()));
213 samplingR_t samplingR(distR, rmax, rmin, rlayout, totalP);
214 size_type nlocal = samplingR.getLocalSamplesNum();
219 samplingR.generate(*R, rand_pool64);
225 for (
unsigned int i = 0; i <
Dim; i++) {
236 m <<
"particles created and initial conditions assigned " <<
endl;
258 double dt = this->
dt_m;
259 std::shared_ptr<ParticleContainer_t> pc = this->
pcontainer_m;
260 std::shared_ptr<FieldContainer_t> fc = this->
fcontainer_m;
263 pc->P = pc->P - 0.5 * dt * pc->E;
268 pc->R = pc->R + dt * pc->P;
278 bool isFirstRepartition =
false;
281 auto* mesh = &fc->getRho().get_mesh();
282 auto* FL = &fc->getFL();
300 pc->P = pc->P - 0.5 * dt * pc->E;
311 template <
typename View>
313 const int nghostE = this->
fcontainer_m->getE().getNghost();
316 double localEx2 = 0, localExNorm = 0;
319 KOKKOS_LAMBDA(
const index_array_type& args,
double& E2,
double& ENorm) {
323 double e2 = Kokkos::pow(val, 2);
326 double norm = Kokkos::fabs(
ippl::apply(Eview, args)[0]);
331 Kokkos::Sum<double>(localEx2), Kokkos::Max<double>(localExNorm));
333 double globaltemp = 0.0;
334 ippl::Comm->reduce(localEx2, globaltemp, 1, std::plus<double>());
337 std::reduce(this->
fcontainer_m->getHr().begin(), this->fcontainer_m->getHr().end(),
338 globaltemp, std::multiplies<double>());
341 ippl::Comm->reduce(localExNorm, ExAmp, 1, std::greater<double>());
344 std::stringstream fname;
345 fname <<
"data/FieldLandau_";
351 csvout.
setf(std::ios::scientific, std::ios::floatfield);
352 if (std::fabs(this->
time_m) < 1e-14) {
353 csvout <<
"time, Ex_field_energy, Ex_max_norm" <<
endl;
355 csvout << this->
time_m <<
" " << fieldEnergy <<
" " << ExAmp <<
endl;
typename ippl::detail::ViewType< ippl::Vector< double, Dim >, 1 >::view_type view_type
KOKKOS_FUNCTION double PDF(const Vector_t< double, Dim > &xvec, const double &alpha, const Vector_t< double, Dim > &kw, const unsigned Dim)
double CDF(const double &x, const double &alpha, const double &k)
typename ippl::detail::ViewType< ippl::Vector< double, Dim >, 1 >::view_type view_type
ippl::detail::size_type size_type
ippl::Vector< T, Dim > Vector_t
Inform & endl(Inform &inf)
KOKKOS_INLINE_FUNCTION constexpr decltype(auto) apply(const View &view, const Coords &coords)
RangePolicy< View::rank, typenameView::execution_space, PolicyArgs... >::policy_type getRangePolicy(const View &view, int shift=0)
void parallel_for(const std::string &name, const ExecPolicy &policy, const FunctorType &functor)
void parallel_reduce(const std::string &name, const ExecPolicy &policy, const FunctorType &functor, ReducerArgument &&... reducer)
std::unique_ptr< mpi::Communicator > Comm
KOKKOS_INLINE_FUNCTION Vector< int, Dim > first() const
void setFieldSolver(std::shared_ptr< ippl::FieldSolverBase< T, Dim > > fsolver)
std::shared_ptr< ParticleContainer< T, Dim > > pcontainer_m
void setParticleContainer(std::shared_ptr< ParticleContainer< T, Dim > > pcontainer)
std::shared_ptr< ippl::FieldSolverBase< T, Dim > > fsolver_m
void setLoadBalancer(std::shared_ptr< LoadBalancer< T, Dim > > loadbalancer)
std::shared_ptr< FieldContainer< T, Dim > > fcontainer_m
std::shared_ptr< LoadBalancer< T, Dim > > loadbalancer_m
void setFieldContainer(std::shared_ptr< FieldContainer< T, Dim > > fcontainer)
The class that represents a distribution.
A class for inverse transform sampling.
Functor to generate random numbers from a normal distribution.
FmtFlags_t setf(FmtFlags_t setbits, FmtFlags_t field)
Timing::TimerRef TimerRef
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)
::ippl::Vector< index_type, Dim > index_array_type
Vector_t< double, Dim > kw_m
void par2grid() override
Particle-to-grid operation.
Vector_t< double, Dim > origin_m
ippl::NDIndex< Dim > domain_m
Vector_t< int, Dim > nr_m
Vector_t< double, Dim > hr_m
Vector_t< double, Dim > rmin_m
const std::string & getSolver() const
bool isFirstRepartition_m
std::array< bool, Dim > decomp_m
Vector_t< double, Dim > rmax_m
AlpineManager(size_type totalP_, int nt_, Vector_t< int, Dim > &nr_, double lbt_, std::string &solver_, std::string &stepMethod_, std::vector< std::string > preconditioner_params={})
void grid2par() override
Grid-to-particle operation.
KOKKOS_INLINE_FUNCTION double operator()(double x, unsigned int d, const double *params_p) const
KOKKOS_INLINE_FUNCTION double operator()(double x, unsigned int d, double const *params_p) const
KOKKOS_INLINE_FUNCTION double operator()(double u, unsigned int d, double const *params_p) const
ParticleContainer< T, Dim > ParticleContainer_t
void advance() override
A method that should be used to execute/advance a step of simulation.
void initializeParticles()
LoadBalancer< T, Dim > LoadBalancer_t
FieldSolver< T, Dim > FieldSolver_t
LandauDampingManager(size_type totalP_, int nt_, Vector_t< int, Dim > &nr_, double lbt_, std::string &solver_, std::string &stepMethod_, std::vector< std::string > preconditioner_params_)
void dumpLandau(const View &Eview)
void pre_run() override
A method that should be used for setting up the simulation.
LandauDampingManager(size_type totalP_, int nt_, Vector_t< int, Dim > &nr_, double lbt_, std::string &solver_, std::string &stepMethod_)
FieldContainer< T, Dim > FieldContainer_t