Unit operations

Contents

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

Unit operations#

A unit operation contributes its states and residual equations to the model system, which the time integrator solves as one DAE. Every unit operation implements cadet::IUnitOperation; most derive from cadet::model::UnitOperationBase, which handles the parameter configuration. Column models delegate the transport of their bulk liquid to a convection-dispersion operator and their particle phases to Particle models, one per particle type.

The steps for adding a unit operation are described in Model Expansion.

Interface#

class IUnitOperation : public cadet::IModel#
[source]

Defines an unit operation model interface.

Subclassed by cadet::model::InletModel, cadet::model::OutletModel, cadet::model::UnitOperationBase

Public Functions

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

Return the number of required DOFs.

This includes any additional coupling DOFs.

Returns:

The number of required DOFs

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

Return the number of pure DOFs excluding all additional coupling DOFs.

If numDofs() == numPureDofs(), then no additional coupling DOFs are used. Otherwise, the number of pure DOFs (e.g., sum of DOFs of all submodels) is returned.

Returns:

The number of pure DOFs

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

Returns whether AD is used for computing the system Jacobian.

This is independent of any parameter sensitivity.

Returns:

true if AD is required, otherwise false

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

Returns the amount of required AD seed vectors / directions.

Only internally required AD directions count (e.g., for Jacobian computation). Directions used for parameter sensitivities should not be included here.

Returns:

The number of required AD seed vectors / directions

virtual bool configureModelDiscretization(IParameterProvider &paramProvider, const IConfigHelper &helper) = 0#
[source]

Configures the model discretization by extracting all structural parameters from the given paramProvider.

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

     Only the structure / discretization (e.g., number of components, adsorption
     model, bound states) is configured. The actual model parameters are configured
     in configure(). 

     This function can only be called once. Once the discretization is set, it cannot
     be changed.

Parameters:
  • paramProvider – [in] Parameter provider

  • helper – [in] Used to inject or create required objects

Returns:

true if the configuration was successful, otherwise false

virtual bool configure(IParameterProvider &paramProvider) = 0#
[source]

(Re-)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. Only true (non-structural) model parameters are read and
     changed. Parameters that concern discretization (e.g., number of cells), model
     structure (e.g., number of components, binding model), and numerical solution
     (e.g., tolerances in GMRES iterations) are left untouched.

     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

Returns:

true if the configuration was successful, otherwise false

virtual void reportSolution(ISolutionRecorder &reporter, double const *const solution) const = 0#
[source]

Reports the given solution to the cadet::ISolutionRecorder.

Parameters:
  • reporter – [in] Where to report the solution to

  • solution – [in] Solution that is reported (from index 0 to numDofs())

virtual void reportSolutionStructure(ISolutionRecorder &reporter) const = 0#
[source]

Reports the solution structure (ordering of DOFs) to the cadet::ISolutionRecorder.

Parameters:

reporter – [in] Where to report the solution structure to

virtual bool setSensitiveParameter(const ParameterId &pId, unsigned int adDirection, double adValue) = 0#
[source]

Marks a parameter as sensitive (i.e., sensitivities for this parameter are to be computed).

Parameters:
  • pId – [in] Parameter Id of the sensitive parameter

  • adDirection – [in] AD direction assigned to this parameter

  • adValue – [in] Value of the derivative in the given direction

Returns:

true if the parameter has been found in the model, otherwise false

virtual void setSensitiveParameterValue(const ParameterId &id, double value) = 0#
[source]

Sets the value of a parameter that can be sensitive.

This also sets values of parameters that are not marked as sensitive at the moment. If the parameter is part of a fused sensitivity, then all fused parameters are set to the same value by calling this function for each parameter.

Note that the AD directions are kept invariant (i.e., they are not resetted).

Parameters:
  • id – [in] Parameter ID of the parameter to be manipulated

  • value – [in] Value of the parameter

virtual void clearSensParams() = 0#
[source]

Clears all sensitive parameters.

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

Returns the number of sensitive parameters in this unit operation.

Returns:

Number of sensitive parameters

virtual void notifyDiscontinuousSectionTransition(double t, unsigned int secIdx, const ConstSimulationState &simState, const AdJacobianParams &adJac) = 0#
[source]

Notifies the model that a discontinuous section transition is in progress.

This function is called after time integration of a section has finished and a new section is about to be integrated. This allows the model to update internal state before consistent initialization is performed.

This function is also called at the beginning of the time integration, which allows the model to perform setup operations.

If AD is used by the model, the function has the opportunity to update the seed vectors. The general initialization of the seed vectors is performed by prepareADvectors().

Parameters:
  • t – [in] Current time point

  • secIdx – [in] Index of the new section that is about to be integrated

  • simState – [in] Simulation state

  • adJac – [inout] Jacobian information for AD (AD vectors for residual and state, direction offset)

virtual void applyInitialCondition(const SimulationState &simState) const = 0#
[source]

