class pot::PotentialWrapper¶
Overview¶
Type-erased wrapper around any potential that provides a force() interface. More…
#include <gpr/potentials/PotentialWrapper.h>
class PotentialWrapper {
public:
// typedefs
typedef std::function<void(long N, const double*R, const int*atomicNrs, double*F, double*U, double*energy_noise_rms, const double*box)> ForceFn;
typedef std::function<void(long N, const double*R, const int*atomicNrs, double*F, double*U, double*energy_noise_rms, double*force_noise_rms, const double*box)> ForceWithUncertaintyFn;
typedef std::function<void(long N, std::size_t B, const double*R, const int*atomicNrs, double*F, double*U, const double*box)> ForceBatchFn;
typedef std::function<void(long N, std::size_t B, const double*R, const int*atomicNrs, double*F, double*U, double*V, const double*box)> ForceBatchWithForceNoiseFn;
typedef std::function<void(long N, std::size_t B, const double*R, const int*atomicNrs, double*F, double*U, double*energy_noise_rms, double*force_noise_rms, const double*box)> ForceBatchWithUncertaintyFn;
// structs
struct RichForceTag;
template <typename T>
struct dependent_false;
// construction
PotentialWrapper(ForceFn fn);
// methods
void force(long N, const double* R, const int* atomicNrs, double* F, double* U, double* energy_noise_rms, const double* box);
void forceWithUncertainty(long N, const double* R, const int* atomicNrs, double* F, double* U, double* energy_noise_rms, double* force_noise_rms, const double* box);
bool hasForceBatch() const;
bool hasForceBatchWithUncertainty() const;
void setForceBatch(ForceBatchFn fn);
void setForceBatch(std::nullptr_t);
void setForceBatch(ForceBatchWithForceNoiseFn fn);
void setForceBatchWithUncertainty(ForceBatchWithUncertaintyFn fn);
void forceBatch(long N, std::size_t B, const double* R, const int* atomicNrs, double* F, double* U, const double* box);
void forceBatch(long N, std::size_t B, const double* R, const int* atomicNrs, double* F, double* U, double* V, const double* box);
void forceBatchWithUncertainty(long N, std::size_t B, const double* R, const int* atomicNrs, double* F, double* U, double* energy_noise, double* force_noise, const double* box);
static PotentialWrapper from_force_with_uncertainty(ForceWithUncertaintyFn fn);
static PotentialWrapper composeGeometryAndEnergyUncertainty(PotentialWrapper geometry, PotentialWrapper uncertainty);
static PotentialWrapper routeEnergyUncertaintyToForceChannel(PotentialWrapper source);
template <typename RgPot>
static PotentialWrapper from_rgpot(RgPot& pot);
template <typename RgPot>
static PotentialWrapper from_rgpot(std::shared_ptr<RgPot> pot);
static PotentialWrapper from_rgpot(std::shared_ptr<rgpot::PotentialBase> pot);
};
Detailed Documentation¶
Type-erased wrapper around any potential that provides a force() interface.
Accepts a std::function with the legacy EON force() signature, allowing any potential (EAM, Morse, rgpot, RPC, lambda) to be used without templates.
Typedefs¶
typedef std::function<void(long N, const double*R, const int*atomicNrs, double*F, double*U, double*energy_noise_rms, const double*box)> ForceFn
The legacy force signature. The slot before the cell is the energy-noise RMS, a standard deviation in eV and not a variance; it is forwarded as the energy_noise_rms of ForceWithUncertaintyFn and there is no force-noise slot.
typedef std::function<void(long N, std::size_t B, const double*R, const int*atomicNrs, double*F, double*U, const double*box)> ForceBatchFn
Batched means: B same-composition systems, B * 3N coordinates and forces, B energies, and one shared box.
typedef std::function<void(long N, std::size_t B, const double*R, const int*atomicNrs, double*F, double*U, double*V, const double*box)> ForceBatchWithForceNoiseFn
A batch with force noise and zero energy noise.
typedef std::function<void(long N, std::size_t B, const double*R, const int*atomicNrs, double*F, double*U, double*energy_noise_rms, double*force_noise_rms, const double*box)> ForceBatchWithUncertaintyFn
Both optional noise arrays use the single-call RMS conventions.
Methods¶
void force(long N, const double* R, const int* atomicNrs, double* F, double* U, double* energy_noise_rms, const double* box)
Invoke the wrapped potential.
bool hasForceBatch() const
True when the wrapped source can evaluate a same-composition batch in one call (rgpot forceBatch surface).
void forceBatch(long N, std::size_t B, const double* R, const int* atomicNrs, double* F, double* U, const double* box)
Batched means; requires hasForceBatch().
void forceBatch(long N, std::size_t B, const double* R, const int* atomicNrs, double* F, double* U, double* V, const double* box)
Batched evaluation with optional force noise.
void forceBatchWithUncertainty(long N, std::size_t B, const double* R, const int* atomicNrs, double* F, double* U, double* energy_noise, double* force_noise, const double* box)
Preserve both noise channels, using single calls if the batch surface provides only means.
static PotentialWrapper composeGeometryAndEnergyUncertainty(PotentialWrapper geometry, PotentialWrapper uncertainty)
Compose geometry output with an independent energy-uncertainty source.
Energy, forces, and force noise come from geometry. Energy noise is published from the second potential only after that call returns. The second potential is evaluated only when energy noise is requested; its energy and forces are discarded.
static PotentialWrapper routeEnergyUncertaintyToForceChannel(PotentialWrapper source)
Route a legacy scalar uncertainty into the force-noise channel.
This adapts sources whose three-value interface reports a force-scale diagnostic through the legacy energy-uncertainty slot.
template <typename RgPot>
static PotentialWrapper from_rgpot(RgPot& pot)
Factory: adapt an rgpot PotentialBase subclass.
Bridges rgpot’s operator()(AtomMatrix, vector<int>, box) -> (energy, AtomMatrix) to the legacy force() signature.
template <typename RgPot>
static PotentialWrapper from_rgpot(std::shared_ptr<RgPot> pot)
Factory: adapt and own an rgpot PotentialBase subclass.
Use this when the wrapper outlives the local scope that creates the rgpot instance.
static PotentialWrapper from_rgpot(std::shared_ptr<rgpot::PotentialBase> pot)
C++-only helper: wrap a virtual rgpot::PotentialBase.
rgpot does not publish nanobind/pybind types, so Python cannot name this overload. C++ callers that already hold a PotentialBase use this (the caller does not need Potential.hpp in the same TU). Python from_rgpot accepts a bound PotentialBase via the nanobind trampoline, or a callable with the same operator() contract.