Reaction models

Contents

You're reading the documentation for a development version. For the latest stable documentation, please have a look at v5.1.X.

Reaction models#

A dynamic reaction model adds reaction terms to one phase: the liquid (bulk or pore liquid), the solid, or across liquid and solid. Every reaction model implements cadet::model::IDynamicReactionModel; most derive from cadet::model::DynamicReactionModelBase, which handles the common parameter configuration. Unit operations and particle models hold their reaction models in a cadet::model::ReactionSystem, which groups them by phase.

Interface#

class IDynamicReactionModel#
[source]

Defines an internal DynamicReactionModel interface.

Represents dynamic reactions between components in a finite volume cell. Both simple and extended cells are supported. A simple cell contains only liquid phase components. An extended cell contains liquid and solid phase components.

Subclassed by cadet::model::CrystallizationReaction, cadet::model::DummyDynamicReaction, cadet::model::DynamicReactionModelBase

Public Functions

inline virtual ~IDynamicReactionModel() noexcept#
[source]
virtual const char *name() const noexcept = 0#
[source]

Returns the name of the dynamic reaction model.

This name is also used to identify and create the dynamic reaction model in the factory.

Returns:

Name of the dynamic reaction model

virtual bool requiresConfiguration() const noexcept = 0#
[source]

Returns whether the dynamic reaction model requires additional parameters supplied by configure().

After construction of an IDynamicReactionModel object, configureModelDiscretization() is called. The dynamic reaction model may require to read additional parameters from the reaction group of the parameter provider. This opportunity is given by a call to configure(). However, a dynamic reaction model may not require this. This function communicates to the outside whether a call to configure() is necessary.

Returns:

true if configure() has to be called, otherwise false

virtual bool usesParamProviderInDiscretizationConfig() const noexcept = 0#
[source]

Returns whether the dynamic reaction model uses the IParameterProvider in configureModelDiscretization().

If the IParameterProvider is used in configureModelDiscretization(), it has to be in the correct scope.

Returns:

true if the IParameterProvider is used in configureModelDiscretization(), otherwise false

virtual bool configureModelDiscretization(IParameterProvider &paramProvider, unsigned int nComp, unsigned int const *nBound, unsigned int const *boundOffset) = 0#
[source]

Sets the number of components in the model.

This function is called prior to configure() by the underlying model. It can only be called once. Model parameters are configured by configure().

Parameters:
  • paramProvider – [in] Parameter provider

  • nComp – [in] Number of components

  • nBound – [in] Array of size nComp which contains the number of bound states for each component

  • boundOffset – [in] Array of size nComp with offsets to the first bound state of each component beginning from the solid phase

virtual bool configure(IParameterProvider &paramProvider, UnitOpIdx unitOpIdx, ParticleTypeIdx parTypeIdx) = 0#
[source]

Configures the model by extracting all non-structural parameters (e.g., model parameters) from the given paramProvider.

The scope of the cadet::IParameterProvider is left unchanged on return.

     The structure of the model is left unchanged, that is, the number of degrees of
     freedom stays the same (e.g., number of bound states is left unchanged). Only
     true (non-structural) model parameters are read and changed.

     This function may only be called if configureModelDiscretization() has been called
     in the past. Contrary to configureModelDiscretization(), it can be called multiple
     times.

Parameters:
  • paramProvider – [in] Parameter provider

  • unitOpIdx – [in] Index of the unit operation this dynamic reaction model belongs to

  • parTypeIdx – [in] Index of the particle type this dynamic reaction model belongs to

Returns:

true if the configuration was successful, otherwise false

virtual void setExternalFunctions(IExternalFunction **extFuns, unsigned int size) = 0#
[source]

Sets external functions for this dynamic reaction model.

The external functions are not owned by this IDynamicReactionModel.

Parameters:
  • extFuns – [in] Pointer to array of IExternalFunction objects of size size

  • size – [in] Number of elements in the IExternalFunction array extFuns

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:

true if the parameter exists, otherwise false

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 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:

