class rgpot::CalcResult

Overview

Owns the force DLPack tensor and stores energy/variance from a calculation. More…

#include <types.hpp>
 
class CalcResult {
public:
    // construction
 
    CalcResult();
    CalcResult(CalcResult&& other);
    CalcResult(const CalcResult&);
    ~CalcResult();
 
    // methods
 
    CalcResult& operator=(CalcResult&& other);
    CalcResult& operator=(const CalcResult&);
    rgpot_force_out_t& c_struct();
    double energy() const;
    double variance() const;
    const double* forces_data(size_t& n_elements) const;
    std::vector<double> forces_vec() const;
    bool has_forces() const;
};

Detailed Documentation

Owns the force DLPack tensor and stores energy/variance from a calculation.

Wraps rgpot_force_out_t. The forces field starts as NULL and is set by the potential callback to an owning DLPack tensor. The destructor calls rgpot_tensor_free() to release the forces tensor.

For CPU tensors, use forces_data() to access the raw pointer or forces_vec() to copy forces into a std::vector<double>.

Construction

CalcResult()

Create a zeroed result buffer for a calculation.

Methods

rgpot_force_out_t& c_struct()

Access the underlying C struct (mutable).

Returns:

Mutable reference; used internally by PotentialHandle::calculate().

double energy() const

Returns the calculated potential energy.

Returns:

Energy in the unit system of the potential.

double variance() const

Returns the variance / uncertainty estimate.

Returns:

Variance (0.0 when not applicable).

const double* forces_data(size_t& n_elements) const

Returns a raw pointer to the forces data (CPU only).

The returned pointer is valid for the lifetime of this CalcResult.

Parameters:

n_elements

Output: number of doubles in the forces array.

Returns:

Raw pointer to the force data, or nullptr if no forces tensor.

std::vector<double> forces_vec() const

Copy forces into a std::vector<double>.

Returns:

Vector of forces [n_atoms * 3].

bool has_forces() const

Check if forces are available.

Returns:

True if the forces tensor has been set by the callback.