ORB5X 1.0.0
Performance-portable global electromagnetic gyrokinetic PIC code
orb5x::Util Class Reference

Small host-side numerical, interpolation, fitting, and I/O utilities. More...

#include "util.hpp"

Public Types

using HostVectorView = Kokkos::View< Real *, Kokkos::HostSpace >
 Unmanaged-compatible host view type passed to fit callbacks.
 

Static Public Member Functions

static void A3deriv (const Kokkos::View< Real * > &y_in, const Kokkos::View< Real * > &x_in, Kokkos::View< Real * > &dydx_out, const Kokkos::View< Real * > &x_out)
 Evaluate derivatives of local four-point cubic interpolants.
 
static void A3interp (const Kokkos::View< Real * > &y_in, const Kokkos::View< Real * > &x_in, Kokkos::View< Real * > &y_out, const Kokkos::View< Real * > &x_out)
 Evaluate local four-point cubic Lagrange interpolants.
 
static void append_stat (const std::string &filename, const std::string &data)
 Append one newline-terminated record to a statistics file.
 
static int choose_int (const Kokkos::View< int * > &arr, int val)
 Find the first occurrence of an integer in a Kokkos View.
 
static int choose_int (const std::vector< int > &arr, int val)
 Find the first occurrence of an integer in a standard vector.
 
static void creatd_stat (const std::string &filename)
 Create or truncate an empty statistics text file.
 
static int execute_command_line_wrapper (const std::string &command)
 Execute a command through the host C runtime shell.
 
static void gaussj (Kokkos::View< Real ** > &a, Kokkos::View< Real ** > &b, int n, int m)
 Solve dense linear systems by full-pivot Gauss–Jordan elimination.
 
static Real interp1 (Real x, const Kokkos::View< Real * > &xp, const Kokkos::View< Real * > &yp)
 Linearly interpolate a monotone one-dimensional table.
 
static Real log2real (bool lin)
 Convert a logical flag to an exact real indicator.
 
static void mrqcof (const Kokkos::View< Real * > &x, const Kokkos::View< Real * > &y, const Kokkos::View< Real * > &sig, Kokkos::View< Real * > &a, const Kokkos::View< int * > &ia, Kokkos::View< Real ** > &alpha, Kokkos::View< Real * > &beta, Real &chisq, std::function< void(Real, const HostVectorView &, Real &, HostVectorView &)> funcs)
 Assemble Levenberg–Marquardt normal-equation coefficients.
 
template<typename ViewType >
static void putarr_attime (const ViewType &arr, Real time, const std::string &name)
 Compatibility placeholder for time-tagged diagnostic array output.
 
static Real zbrent (std::function< Real(Real)> func, Real x1, Real x2, Real tol)
 Find a bracketed scalar root with Brent's method.
 

Detailed Description

Small host-side numerical, interpolation, fitting, and I/O utilities.

Routines accept Kokkos Views for integration with ORB5X storage but currently execute through host mirrors. Coordinate and value units pass through unchanged; derivatives have y/x units, and tolerances use the units of their corresponding independent variable.

Member Typedef Documentation

◆ HostVectorView

using orb5x::Util::HostVectorView = Kokkos::View<Real*, Kokkos::HostSpace>

Unmanaged-compatible host view type passed to fit callbacks.

Member Function Documentation

◆ A3deriv()

static void orb5x::Util::A3deriv ( const Kokkos::View< Real * > &  y_in,
const Kokkos::View< Real * > &  x_in,
Kokkos::View< Real * > &  dydx_out,
const Kokkos::View< Real * > &  x_out 
)
static

Evaluate derivatives of local four-point cubic interpolants.

Parameters
[in]y_inTabulated dependent values.
[in]x_inIncreasing, distinct tabulation coordinates.
[in,out]dydx_outDerivatives in y_in/x_in units; unchanged when fewer than four input points are available.
[in]x_outNondecreasing query coordinates.

◆ A3interp()

static void orb5x::Util::A3interp ( const Kokkos::View< Real * > &  y_in,
const Kokkos::View< Real * > &  x_in,
Kokkos::View< Real * > &  y_out,
const Kokkos::View< Real * > &  x_out 
)
static

Evaluate local four-point cubic Lagrange interpolants.

Parameters
[in]y_inTabulated dependent values.
[in]x_inIncreasing, distinct tabulation coordinates.
[in,out]y_outOutput values; unchanged if fewer than four inputs.
[in]x_outQuery coordinates, expected in nondecreasing order.

◆ append_stat()

static void orb5x::Util::append_stat ( const std::string &  filename,
const std::string &  data 
)
static

Append one newline-terminated record to a statistics file.

