IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
Utility.h
Go to the documentation of this file.
1#ifndef IPPL_RANDOM_UTILITY_H
2#define IPPL_RANDOM_UTILITY_H
3
4#include <Kokkos_MathematicalConstants.hpp>
5#include <Kokkos_MathematicalFunctions.hpp>
6#include <Kokkos_Random.hpp>
7
8#include "Types/ViewTypes.h"
9
10namespace ippl {
11 namespace random {
12 namespace detail {
27 template <typename T, class Distribution>
30 double atol = 1e-12;
31 unsigned int max_iter = 20;
32
33 KOKKOS_FUNCTION
34 NewtonRaphson() = default;
35
36 KOKKOS_FUNCTION
37 ~NewtonRaphson() = default;
38
39 KOKKOS_INLINE_FUNCTION NewtonRaphson(const Distribution& dist_)
40 : dist(dist_) {}
41
52 KOKKOS_INLINE_FUNCTION void solve(unsigned int d, T& x, T& u) {
53 unsigned int iter = 0;
54 while (iter < max_iter && Kokkos::fabs(dist.getObjFunc(x, d, u)) > atol) {
55 // Find x, such that "cdf(x) - u = 0" for a given sample of u~uniform(0,1)
56 x = x - (dist.getObjFunc(x, d, u) / dist.getDerObjFunc(x, d));
57 iter += 1;
58 }
59 }
60 };
61 } // namespace detail
62 } // namespace random
63} // namespace ippl
64
65#endif
Definition Archive.h:20
The class that represents a distribution.
KOKKOS_FUNCTION ~NewtonRaphson()=default
KOKKOS_INLINE_FUNCTION NewtonRaphson(const Distribution &dist_)
Definition Utility.h:39
KOKKOS_INLINE_FUNCTION void solve(unsigned int d, T &x, T &u)
Solve an equation using the Newton-Raphson method.
Definition Utility.h:52
KOKKOS_FUNCTION NewtonRaphson()=default