Applies initial conditions to the state vector and its time derivative.

The initial conditions do not need to be consistent at this point. On a (discontinuous) transition from one section to the next, consistentInitialConditions() is called by the time integrator in order to compute consistent initial conditions. Therefore, consistentInitialConditions() is also called at the beginning of the simulation, that is, the initial conditions set by this function will be corrected for consistency. Note that the state vector and its time derivative are pre-initialized with zero by the time integrator.

Parameters:

simState – [inout] State of the simulation (state vector and its time derivatives) to be updated with initial values

virtual void readInitialCondition(IParameterProvider &paramProvider) = 0#
[source]

Reads initial conditions for the state vector and its time derivative from the given parameter provider.

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

Parameters:

paramProvider – [in] Parameter provider

virtual int residual(const SimulationTime &simTime, const ConstSimulationState &simState, double *const res, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes the residual.

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • res – [out] Pointer to local residual vector

Returns:

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

virtual int jacobian(const SimulationTime &simTime, const ConstSimulationState &simState, double *const res, const AdJacobianParams &adJac, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes the Jacobian (analytical or AD).

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • res – [out] Pointer to local residual vector, optional

  • adJac – [inout] Jacobian information for AD (AD vectors for residual and state, direction offset)

Returns:

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

virtual int residualWithJacobian(const SimulationTime &simTime, const ConstSimulationState &simState, double *const res, const AdJacobianParams &adJac, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes the residual and updates the Jacobian.

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • res – [out] Pointer to local residual vector

  • adJac – [inout] Jacobian information for AD (AD vectors for residual and state, direction offset)

Returns:

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

virtual int linearSolve(double t, double alpha, double tol, double *const rhs, double const *const weight, const ConstSimulationState &simState) = 0#
[source]

Computes the solution of the linear system involving the system Jacobian.

The system

\[ \left( \frac{\partial F}{\partial y} + \alpha \frac{\partial F}{\partial \dot{y}} \right) x = b \]
has to be solved. The right hand side \( b \) is given by rhs, the Jacobians are evaluated at the point \((y, \dot{y})\) given by y and yDot. The residual res at this point, \( F(t, y, \dot{y}) \), may help with this. Error weights (see IDAS guide) are given in weight. The solution is returned in rhs.

Parameters:
  • t – [in] Current time point

  • alpha – [in] Value of \( \alpha \) (arises from BDF time discretization)

  • tol – [in] Error tolerance for the solution of the linear system from outer Newton iteration

  • rhs – [inout] On entry the right hand side of the linear equation system, on exit the solution

  • weight – [in] Vector with error weights

  • simState – [in] State of the simulation (state vector and its time derivative)

Returns:

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

virtual void prepareADvectors(const AdJacobianParams &adJac) const = 0#
[source]

Prepares the AD system vectors by constructing seed vectors.

Sets the seed vectors used in AD. Since the AD vector slice is fully managed by the model, the seeds are unchanged during one time integration (except for possible changes in notifyDiscontinuousSectionTransition()). This function is called at the beginning of every time integration and should initialize the AD seed vectors.

If those vectors do not change during one time integration, their initialization should be performed in this function. The notifyDiscontinuousSectionTransition() function is only used to update seed vectors during time integration.

Parameters:

adJac – [inout] Jacobian information for AD (AD vectors for residual and state, direction offset)

virtual void initializeSensitivityStates(const std::vector<double*> &vecSensY) const = 0#
[source]

Sets initial sensitivity system state.

Given the DAE

\[ F(t, y, \dot{y}, p) = 0, \]
the corresponding (linear) forward sensitivity system reads
\[ \frac{\partial F}{\partial y}(t, y, \dot{y}) s + \frac{\partial F}{\partial \dot{y}}(t, y, \dot{y}) \dot{s} + \frac{\partial F}{\partial p}(t, y, \dot{y}) = 0. \]
The initial value of \( s_0 = \frac{\mathrm{d} y_0}{\mathrm{d}p} \) is set by this function. Note that consistent initialization is performed later, which in particular calculates a matching \( \dot{s}_0 = \frac{\mathrm{d} \dot{y}_0}{\mathrm{d}p}. \)

The sensitivity state vectors passed to this function are initialized to 0. They only have to change in case of sensitivities with respect to initial conditions.

Parameters:

vecSensY – [out] Sensitivity subsystem state vectors

virtual void setSectionTimes(double const *secTimes, bool const *secContinuity, unsigned int nSections) = 0#
[source]

Sets the section time vector.

The integration time is partitioned into sections. All parameters and equations are assumed continuous inside one section. Thus, sections provide means to implement discontinuous behavior (e.g., pulse injection profiles, switching of valves). After initialization, the simulator notifies all entities such as models or data sources of its section times.

The vector of section times consists of strictly increasing time points

\[ t_0 < t_1 < t_2 < \dots t_N \]
which mark the beginning and end of a section. The \( i\)-th section is given by \( \left[ t_i, t_{i+1} \right]. \) If a transition from one section to the next is continuous, the secContinuity flag for that transition is true. In this case, the time integrator will not stop at the transition time point and reinitialize consistently (which will be done for discontinuous transitions).

Parameters:
  • secTimes – [in] Vector with section time points (length is nSections + 1)

  • secContinuity – [in] Vector of flags that indicate a continuous (true) or discontinuous (false) transition from the current section to the next one (length is nSections - 1). For instance, the first element indicates whether the transition from section 0 to 1 is continuous.

  • nSections – [in] Number of sections

virtual void expandErrorTol(double const *errorSpec, unsigned int errorSpecSize, double *expandOut) = 0#
[source]

Expand a (short) error tolerance specification into a detailed / full one.

The format of the short error specification is model specific. Common variants are error tolerances for each component in each phase (independent of the specific discretization of the model). The short error spec is expanded into a full one which contains an error tolerance for each (pure) DOF of the model.

Parameters:
  • errorSpec – [in] Pointer to first element of an array containing the short error spec

  • errorSpecSize – [in] Size of the short error tolerance spec

  • expandOut – [out] Pointer to the first element of an array receiving the full error specification

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

Returns the number of components.

It is assumed that the number of components is also the number of inputs and outputs of the unit operation.

Returns:

Number of components

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

Returns whether this unit operation possesses an inlet.

Returns:

true if the unit operation can take in a stream, otherwise false

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

Returns whether this unit operation possesses an outlet.

Returns:

true if the unit operation can output a stream, otherwise false

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

Returns the number of inlet ports.

Returns:

Number of inlet ports

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

Returns the number of outlet ports.

Returns:

Number of outlet ports

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

Returns the local index of the first outlet component of the given port in the managed state vector slice.

As each unit operation manages a slice of the global state vector on its own, the position of inlet and outlet components as DOF in the slice may differ. This function returns the local index in the slice of the first outlet component of the given port.

Parameters:

port – [in] Index of the port

Returns:

Local index of the first outlet component in the state vector slice

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

Returns the local index stride in the managed state vector slice.

This function returns the number of elements between two components of a given port in the slice of the global state vector.

Parameters:

port – [in] Index of the port

Returns:

Local stride in the state vector slice

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

Returns the local index of the first inlet component of the given port in the managed state vector slice.

As each unit operation manages a slice of the global state vector on its own, the position of inlet and outlet components as DOF in the slice may differ. This function returns the local index in the slice of the first inlet component of the given port.

Parameters:

port – [in] Index of the port

Returns:

Local index of the first inlet component in the state vector slice

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

Returns the local index stride in the managed state vector slice.

This function returns the number of elements between two components of a given port in the slice of the global state vector.

Parameters:

port – [in] Index of the port

Returns:

Local stride in the state vector slice

virtual int residualSensFwdAdOnly(const SimulationTime &simTime, const ConstSimulationState &simState, active *const adRes, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Evaluates the residuals with AD to compute the sensitivity derivatives.

Evaluates \( \frac{\partial F}{\partial p} \), where \( p \) are the sensitive parameters and \( F \) is the residual function of this model.

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • adRes – [inout] Pointer to local residual vector of AD datatypes for computing the sensitivity derivatives

Returns:

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

virtual int residualSensFwdCombine(const SimulationTime &simTime, const ConstSimulationState &simState, const std::vector<const double*> &yS, const std::vector<const double*> &ySdot, const std::vector<double*> &resS, active const *adRes, double *const tmp1, double *const tmp2, double *const tmp3) = 0#
[source]

Computes the residual of the forward sensitivity systems using the result of residualSensFwdAdOnly().

Assembles and evaluates the residuals of the sensitivity systems

\[ \frac{F}{\partial y} s + \frac{F}{\partial \dot{y}} \dot{s} + \frac{\partial F}{\partial p_i} = 0. \]

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • yS – [in] Pointers to local sensitivity state vectors

  • ySdot – [in] Pointers to local sensitivity time derivative state vectors

  • resS – [out] Pointers to local sensitivity residuals

  • adRes – [in] Pointer to local residual vector of AD datatypes with the sensitivity derivatives from residualSensFwdAdOnly()

  • tmp1 – [in] Temporary storage in the size of local state vector y

  • tmp2 – [in] Temporary storage in the size of local state vector of y

  • tmp3 – [in] Temporary storage in the size of local state vector of y

Returns:

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

virtual int residualSensFwdWithJacobian(const SimulationTime &simTime, const ConstSimulationState &simState, const AdJacobianParams &adJac, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Evaluates the residuals with AD to compute the parameter sensitivities and at the same time updates the Jacobian.

Evaluates \( \frac{\partial F}{\partial p} \), where \( p \) are the sensitive parameters and \( F \) is the residual function of this model. At the same time updates the Jacobian of the system.

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • adJac – [inout] Jacobian information for AD (AD vectors for residual and state, direction offset)

Returns:

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

virtual void consistentInitialState(const SimulationTime &simTime, double *const vecStateY, const AdJacobianParams &adJac, double errorTol, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes consistent initial values (state variables without their time derivatives).

Given the DAE

\[ F(t, y, \dot{y}) = 0, \]
the initial values \( y_0 \) and \( \dot{y}_0 \) have to be consistent. This functions updates the initial state \( y_0 \) and, therefore, provides the first step in consistent initialization.

This function is to be used with consistentInitialTimeDerivative(). Do not mix normal and lean consistent initialization!

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • vecStateY – [inout] State vector with initial values that are to be updated for consistency

  • adJac – [inout] Jacobian information for AD (AD vectors for residual and state, direction offset)

  • errorTol – [in] Error tolerance for algebraic equations

virtual void consistentInitialTimeDerivative(const SimulationTime &simTime, double const *vecStateY, double *const vecStateYdot, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes consistent initial time derivatives.

Given the DAE

\[ F(t, y, \dot{y}) = 0, \]
the initial values \( y_0 \) and \( \dot{y}_0 \) have to be consistent. This functions overwrites the initial time derivatives \( \dot{y}_0 \) such that the residual is zero. Thus, this function provides the final step in consistent initialization.

This function is to be used with consistentInitialState(). Do not mix normal and lean consistent initialization!

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • vecStateY – [in] Consistently initialized state vector

  • vecStateYdot – [inout] On entry, residual without taking time derivatives into account. On exit, consistent state time derivatives.

virtual void leanConsistentInitialState(const SimulationTime &simTime, double *const vecStateY, const AdJacobianParams &adJac, double errorTol, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes approximately / partially consistent initial values (state variables without their time derivatives).

Given the DAE

\[ F(t, y, \dot{y}) = 0, \]
the initial values \( y_0 \) and \( \dot{y}_0 \) have to be consistent. This functions updates the initial state \( y_0 \) and, therefore, provides the first step in consistent initialization.

This function is possibly faster than consistentInitialState(), but updates only a part of the state vector. Hence, the result is not guaranteed to be consistent.

This function is to be used with leanConsistentInitialTimeDerivative(). Do not mix normal and lean consistent initialization!

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • vecStateY – [inout] State vector with initial values that are to be updated for consistency

  • adJac – [inout] Jacobian information for AD (AD vectors for residual and state, direction offset)

  • errorTol – [in] Error tolerance for algebraic equations

virtual void leanConsistentInitialTimeDerivative(double t, double const *const vecStateY, double *const vecStateYdot, double *const res, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes approximately / partially consistent initial time derivatives.

Given the DAE

\[ F(t, y, \dot{y}) = 0, \]
the initial values \( y_0 \) and \( \dot{y}_0 \) have to be consistent. This functions overwrites the initial time derivatives \( \dot{y}_0 \) such that the residual is zero. Thus, this function provides the final step in consistent initialization.

This function is possibly faster than consistentInitialTimeDerivative(), but updates only a part of the time derivative vector. Hence, the result is not guaranteed to be consistent.

This function is to be used with leanConsistentInitialState(). Do not mix normal and lean consistent initialization!

Parameters:
  • t – [in] Current time point

  • vecStateY – [in] (Lean) consistent initial state

  • vecStateYdot – [inout] On entry, inconsistent state time derivatives. On exit, partially consistent state time derivatives.

  • res – [in] On entry, residual without taking time derivatives into account. The data is overwritten during execution of the function.

virtual void consistentInitialSensitivity(const SimulationTime &simTime, const ConstSimulationState &simState, std::vector<double*> &vecSensY, std::vector<double*> &vecSensYdot, active const *const adRes, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes consistent initial conditions for all sensitivity subsystems.

Given the DAE

\[ F(t, y, \dot{y}, p) = 0, \]
the corresponding (linear) forward sensitivity system reads
\[ \frac{\partial F}{\partial y}(t, y, \dot{y}) s + \frac{\partial F}{\partial \dot{y}}(t, y, \dot{y}) \dot{s} + \frac{\partial F}{\partial p}(t, y, \dot{y}) = 0. \]
The initial values of \( s_0 = \frac{\mathrm{d} y_0}{\mathrm{d}p} \) and \( \dot{s}_0 = \frac{\mathrm{d} \dot{y}_0}{\mathrm{d}p} \) have to be consistent, that means, they have to satisfy the sensitivity equation. This function computes the correct \( s_0 \) and \( \dot{s}_0 \) given \( y_0 \) and \( s_0 \).

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • vecSensY – [inout] Sensitivity subsystem state vectors

  • vecSensYdot – [inout] Time derivative state vectors of the sensitivity subsystems to be initialized

  • adRes – [in] Pointer to local residual vector of AD datatypes with parameter sensitivities

virtual void leanConsistentInitialSensitivity(const SimulationTime &simTime, const ConstSimulationState &simState, std::vector<double*> &vecSensY, std::vector<double*> &vecSensYdot, active const *const adRes, util::ThreadLocalStorage &threadLocalMem) = 0#
[source]

Computes approximately / partially consistent initial conditions for all sensitivity subsystems.

Given the DAE

\[ F(t, y, \dot{y}, p) = 0, \]
the corresponding (linear) forward sensitivity system reads
\[ \frac{\partial F}{\partial y}(t, y, \dot{y}) s + \frac{\partial F}{\partial \dot{y}}(t, y, \dot{y}) \dot{s} + \frac{\partial F}{\partial p}(t, y, \dot{y}) = 0. \]
The initial values of \( s_0 = \frac{\mathrm{d} y_0}{\mathrm{d}p} \) and \( \dot{s}_0 = \frac{\mathrm{d} \dot{y}_0}{\mathrm{d}p} \) have to be consistent, that means, they have to satisfy the sensitivity equation. This function computes the correct \( s_0 \) and \( \dot{s}_0 \) given \( y_0 \) and \( s_0 \).

This function is possibly faster than consistentInitialSensitivity(), but updates only a part of the vectors. Hence, the result is not guaranteed to be consistent.

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • vecSensY – [inout] Sensitivity subsystem state vectors

  • vecSensYdot – [inout] Time derivative state vectors of the sensitivity subsystems to be initialized

  • adRes – [in] Pointer to local residual vector of AD datatypes with parameter sensitivities

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

Sets external functions for this binding model.

The external functions are not owned by this IBindingModel.

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

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

virtual void setFlowRates(active const *in, active const *out) = 0#
[source]

Sets the flow rates for the current time section.

The flow rates may change due to valve switches.

Parameters:
  • in – [in] Array with total volumetric inlet flow rate for each port

  • out – [in] Array with total volumetric outlet flow rate for each port

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

Returns whether this unit operation supports non-matching volumetric inlet and outlet flow rates.

If inlet and outlet flow rates do not match, mass is accumulated or lost during time integration.

Returns:

true if flow rates are allowed to differ, otherwise false

virtual void multiplyWithJacobian(const SimulationTime &simTime, const ConstSimulationState &simState, double const *yS, double alpha, double beta, double *ret) = 0#
[source]

Multiplies the given vector with the system Jacobian (i.e., \( \frac{\partial F}{\partial y}\left(t, y, \dot{y}\right) \)).

Actually, the operation \( z = \alpha \frac{\partial F}{\partial y} x + \beta z \) is performed. As in BLAS, \( z \) is not read if \( \beta = 0 \), so it may be uninitialized then. Implementations must honor this: computing \( 0 \cdot z \) turns an uninitialized \( z \) into NaN whenever its bytes happen to form a NaN or infinity.

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • yS – [in] Vector \( x \) that is transformed by the Jacobian \( \frac{\partial F}{\partial y} \)

  • alpha – [in] Factor \( \alpha \) in front of \( \frac{\partial F}{\partial y} \)

  • beta – [in] Factor \( \beta \) in front of \( z \)

  • ret – [inout] Vector \( z \) which stores the result of the operation

virtual void multiplyWithDerivativeJacobian(const SimulationTime &simTime, const ConstSimulationState &simState, double const *sDot, double *ret) = 0#
[source]

Multiplies the time derivative Jacobian \( \frac{\partial F}{\partial \dot{y}}\left(t, y, \dot{y}\right) \) with a given vector.

The operation \( z = \frac{\partial F}{\partial \dot{y}} x \) is performed. The matrix-vector multiplication is performed matrix-free (i.e., no matrix is explicitly formed).

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • sDot – [in] Vector \( x \) that is transformed by the Jacobian \( \frac{\partial F}{\partial \dot{y}} \)

  • ret – [out] Vector \( z \) which stores the result of the operation

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

Returns the amount of thread local memory required by the unit operation.

The amount of thread local memory is returned in bytes.

Returns:

Required thread local memory size in bytes

Base class#

class UnitOperationBase : public cadet::IUnitOperation#
[source]

Base class for unit operation models.

Provides parameter handling.

Subclassed by cadet::model::ColumnModel1D< ConvDispOperator >, cadet::model::ColumnModel1D< ConvDispOperator >, cadet::model::ColumnModel2D, cadet::model::GeneralRateModel< ConvDispOperator >, cadet::model::GeneralRateModel2D, cadet::model::LumpedRateModelWithPores< ConvDispOperator >, cadet::model::LumpedRateModelWithoutPores< ConvDispOperator >, cadet::model::LumpedRateModelWithoutPoresDG< ConvDispOperator >, cadet::model::MultiChannelTransportModel, cadet::model::StirredTankModel

Public Functions

inline virtual UnitOpIdx unitOperationId() const noexcept#
[source]

Returns the unit operation Id, which is just an index.

Index of this unit operation model in a system

Returns:

Unit operation index

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 double getParameterDouble(const ParameterId &pId) const#
[source]

Returns the value of a parameter that can be made sensitive.

Returns NaN if the parameter is not present in the model.

Parameters:

pId – [in] ParameterId that identifies the parameter uniquely

Returns:

Value of the parameter or NaN if the parameter was not found

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 bool setSensitiveParameter(const ParameterId &pId, unsigned int adDirection, double adValue)#
[source]

Marks a parameter as sensitive (i.e., sensitivities for this parameter are to be computed).

Parameters:
  • pId – [in] Parameter Id of the sensitive parameter

  • adDirection – [in] AD direction assigned to this parameter

  • adValue – [in] Value of the derivative in the given direction

Returns:

true if the parameter has been found in the model, otherwise false

virtual void setSensitiveParameterValue(const ParameterId &id, double value)#
[source]

Sets the value of a parameter that can be sensitive.

This also sets values of parameters that are not marked as sensitive at the moment. If the parameter is part of a fused sensitivity, then all fused parameters are set to the same value by calling this function for each parameter.

Note that the AD directions are kept invariant (i.e., they are not resetted).

Parameters:
  • id – [in] Parameter ID of the parameter to be manipulated

  • value – [in] Value of the parameter

virtual void clearSensParams()#
[source]

Clears all sensitive parameters.

virtual unsigned int numSensParams() const#
[source]

Returns the number of sensitive parameters in this unit operation.

Returns:

Number of sensitive parameters

virtual int residualSensFwdCombine(const SimulationTime &simTime, const ConstSimulationState &simState, const std::vector<const double*> &yS, const std::vector<const double*> &ySdot, const std::vector<double*> &resS, active const *adRes, double *const tmp1, double *const tmp2, double *const tmp3)#
[source]

Computes the residual of the forward sensitivity systems using the result of residualSensFwdAdOnly().

Assembles and evaluates the residuals of the sensitivity systems

\[ \frac{F}{\partial y} s + \frac{F}{\partial \dot{y}} \dot{s} + \frac{\partial F}{\partial p_i} = 0. \]

Parameters:
  • simTime – [in] Simulation time information (time point, section index, pre-factor of time derivatives)

  • simState – [in] State of the simulation (state vector and its time derivative)

  • yS – [in] Pointers to local sensitivity state vectors

  • ySdot – [in] Pointers to local sensitivity time derivative state vectors

  • resS – [out] Pointers to local sensitivity residuals

  • adRes – [in] Pointer to local residual vector of AD datatypes with the sensitivity derivatives from residualSensFwdAdOnly()

  • tmp1 – [in] Temporary storage in the size of local state vector y

  • tmp2 – [in] Temporary storage in the size of local state vector of y

  • tmp3 – [in] Temporary storage in the size of local state vector of y

Returns:

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

Protected Attributes

UnitOpIdx _unitOpIdx#
[source]

Unit operation index.

std::vector<IBindingModel*> _binding#
[source]

Binding model.

std::vector<IExchangeModel*> _exchange#
[source]

Exchange model.

bool _singleBinding#
[source]

Determines whether only a single binding model is present.

std::vector<ReactionSystem*> _reacParticle#
[source]

Reaction systems for particle bound states.

bool _singleDynReaction#
[source]

Determines whether only a single dynamic reaction model is present.

paramMap_t _parameters#
[source]

Provides access to all parameters.

std::unordered_set<active*> _sensParams#
[source]

Holds all parameters with activated AD directions.

nonlin::Solver *_nonlinearSolver#
[source]

Solver for nonlinear equations (consistent initialization).

Bulk transport operators#

A convection-dispersion operator combines the transport model of the bulk liquid (axial, radial or frustum flow) with its spatial discretization (finite volumes or discontinuous Galerkin). The one-dimensional operators share the following interface.

class IConvectionDispersionOperatorBase1D#
[source]

Interface for one-dimensional convection-dispersion transport base operators.

Abstracts the common API shared by all 1D convection-dispersion operator implementations (DG and FV, axial and radial). Covers configuration, residual evaluation, Jacobian assembly, parameter handling, and solution export.

Subclassed by cadet::model::parts::AxialConvectionDispersionOperatorBaseCollocationDG, cadet::model::parts::AxialConvectionDispersionOperatorBaseFV, cadet::model::parts::FrustumConvectionDispersionOperatorBaseFV, cadet::model::parts::RadialConvectionDispersionOperatorBaseFV, cadet::model::parts::VariableCrossSectionConvectionDispersionOperatorBaseDG

Public Functions

virtual ~IConvectionDispersionOperatorBase1D() noexcept = default#
[source]
virtual bool configureModelDiscretization(IParameterProvider &paramProvider, const IConfigHelper &helper, unsigned int nComp, unsigned int nElem, unsigned int polyDeg, unsigned int strideNode) = 0#
[source]

Configures the spatial discretization.

Parameters:
  • paramProvider – [in] Parameter provider

  • helper – [in] Configuration helper

  • nComp – [in] Number of components

  • nElem – [in] Number of elements (DG) or cells (FV)

  • polyDeg – [in] Polynomial degree; pass 0 for FV

  • strideNode – [in] Node stride in the global state vector

Returns:

true on success

virtual bool configure(UnitOpIdx unitOpIdx, IParameterProvider &paramProvider, std::unordered_map<ParameterId, active*> &parameters) = 0#
[source]

Configures section-dependent model parameters.

Parameters:
  • unitOpIdx – [in] Index of the owning unit operation

  • paramProvider – [in] Parameter provider

  • parameters – [inout] Map in which sensitive parameters are registered

Returns:

true on success

virtual bool notifyDiscontinuousSectionTransition(double t, unsigned int secIdx, Eigen::MatrixXd &jacInlet) = 0#
[source]

Notifies the operator of a discontinuous section transition.

Parameters:
  • t – [in] Current time

  • secIdx – [in] New section index

  • jacInlet – [inout] Dense Jacobian block connecting inlet DOFs to the first bulk cells

Returns:

true if the Jacobian sparsity pattern has changed

virtual void setFlowRates(const active &in, const active &out, const active &colPorosity) noexcept = 0#
[source]

Sets the volumetric flow rates for the current time section.

Parameters:
  • in – [in] Inlet volumetric flow rate

  • out – [in] Outlet volumetric flow rate

  • colPorosity – [in] Column porosity \( \varepsilon_c \)

inline virtual bool setPorosityProfile(active const *porosity, unsigned int nPoints)#
[source]

Hands an axially varying bulk porosity profile to the operator.

The transport operator sees the porosity only through the flow through area \( w(x) = \varepsilon_c(x) A(x) \). A constant porosity cancels from every ratio the operators are built from and is handed over through setFlowRates() instead; a profile has to be baked into the operators, which requires an operator whose weight is not a closed-form analytic expression. Operators that cannot represent a varying weight return false, which the owning unit operation turns into a configuration error. Has to be called after configureModelDiscretization() and before configure(), since configure() assembles the geometry dependent operators.

Parameters:
  • porosity – [in] Porosity profile with one entry per discrete bulk point, owned by the caller, which has to outlive the operator. Pass nullptr for a constant porosity.

  • nPoints – [in] Number of entries in porosity, i.e. 1 for a constant porosity and the number of discrete bulk points for a profile

Returns:

true if the operator can represent the given profile

virtual int residual(const IModel &model, double t, unsigned int secIdx, double const *y, double const *yDot, double *res, WithoutParamSensitivity) = 0#
[source]
virtual int residual(const IModel &model, double t, unsigned int secIdx, double const *y, double const *yDot, active *res, WithParamSensitivity) = 0#
[source]
virtual int residual(const IModel &model, double t, unsigned int secIdx, active const *y, double const *yDot, active *res, WithParamSensitivity) = 0#
[source]
virtual int residual(const IModel &model, double t, unsigned int secIdx, active const *y, double const *yDot, active *res, WithoutParamSensitivity) = 0#
[source]
virtual void convDispJacPattern(std::vector<Eigen::Triplet<double>> &tripletList, int bulkOffset) const = 0#
[source]

Populates the sparsity pattern of the convection-dispersion Jacobian block.

Parameters:
  • tripletList – [inout] Triplet list to append entries to

  • bulkOffset – [in] Row/column offset to the first bulk DOF in the global state vector

virtual unsigned int nJacEntries(bool pureNNZ) const noexcept = 0#
[source]

Returns the number of non-zero Jacobian entries contributed by this operator.

Parameters:

pureNNZ – [in] If true, returns only structural NNZ (dispersion stencil); if false, includes convection entries (a subset of the dispersion stencil)

virtual int calcTransportJacobian(const IModel &model, double t, unsigned int secIdx, Eigen::SparseMatrix<double, Eigen::RowMajor> &jacobian, Eigen::MatrixXd &jacInlet, int bulkOffset, double const *y) = 0#
[source]

Analytically assembles the static transport Jacobian (double state).

Non-template virtual override; concrete implementations delegate to the corresponding template instantiation calcTransportJacobian<double>.

Parameters:
  • model – [in] Owning model (used by some FV implementations)

  • t – [in] Current time

  • secIdx – [in] Current section index

  • jacobian – [inout] Sparse row-major system Jacobian to fill

  • jacInlet – [inout] Dense inlet Jacobian block

  • bulkOffset – [in] Offset to the first bulk DOF

  • y – [in] Current state vector (double)

Returns:

true if the filled pattern matches the stored sparsity pattern

virtual int calcTransportJacobian(const IModel &model, double t, unsigned int secIdx, Eigen::SparseMatrix<double, Eigen::RowMajor> &jacobian, Eigen::MatrixXd &jacInlet, int bulkOffset, active const *y) = 0#
[source]

Analytically assembles the static transport Jacobian (active/AD state).

Non-template virtual override; concrete implementations delegate to the corresponding template instantiation calcTransportJacobian<active>.

virtual void multiplyWithDerivativeJacobian(const SimulationTime &simTime, double const *sDot, double *ret) const = 0#
[source]

Multiplies the time-derivative Jacobian \( \frac{\partial F}{\partial \dot{y}} \) with the given vector.

Parameters:
  • simTime – [in] Simulation time point and section index

  • sDot – [in] Input vector

  • ret – [out] Result vector

virtual void addTimeDerivativeToJacobian(double alpha, Eigen::SparseMatrix<double, Eigen::RowMajor> &jacDisc, unsigned int blockOffset) const = 0#
[source]

Adds \( \alpha \frac{\partial F}{\partial \dot{y}} \) to the discretized Jacobian.

Used during BDF time integration to assemble the full linear system Jacobian.

Parameters:
  • alpha – [in] BDF time-integration factor

  • jacDisc – [inout] Sparse Jacobian to which the time-derivative contribution is added

  • blockOffset – [in] Row/column offset to the bulk block in the global Jacobian

virtual double relativeCoordinate(unsigned int idx) const noexcept = 0#
[source]

Returns the relative coordinate in [0, 1] of a global discrete point.

Parameters:

idx – [in] Zero-based global discrete point (node) index

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

Returns true if the current interstitial velocity is non-negative (forward flow).

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

Returns the number of AD seed directions required for full Jacobian computation.

virtual bool hasSmoothnessIndicator() const noexcept = 0#
[source]
virtual int writeSmoothnessIndicator(double *buffer) const noexcept = 0#
[source]
virtual int writeCoordinates(double *coords) const noexcept = 0#
[source]

Writes the physical primary coordinates (axial or radial) of all discrete points.

Parameters:

coords – [out] Output buffer of length nPoints

Returns:

Number of coordinates written

inline virtual int filmTransferStencilSize() const noexcept#
[source]

Number of discrete points that the bulk side of the film transfer term is spread over.

The weak form multiplies the bulk balance by the flow through area \( A^\varepsilon = \varepsilon^{\mathrm{b}} A \), so that the time derivative carries the weight \( A^\varepsilon \) while the film transfer source carries the weight \( A^\varepsilon \left(1 - \varepsilon^{\mathrm{b}}\right) k^{\mathrm{f}} / \varepsilon^{\mathrm{b}} \). The two are proportional, and the source is therefore integrated node locally, unless the porosity or the film transfer coefficient varies within an element. Returns one as long as this operator cannot produce anything but a node local source, whether because of its geometry or because its operators are not set up yet.

Returns:

Upper bound on the number of discrete points of the stencil

inline virtual bool assembleFilmTransferOperator(active const *const colPorosity, active const *const filmDiffusion, const unsigned int nComp, active *weights, int *offsets) const#
[source]

Assembles the bulk side operator of the film transfer term.

Inverting the mass matrix of the time derivative leaves the element-wise operator

         T^(e) = (M^{A^eps})^{-1} Mtilde^{A^eps (1 - eps) kf / eps},

     which maps the nodal values of \f$ k^{\mathrm{f}} \left(c^{\mathrm{b}} - c^{\mathrm{p}}\right) \f$
     onto the bulk residual. The weights returned here are divided by the nodal film transfer
     coefficient, so that they apply to the film transfer flux itself and reduce to
     \f$ \left(1 - \varepsilon^{\mathrm{b}}\right) / \varepsilon^{\mathrm{b}} \f$ for a porosity and a
     film transfer coefficient that are constant on an element.

Parameters:
  • colPorosity – [in] Bulk porosity at each of the nPoints discrete points

  • filmDiffusion – [in] Film transfer coefficient at each discrete point and component, point major

  • nComp – [in] Number of components

  • weights – [out] nPoints * nComp * filmTransferStencilSize() weights, point major, then component, then stencil

  • offsets – [out] nPoints * filmTransferStencilSize() signed offsets in discrete points

Returns:

false if the source is node local for the given porosity and film transfer coefficient, in which case nothing is written and the caller keeps using the plain prefactor

virtual bool setParameter(const ParameterId &pId, double value) = 0#
[source]
virtual bool setSensitiveParameter(std::unordered_set<active*> &sensParams, const ParameterId &pId, unsigned int adDirection, double adValue) = 0#
[source]
virtual bool setSensitiveParameterValue(const std::unordered_set<active*> &sensParams, const ParameterId &id, double value) = 0#
[source]