true if the parameter has been successfully set to the given value, otherwise false (e.g., if the parameter is not available in this model)

virtual bool setParameter(const ParameterId &pId, double value) = 0#
[source]
virtual bool setParameter(const ParameterId &pId, bool value) = 0#
[source]
virtual active *getParameter(const ParameterId &pId) = 0#
[source]

Returns a pointer to the parameter identified by the given id.

Parameters:

pId – [in] Parameter Id of the sensitive parameter

Returns:

a pointer to the parameter if the dynamic reaction model contains the parameter, otherwise nullptr

virtual bool dependsOnTime() const noexcept = 0#
[source]

Returns whether this dynamic reaction model depends on time.

Dynamic reaction models may depend on time if external functions are used.

Returns:

true if the model is time-dependent, otherwise false

virtual bool requiresWorkspace() const noexcept = 0#
[source]

Returns whether this dynamic reaction model requires workspace.

The workspace may be required for evaluation of residual and Jacobian. A workspace is a memory buffer whose size is given by workspaceSize().

Returns:

true if the model requires a workspace, otherwise false

virtual unsigned int workspaceSize(unsigned int nComp, unsigned int totalNumBoundStates, unsigned int const *nBoundStates) const noexcept = 0#
[source]

Returns the size of the required workspace in bytes.

The memory is required for externally dependent dynamic reaction models.

Parameters:
  • nComp – [in] Number of components

  • totalNumBoundStates – [in] Total number of bound states

  • nBoundStates – [in] Array with bound states for each component

Returns:

Size of the workspace in bytes

virtual int residualFluxAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, active const *y, active *res, const active &factor, LinearBufferAllocator workSpace) const = 0#
[source]

Evaluates the residual for one liquid phase cell.

Adds the dynamic reaction terms to the residual vector for the given liquid phase cell. The reaction terms are premultiplied with a given factor. That is, this function realizes

\[ \begin{align} \text{res} = \text{res} + \gamma R \end{align} \]
where \( R \) are the reaction terms.

This function is called simultaneously from multiple threads.

Parameters:
  • t – [in] Current time point

  • secIdx – [in] Index of the current section

  • colPos – [in] Position in normalized coordinates (column inlet = 0, column outlet = 1; outer shell = 1, inner center = 0)

  • y – [in] Pointer to first component in the current cell

  • res – [out] Pointer to residual of the first component in the current particle shell’s liquid phase

  • factor – [in] Factor \( \gamma \)

  • workSpace – [inout] Memory work space

Returns:

0 on success, -1 on non-recoverable error, and +1 on recoverable error

virtual int residualFluxAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, active const *y, active *res, double factor, LinearBufferAllocator workSpace) const = 0#
[source]
virtual int residualFluxAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, active *res, double factor, LinearBufferAllocator workSpace) const = 0#
[source]
virtual int residualFluxAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, double *res, double factor, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticJacobianAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, double factor, linalg::BandMatrix::RowIterator jac, LinearBufferAllocator workSpace) const = 0#
[source]

Adds the analytical Jacobian of the reaction terms for one liquid phase cell.

Adds the Jacobian of the dynamic reaction terms for the given liquid phase cell to the full Jacobian. The reaction terms are premultiplied with a given factor. That is, this function realizes

\[ \begin{align} J = J + \gamma J_R \end{align} \]
where \( J_R \) is the Jacobian of the reaction terms.

This function is called simultaneously from multiple threads. It can be left out (empty implementation) if AD is used to evaluate the Jacobian.

Parameters:
  • t – [in] Current time point

  • secIdx – [in] Index of the current section

  • colPos – [in] Position in normalized coordinates (column inlet = 0, column outlet = 1; outer shell = 1, inner center = 0)

  • nStates – [in] number of states

  • y – [in] Pointer to first component in the current cell

  • factor – [in] Factor \( \gamma \)

  • jac – [inout] Row iterator pointing to the first component row of the underlying matrix in which the Jacobian is stored

  • workSpace – [inout] Memory work space

