BioCMAMC-ST
Api::SimulationInstance Class Reference

Represents an instance of a simulation with customizable parameters and behaviors. More...

#include <api.hpp>

Collaboration diagram for Api::SimulationInstance:
[legend]

Public Member Functions

 SimulationInstance (const SimulationInstance &)=delete
 Deleted copy constructor to prevent copying.
 
 SimulationInstance (SimulationInstance &&)=default
 Defaulted move constructor for efficient resource transfer.
 
SimulationInstanceoperator= (const SimulationInstance &)=delete
 Deleted copy assignment operator to prevent copying.
 
SimulationInstanceoperator= (SimulationInstance &&)=default
 Defaulted move assignment operator for efficient resource transfer.
 
 SimulationInstance ()=delete
 Default constructor.
 
 ~SimulationInstance ()
 Default destructor.
 
ApiResult apply (bool to_load) noexcept
 Apply the simulation configuration and prepare for execution.
 
ApiResult apply () noexcept
 Apply the simulation configuration and prepare for execution.
 
ApiResult apply_load () noexcept
 Load ad apply the simulation configuration and prepare for execution based on file.
 
ApiResult register_parameters (Core::UserControlParameters &&params) noexcept
 Register user control parameters for the simulation.
 
bool register_result_path (std::string_view path)
 Register a result output path.
 
ApiResult register_initial_condition (Core::ScalarFactory::ScalarVariant &&type)
 
ApiResult register_initialiser_file_path (std::string_view path)
 
bool register_cma_path (std::string_view path, bool recursive=false)
 Register a path for CMA data.
 
bool register_serde (std::string_view path)
 Register a serialization/deserialization (serde) path.
 
ApiResult register_model_name (std::string_view path)
 Register the model name for the simulation.
 
bool set_feed_constant (double _flow, std::span< double > _concentration, std::span< std::size_t > _position, std::span< std::size_t > _species, bool gas=false, bool fed_batch=false)
 Configure feed constants for the simulation.
 
bool set_feed_constant_from_rvalue (double _f, std::vector< double > &&_target, std::vector< std::size_t > &&_position, std::vector< std::size_t > &&_species, bool gas=false, bool fed_batch=false)
 
ApiResult register_scalar_initiazer (Core::ScalarFactory::ScalarVariant &&var)
 
int get_id () const
 Retrieve the simulation instance's unique identifier.
 
const ExecInfoget_exec_info () const
 
ApiResult exec () noexcept
 Execute the simulation.
 

Static Public Member Functions

static std::optional< std::unique_ptr< SimulationInstance > > init (int argc, char **argv, std::optional< std::size_t > run_id=std::nullopt) noexcept
 Initialize a simulation instance.
 

Private Member Functions

 SimulationInstance (int argc, char **argv, std::optional< std::size_t > run_id)
 simulation instance constructor
 

Private Attributes

int id {}
 The unique identifier to connect with c api.
 
std::optional< Core::ScalarFactory::ScalarVariantscalar_initializer_variant = std::nullopt
 
Core::CaseData _data
 Case data for the simulation.
 
Core::UserControlParameters params
 User-defined control parameters.
 
bool loaded = false
 Flag indicating if the instance is loaded.
 
bool applied = false
 Flag indicating if the configuration is applied.
 
bool registered = false
 Flag indicating if resources are registered.
 
std::optional< Simulation::Feed::SimulationFeedfeed
 Optional feed configuration.
 

Detailed Description

Represents an instance of a simulation with customizable parameters and behaviors.

The SimulationInstance class is designed to encapsulate the configuration, execution, and management of a simulation process. It supports initialization for single-threaded or multi-threaded (optionally MPI-enabled) scenarios, parameter registration, and execution control.

The class is non-copyable but movable to ensure unique ownership and efficient resource management. Note: Define this struct as struct and not class to be coherent with the C opaque type defined as typedef struct This change absolutely nothing to the code behaviour it's just a name

Constructor & Destructor Documentation

◆ SimulationInstance() [1/4]

Api::SimulationInstance::SimulationInstance ( const SimulationInstance & )
delete

Deleted copy constructor to prevent copying.

◆ SimulationInstance() [2/4]

Api::SimulationInstance::SimulationInstance ( SimulationInstance && )
default

Defaulted move constructor for efficient resource transfer.

◆ SimulationInstance() [3/4]

Api::SimulationInstance::SimulationInstance ( )
delete

Default constructor.

◆ ~SimulationInstance()

Api::SimulationInstance::~SimulationInstance ( )

Default destructor.

◆ SimulationInstance() [4/4]

Api::SimulationInstance::SimulationInstance ( int argc,
char ** argv,
std::optional< std::size_t > run_id )
private

simulation instance constructor

Parameters
argcNumber of runtime argument.
argvTuntime arguments.
idA unique identifier for the simulation instance (optional).
Here is the call graph for this function:

Member Function Documentation

◆ apply() [1/2]

ApiResult Api::SimulationInstance::apply ( )
noexcept

Apply the simulation configuration and prepare for execution.

Returns
An ApiResult indicating the success or failure of the operation.
Here is the call graph for this function:

◆ apply() [2/2]

ApiResult Api::SimulationInstance::apply ( bool to_load)
noexcept