Parameters
[in]filenameOutput path.
[in]dataRecord text without the added newline.

◆ choose_int() [1/2]

static int orb5x::Util::choose_int ( const Kokkos::View< int * > &  arr,
int  val 
)
static

Find the first occurrence of an integer in a Kokkos View.

Parameters
[in]arrValues copied to host for the search.
[in]valRequested value.
Returns
Zero-based index, or -1 when absent.

◆ choose_int() [2/2]

static int orb5x::Util::choose_int ( const std::vector< int > &  arr,
int  val 
)
static

Find the first occurrence of an integer in a standard vector.

Parameters
[in]arrValues to search.
[in]valRequested value.
Returns
Zero-based index, or -1 when absent.

◆ creatd_stat()

static void orb5x::Util::creatd_stat ( const std::string &  filename)
static

Create or truncate an empty statistics text file.

Parameters
[in]filenameOutput path.
Note
Failure is reported to standard error and is not thrown.

◆ execute_command_line_wrapper()

static int orb5x::Util::execute_command_line_wrapper ( const std::string &  command)
static

Execute a command through the host C runtime shell.

Parameters
[in]commandShell command string.
Returns
Implementation-defined std::system status code.
Warning
Do not pass untrusted or unsanitized text.

◆ gaussj()

static void orb5x::Util::gaussj ( Kokkos::View< Real ** > &  a,
Kokkos::View< Real ** > &  b,
int  n,
int  m 
)
static

Solve dense linear systems by full-pivot Gauss–Jordan elimination.

Parameters
[in,out]aLeading n x n matrix, replaced by its inverse.
[in,out]bLeading n x m right-hand sides, replaced by solutions.
[in]nSystem dimension.
[in]mNumber of right-hand sides.
Exceptions
std::runtime_errorIf a pivot is repeated or has magnitude below 1e-15.

◆ interp1()

static Real orb5x::Util::interp1 ( Real  x,
const Kokkos::View< Real * > &  xp,
const Kokkos::View< Real * > &  yp 
)
static

Linearly interpolate a monotone one-dimensional table.

Parameters
[in]xQuery coordinate in the units of xp.
[in]xpIncreasing tabulation coordinates.
[in]ypValues in the same order and with at least xp.extent(0) entries.
Returns
Interpolated value; endpoint value outside the table, zero for an empty table, or the left value across a numerically zero-width cell.

◆ log2real()

static Real orb5x::Util::log2real ( bool  lin)
static

Convert a logical flag to an exact real indicator.

Parameters
[in]linLogical input.
Returns
1.0 for true and 0.0 for false.

◆ mrqcof()

static void orb5x::Util::mrqcof ( const Kokkos::View< Real * > &  x,
const Kokkos::View< Real * > &  y,
const Kokkos::View< Real * > &  sig,
Kokkos::View< Real * > &  a,
const Kokkos::View< int * > &  ia,
Kokkos::View< Real ** > &  alpha,
Kokkos::View< Real * > &  beta,
Real &  chisq,
std::function< void(Real, const HostVectorView &, Real &, HostVectorView &)>  funcs 
)
static

Assemble Levenberg–Marquardt normal-equation coefficients.

Parameters
[in]xIndependent data coordinates.
[in]yObservations.
[in]sigOne-standard-deviation uncertainties in y units.
[in,out]aModel parameters supplied to funcs.
[in]iaNonzero entries select parameters to fit.
[out]alphaSymmetric curvature matrix for selected parameters.
[out]betaGradient vector for selected parameters.
[out]chisqSum of squared uncertainty-normalized residuals.
[in]funcsCallback returning model value and derivatives with respect to every parameter for one x coordinate.

◆ putarr_attime()

template<typename ViewType >
static void orb5x::Util::putarr_attime ( const ViewType &  arr,
Real  time,
const std::string &  name 
)
static

Compatibility placeholder for time-tagged diagnostic array output.

Parameters
[in]arrArray that would be written.
[in]timeSimulation time in ORB5X normalized units.
[in]nameDiagnostic quantity name.
Note
The current implementation performs no I/O.

◆ zbrent()

static Real orb5x::Util::zbrent ( std::function< Real(Real)>  func,
Real  x1,
Real  x2,
Real  tol 
)
static

Find a bracketed scalar root with Brent's method.

Parameters
[in]funcContinuous scalar function.
[in]x1First bracket endpoint.
[in]x2Second bracket endpoint.
[in]tolAbsolute convergence tolerance in x units.
Returns
Approximate root, or quiet NaN when the endpoints do not bracket a sign change. After 100 iterations, returns the best current point.

The documentation for this class was generated from the following file: