Skip to content

Commit

Permalink
Improve parameter interface (#177)
Browse files Browse the repository at this point in the history
Some model parameters were written in the discretization group and are moved to the model group. Backwards compatibility of the interface is ensured.

Move NBOUND from discretization to unit_XXX

Move NPARTYPE from discretization to unit_XXX

Move PAR_GEOM from discretization to unit_XXX
  • Loading branch information
jbreue16 authored Mar 22, 2024
1 parent f6ca044 commit 59806c0
Show file tree
Hide file tree
Showing 20 changed files with 231 additions and 156 deletions.
4 changes: 2 additions & 2 deletions doc/interface/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ Common notation and identifiers that are used in the subsequent description are
- Total number of components in the system (sum of all unit operation components)
* - NPARTYPE
- Number of particles types of a unit operation
* - NBND\ :sub:`i` \
* - NBOUND\ :sub:`i` \
- Number of bound states of component i of the current particle type
* - NTOTALBND
* - NTOTALBOUND
- Total number of bound states of the current particle type (sum of all bound states of all components)
* - NSTATES
- Maximum of the number of bound states for each component of a particle type
Expand Down
48 changes: 24 additions & 24 deletions doc/interface/unit_operations/2d_general_rate_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ For information on model equations, refer to :ref:`2d_general_rate_model_model`.
**Type:** int **Range:** :math:`\{0, 1\}` **Length:** 1
============= =========================== =============

``NBOUND``

Number of bound states for each component in each particle type in type-major ordering

============= ========================= ==========================================================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NCOMP} / \texttt{NPARTYPE} \cdot \texttt{NCOMP}`
============= ========================= ==========================================================================

``REACTION_MODEL_BULK``

Specifies the type of reaction model of the bulk volume. The model is configured in the subgroup :math:`\texttt{reaction_bulk}`.
Expand Down Expand Up @@ -327,6 +335,22 @@ For information on model equations, refer to :ref:`2d_general_rate_model_model`.
**Type:** int **Range:** :math:`\{0, \dots, 3 \}` **Length:** 1
============= =================================== =============

``NPARTYPE``

Number of particle types. Optional, inferred from the length of :math:`\texttt{NPAR}` or :math:`\texttt{NBOUND}` if left out.

============= ========================= =============
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``PAR_GEOM``

Specifies the particle geometry for all or each particle type. Valid values are :math:`\texttt{SPHERE}`, :math:`\texttt{CYLINDER}`, :math:`\texttt{SLAB}`. Optional, defaults to :math:`\texttt{SPHERE}`.

================ =================================================
**Type:** string **Length:** :math:`1` / :math:`\texttt{NPARTYPE}`
================ =================================================

``PAR_TYPE_VOLFRAC``

Volume fractions of the particle types. The volume fractions can be set homogeneous or individually along both axes. For each cell, the volume fractions have to sum to 1. In case of a spatially inhomogeneous setting, the :math:`\texttt{SENS_SECTION}` field is used for indexing the axial cell and the :math:`\texttt{SENS_REACTION}` field is used for indexing the radial cell when specifying parameter sensitivities. This field is optional in case of only one particle type.
Expand Down Expand Up @@ -368,14 +392,6 @@ Group /input/model/unit_XXX/discretization - UNIT_TYPE - GENERAL_RATE_MODEL_2D
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``NPARTYPE``

Number of particle types. Optional, inferred from the length of :math:`\texttt{NPAR}` or :math:`\texttt{NBOUND}` if left out.

============= ========================= =============
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``NPAR``

Number of particle (radial) discretization cells for each particle type
Expand All @@ -384,22 +400,6 @@ Group /input/model/unit_XXX/discretization - UNIT_TYPE - GENERAL_RATE_MODEL_2D
**Type:** int **Range:** :math:`\geq 1` **Length:** :math:`1 / \texttt{NPARTYPE}`
============= ========================= =========================================

``NBOUND``

Number of bound states for each component in each particle type in type-major ordering

============= ========================= ==========================================================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NCOMP} / \texttt{NPARTYPE} \cdot \texttt{NCOMP}`
============= ========================= ==========================================================================

``PAR_GEOM``

Specifies the particle geometry for all or each particle type. Valid values are :math:`\texttt{SPHERE}`, :math:`\texttt{CYLINDER}`, :math:`\texttt{SLAB}`. Optional, defaults to :math:`\texttt{SPHERE}`.

================ =================================================
**Type:** string **Length:** :math:`1` / :math:`\texttt{NPARTYPE}`
================ =================================================

``RADIAL_DISC_TYPE``

Specifies the radial discretization scheme. Valid values are :math:`\texttt{EQUIDISTANT}`, :math:`\texttt{EQUIVOLUME}`, and :math:`\texttt{USER_DEFINED}`.
Expand Down
16 changes: 8 additions & 8 deletions doc/interface/unit_operations/cstr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ For information on model equations, refer to :ref:`cstr_model`.
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``NBOUND``

Number of bound states for each component in each particle type in type-major ordering (optional, defaults to all 0)

============= ========================= ===========================================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NPARTYPE} \cdot \texttt{NCOMP}`
============= ========================= ===========================================================

``USE_ANALYTIC_JACOBIAN``

Determines whether analytically computed Jacobian matrix (faster) is used (value is 1) instead of Jacobians generated by algorithmic differentiation (slower, value is 0)
Expand All @@ -49,6 +41,14 @@ For information on model equations, refer to :ref:`cstr_model`.
**Type:** string **Range:** See Section :ref:`FFAdsorption` **Length:** :math:`\texttt{NPARTYPE}`
================ ========================================== =====================================

``NBOUND``

Number of bound states for each component in each particle type in type-major ordering (optional, defaults to all 0)

============= ========================= ===========================================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NPARTYPE} \cdot \texttt{NCOMP}`
============= ========================= ===========================================================

``REACTION_MODEL``

Specifies the type of reaction model of the bulk volume. The model is configured in the subgroup :math:`\texttt{reaction_bulk}`.
Expand Down
48 changes: 24 additions & 24 deletions doc/interface/unit_operations/general_rate_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ For information on model equations, refer to :ref:`general_rate_model_model`.
**Type:** int **Range:** :math:`\{0, 1\}` **Length:** 1
============= =========================== =============

``NBOUND``

Number of bound states for each component in each particle type in type-major ordering

============= ========================= ===================================================================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NCOMP}` / :math:`\texttt{NPARTYPE} \cdot \texttt{NCOMP}`
============= ========================= ===================================================================================

``REACTION_MODEL_BULK``

Specifies the type of reaction model of the bulk volume. The model is configured in the subgroup :math:`\texttt{reaction_bulk}`.
Expand Down Expand Up @@ -421,6 +429,22 @@ For information on model equations, refer to :ref:`general_rate_model_model`.
**Type:** double **Range:** :math:`>0` **Length:** 1
================ ===================== =============

``NPARTYPE``

Number of particle types. Optional, inferred from the length of :math:`\texttt{NPAR}` or :math:`\texttt{NBOUND}` if left out.

============= ========================= =============
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``PAR_GEOM``

Specifies the particle geometry for all or each particle type. Valid values are :math:`\texttt{SPHERE}`, :math:`\texttt{CYLINDER}`, :math:`\texttt{SLAB}`. Optional, defaults to :math:`\texttt{SPHERE}`.

================ =================================================
**Type:** string **Length:** :math:`1` / :math:`\texttt{NPARTYPE}`
================ =================================================

``PAR_TYPE_VOLFRAC``

Volume fractions of the particle types. The volume fractions can be set for all axial cells together or for each individual axial cell. For each cell, the volume fractions have to sum to :math:`1`. In case of a spatially inhomogeneous setting, the data is expected in cell-major ordering and the :math:`\texttt{SENS_SECTION}` field is used for indexing the axial cell when specifying parameter sensitivities. This field is optional in case of only one particle type.
Expand All @@ -442,14 +466,6 @@ Group /input/model/unit_XXX/discretization - UNIT_TYPE - GENERAL_RATE_MODEL
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``NPARTYPE``

Number of particle types. Optional, inferred from the length of :math:`\texttt{NPAR}` or :math:`\texttt{NBOUND}` if left out.

============= ========================= =============
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``NPAR``

Number of particle (radial) discretization cells for each particle type
Expand All @@ -458,22 +474,6 @@ Group /input/model/unit_XXX/discretization - UNIT_TYPE - GENERAL_RATE_MODEL
**Type:** int **Range:** :math:`\geq 1` **Length:** :math:`1` / :math:`\texttt{NPARTYPE}`
============= ========================= =================================================

``NBOUND``

Number of bound states for each component in each particle type in type-major ordering

============= ========================= ===================================================================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NCOMP}` / :math:`\texttt{NPARTYPE} \cdot \texttt{NCOMP}`
============= ========================= ===================================================================================