Apply the simulation configuration and prepare for execution.

Parameters
to_loadFlag indicating whether the configuration should be loaded.
Returns
An ApiResult indicating the success or failure of the operation.

◆ apply_load()

ApiResult Api::SimulationInstance::apply_load ( )
noexcept

Load ad apply the simulation configuration and prepare for execution based on file.

Returns
An ApiResult indicating the success or failure of the operation.
Here is the call graph for this function:

◆ exec()

ApiResult Api::SimulationInstance::exec ( )
noexcept

Execute the simulation.

Returns
An ApiResult indicating the success or failure of the operation.
Here is the call graph for this function:

◆ get_exec_info()

const ExecInfo & Api::SimulationInstance::get_exec_info ( ) const
inlinenodiscard

◆ get_id()

int Api::SimulationInstance::get_id ( ) const
nodiscard

Retrieve the simulation instance's unique identifier.

Returns
The ID of the simulation instance.

◆ init()

std::optional< std::unique_ptr< SimulationInstance > > Api::SimulationInstance::init ( int argc,
char ** argv,
std::optional< std::size_t > run_id = std::nullopt )
staticnoexcept

Initialize a simulation instance.

Parameters
argcNumber of runtime argument.
argvTuntime arguments.
idA unique identifier for the simulation instance (optional).
Returns
An optional containing a unique pointer to the instance if successful, or std::nullopt if initialization failed.

◆ operator=() [1/2]

SimulationInstance & Api::SimulationInstance::operator= ( const SimulationInstance & )
delete

Deleted copy assignment operator to prevent copying.

◆ operator=() [2/2]

SimulationInstance & Api::SimulationInstance::operator= ( SimulationInstance && )
default

Defaulted move assignment operator for efficient resource transfer.

◆ register_cma_path()

bool Api::SimulationInstance::register_cma_path ( std::string_view path,
bool recursive = false )

Register a path for CMA data.

Parameters
pathThe file system path for CMA data.
recursiveFlag indicating if recursive registration is required.
Returns
True if the path was successfully registered; false otherwise.

◆ register_initial_condition()

ApiResult Api::SimulationInstance::register_initial_condition ( Core::ScalarFactory::ScalarVariant && type)

◆ register_initialiser_file_path()

ApiResult Api::SimulationInstance::register_initialiser_file_path ( std::string_view path)

◆ register_model_name()

ApiResult Api::SimulationInstance::register_model_name ( std::string_view path)

Register the model name for the simulation.

Parameters
pathThe model name or path.
Returns
An ApiResult indicating the success or failure of the operation.

◆ register_parameters()

ApiResult Api::SimulationInstance::register_parameters ( Core::UserControlParameters && params)
noexcept

Register user control parameters for the simulation.

Parameters
paramsA rvalue reference to a UserControlParameters object.
Returns
An ApiResult indicating the success or failure of the operation.

◆ register_result_path()

bool Api::SimulationInstance::register_result_path ( std::string_view path)

Register a result output path.

Parameters
pathThe file system path to store simulation results.
Returns
True if the path was successfully registered; false otherwise.

◆ register_scalar_initiazer()

ApiResult Api::SimulationInstance::register_scalar_initiazer ( Core::ScalarFactory::ScalarVariant && var)

◆ register_serde()

bool Api::SimulationInstance::register_serde ( std::string_view path)

Register a serialization/deserialization (serde) path.

Parameters
pathThe file system path for serde operations.
Returns
True if the path was successfully registered; false otherwise.

◆ set_feed_constant()

bool Api::SimulationInstance::set_feed_constant ( double _flow,
std::span< double > _concentration,
std::span< std::size_t > _position,
std::span< std::size_t > _species,
bool gas = false,
bool fed_batch = false )

Configure feed constants for the simulation.

Parameters
_flowA constant flow value.
concentrationsA span of concentrations values.
_positionA span of position indices.
_speciesA span of species indices.
gasFlag indicating whether the feed is gas-phase.
Returns
True if the feed was successfully configured; false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_feed_constant_from_rvalue()

bool Api::SimulationInstance::set_feed_constant_from_rvalue ( double _f,
std::vector< double > && _target,
std::vector< std::size_t > && _position,
std::vector< std::size_t > && _species,
bool gas = false,
bool fed_batch = false )
Here is the call graph for this function:

Member Data Documentation

◆ _data

Core::CaseData Api::SimulationInstance::_data
private

Case data for the simulation.

◆ applied

bool Api::SimulationInstance::applied = false
private

Flag indicating if the configuration is applied.

◆ feed

std::optional<Simulation::Feed::SimulationFeed> Api::SimulationInstance::feed
private
Initial value:
=
std::nullopt

Optional feed configuration.

◆ id

int Api::SimulationInstance::id {}
private

The unique identifier to connect with c api.

◆ loaded

bool Api::SimulationInstance::loaded = false
private

Flag indicating if the instance is loaded.

◆ params

Core::UserControlParameters Api::SimulationInstance::params
private

User-defined control parameters.

◆ registered

bool Api::SimulationInstance::registered = false
private

Flag indicating if resources are registered.

◆ scalar_initializer_variant

std::optional<Core::ScalarFactory::ScalarVariant> Api::SimulationInstance::scalar_initializer_variant = std::nullopt
private

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