virtual void analyticJacobianAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, double factor, linalg::DenseBandedRowIterator jac, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticJacobianAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, double factor, linalg::BandedSparseRowIterator jac, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticJacobianAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, double factor, linalg::BandedEigenSparseRowIterator jac, LinearBufferAllocator workSpace) const = 0#
[source]
virtual int residualCombinedAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, active const *yLiquid, active const *ySolid, active *resLiquid, active *resSolid, double factor, LinearBufferAllocator workSpace) const = 0#
[source]

Evaluates the residual for one combined phase cell.

Adds the dynamic reaction terms to the residual vector for the given combined phase cell. The reaction terms are premultiplied with a given factor. That is, this function realizes

\[ \begin{align} \text{res} = \text{res} + \gamma R \end{align} \]
where \( R \) are the reaction terms.

This function is called simultaneously from multiple threads.

Parameters:
  • t – [in] Current time point

  • secIdx – [in] Index of the current section

  • colPos – [in] Position in normalized coordinates (column inlet = 0, column outlet = 1; outer shell = 1, inner center = 0)

  • yLiquid – [in] Pointer to first component in the current cell’s liquid phase

  • ySolid – [in] Pointer to first component in the current cell’s solid phase

  • resLiquid – [out] Pointer to residual of the first component in the current particle shell’s liquid phase

  • resSolid – [out] Pointer to residual of the first bound state of the first component in the current particle shell

  • factor – [in] Factor \( \gamma \)

  • workSpace – [inout] Memory work space

Returns:

0 on success, -1 on non-recoverable error, and +1 on recoverable error

virtual int residualCombinedAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, double const *yLiquid, double const *ySolid, active *resLiquid, active *resSolid, double factor, LinearBufferAllocator workSpace) const = 0#
[source]
virtual int residualCombinedAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, double const *yLiquid, double const *ySolid, double *resLiquid, double *resSolid, double factor, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticJacobianCombinedAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, double const *yLiquid, double const *ySolid, double factor, linalg::BandMatrix::RowIterator jacLiquid, linalg::BandMatrix::RowIterator jacSolid, LinearBufferAllocator workSpace) const = 0#
[source]

Adds the analytical Jacobian of the reaction terms for one combined phase cell.

Adds the Jacobian of the dynamic reaction terms for the given combined phase cell to the full Jacobian. The reaction terms are premultiplied with a given factor. That is, this function realizes

\[ \begin{align} J = J + \gamma J_R \end{align} \]
where \( J_R \) is the Jacobian of the reaction terms.

This function is called simultaneously from multiple threads. It can be left out (empty implementation) if AD is used to evaluate the Jacobian.

Parameters:
  • t – [in] Current time point

  • secIdx – [in] Index of the current section

  • colPos – [in] Position in normalized coordinates (column inlet = 0, column outlet = 1; outer shell = 1, inner center = 0)

  • yLiquid – [in] Pointer to first component in the current cell’s liquid phase

  • ySolid – [in] Pointer to first component in the current cell’s solid phase

  • factor – [in] Factor \( \gamma \)

  • jacLiquid – [inout] Row iterator pointing to the first component row of the underlying matrix in which the Jacobian is stored

  • jacSolid – [inout] Row iterator pointing to the first bound state row of the underlying matrix in which the Jacobian is stored

  • workSpace – [inout] Memory work space

virtual void analyticJacobianCombinedAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, double const *yLiquid, double const *ySolid, double factor, linalg::DenseBandedRowIterator jacLiquid, linalg::DenseBandedRowIterator jacSolid, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticJacobianCombinedAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, double const *yLiquid, double const *ySolid, double factor, linalg::BandMatrix::RowIterator jacLiquid, linalg::DenseBandedRowIterator jacSolid, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticJacobianCombinedAdd(double t, unsigned int secIdx, const ColumnPosition &colPos, double const *yLiquid, double const *ySolid, double factor, linalg::BandedEigenSparseRowIterator jacLiquid, linalg::DenseBandedRowIterator jacSolid, LinearBufferAllocator workSpace) const = 0#
[source]
virtual unsigned int numReactionsLiquid() const noexcept = 0#
[source]