``PAR_GEOM``

Specifies the particle geometry for all or each particle type. Valid values are :math:`\texttt{SPHERE}`, :math:`\texttt{CYLINDER}`, :math:`\texttt{SLAB}`. Optional, defaults to :math:`\texttt{SPHERE}`.

================ =================================================
**Type:** string **Length:** :math:`1` / :math:`\texttt{NPARTYPE}`
================ =================================================

``PAR_DISC_TYPE``

Specifies the discretization scheme inside the particles for all or each particle type. Valid values are :math:`\texttt{EQUIDISTANT_PAR}`, :math:`\texttt{EQUIVOLUME_PAR}`, and :math:`\texttt{USER_DEFINED_PAR}`.
Expand Down
48 changes: 24 additions & 24 deletions doc/interface/unit_operations/lumped_rate_model_with_pores.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ For information on model equations, refer to :ref:`lumped_rate_model_with_pores_
**Type:** int **Range:** :math:`\{0, 1\}` **Length:** 1
============= =========================== =============

``NBOUND``

Number of bound states for each component in each particle type in type-major ordering

============= ========================= ===========================================================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NCOMP} / \texttt{NPARTYPE} \cdot \texttt{NCOMP}`
============= ========================= ===========================================================================

``REACTION_MODEL_BULK``
Specifies the type of reaction model of the bulk volume. The model is configured in the subgroup :math:`\texttt{reaction_bulk}`.

Expand Down Expand Up @@ -214,6 +222,22 @@ For information on model equations, refer to :ref:`lumped_rate_model_with_pores_
**Type:** double **Range:** :math:`>0` **Length:** 1
================ ===================== =============

``NPARTYPE``

Number of particle types. Optional, inferred from the length of :math:`\texttt{NBOUND}` if left out.

============= ========================= =============
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``PAR_GEOM``

Specifies the particle geometry for all or each particle type. Valid values are :math:`\texttt{SPHERE}`, :math:`\texttt{CYLINDER}`, :math:`\texttt{SLAB}`. Optional, defaults to :math:`\texttt{SPHERE}`.

================ =================================================
**Type:** string **Length:** :math:`1` / :math:`\texttt{NPARTYPE}`
================ =================================================

``PAR_TYPE_VOLFRAC``

Volume fractions of the particle types. The volume fractions can be set for all axial cells together or for each individual axial cell. For each cell, the volume fractions have to sum to :math:`1`. In case of a spatially inhomogeneous setting, the data is expected in cell-major ordering and the :math:`\texttt{SENS_SECTION}` field is used for indexing the axial cell when specifying parameter sensitivities. This field is optional in case of only one particle type.
Expand All @@ -235,30 +259,6 @@ Group /input/model/unit_XXX/discretization - UNIT_TYPE = LUMPED_RATE_MODEL_WITH_
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``NPARTYPE``

Number of particle types. Optional, inferred from the length of :math:`\texttt{NBOUND}` if left out.

============= ========================= =============
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``NBOUND``

Number of bound states for each component in each particle type in type-major ordering

============= ========================= ===========================================================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NCOMP} / \texttt{NPARTYPE} \cdot \texttt{NCOMP}`
============= ========================= ===========================================================================

``PAR_GEOM``

Specifies the particle geometry for all or each particle type. Valid values are :math:`\texttt{SPHERE}`, :math:`\texttt{CYLINDER}`, :math:`\texttt{SLAB}`. Optional, defaults to :math:`\texttt{SPHERE}`.

================ =================================================
**Type:** string **Length:** :math:`1` / :math:`\texttt{NPARTYPE}`
================ =================================================

``USE_ANALYTIC_JACOBIAN``

Determines whether analytically computed Jacobian matrix (faster) is used (value is :math:`1`) instead of Jacobians generated by algorithmic differentiation (slower, value is :math:`0`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ For information on model equations, refer to :ref:`lumped_rate_model_without_por
**Type:** string **Range:** See Section :ref:`FFAdsorption` **Length:** 1
================ ========================================== =============

``NBOUND``

Number of bound states for each component

============= ========================= ==================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NCOMP}`
============= ========================= ==================================

``REACTION_MODEL``

Specifies the type of reaction model of the combined bulk and particle volume. The model is configured in the subgroup :math:`\texttt{reaction}`.
Expand Down Expand Up @@ -145,14 +153,6 @@ Group /input/model/unit_XXX/discretization - UNIT_TYPE = LUMPED_RATE_MODEL_WITHO
**Type:** int **Range:** :math:`\geq 1` **Length:** 1
============= ========================= =============

``NBOUND``

Number of bound states for each component

============= ========================= ==================================
**Type:** int **Range:** :math:`\geq 0` **Length:** :math:`\texttt{NCOMP}`
============= ========================= ==================================

``USE_ANALYTIC_JACOBIAN``

Determines whether analytically computed Jacobian matrix (faster) is used (value is 1) instead of Jacobians generated by algorithmic differentiation (slower, value is 0)
Expand Down
29 changes: 24 additions & 5 deletions src/libcadet/model/GeneralRateModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,35 @@ bool GeneralRateModel::configureModelDiscretization(IParameterProvider& paramPro
// ==== Read discretization
_disc.nComp = paramProvider.getInt("NCOMP");

std::vector<int> nBound;
const bool newNBoundInterface = paramProvider.exists("NBOUND");
const bool newNPartypeInterface = paramProvider.exists("NPARTYPE");

paramProvider.pushScope("discretization");

if (!newNBoundInterface && paramProvider.exists("NBOUND")) // done here and in this order for backwards compatibility
nBound = paramProvider.getIntArray("NBOUND");
else
{
paramProvider.popScope();
nBound = paramProvider.getIntArray("NBOUND");
paramProvider.pushScope("discretization");
}
if (nBound.size() < _disc.nComp)
throw InvalidParameterException("Field NBOUND contains too few elements (NCOMP = " + std::to_string(_disc.nComp) + " required)");

_disc.nCol = paramProvider.getInt("NCOL");

const std::vector<int> nParCell = paramProvider.getIntArray("NPAR");

const std::vector<int> nBound = paramProvider.getIntArray("NBOUND");
if (nBound.size() < _disc.nComp)
throw InvalidParameterException("Field NBOUND contains too few elements (NCOMP = " + std::to_string(_disc.nComp) + " required)");

if (paramProvider.exists("NPARTYPE"))
if (!newNPartypeInterface && paramProvider.exists("NPARTYPE")) // done here and in this order for backwards compatibility
_disc.nParType = paramProvider.getInt("NPARTYPE");
else if (newNPartypeInterface)
{
paramProvider.popScope();
_disc.nParType = paramProvider.getInt("NPARTYPE");
paramProvider.pushScope("discretization");
}
else
{
// Infer number of particle types
Expand Down Expand Up @@ -256,6 +273,7 @@ bool GeneralRateModel::configureModelDiscretization(IParameterProvider& paramPro

// Read particle geometry and default to "SPHERICAL"
_parGeomSurfToVol = std::vector<double>(_disc.nParType, SurfVolRatioSphere);
paramProvider.popScope();
if (paramProvider.exists("PAR_GEOM"))
{
std::vector<std::string> pg = paramProvider.getStringArray("PAR_GEOM");
Expand All @@ -279,6 +297,7 @@ bool GeneralRateModel::configureModelDiscretization(IParameterProvider& paramPro
throw InvalidParameterException("Unknown particle geometry type \"" + pg[i] + "\" at index " + std::to_string(i) + " of field PAR_GEOM");
}
}
paramProvider.pushScope("discretization");

if (paramProvider.exists("PAR_DISC_VECTOR"))
{
Expand Down
Loading

0 comments on commit 59806c0

Please sign in to comment.