Simulation object¶
-
class mdk::Simulation
The main class of the library, responsible for:
storing the simulation state;
storing the forces and other associated objects, and (optionally) binding them to the simulation;
running, or rather stepping through, the simulation.
Public Functions
-
inline Simulation(Model model, param::Parameters params)
Initialize simulation from a
Model
object and the parameters.- Parameters
model – Model of the simulation.
params – Parameters of the simulation.
-
template<typename Data>
inline Data const &data() Access the “static” data as created by the
DataFactory
. We access the data by the type, but insofar as these objects represent functions of the state and the simulation, this is (in my estimation) appropriate. Providing an invalid type will lead to linker error.- Template Parameters
Data – Type of static data to access.
- Returns
Const reference to the data object.
-
template<typename Var>
inline Var &var() Accesses the variables associated with the simulation. The access is by type, thus it’s most suited to variables that are effectively functions of the simulation (for example the physical state or the Verlet list). If the referenced variable has not been yet added, the function tries to emplace it (if it’s default-constructible) such is, for example, the case with
State
orvl::List
. Cannot be run after simulation initialization. The reference is never invalidated.- Template Parameters
Var – Type of the variable to access.
- Returns
Accessed variable. The function returns a non-const reference, thus care must be taken as to modify the variables only on agreed-upon points of the simulation (say, integration of forces).
-
template<typename T, typename ...Args>
inline T &add(Args&&... args) Add a variable to the simulation. Depending on the type of the variable, additional actions may be performed (such as binding to the simulation or adding forces and/or nonlocal forces to appropriate lists). Cannot be run after simulation initialization. The reference is never invalidated.
- Template Parameters
T – Type of the variable to add.
Args – Types of arguments to use in construction.
- Parameters
args – Values of arguments to use in construction.
- Returns
Reference to a constructed and emplaced
T
(Args
…).
-
inline void addAsyncTask(std::function<void()> const &f)
Add an “async task”. Cannot be run after simulation initialization.
- Parameters
f – Function/lambda to add. (Seemingly the lambda cannot capture the environment, i.e. must be trivial)
-
void init()
Initialize the simulation.
-
void step()
Step once through the simulation; the time step is as determined by the used integrator (usually 5 ps).
-
void step(double t)
Step a total of time
t
through the simulation.- Parameters
t – Time to advance.
Private Functions
-
void calcForces()
Internal function for invoking force fields.
Private Members
-
param::Parameters params
Parameters of the simulation.
-
DataFactory df
Data factory.
-
std::unordered_map<std::type_index, std::shared_ptr<void>> vars
A heterogeneous collection of objects (stored as shared pointers to void) indexed by their types.
-
std::vector<NonlocalForce*> nonlocalForces
List of nonlocal forces of the simulation - the distinction is used when the Verlet list is updated, so as to invoke appropriate update functions.
-
Integrator *integrator = nullptr
Pointer to the integrator used in the simulation.
-
bool initialized = false
Whether simulation has yet been initialized; used for running the init function only once.
-
int step_nr = 0
Number of steps performed.