apoCHARMM 1.0.0
High-performance molecular dynamics simulations on GPUs
 
Loading...
Searching...
No Matches
ForceView Class Reference

Dispatches a subscribed force through a non-owning type-erased view. More...

#include <ForceManager.h>

Public Member Functions

template<typename ForceType >
 ForceView (ForceType *inputForce)
 Constructs a view over a concrete force object.
 
bool supportsPBC (const PBC pbc) const
 Reports whether the viewed force supports a periodic-boundary mode.
 
void initialize (const int numAtoms, const std::vector< double > &boxDimensions)
 Initializes the viewed force for an atom count and periodic box.
 
void clear (const bool calcEnergy=true, const bool calcVirial=true)
 Clears forces and requested output through the concrete interface.
 
void calcForce (const float4 *xyzq, const bool calcEnergy, const bool calcVirial)
 Computes the viewed force for a device coordinate-charge array.
 
void setBoxDimensions (const std::vector< double > &boxDimensions)
 Updates the viewed force's box dimensions.
 
std::shared_ptr< Force< long long int > > getForce (void)
 Returns the viewed force's fixed-point force storage.
 
std::shared_ptr< CudaEnergyVirial > getEnergyVirial (void) const
 Returns the viewed force's energy and virial storage.
 
bool contributesVirial (void) const
 Reports whether the viewed force contributes a virial.
 
bool requiresVirialCalculation (void) const
 

Detailed Description

Dispatches a subscribed force through a non-owning type-erased view.

ForceManager uses this helper to invoke a force implementation without requiring a common virtual base class. The view stores a raw pointer to the supplied object together with function pointers generated from ForceType. It does not own the force.

A force accepted by this view must provide:

A force may additionally provide supportsPBC(PBC) returning a value convertible to bool. When the operation is absent, the view treats the forces as compatible with every valid PBC value.

Optional static constexpr bool computesVirial = true declares that calcForce() supplies the complete virial tensor. Such a force participates in aggregation but skips manager-side force conversion and reconstruction. The absent trait defaults to false, preserving existing force behavior.

Optional clear(const bool calcEnergy, const bool calcVirial) clears the forces and only requested energy/virial outputs. Without it, the original clear() is used.

ForceManager preserves the pointee lifetime while a force is subscribed by retaining a shared owner in its parallel subscription state.

Warning
A standalone ForceView does not validate or extend the pointee lifetime. Destroying or moving the pointee while the view remains in use leaves the view invalid.
This helper and the object it dispatches provide no internal synchronization for concurrent host access.

Constructor & Destructor Documentation

◆ ForceView()

template<typename ForceType >
ForceView::ForceView ( ForceType *  inputForce)
inline

Constructs a view over a concrete force object.

The constructor captures ForceType's compile-time virial trait and creates dispatch functions for the required force interface. No data is copied from the force and no ownership is acquired.

Template Parameters
ForceTypeConcrete subscribed-force implementation satisfying the interface documented for ForceView.
Parameters
[in]inputForceBorrowed non-null pointer to the force. The pointee must remain alive and at the same address for every subsequent operation on this view.
Precondition
inputForce is non-null.
ForceType satisfies the required subscribed-force interface.

Member Function Documentation

◆ calcForce()

void ForceView::calcForce ( const float4 *  xyzq,
const bool  calcEnergy,
const bool  calcVirial 
)
inline

Computes the viewed force for a device coordinate-charge array.

Parameters
[in]xyzqBorrowed device pointer to at least numAtoms float4 records in [x, y, z, charge] order. Coordinates are in angstroms and charge is in elementary-charge units. The pointer must remain valid until the viewed force has completed its CUDA work.
[in]calcEnergyWhether to update the viewed force's energy state.
[in]calcVirialWhether to update the viewed force's virial state.
Precondition
The borrowed force pointer remains valid.
The force has been initialized for the supplied array.
Note
CUDA launch and synchronization behavior is defined by ForceType::calcForce().

◆ clear()

void ForceView::clear ( const bool  calcEnergy = true,
const bool  calcVirial = true 
)
inline

Clears forces and requested output through the concrete interface.

If selective clearing is supported, false flags preserve stale output. Otherwise this calls the original unconditional ForceType::clear(). Default arguments retain unconditional standalone clearing.

Precondition
The borrowed force pointer remains valid.
Note
CUDA stream and synchronization behavior is defined by the force.

◆ contributesVirial()

bool ForceView::contributesVirial ( void  ) const
inline

Reports whether the viewed force contributes a virial.

Returns
The value of ForceType::contributesVirial captured when the view was constructed.

◆ getEnergyVirial()

std::shared_ptr< CudaEnergyVirial > ForceView::getEnergyVirial ( void  ) const
inline

Returns the viewed force's energy and virial storage.

Returns
A copied shared owner of the CudaEnergyVirial object returned by ForceType::getEnergyVirial().
Precondition
The borrowed force pointer remains valid.

◆ getForce()

std::shared_ptr< Force< long long int > > ForceView::getForce ( void  )
inline

Returns the viewed force's fixed-point force storage.

Returns
A copied shared owner of the Force<long long int> object returned by ForceType::getForce(). Its device array uses structure-of-arrays component layout with the object's reported stride.
Precondition
The borrowed force pointer remains valid.

◆ initialize()

void ForceView::initialize ( const int  numAtoms,
const std::vector< double > &  boxDimensions 
)
inline

Initializes the viewed force for an atom count and periodic box.

Parameters
[in]numAtomsNumber of atoms represented by subsequent coordinate and force arrays.
[in]boxDimensionsThree box lengths in [x, y, z] order, in angstroms.
Precondition
The borrowed force pointer remains valid.
Note
All validation, allocation, host-to-device transfer, and synchronization behavior is defined by ForceType::initialize().

◆ requiresVirialCalculation()

bool ForceView::requiresVirialCalculation ( void  ) const
inline

Reports whether the manager must construct this force's virial.

◆ setBoxDimensions()

void ForceView::setBoxDimensions ( const std::vector< double > &  boxDimensions)
inline

Updates the viewed force's box dimensions.

Parameters
[in]boxDimensionsThree box lengths in [x, y, z] order, in angstroms.
Precondition
The borrowed force pointer remains valid.
Note
Validation, transfer, and synchronization behavior is defined by ForceType::setBoxDimensions().

◆ supportsPBC()

bool ForceView::supportsPBC ( const PBC  pbc) const
inline

Reports whether the viewed force supports a periodic-boundary mode.

Parameters
[in]pbcPeriodic-boundary mode proposed by ForceManager.
Returns
The value returned by ForceType::supportsPBC(pbc) when that expression is well-formed and convertible to bool; otherwise true.
Precondition
The borrowed force pointer remains valid.
Note
ForceManager separately validates that pbc is a named PBC enumerator.