You're reading the documentation for a development version. For the latest stable documentation, please have a look at v5.1.X.
Simulation#
A program that embeds CADET-Core builds a model system with cadet::IModelBuilder, configures it from a cadet::IParameterProvider and runs it with cadet::ISimulator.
The model system (cadet::IModelSystem) connects the unit operations and assembles their equations into one DAE.
A cadet::ISolutionRecorder receives the solution while the simulator integrates.
Simulator#
-
class ISimulator#
[source] Provides functionality to simulate a model using a time integrator.
Subclassed by cadet::Simulator
Public Functions
-
virtual void setSensitiveParameter(const ParameterId &id) = 0#
[source] Sets a parameter sensitive.
The method enables sensitivity computation for the given parameter. For each parameter marked as sensitive, another system in size of the original DAE system is to be solved.
- Parameters:
id – [in] Parameter ID of the sensitive parameter
-
virtual void setSensitiveParameter(const ParameterId &id, double absTolS) = 0#
[source] Sets a parameter sensitive.
The method enables sensitivity computation for the given parameter. For each parameter marked as sensitive, another system in size of the original DAE system is to be solved.
- Parameters:
id – [in] Parameter ID of the sensitive parameter
absTolS – [in] Absolute tolerance used in the sensitivity computation for this parameter (try 1.0e-5)
-
virtual void setSensitiveParameter(ParameterId const *ids, unsigned int numParams, double absTolS) = 0#
[source] Fuses multiple parameters to one sensitivity.
Multiple parameters are fused into a single parameter sensitivity. Given two parameters \( p_1, p_2 \), this is equivalent to setting the constraint \( p_1 = p_2 = p \) and computing the parameter sensitivity of any of the two parameters:
\[ f(p_1, p_2) = f(p, p) \quad \Rightarrow \quad \frac{df}{dp} = \partial_1 f + \partial_2 f. \]One additional system in size of the original DAE system is to be solved regardless of the number of fused parameters.- Parameters:
ids – [in] Parameter IDs of the fused sensitive parameters
numParams – [in] Number of fused parameters
absTolS – [in] Absolute tolerance used in the sensitivity computation for this parameter (try 1.0e-5)
-
virtual void setSensitiveParameter(ParameterId const *ids, double const *diffFactors, unsigned int numParams, double absTolS) = 0#
[source] Fuses multiple parameters to one sensitivity.
Multiple parameters are fused into a single parameter sensitivity that is a linear combination of the single parameters. Given two parameters \( p_1, p_2 \), this means setting
\[\begin{split} \begin{pmatrix} p_1 \\ p_2 \end{pmatrix} = g\left(p\right) = \begin{pmatrix} a_1 p \\ a_2 p \end{pmatrix} \end{split}\]and computing the parameter sensitivity of \( p\):\[ \frac{d}{dp} f(g(p)) = a_1 \partial_1 f + a_2 \partial_2 f. \]One additional system in size of the original DAE system is to be solved.- Parameters:
ids – [in] Parameter IDs of the fused sensitive parameters
diffFactors – [in] Factors \( a_i \) of the linear combination
numParams – [in] Number of fused parameters
absTolS – [in] Absolute tolerance used in the sensitivity computation for this parameter (try 1.0e-5)
-
virtual unsigned int numSensParams() const noexcept = 0#
[source] Returns the number of sensitive parameters All parameters that are set sensitive are counted. This includes model parameters as well as inlet parameters.
- Returns:
The number of sensitive parameters
-
virtual void setSensitiveParameterValue(const ParameterId &id, double value) = 0#
[source] Sets the value of a sensitive parameter If the parameter is part of a fused sensitivity, then all fused parameters are set to the same value (honouring their linear coefficients).
- Parameters:
id – [in] Parameter ID of the parameter to be manipulated
value – [in] Value of the parameter
-
virtual void setSensitiveParameterValue(unsigned int idx, double value) = 0#
[source] Sets the value of a sensitive parameter If the parameter is part of a fused sensitivity, then all fused parameters are set to the same value (honouring their linear coefficients).
- Parameters:
idx – [in] Index of the sensitive parameter to be manipulated
value – [in] Value of the parameter
-
virtual void setSensitiveParameterFactors(unsigned int idx, double const *factors) = 0#
[source] Sets the linear factors of a sensitive parameter group.
- Parameters:
idx – [in] Index of the sensitive parameter group to be manipulated
factors – [in] Array with linear factors of the individual parameters in the group
-
virtual void setParameterValue(const ParameterId &id, double value) = 0#
[source] Sets the value of a parameter This function does not respect fused parameters and treats them as individuals.
- Parameters:
id – [in] Parameter ID of the parameter to be manipulated
value – [in] Value of the parameter
-
virtual bool hasParameter(const ParameterId &pId) const = 0#
[source] Checks whether a given parameter exists.
- Parameters:
pId – [in] pId ParameterId that identifies the parameter uniquely
- Returns:
trueif the parameter exists, otherwisefalse
-
virtual std::unordered_map<ParameterId, double> getAllParameterValues() const = 0#
[source] Returns all parameters with their current values that can be made sensitive.
- Returns:
Map with all parameters that can be made sensitive along with their current value
-
virtual void setSolutionTimes(const std::vector<double> &solutionTimes) = 0#
[source] Sets the time points at which a solution is written.
The simulator returns solutions by default only at its internal integration timepoints. This timepoints are usually unevenly spaced and are more dense in regions where gradients are steep. If the user is interested in solutions at specific timepoints he can set them using this method. The points may lie in the range \([t_{\text{start}}, t_{\text{end}}]\). Note that the timepoints should not exceed the section times.
- Parameters:
solutionTimes – [in] A vector containing the timepoints at which a solution should be computed
-
virtual const std::vector<double> &getSolutionTimes() const = 0#
[source] Returns the time points at which a solution has been written.
- Returns:
Vector containing the timepoints at which a solution has been be computed
-
virtual void setSolutionTimesUnitState(const std::vector<double> &solutionTimesUnitState) = 0#
[source] Sets the time points at which internal unit operation state (bulk, particle, solid, flux) is written.
Must be a subset of the solution times set via setSolutionTimes(). At time points not in this list, only inlet/outlet data is recorded. If empty (default), internal state is written at all solution times.
- Parameters:
solutionTimesUnitState – [in] Time points for unit state output
-
virtual const std::vector<double> &getSolutionTimesUnitState() const = 0#
[source] Returns the time points at which internal unit operation state is written.
- Returns:
Vector containing the time points for unit state output (empty means all solution times)
-
virtual void setSectionTimes(const std::vector<double> §ionTimes) = 0#
[source] Sets the timepoints of (potential) discontinuities.
Sets the timepoints of (potential) discontinuities where an integrator restart with adjusted initial conditions might be required. This applies to all timepoints at which the inlet concentration function is not continuously differentiable. Hereby the simulation is split into sections which are solved independently. The
sectionTimesvector must contain at least \(t_{\text{start}}\) and \(t_{\text{end}}\) and is of lengthnsec + 1.- Parameters:
sectionTimes – [in] A vector containing the timepoints of all sections
-
virtual void setSectionTimes(const std::vector<double> §ionTimes, const std::vector<bool> §ionContinuity) = 0#
[source] Sets the timepoints of (potential) discontinuities.
Sets the timepoints of (potential) discontinuities where an integrator restart with adjusted initial conditions might be required. This applies to all timepoints at which the inlet concentration function is not continuously differentiable. Hereby the simulation is split into sections which are solved independently. The
sectionTimesvector must contain at least \(t_{start}\) and \(t_{end}\) and is of lengthnsec + 1.Also sets the continuity of section transitions. A continuous section transition from section i to section i+1 is indicated by setting the ith entry of
sectionContinuitytotrue. The integrator will not be reset on continuous section transitions, thus increasing performance.- Parameters:
sectionTimes – [in] A vector containing the timepoints of all sections
sectionContinuity – [in] A vector determining the continuity of section transitions
-
virtual void initializeModel(IModelSystem &model) = 0#
[source] Initializes the time integrator with the given model system.
Allocates internal memory and initializes and sets up the IDAS package.
- Parameters:
model – [in] Model system that is to be simulated
-
virtual void applyInitialCondition() = 0#
[source] Applies the initial conditions that are currently set.
Initial conditions are set by calling setInitialCondition(IParameterProvider& paramProvider). This function has to be called once for applyInitialCondition() to work, which will do nothing otherwise.
This function applies the initial conditions to the state vectors. Consistent initialization will be performed later according to the mode set by setConsistentInitialization().
-
virtual void setInitialCondition(IParameterProvider ¶mProvider) = 0#
[source] Reads initial condition of the model from the given parameter provider.
The scope of the cadet::IParameterProvider is unchanged on return. Note that the initial conditions are not applied, which is performed by applyInitialCondition().
- Parameters:
paramProvider – [in] Parameter provider
-
virtual void applyInitialCondition(double const *const initState) = 0#
[source] Applies the given initial state to the model.
The initial state consists of the state \( y_0 \) and its time derivative \(\dot{y}_0\). It has to be consistent, which means that
\[ f\left( t_0, y_0, \dot{y}_0 ) = 0 \]has to hold. In other words, the initial condition has to fulfill the DAE at the initial time point \( t_0\).If only \( y_0 \) is given, the simulator will try to find a matching \( \dot{y}_0\) later. This is done according to the consistent initialization mode set by setConsistentInitialization(). Because of nonlinearities, it is usually faster to also provide \( \dot{y}_0\).
- Parameters:
initState – [in] Initial state \( y_0 \) of the model
-
virtual void applyInitialCondition(double const *const initState, double const *const initStateDot) = 0#
[source] Applies the given initial state to the model.
The initial state consists of the state \( y_0 \) and its time derivative \(\dot{y}_0\). It has to be consistent, which means that
\[ f\left( t_0, y_0, \dot{y}_0 ) = 0 \]has to hold. In other words, the initial condition has to fulfill the DAE at the initial time point \( t_0\).If only \( y_0 \) is given, the simulator will try to find a matching \( \dot{y}_0\) later. This is done according to the consistent initialization mode set by setConsistentInitialization(). Because of nonlinearities, it is usually faster to also provide \( \dot{y}_0\).
- Parameters:
initState – [in] Initial state \( y_0 \) of the model
initStateDot – [in] Initial time derivative state \( \dot{y}_0 \) of the model
-
virtual void applyInitialConditionFwdSensitivities(double const *const *const initSens, double const *const *const initSensDot) = 0#
[source] Applies the given initial state to the forward sensitivity systems.
The initial sensitivities are given by the argument
initSensand their time derivatives byinitSensDot. The model is not invoked to make changes to the initial values.If one of the parameters (
initSensorinitSensDot) isnullptr, the state vector and its time derivative will be set to zero and consistent values will be computed later.Consistent initialization is performed later according to the mode set by setConsistentInitializationSens().
- Parameters:
initSens – [in] Pointer to array with pointers to initial sensitivities or
nullptrinitSensDot – [in] Pointer to array with pointers to initial sensitivity time derivatives or
nullptr
-
virtual void initializeFwdSensitivities() = 0#
[source] Initializes the forward sensitivity subsystems with zero initial values.
The initial sensitivities are set to zero and (later) handed over to the model for consistent initialization.
-
virtual void skipConsistentInitialization() = 0#
[source] Skips consistent initialization at the beginning of integrate().
By skipping consistent initialization at the beginning of integrate(), a previous simulation can be resumed.
More detailed options can be applied with setConsistentInitialization().
-
virtual void setConsistentInitialization(ConsistentInitialization ci) = 0#
[source] Sets consistent initialization mode.
Sets consistent initialization mode for the subsequent calls to integrate(). Use skipConsistentInitialization() to skip the first consistent initialization.
- Parameters:
ci – [in] Consistent initialization mode
-
virtual void setConsistentInitializationSens(ConsistentInitialization ci) = 0#
[source] Sets consistent initialization mode of the sensitivity systems.
Sets consistent initialization mode for the subsequent calls to integrate(). Use skipConsistentInitialization() to skip the first consistent initialization.
- Parameters:
ci – [in] Consistent initialization mode of the sensitivity systems
-
virtual void initializeFwdSensitivities(double const *const *const initSens, double const *const *const initSensDot) = 0#
[source] Initializes the forward sensitivity subsystems with given initial values.
The initial sensitivities are given by the argument
initSensand their time derivatives byinitSensDot. The user is responsible for checking whether the initial values are correct and consistent with the sensitive parameters. The model is not invoked to make changes to the initial values.- Parameters:
initSens – [in] Pointer to array with pointers to initial sensitivities
initSensDot – [in] Pointer to array with pointers to initial sensitivity time derivatives
-
virtual void setSolutionRecorder(ISolutionRecorder *recorder) = 0#
[source] Sets the solution recorder which receives the solution of each time step.
The solution recorder is invoked for every time step when a solution and its sensitivities are to be saved. Setting the recorder to
NULLdisables recording the solution.- Parameters:
recorder – [in] Implementation of the cadet::ISolutionRecorder interface
-
virtual void integrate() = 0#
[source] Starts the solution of the system specified for this simulator object.
Checks all model parameters to lie inside their possible bounds and then runs the time integration from \(t_{start}\) to \(t_{end}\), restarting the time integrator at every section time specified by setSectionTimes. Solutions are stored by default at internal timesteps of the integration routine, or if a call to setSolutionTimes was made, at the specified user defined solution timepoints.
-
virtual double const *getLastSolution(unsigned int &len) const = 0#
[source] Returns the bare state vector for the last timepoint.
The method returns the last solution as it was written to the memory. The whole state vetor (including column, particle and flux parts) is returned. The ordering is rather unhandy, since the column, the particle, and the flux parts are of different size.
- Parameters:
len – [out] Length of the state vector
- Returns:
Pointer to the first element of the state vector
-
virtual double const *getLastSolutionDerivative(unsigned int &len) const = 0#
[source] Returns the bare time derivative state vector for the last timepoint.
See getLastSolution().
- Parameters:
len – [out] Length of the state vector
- Returns:
Pointer to first element of the state vector
-
virtual std::vector<double const*> getLastSensitivities(unsigned int &len) const = 0#
[source] Returns the bare sensitivity state vectors for the last timepoint.
The method returns the last solution of the sensitivity systems as it was written to memory. The whole state vetor (including column, particle and flux parts) is returned. The ordering is rather unhandy, since the column, the particle and the flux parts are of different size.
- Parameters:
len – [out] Length of the sensitivity state vector
- Returns:
Array with pointers to sensitivity state vectors
-
virtual std::vector<double const*> getLastSensitivityDerivatives(unsigned int &len) const = 0#
[source] Returns the bare time derivative state vectors of the sensitivity subsystems for the last timepoint.
See getLastSolutionDerivative().
- Parameters:
len – [out] Length of the sensitivity state vector
- Returns:
Array with pointers to sensitivity state vectors
-
virtual IModelSystem *model() noexcept = 0#
[source] Returns the simulated model.
- Returns:
Simulated model or
NULL
-
virtual IModelSystem const *model() const noexcept = 0#
[source]
-
virtual unsigned int numDofs() const noexcept = 0#
[source] Return the number of DOFs in the current simulation.
- Returns:
The number of DOFs
-
virtual void configure(IParameterProvider ¶mProvider) = 0#
[source] Reads all configuration values from the given parameter provider.
The scope of the cadet::IParameterProvider is unchanged on return.
- Parameters:
paramProvider – [in] Parameter provider
-
virtual void reconfigure(IParameterProvider ¶mProvider) = 0#
[source] Rereads all configuration values from the given parameter provider.
The scope of the cadet::IParameterProvider is unchanged on return.
- Parameters:
paramProvider – [in] Parameter provider
-
virtual bool reconfigureModel(IParameterProvider ¶mProvider) = 0#
[source] Rereads all configuration values of the current model from the given parameter provider.
The scope of the cadet::IParameterProvider is unchanged on return. This function only reconfigures the current model without recursing into submodels.
- Parameters:
paramProvider – [in] Parameter provider
- Returns:
trueif the configuration was successful, otherwisefalse
-
virtual bool reconfigureModel(IParameterProvider ¶mProvider, unsigned int unitOpIdx) = 0#
[source] Rereads all configuration values of the current model from the given parameter provider.
The scope of the cadet::IParameterProvider is unchanged on return. This function only reconfigures the unit operation model identified by its unit operation ID without recursing into submodels.
- Parameters:
paramProvider – [in] Parameter provider
unitOpIdx – [in] Unit operation index of the model to be reconfigured
- Returns:
trueif the configuration was successful, otherwisefalse
-
virtual void configureTimeIntegrator(double relTol, double absTol, double initStepSize, unsigned int maxSteps, double maxStepSize) = 0#
[source] Configures the time integrator.
Alternative to configure() and reconfigure().
- Parameters:
relTol – [in] Relative error tolerance
absTol – [in] Absolute error tolerance for each DOF
initStepSize – [in] Initial step size for each section
maxSteps – [in] Maximum number of time integration steps
maxStepSize – [in] Maximum step size of the time integrator
-
virtual void configureTimeIntegrator(double relTol, double absTol, const std::vector<double> &initStepSizes, unsigned int maxSteps, double maxStepSize) = 0#
[source]
-
virtual void setSensitivityErrorTolerance(double relTol, double const *absTol) = 0#
[source] Sets the error tolerances of the sensitivity systems.
One absolute error tolerance per sensitivity system is required.
- Parameters:
relTol – [in] Relative error tolerance
absTol – [in] Vector with absolute error tolerance for each sensitivity system
-
virtual void setNumThreads(unsigned int nThreads) noexcept = 0#
[source] Sets the number of threads for the simulation.
If the number of threads
nThreadsis0, the maximum number of threads is used.- Parameters:
nThreads – [in] Number of threads
-
virtual void setRelativeErrorTolerance(double relTol) = 0#
[source] Sets the relative error tolerance of the time integrator.
This tolerance is used for all elements of the state vector. Each element \( r_i \) in the residual is weighted by
\[ \frac{1}{\text{relTol} \left|r_i\right| + \text{absTol}_i}. \]- Parameters:
relTol – [in] Relative error tolerance
-
virtual void setAbsoluteErrorTolerance(double absTol) = 0#
[source] Sets the absolute error tolerance of the time integrator.
This tolerance is used for all elements of the state vector. Each element \( r_i \) in the residual is weighted by
\[ \frac{1}{\text{relTol} \left|r_i\right| + \text{absTol}_i}, \]which means that \( \text{absTol}_i \) does not depend on the index \( i \).- Parameters:
absTol – [in] Absolute error tolerance
-
virtual void setAbsoluteErrorTolerance(const std::vector<double> &absTol) = 0#
[source] Sets the absolute error tolerance of the time integrator.
Each element \( r_i \) in the residual is weighted by
\[ \frac{1}{\text{relTol} \left|r_i\right| + \text{absTol}_i}. \]- Parameters:
absTol – [in] Vector with absolute error tolerances for each component of the state vector
-
virtual void setAlgebraicErrorTolerance(double algTol) noexcept = 0#
[source] Sets the error tolerance of the nonlinear algebraic equation solvers.
This tolerance is used for consistent initialization of the nonlinear algebraic equations.
- Parameters:
algTol – [in] Algebraic error tolerance
-
virtual void setInitialStepSize(double stepSize) = 0#
[source] Sets the initial step size of the time integrator for each section.
Uses the same initial time step size for all sections.
- Parameters:
stepSize – [in] Size of the first attempted time step in each section
-
virtual void setInitialStepSize(const std::vector<double> &stepSize) = 0#
[source] Sets the initial step size of the time integrator for each section.
Uses a different initial time step size for each section.
- Parameters:
stepSize – [in] Vector of time step sizes for the first attempted step in each section
-
virtual void setMaximumSteps(unsigned int maxSteps) = 0#
[source] Sets the maximum number of time steps in each section.
If an integration process requires more than the specified number of time steps, the time integrator aborts with an exception.
- Parameters:
maxSteps – [in] Maximum number of time steps in each section
-
virtual void setMaximumStepSize(double maxStepSize) = 0#
[source] Sets the maximum time step size.
Set to
0.0to not impose any step size restriction.- Parameters:
maxStepSize – [in] Maximum size of time steps
-
virtual void setRelativeErrorToleranceSens(double relTol) = 0#
[source] Sets the relative error tolerance for sensitivity systems in the time integrator.
This tolerance is used for all elements of the sensitivity state vectors in all sensitivity systems. Each element \( r_i \) in the residual is weighted by
\[ \frac{1}{\text{relTol} \left|r_i\right| + \text{absTol}_i}. \]- Parameters:
relTol – [in] Relative error tolerance
-
virtual void setSensitivityErrorControl(bool enabled) = 0#
[source] Controls whether forward sensitivity systems are taken into account for the local error test in time integration.
The error in time integration can be estimated and is used for step size and order selection. This function controls whether forward sensitivity systems are taken into account in the local error test, which they are by default (
true).- Parameters:
enabled – [in] Determines whether sensitivities are taken into account in local error test
-
virtual void setMaxNewtonIteration(unsigned int nIter) = 0#
[source] Sets the maximum number of Newton iterations for a time integration step.
Each time step requires the solution of a nonlinear equation system which is performed by Newton iteration. Due to a good starting point (the last time step’s solution is supposed to be very close to the current step’s solution) a maximum of 3 iterations is used by default (see SUNDIALS 2.7.0). The iteration is stopped when the specified number of iterations is exceeded. A final convergence test is performed.
- Parameters:
nIter – [in] Maximum number of Newton iterations for a time step
-
virtual void setMaxErrorTestFails(unsigned int nFails) = 0#
[source] Sets the maximum number of (local truncation) error test failures for a time integration step.
The error in time integration can be estimated and is used for step size and order selection. The maximum number of failed local time step error tests defaults to 7 (see SUNDIALS 2.7.0). Time integration fails when the number of failures exceeds the specified value.
- Parameters:
nFails – [in] Maximum number of local error test failures for a time step
-
virtual void setMaxConvergenceFails(unsigned int nFails) = 0#
[source] Sets the maximum number of convergence test failures in the Newton iteration of a time step.
Each time step requires the solution of a nonlinear equation system which is performed by Newton iteration. If the convergence check of the iteration fails, the step size is reduced and a new iteration is started. The default for the number of failed convergence tests (i.e., Newton iterations) is set to 10 (see SUNDIALS 2.7.0). When the specified number of failures is exceeded, time integration fails.
- Parameters:
nFails – [in] Maximum number of convergence test failures
-
virtual void setMaxSensNewtonIteration(unsigned int nIter) = 0#
[source] Sets the maximum number of Newton iterations for each forward sensitivity system in a time integration step.
Each time step requires the solution of a nonlinear equation system which is performed by Newton iteration. After the original system has been solved, each forward sensitivity system is solved using a separate Newton iteration. The maximum number of iterations is controlled by this function and defaults to 3 (see SUNDIALS 2.7.0). After the iteration a convergence test is performed.
- Parameters:
nIter – [in] Maximum number of Newton iterations for a time step
-
virtual double lastSimulationDuration() const noexcept = 0#
[source] Returns the elapsed time of the last simulation run in seconds.
- Returns:
Elapsed time the last call of integrate() took in seconds
-
virtual double totalSimulationDuration() const noexcept = 0#
[source] Returns the accumulated time of all simulation runs in seconds.
- Returns:
Accumulated time of all calls of integrate() in seconds
-
virtual void setNotificationCallback(INotificationCallback *nc) noexcept = 0#
[source] Sets the receiver for notifications.
The callback is not owned by the simulator.
- Parameters:
nc – [in] Object to receive notifications or
nullptrto disable notifications
-
virtual bool stoppedByNotificationCallback() noexcept = 0#
[source] Checks whether the simulation was stopped by the notification callback.
-
virtual void prepareIntegrator() = 0#
[source] Prepares the simulator for step-by-step integration.
Performs initialization steps normally done in integrate(), including: parallelization setup, AD vector preparation, consistent initial conditions, and IDAS initialization. Stops before the actual time integration loop.
-
virtual int integrateStep(double tEnd, double &tReached) = 0#
[source] Performs one integration step to the specified target time.
Only supports single-section integration. Uses IDAS solver to advance the simulation and extracts sensitivity information if available.
- Parameters:
tEnd – [in] Target time to integrate to
tReached – [out] Actually reached time (may differ from tEnd)
- Returns:
0 on success, negative error code on failure
-
virtual int reinitialize(double currentTime) = 0#
[source] Reinitializes the integrator at the specified time.
Determines the current section, zeros yDot, notifies model of discontinuous section transition, applies lean consistent initialization, and reinitializes IDAS solver with the new state.
- Parameters:
currentTime – [in] Simulation time to reinitialize at
- Returns:
0 on success, negative error code on failure (e.g., -1 if IDAS not initialized)
-
virtual void setSensitiveParameter(const ParameterId &id) = 0#
Model builder#
-
class IModelBuilder#
[source] Provides functionality to build a model.
Builds a system of unit operation models or creates single unit operation models from given parameters.
The IModelBuilder owns all IModelSystem it created. The ownership of a specific system can be released by calling detachSystem(). Detached IModelSystem objects can be destroyed by calling destroySystem().
Note that the IModelBuilder does not own the created IModel objects. Unit operation models are supposed to be assigned to an IModelSystem which owns them. However, wrongfully created IModel objects can be destroyed by calling destroyUnitOperation().
Once registered, external functions are also owned by the IModelBuilder and can be released via detachExternalFunction(). Otherwise they will be deleted when the IModelBuilder is deleted. The external functions are indexed by the IModelBuilder, which serves as their ID.
Subclassed by cadet::ModelBuilder
Public Functions
-
virtual IModelSystem *createSystem(IParameterProvider ¶mProvider) = 0#
[source] Automatically constructs a system of unit operations and populates it from provided parameters.
Creates a unit operation system and uses the provided parameters to populate it with configured unit operation models that are also initialized. If one of the unit operation models could not be constructed from the parameters or an error occurred,
nullptris returned.The created IModelSystem is owned by the creating instance of IModelBuilder. It is automatically destroyed when the IModelBuilder that created it is destroyed. Ownership can be transferred by calling detachSystem().
- Parameters:
paramProvider – [in] ParameterProvider from which all necessary information is read
- Returns:
A fully populated system of unit operation models or
nullptrif an error occurred
-
virtual IModelSystem *createSystem() = 0#
[source] Creates an empty IModelSystem.
The created IModelSystem is empty and not configured
The created IModelSystem is owned by the creating instance of IModelBuilder. It is automatically destroyed when the IModelBuilder that created it is destroyed. Ownership can be transferred by calling detachSystem().
- Returns:
Empty IModelSystem
-
virtual void detachSystem(IModelSystem const *sys) = 0#
[source] Detaches the given IModelSystem from this IModelBuilder instance.
After the call this IModelBuilder object does not longer own the given IModelSystem.
- Parameters:
sys – [in] IModelSystem object to be detached
-
virtual void destroySystem(IModelSystem *sys) = 0#
[source] Destroys the given IModelSystem.
Frees all allocated memory corresponding to the given IModelSystem. Note that the given
sysmust not be owned by some IModelBuilder object, otherwise delete will be called on its memory location multiple times.- Parameters:
sys – [in] Ownerless IModelSystem object to be deleted
-
virtual IModel *createUnitOperation(IParameterProvider ¶mProvider, UnitOpIdx uoId) = 0#
[source] Automatically constructs a unit operation model from provided parameters.
Uses the provided parameters to create the correct unit operation model and initializes it with the corresponding parameter values. If the model could not be constructed from the provided parameters or an error occurred,
nullptris returned.The created unit operation model is not owned by the IModelBuilder. Ownership of unit operation models is handled by IModelSystem. Unit operation models can be destroyed by calling destroyUnitOperation().
- Parameters:
paramProvider – [in] ParameterProvider from which all necessary information is read
uoId – [in] Unit operation index assigned to the created unit operation
- Returns:
A fully populated unit operation model or
nullptrif an error occurred
-
virtual void destroyUnitOperation(IModel *unitOp) = 0#
[source] - virtual IModel* createUnitOperation(const std::string& uoType, UnitOpIdx uoId) = 0;
@brief Creates a unit operation model @details The created unit operation model is not owned by the IModelBuilder. Ownership of unit operation models is handled by IModelSystem. Unit operation models can be destroyed by calling destroyUnitOperation(). @param [in] uoType Name of the unit operation model @param [in] uoId Unit operation index assigned to the created unit operation @return Uninitialized unit operation model or @c nullptr if an error occurred ‍/
/** @brief Destroys the given IModel @details Frees all allocated memory corresponding to the given IModel. Note that the given @p unitOp must not be owned by some IModelSystem object, otherwise delete will be called on its memory location multiple times. @param [in] unitOp Ownerless IModel object to be deleted
-
virtual void registerInletType(const std::string &name, std::function<IInletProfile*(void)> factory) = 0#
Registers an inlet profile type.
- Parameters:
name – [in] Name of the inlet profile type
factory – [in] Factory function that creates the registered IInletProfile
-
virtual void registerExternalFunctionType(const std::string &name, std::function<IExternalFunction*(void)> factory) = 0#
Registers an external function type.
- Parameters:
name – [in] Name of the external function type
factory – [in] Factory function that creates the registered IExternalFunction
-
virtual IModelSystem *createSystem(IParameterProvider ¶mProvider) = 0#
Model system#
-
class IModelSystem#
[source] Interface for the main system of unit operation models.
Users of the library are not supposed to implement this interface! The simulator provided by this library is not capable of simulating models defined by custom user code. Instead, this interface defines all possible interactions of user code with this entity.
Subclassed by cadet::ISimulatableModel
Public Functions
-
virtual UnitOpIdx maxUnitOperationId() const noexcept = 0#
[source] Returns the highest unit operation index in the model system.
- Returns:
Highest unit operation index in the system or UnitOpIndep if there are no unit operations
-
virtual bool setParameter(const ParameterId &pId, int value) = 0#
[source] Sets a parameter value.
The parameter identified by its unique parameter is set to the given value.
- Parameters:
pId – [in] ParameterId that identifies the parameter uniquely
value – [in] Value of the parameter
- Returns:
trueif the parameter has been successfully set to the given value, otherwisefalse(e.g., if the parameter is not available in this model)
-
virtual bool hasParameter(const ParameterId &pId) const = 0#
[source] Checks whether a given parameter exists.
- Parameters:
pId – [in] ParameterId that identifies the parameter uniquely
- Returns:
trueif the parameter exists, otherwisefalse
-
virtual double getParameterDouble(const ParameterId &pId) const = 0#
[source] Returns the value of a parameter that can be made sensitive.
Returns
NaNif the parameter is not present in the model.- Parameters:
pId – [in] ParameterId that identifies the parameter uniquely
- Returns:
Value of the parameter or
NaNif the parameter was not found
-
virtual std::unordered_map<ParameterId, double> getAllParameterValues() const = 0#
[source] Returns all parameters with their current values that can be made sensitive.
- Returns:
Map with all parameters that can be made sensitive along with their current value
-
virtual void addModel(IModel *unitOp) = 0#
[source] Adds a given unit operation model to the system.
Ownership of the unit operation model is transferred to the IModelSystem
- Parameters:
unitOp – [in] Pointer to unit operation model to be added to the system
-
virtual IModel *getModel(unsigned int index) = 0#
[source] Returns a unit operation model identified by linear index (registration order) from the system.
- Parameters:
index – [in] Index of the queried model
- Returns:
Unit operation at the queried index or
nullptrif the index is invalid
-
virtual IModel *getUnitOperationModel(unsigned int unitOpIdx) = 0#
[source] Returns a unit operation model identified by unit operation index (creation order) from the system.
- Parameters:
unitOpIdx – [in] Unit operation index of the queried model
- Returns:
Unit operation with the queried unit operation index or
nullptrif no such unit operation exists
-
virtual unsigned int numModels() const noexcept = 0#
[source] Returns the number of unit operation models in the system.
- Returns:
Number of unit operation models in the system
-
virtual void removeModel(IModel const *unitOp) = 0#
[source] Removes the given unit operation model from the system.
Ownership is also removed from the system and transferred to the caller
- Parameters:
unitOp – [in] Unit operation to be removed from the system
-
virtual IModel *removeModel(UnitOpIdx unitOp) = 0#
[source] Removes the given unit operation model from the system if it exists.
Ownership is also removed from the system and transferred to the caller
- Parameters:
unitOp – [in] Unit operation ID of the model to be removed from the system
- Returns:
Pointer to the removed model if it was found, otherwise
nullptr
-
virtual unsigned int addExternalFunction(IExternalFunction &extFun) = 0#
[source] Adds an external function and hands over ownership to this object.
Ownership of the given IExternalFunction object is transferred to this IModelSystem object. It can be detached by calling removeExternalFunction().
- Parameters:
extFun – [in] Object implementing IExternalFunction interface
- Returns:
Index of the external function in this IModelSystem
-
virtual IExternalFunction *getExternalFunction(unsigned int index) = 0#
[source] Returns an external functions from the system.
- Parameters:
index – [in] Index of the queried external function
- Returns:
External function at the queried index or
nullptrif the index is invalid
-
virtual unsigned int numExternalFunctions() const noexcept = 0#
[source] Returns the number of external functions in the system.
- Returns:
Number of external functions in the system
-
virtual void removeExternalFunction(IExternalFunction const *extFun) = 0#
[source] Removes the given IExternalFunction from this IModelSystem instance.
After the call this IModelSystem object does not longer own the given IExternalFunction.
- Parameters:
extFun – [in] External function object to be removed
-
virtual std::tuple<unsigned int, unsigned int> getModelStateOffsets(UnitOpIdx unitOp) const noexcept = 0#
[source] Returns the start and end indices of a unit operation’s local slice in the global state vector.
- Parameters:
unitOp – [in] Unit operation ID for which local state position is required
- Returns:
Start and end indices of the local slice of model
unitOp
-
virtual UnitOpIdx maxUnitOperationId() const noexcept = 0#
Parameter provider#
-
class IParameterProvider#
[source] ParameterProvider interface is used for querying parameters and data.
Subclassed by cadet::JsonParameterProvider, cadet::ParameterProviderImpl< Reader_t >, cadet::api::v1::CallbackParameterProvider
Public Functions
-
virtual double getDouble(const std::string ¶mName) = 0#
[source] Returns the value of a parameter of type double.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter value
-
virtual int getInt(const std::string ¶mName) = 0#
[source] Returns the value of a parameter of type int.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter value
-
virtual uint64_t getUint64(const std::string ¶mName) = 0#
[source] Returns the value of a parameter of type uint64_t.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter value
-
virtual bool getBool(const std::string ¶mName) = 0#
[source] Returns the value of a parameter of type bool.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter value
-
virtual std::string getString(const std::string ¶mName) = 0#
[source] Returns the value of a parameter of type string.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter value
-
virtual std::vector<double> getDoubleArray(const std::string ¶mName) = 0#
[source] Returns a parameter array of type double.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter values
-
virtual std::vector<int> getIntArray(const std::string ¶mName) = 0#
[source] Returns a parameter array of type int.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter values
-
virtual std::vector<uint64_t> getUint64Array(const std::string ¶mName) = 0#
[source] Returns a parameter array of type uint64_t.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter values
-
virtual std::vector<bool> getBoolArray(const std::string ¶mName) = 0#
[source] Returns a parameter array of type bool.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter values
-
virtual std::vector<std::string> getStringArray(const std::string ¶mName) = 0#
[source] Returns a parameter array of type string.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Parameter values
-
virtual bool exists(const std::string ¶mName) = 0#
[source] Checks whether a given parameter exists.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
trueif the parameter exists, otherwisefalse
-
virtual bool isArray(const std::string ¶mName) = 0#
[source] Checks whether a given parameter is an array.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
trueif the parameter is an array, otherwisefalse
-
virtual std::size_t numElements(const std::string ¶mName) = 0#
[source] Returns the number of elements (of an array) in a given field.
- Parameters:
paramName – [in] Name of the parameter
- Returns:
Number of elements in the given field
-
virtual double getDouble(const std::string ¶mName) = 0#
Solution recorder#
-
class ISolutionRecorder#
[source] Interface providing functionality for recording the solution in the user space.
Library users implement this interface which is then used by the cadet::ISimulator to signal the user that a timestep has been finished and the solution is to be recorded.
First, the solution of the original system is reported by all unit operations. This is signaled by beginSolution(). Then, the solution of the forward sensitivity systems is reported, which is indicated by beginSensitivity().
Subclassed by cadet::InternalStorageSystemRecorder, cadet::InternalStorageUnitOpRecorder
Public Functions
-
virtual void clear() = 0#
[source] Clears existing data from memory.
Removes all stored results from memory.
-
virtual void prepare(unsigned int numDofs, unsigned int numSens, unsigned int numTimesteps) = 0#
[source] Prepares the recorder and allows it to allocate memory in advance.
This function is called after the recorder is passed to ISimulator.
- Parameters:
numDofs – [in] Number of DOFs in the model
numSens – [in] Number of forward sensitivities
numTimesteps – [in] Number of anticipated timesteps, can be
0if no estimate is available
-
virtual void notifyIntegrationStart(unsigned int numDofs, unsigned int numSens, unsigned int numTimesteps) = 0#
[source] Notifies the recorder of a starting time integration.
This function is called before ISimulator starts the time integration process. The ISolutionRecorder can choose to simply append the results of the time integration or clear all existing results from memory.
- Parameters:
numDofs – [in] Number of DOFs in the model
numSens – [in] Number of forward sensitivities
numTimesteps – [in] Number of anticipated timesteps, can be
0if no estimate is available
-
virtual void unitOperationStructure(UnitOpIdx idx, const IModel &model, const ISolutionExporter &exporter) = 0#
[source] Provides the internal structure of a unit operation which can be used for memory allocation.
After prepare() or notifyIntegrationStart() has been called, this function is called by each unit operation.
- Parameters:
idx – [in] Index of the unit operation
model – [in] Unit operation model
exporter – [in] Solution exporter providing access to the solution structure (no solution data is available)
-
virtual void beginTimestep(double t, bool writeUnitState = true) = 0#
[source] Signals the beginning of a new timestep solution export.
After a timestep has been finished, the solution is exported to the user space. This function is called once before all unit operations report their solutions via beginUnitOperation().
- Parameters:
t – [in] Current timepoint
writeUnitState – [in] If
true, internal unit state (bulk, particle, etc.) is recorded. Iffalse, only inlet/outlet data is recorded at this time point.
-
virtual void integratorMetaData(const IDASMeta &idasMeta) = 0#
[source] Signals the beginning of new IDAS meta data to export.
- Parameters:
idasMeta – [in] Container for IDAS meta data
-
virtual void beginUnitOperation(UnitOpIdx idx, const IModel &model, const ISolutionExporter &exporter) = 0#
[source] Signals the export of the given unit operation.
The solution of the given unit operation identified by its index
idxis provided by the correspondingexporter.- Parameters:
idx – [in] Index of the unit operation
model – [in] Unit operation model
exporter – [in] Solution exporter providing access to the solution
-
virtual void endUnitOperation() = 0#
[source] Signals the end of the solution export of the current unit operation.
This function is called after beginTimestep().
-
virtual void endTimestep() = 0#
[source] Signals the end of the solution export of the current timestep.
This function is called once after all unit operations have reported their solutions. The next timestep is about to be computed.
-
virtual void beginSolution() = 0#
[source] Signals the export of the solution of the original system.
This function is called once before all unit operations report their solutions via beginUnitOperation().
-
virtual void endSolution() = 0#
[source] Signals the end of the solution export of the original system.
This function is called once after all unit operations have reported their solutions to the user.
-
virtual void beginSolutionDerivative() = 0#
[source] Signals the export of the time derivative of the solution of the original system.
This function is called once before all unit operations report their solutions via beginUnitOperation().
-
virtual void endSolutionDerivative() = 0#
[source] Signals the end of the time derivative of the solution export of the original system.
This function is called once after all unit operations have reported their solutions to the user.
-
virtual void beginSensitivity(const ParameterId &pId, unsigned int sensIdx) = 0#
[source] Signals the beginning of the export of the sensitivity of the given parameter.
This function is called once for every sensitive parameter and is succeeded by calls reporting the sensitivity in each unit operation (beginUnitOperation()).
- Parameters:
pId – [in] Parameter Id of the sensitive parameter
sensIdx – [in] Index of the sensitive parameter (among all sensitive parameters)
-
virtual void endSensitivity(const ParameterId &pId, unsigned int sensIdx) = 0#
[source] Signals the end of the sensitivity export.
This function is called once for each sensitive parameter after all unit operations have reported their sensitivities.
- Parameters:
pId – [in] Parameter Id of the sensitive parameter
sensIdx – [in] Index of the sensitive parameter (among all sensitive parameters)
-
virtual void beginSensitivityDerivative(const ParameterId &pId, unsigned int sensIdx) = 0#
[source] Signals the beginning of the export of the parameter sensitivity’s time derivative.
This function is called once for every sensitive parameter and is succeeded by calls reporting the sensitivity in each unit operation (beginUnitOperation()).
- Parameters:
pId – [in] Parameter Id of the sensitive parameter
sensIdx – [in] Index of the sensitive parameter (among all sensitive parameters)
-
virtual void endSensitivityDerivative(const ParameterId &pId, unsigned int sensIdx) = 0#
[source] Signals the end of the sensitivity time derivative export.
This function is called once for each sensitive parameter after all unit operations have reported their sensitivities.
- Parameters:
pId – [in] Parameter Id of the sensitive parameter
sensIdx – [in] Index of the sensitive parameter (among all sensitive parameters)
-
virtual void clear() = 0#