Returns the number of reactions for a liquid phase cell.

Returns:

Number of reactions

virtual unsigned int numReactionsCombined() const noexcept = 0#
[source]

Returns the number of reactions for a combined phase cell.

Returns:

Number of reactions

inline virtual unsigned int numReactions() const noexcept#
[source]
inline virtual bool supportsConservedMoieties() const noexcept#
[source]
inline virtual bool isInEquilibrium(unsigned int reaction) const noexcept#
[source]
inline virtual double getStoichiometry(unsigned int component, unsigned int reaction) const noexcept#
[source]
virtual int residualEquilibriumFlux(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, active const *y, active *res, unsigned int &eqIdx, LinearBufferAllocator workSpace) const = 0#
[source]
virtual int residualEquilibriumFlux(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, active *res, unsigned int &eqIdx, LinearBufferAllocator workSpace) const = 0#
[source]
virtual int residualEquilibriumFlux(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, double *res, unsigned int &eqIdx, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticEquilibriumJacobian(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, unsigned int &eqIdx, unsigned int eqRowOffset, linalg::BandMatrix::RowIterator jac, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticEquilibriumJacobian(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, unsigned int &eqIdx, unsigned int eqRowOffset, linalg::DenseBandedRowIterator jac, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticEquilibriumJacobian(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, unsigned int &eqIdx, unsigned int eqRowOffset, linalg::BandedSparseRowIterator jac, LinearBufferAllocator workSpace) const = 0#
[source]
virtual void analyticEquilibriumJacobian(double t, unsigned int secIdx, const ColumnPosition &colPos, const unsigned int nStates, double const *y, unsigned int &eqIdx, unsigned int eqRowOffset, linalg::BandedEigenSparseRowIterator jac, LinearBufferAllocator workSpace) const = 0#
[source]

Base class#

class DynamicReactionModelBase : public cadet::model::IDynamicReactionModel#
[source]

Defines a DynamicReactionModel base class that can be used to implement other dynamic reaction models.

This base class can be used as a starting point for new dynamic reaction models. Some common parameter handling is provided using a hash map (std::unordered_map).

Subclassed by cadet::model::ActivatedSludgeModelThreeBase< ActivatedSludgeModelThreeParamHandler >, cadet::model::ActivatedSludgeModelThreeBase< ExtActivatedSludgeModelThreeParamHandler >, cadet::model::MassActionLawCrossPhaseReactionBase< MassActionLawCrossPhaseParamHandler >, cadet::model::MassActionLawCrossPhaseReactionBase< ExtMassActionLawCrossPhaseParamHandler >, cadet::model::MassActionLawReactionBase< MassActionLawParamHandler >, cadet::model::MassActionLawReactionBase< ExtMassActionLawParamHandler >, cadet::model::MichaelisMentenBase< MichaelisMentenParamHandler >, cadet::model::MichaelisMentenBase< ExtMichaelisMentenParamHandler >, cadet::model::ActivatedSludgeModelThreeBase< ParamHandler_t >, cadet::model::MassActionLawCrossPhaseReactionBase< ParamHandler_t >, cadet::model::MassActionLawReactionBase< ParamHandler_t >, cadet::model::MichaelisMentenBase< ParamHandler_t >

Public Functions

inline virtual bool requiresConfiguration() const noexcept#
[source]

Returns whether the dynamic reaction model requires additional parameters supplied by configure().

After construction of an IDynamicReactionModel object, configureModelDiscretization() is called. The dynamic reaction model may require to read additional parameters from the reaction group of the parameter provider. This opportunity is given by a call to configure(). However, a dynamic reaction model may not require this. This function communicates to the outside whether a call to configure() is necessary.

Returns:

true if configure() has to be called, otherwise false

inline virtual bool usesParamProviderInDiscretizationConfig() const noexcept#
[source]

Returns whether the dynamic reaction model uses the IParameterProvider in configureModelDiscretization().

If the IParameterProvider is used in configureModelDiscretization(), it has to be in the correct scope.

Returns:

true if the IParameterProvider is used in configureModelDiscretization(), otherwise false

virtual bool configure(IParameterProvider &paramProvider, UnitOpIdx unitOpIdx, ParticleTypeIdx parTypeIdx)#
[source]

Configures the model by extracting all non-structural parameters (e.g., model parameters) from the given paramProvider.

The scope of the cadet::IParameterProvider is left unchanged on return.

     The structure of the model is left unchanged, that is, the number of degrees of
     freedom stays the same (e.g., number of bound states is left unchanged). Only
     true (non-structural) model parameters are read and changed.

     This function may only be called if configureModelDiscretization() has been called
     in the past. Contrary to configureModelDiscretization(), it can be called multiple
     times.

Parameters:
  • paramProvider – [in] Parameter provider

  • unitOpIdx – [in] Index of the unit operation this dynamic reaction model belongs to

  • parTypeIdx – [in] Index of the particle type this dynamic reaction model belongs to

Returns:

true if the configuration was successful, otherwise false

virtual bool configureModelDiscretization(IParameterProvider &paramProvider, unsigned int nComp, unsigned int const *nBound, unsigned int const *boundOffset)#
[source]

Sets the number of components in the model.

This function is called prior to configure() by the underlying model. It can only be called once. Model parameters are configured by configure().

Parameters:
  • paramProvider – [in] Parameter provider

  • nComp – [in] Number of components

  • nBound – [in] Array of size nComp which contains the number of bound states for each component

  • boundOffset – [in] Array of size nComp with offsets to the first bound state of each component beginning from the solid phase

virtual std::unordered_map<ParameterId, double> getAllParameterValues() const#
[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 bool hasParameter(const ParameterId &pId) const#
[source]

Checks whether a given parameter exists.

Parameters:

pId – [in] ParameterId that identifies the parameter uniquely

Returns:

true if the parameter exists, otherwise false

virtual bool setParameter(const ParameterId &pId, int value)#
[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:

true if the parameter has been successfully set to the given value, otherwise false (e.g., if the parameter is not available in this model)

virtual active *getParameter(const ParameterId &pId)#
[source]

Returns a pointer to the parameter identified by the given id.

Parameters:

pId – [in] Parameter Id of the sensitive parameter

Returns:

a pointer to the parameter if the dynamic reaction model contains the parameter, otherwise nullptr

inline virtual void setExternalFunctions(IExternalFunction **extFuns, unsigned int size)#
[source]

Sets external functions for this dynamic reaction model.

The external functions are not owned by this IDynamicReactionModel.

Parameters:
  • extFuns – [in] Pointer to array of IExternalFunction objects of size size

  • size – [in] Number of elements in the IExternalFunction array extFuns

inline bool hasQuasiStationaryReactions() const noexcept#
[source]

Returns whether at least one reaction of this model is in rapid equilibrium.

Protected Functions

virtual bool configureImpl(IParameterProvider &paramProvider, UnitOpIdx unitOpIdx, ParticleTypeIdx parTypeIdx) = 0#
[source]

Configures the reaction model.

This function implements the (re-)configuration of a reaction model. It is called when the reaction model is configured or reconfigured. On call the _parameters map will always be empty.

Parameters:
  • paramProvider – [in] Parameter provider

  • unitOpIdx – [in] Unit operation index

  • parTypeIdx – [in] Particle type index

Returns:

true if the configuration was successful, otherwise false

bool readQuasiStationarity(IParameterProvider &paramProvider)#
[source]

Reads the reaction dynamics (kinetic or rapid equilibrium) of every reaction.

Reads the optional field IS_KINETIC, which is either a scalar applying to all reactions or an array with one entry per reaction. Reactions default to kinetic. Called after configureImpl(), since only then is numReactions() known.

Parameters:

paramProvider – [in] Parameter provider

Throws:

InvalidParameterException – if IS_KINETIC is given for a model without reactions or has too few elements

Returns:

true if the configuration was successful, otherwise false

Protected Attributes

int _nComp#
[source]

Number of components.

unsigned int const *_nBoundStates#
[source]

Array with number of bound states for each component.

unsigned int const *_boundOffset#
[source]

Array with offsets to the first bound state of each component.

std::vector<bool> _reactionQuasistationarity#
[source]

Determines whether each reaction is in rapid equilibrium (true) or kinetic (false).

std::unordered_map<ParameterId, active*> _parameters#
[source]

Map used to translate ParameterIds to actual variables.

Reaction system#

struct ReactionSystem#
[source]

Manages reaction models across different phases in a unit operation.

The ReactionSystem organizes and manages dynamic reaction models for different phases (cross_phase, solid, bulk, liquid) within a unit operation. It handles configuration, discretization, and memory management of reaction models.

Public Functions

inline bool hasReactions()#
[source]

Checks if any reactions are present in the system.

Returns:

True if at least one reaction exists, false otherwise

inline void addReactionModel(const std::string &phaseType, IDynamicReactionModel *reactionModel)#
[source]

Adds a dynamic reaction model to a specific phase.

Parameters:
  • phaseType – The phase type to add the reaction to

  • reactionModel – Pointer to the dynamic reaction model to add

inline const std::vector<IDynamicReactionModel*> &getDynReactionVector(const std::string &phase_type) const#
[source]

Gets const reference to dynamic reaction vector for a phase.

Parameters:

phase_type – The phase type to retrieve reactions for

Returns:

Const reference to the vector of dynamic reaction models

inline std::vector<IDynamicReactionModel*> &getDynReactionVector(const std::string &phase_type)#
[source]

Gets mutable reference to dynamic reaction vector for a phase.

Parameters:

phase_type – The phase type to retrieve reactions for

Returns:

Mutable reference to the vector of dynamic reaction models

inline void configureDimensions(const std::string &phaseType, unsigned int numReac)#
[source]

Configures the dimensions of the dynamic reaction vector for a phase.

Parameters:
  • phaseType – The phase type to configure

  • numReac – Number of reactions to allocate space for

inline bool configureDiscretization(std::string phaseType, int nReactions, unsigned int nComp, unsigned int *nBound, unsigned int *boundOffset, IParameterProvider &paramProvider, const IConfigHelper &helper)#
[source]

Configures discretization for reaction models in a specific phase.

Parameters:
  • phaseType – The phase type to configure

  • nReactions – Number of reactions to configure, as read from NREAC_<PHASE>

  • nComp – Number of components

  • nBound – Array of bound states per component

  • boundOffset – Array of bound state offsets per component

  • paramProvider – Parameter provider for configuration

  • helper – Configuration helper for creating reaction models

Returns:

True if configuration succeeded, false otherwise

inline bool configure(std::string phaseType, unsigned int parType, unsigned int unitOpIdx, IParameterProvider &paramProvider, bool uoImplementsReqReactions, double rankTol = 1e-14)#
[source]

Configures reaction models for a specific phase and particle type.

If any reaction of the phase is declared to be in rapid equilibrium (IS_KINETIC = 0), the conserved-moiety reformulation is set up right after the reaction models themselves, and the configuration is rejected when either the phase or the hosting unit operation cannot solve it.

Parameters:
  • phaseType – The phase type to configure

  • parType – The particle type index

  • unitOpIdx – Unit operation index

  • paramProvider – Parameter provider for configuration

  • uoImplementsReqReactions – Whether the hosting unit operation implements rapid-equilibrium reactions for this phase. Passing true asserts that the host applies the conserved-moiety transform next to its transport operators in all three places that touch the state: residual, Jacobian and consistent initialization. ColumnModel1D is the reference implementation.

  • rankTol – Tolerance on the singular values determining the stoichiometric rank

Throws:

InvalidParameterException – if a rapid-equilibrium reaction is not supported here

Returns:

True if configuration succeeded, false otherwise

inline bool configureConservedMoities(const std::string &phaseType, unsigned int nStates, double rankTol)#
[source]

Builds the conserved-moiety reformulation for the quasi-stationary reactions of a phase.

Computes the left nullspace of the stoichiometry of the phase’s equilibrium reactions, which trades their state rows for conserved-moiety rows plus algebraic equilibrium equations.

Called by configure() whenever a phase holds a rapid-equilibrium reaction, after requireEquilibriumSupport() has established that phase and hosting unit operation can solve it. The host then has to apply the transform alongside its transport operators in all three places that touch the state (residual, Jacobian and consistent initialization) or the reaction is still solved incorrectly. ColumnModel1D is the reference implementation.

Parameters:
  • phaseType – [in] Phase to configure, must not be “cross_phase”

  • nStates – [in] Number of states of the phase (components, or total bound states for solid)

  • rankTol – [in] Tolerance on the singular values determining the stoichiometric rank

Throws:

InvalidParameterException – for “cross_phase”, for redundant equilibrium reactions, or for a reformulation that does not close the system

Returns:

True if configuration succeeded, false otherwise

inline bool hasEquilibriumReactions(const std::string &phaseType) const#
[source]

Checks whether a phase contains reactions that are declared quasi-stationary.

Parameters:

phaseType – The phase type to inspect

Returns:

True if at least one reaction of the phase is in equilibrium, false otherwise

inline void requireEquilibriumSupport(const std::string &phaseType, unsigned int unitOpIdx, bool uoImplementsReqReactions) const#
[source]

Rejects quasi-stationary reactions in phases the hosting model cannot solve.

Quasi-stationary reactions turn the reaction terms of a phase into algebraic equations, which requires the conserved-moiety reformulation set up by configureConservedMoities(). A hosting model that does not call it for a phase only evaluates kinetic reaction fluxes, so a quasi-stationary reaction would be dropped from the residual without anything taking its place. Reject such a configuration instead of silently returning the solution of a system in which the reaction does not happen.

The reformulation replaces the balance equations of the participating states, so it has to be carried by the hosting unit operation as well. Both conditions are checked here: the phase has to be one the reformulation is implemented for, and the host has to declare that it implements it.

Parameters:
  • phaseType – The phase holding the rapid-equilibrium reactions

  • unitOpIdx – Unit operation index, used in the error message

  • uoImplementsReqReactions – Whether the hosting unit operation implements the reformulation

Throws:

InvalidParameterException – if rapid-equilibrium reactions are unsupported here

inline void setWorkspaceRequirements(std::string phaseType, unsigned int nComp, unsigned int const strideBound, LinearMemorySizer &lms) const#
[source]

Sets workspace requirements for all reaction models across all phases.

Parameters:
  • phaseType – The phase type to configure

  • nComp – Number of components

  • strideBound – Stride of bound states

  • lms – Linear memory sizer to configure workspace requirements

inline void clearDynamicReactionModels()#
[source]

Clears and deletes all dynamic reaction models in all phases Properly deallocates memory and resets vectors to safe state.

inline void empty()#
[source]

Empties all reaction vectors without deleting the models Used for cleanup without memory deallocation.

inline ReactionSystem()#
[source]

Default constructor - initializes phase map with default values.

inline ~ReactionSystem()#
[source]

Destructor - cleans up dynamic reaction models.

Public Static Functions

static inline bool isPhaseEquilibriumCapable(const std::string &phaseType) noexcept#
[source]

Returns whether the conserved-moiety reformulation is implemented for a phase.

Independent of the hosting unit operation. A cross phase reaction couples a bulk equation to a boundary condition and a solid phase reaction has no transport of its own, so neither is covered by the reformulation.

static inline void create(std::vector<ReactionSystem*> &reacParticle)#
[source]

Creates and configures a new ReactionSystem for each particle type.

Parameters:

reacParticle – Vector to hold the created ReactionSystem pointers