MICM API#
-
namespace micm#
Typedefs
-
using DenseMatrixVector = VectorMatrix<double, MICM_DEFAULT_VECTOR_SIZE>#
-
using SparseMatrixVector = SparseMatrix<double, SparseMatrixVectorOrdering<MICM_DEFAULT_VECTOR_SIZE>>#
-
using SparseMatrixStandard = SparseMatrix<double, SparseMatrixStandardOrdering>#
-
using VectorState = State<DenseMatrixVector, SparseMatrixVector>#
-
using StandardState = State<DenseMatrixStandard, SparseMatrixStandard>#
-
using RosenbrockVectorType = typename RosenbrockSolverParameters::template SolverType<ProcessSet, LinearSolver<SparseMatrixVector, LuDecomposition>>#
-
using Rosenbrock = Solver<RosenbrockVectorType, State<DenseMatrixVector, SparseMatrixVector>>#
-
using RosenbrockStandardType = typename RosenbrockSolverParameters::template SolverType<ProcessSet, LinearSolver<SparseMatrixStandard, LuDecomposition>>#
-
using RosenbrockStandard = Solver<RosenbrockStandardType, State<DenseMatrixStandard, SparseMatrixStandard>>#
-
using BackwardEulerVectorType = typename BackwardEulerSolverParameters::template SolverType<ProcessSet, LinearSolver<SparseMatrixVector, LuDecomposition>>#
-
using BackwardEuler = Solver<BackwardEulerVectorType, State<DenseMatrixVector, SparseMatrixVector>>#
-
using BackwardEulerStandardType = typename BackwardEulerSolverParameters::template SolverType<ProcessSet, LinearSolver<SparseMatrixStandard, LuDecomposition>>#
-
using BackwardEulerStandard = Solver<BackwardEulerStandardType, State<DenseMatrixStandard, SparseMatrixStandard>>#
-
using RosenbrockThreeStageBuilder = CpuSolverBuilder<RosenbrockSolverParameters, DenseMatrixVector, SparseMatrixVector>#
-
using BackwardEulerBuilder = CpuSolverBuilder<BackwardEulerSolverParameters, DenseMatrixVector, SparseMatrixVector, LuDecompositionDoolittle>#
-
using CudaLuDecomposition = CudaLuDecompositionMozartInPlace#
Alias for the default CUDA LU decomposition algorithm.
-
template<class SolverParametersPolicy, std::size_t L = MICM_DEFAULT_VECTOR_SIZE>
using CudaSolverBuilderInPlace = SolverBuilder<SolverParametersPolicy, CudaDenseMatrix<double, L>, CudaSparseMatrix<double, SparseMatrixVectorOrdering<L>>, CudaProcessSet, CudaLuDecompositionMozartInPlace, CudaLinearSolverInPlace<CudaSparseMatrix<double, SparseMatrixVectorOrdering<L>>, CudaLuDecompositionMozartInPlace>, CudaState<CudaDenseMatrix<double, L>, CudaSparseMatrix<double, SparseMatrixVectorOrdering<L>>, CudaLuDecompositionMozartInPlace>># Builder of CUDA-based general solvers.
GPU solvers only work with vector-ordered matrices
- Template Parameters:
SolverParametersPolicy – Policy for the ODE solver
L – Vector size
-
using CudaDenseMatrixVector = CudaDenseMatrix<double, MICM_DEFAULT_VECTOR_SIZE>#
-
using CudaSparseMatrixVector = CudaSparseMatrix<double, SparseMatrixVectorOrdering<MICM_DEFAULT_VECTOR_SIZE>>#
-
using GpuState = CudaState<CudaDenseMatrixVector, CudaSparseMatrixVector, CudaLuDecompositionMozartInPlace>#
-
using CudaRosenbrockVectorType = typename CudaRosenbrockSolverParameters::template SolverType<CudaProcessSet, CudaLinearSolverInPlace<CudaSparseMatrixVector>>#
-
using CudaRosenbrock = Solver<CudaRosenbrockVectorType, GpuState>#
-
using GpuRosenbrockThreeStageBuilder = CudaSolverBuilderInPlace<CudaRosenbrockSolverParameters>#
-
using LuDecomposition = LuDecompositionDoolittle#
Alias for the default LU decomposition algorithm.
-
using LuDecompositionInPlace = LuDecompositionMozartInPlace#
Alias for the default in-place LU decomposition algorithm.
-
template<class SolverParametersPolicy, class DenseMatrixPolicy = Matrix<double>, class SparseMatrixPolicy = SparseMatrix<double, SparseMatrixStandardOrdering>, class LuDecompositionPolicy = LuDecomposition, class LMatrixPolicy = SparseMatrixPolicy, class UMatrixPolicy = SparseMatrixPolicy>
using CpuSolverBuilder = SolverBuilder<SolverParametersPolicy, DenseMatrixPolicy, SparseMatrixPolicy, ProcessSet, LuDecompositionPolicy, LinearSolver<SparseMatrixPolicy, LuDecompositionPolicy, LMatrixPolicy, UMatrixPolicy>, State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy, LMatrixPolicy, UMatrixPolicy>># Builder of CPU-based general solvers.
- Template Parameters:
SolverParametersPolicy – Parameters for the ODE solver
DenseMatrixPolicy – Policy for dense matrices
SparseMatrixPolicy – Policy for sparse matrices
LuDecompositionPolicy – Policy for the LU decomposition
LMatrixPolicy – Policy for the Lower matrix
UMatrixPolicy – Policy for the Upper matrix
-
template<class SolverParametersPolicy, class DenseMatrix = Matrix<double>, class SparseMatrixPolicy = SparseMatrix<double, SparseMatrixStandardOrdering>, class LuDecompositionPolicy = LuDecompositionInPlace>
using CpuSolverBuilderInPlace = SolverBuilder<SolverParametersPolicy, DenseMatrix, SparseMatrixPolicy, ProcessSet, LuDecompositionPolicy, LinearSolverInPlace<SparseMatrixPolicy, LuDecompositionPolicy>, State<DenseMatrix, SparseMatrixPolicy, LuDecompositionPolicy>># Builder of CPU-based general solvers with in-place LU decomposition.
- Template Parameters:
SolverParametersPolicy – Parameters for the ODE solver
DenseMatrixPolicy – Policy for dense matrices
SparseMatrixPolicy – Policy for sparse matrices
LuDecompositionPolicy – Policy for the LU decomposition
-
using StandardSparseMatrix = SparseMatrix<double, SparseMatrixStandardOrdering>#
-
using SparseMatrixStandardOrdering = SparseMatrixStandardOrderingCompressedSparseRow#
Alias for the default sparse matrix standard ordering.
-
template<std::size_t L = MICM_DEFAULT_VECTOR_SIZE>
using SparseMatrixVectorOrdering = SparseMatrixVectorOrderingCompressedSparseRow<L># Alias for the default sparse matrix vector ordering.
-
using DefaultVectorSparseMatrix = SparseMatrix<double, SparseMatrixVectorOrdering<MICM_DEFAULT_VECTOR_SIZE>>#
Enums
-
enum class SolverState#
The final state the solver was in after the Solve function finishes.
Values:
-
enumerator NotYetCalled#
This is the initial value at the start of the Solve function.
-
enumerator Running#
This is only used for control flow in the Solve function.
-
enumerator Converged#
A successful integration will have this value.
-
enumerator ConvergenceExceededMaxSteps#
If the number of steps exceeds the maximum value on the solver parameter, this value will be returned.
-
enumerator StepSizeTooSmall#
Very stiff systems will likely result in a step size that is not useable for the solver.
-
enumerator RepeatedlySingularMatrix#
Matrices that are singular more than once will set this value. At present, this should never be returned.
-
enumerator NaNDetected#
Mostly this value is returned by systems that tend toward chemical explosions.
-
enumerator InfDetected#
Can happen when unititialized memory is used in the solver.
-
enumerator AcceptingUnconvergedIntegration#
Used for backward euler. This allows us to “succeed” in the same way that cam-chem does.
-
enumerator NotYetCalled#
Functions
-
template<template<class> class MatrixPolicy>
std::vector<std::size_t> DiagonalMarkowitzReorder(const MatrixPolicy<int> &matrix)# Reorders a set of state variables using Diagonal Markowitz algorithm.
- Parameters:
matrix – Original matrix non-zero elements
- Returns:
Reordered mapping vector (reordered[i] = original[map[i]])
-
template<class MatrixPolicy>
inline std::vector<std::size_t> DiagonalMarkowitzReorder(const MatrixPolicy &matrix)#
-
inline std::string SolverStateToString(const SolverState &state)#
-
inline void ThrowInternalError(MicmInternalErrc e, const char *file, int line, const char *msg)#
-
template<class SparseMatrixPolicy>
SparseMatrixPolicy BuildJacobian(const std::set<std::pair<std::size_t, std::size_t>> &nonzero_jacobian_elements, std::size_t number_of_grid_cells, std::size_t state_size, bool indexing_only)#
-
inline std::string GenerateRandomString()#
-
template<class MatrixPolicy>
void CheckCopyToDevice(MatrixPolicy &matrix)#
-
template<class MatrixPolicy>
void CheckCopyToHost(MatrixPolicy &matrix)#
-
inline std::string JoinStrings(const std::vector<std::string> &names)#
-
template<class RatesPolicy, class LinearSolverPolicy>
class AbstractBackwardEuler# - #include <micm/solver/backward_euler.hpp>
An implementation of the fully implicit backward euler method.
Public Types
-
using ParametersType = BackwardEulerSolverParameters#
Solver parameters typename.
Public Functions
-
inline AbstractBackwardEuler(LinearSolverPolicy &&linear_solver, RatesPolicy &&rates, auto &jacobian, const size_t number_of_species)#
Default constructor.
- Parameters:
linear_solver – Linear solver
rates – Rates calculator
-
inline SolverResult Solve(double time_step, auto &state, const BackwardEulerSolverParameters ¶meters) const#
Advances the given step over the specified time step.
- Parameters:
time_step – Time [s] to advance the state by
state – The state to advance
- Returns:
result of the solver (success or failure, and statistics)
Public Static Functions
-
template<class DenseMatrixPolicy>
static inline bool IsConverged(const BackwardEulerSolverParameters ¶meters, const DenseMatrixPolicy &residual, const DenseMatrixPolicy &Yn1, const std::vector<double> &absolute_tolerance, double relative_tolerance)# Determines whether the residual is small enough to stop the internal solver iteration.
- Parameters:
residual – The residual to check
state – The current state being solved for
- Returns:
true if the residual is small enough to stop the iteration
-
using ParametersType = BackwardEulerSolverParameters#
-
template<class RatesPolicy, class LinearSolverPolicy, class Dervied>
class AbstractRosenbrockSolver# - #include <micm/solver/rosenbrock.hpp>
An implementation of the Rosenbrock ODE solver.
This implements the Curiously Recurring Template Pattern to allow the AlphaMinusJacobian and NormalizedError functions to be implemented in extending classes and called from the base class Solve() function. https://en.cppreference.com/w/cpp/language/crtp
- Template Parameters:
RatesPolicy – Calculator of forcing and Jacobian terms
LinearSolverPolicy – Linear solver
Derived – Implementation of the Rosenbock solver
Public Types
-
using ParametersType = RosenbrockSolverParameters#
Solver parameters typename.
Public Functions
-
inline AbstractRosenbrockSolver(LinearSolverPolicy &&linear_solver, RatesPolicy &&rates, auto &jacobian, const size_t number_of_species)#
Default constructor.
- Parameters:
linear_solver – Linear solver
rates – Rates calculator Note: This constructor is not intended to be used directly. Instead, use the SolverBuilder to create a solver
-
inline SolverResult Solve(double time_step, auto &state, const RosenbrockSolverParameters ¶meters) const noexcept#
Advances the given step over the specified time step.
- Parameters:
time_step – Time [s] to advance the state by
- Returns:
A struct containing results and a status code
-
template<class SparseMatrixPolicy>
inline void AlphaMinusJacobian(auto &state, const double &alpha) const# compute [alpha * I - dforce_dy]
- Parameters:
jacobian – Jacobian matrix (dforce_dy)
alpha –
-
inline void LinearFactor(const double alpha, SolverStats &stats, auto &state) const#
Perform the LU decomposition of the matrix.
- Parameters:
alpha – The alpha value
number_densities – The number densities
stats – The solver stats
state – The state
-
template<class DenseMatrixPolicy>
inline double NormalizedError(const DenseMatrixPolicy &y, const DenseMatrixPolicy &y_new, const DenseMatrixPolicy &errors, auto &state) const# Computes the scaled norm of the vector errors.
- Parameters:
y – the original vector
y_new – the new vector
errors – The computed errors
- Returns:
-
class ArrheniusRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/arrhenius_rate_constant.hpp>
An arrhenius rate constant dependent on temperature and pressure.
Public Functions
-
inline ArrheniusRateConstant()#
Default constructor.
-
inline ArrheniusRateConstant(const ArrheniusRateConstantParameters ¶meters)#
An explicit constructor where each term can be set. Set B and E to zero to get the common form of the Arrhenius equation.
- Parameters:
parameters – A set of arrhenius rate constants
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline ArrheniusRateConstant()#
-
struct ArrheniusRateConstantParameters#
Public Members
-
double A_ = {1}#
Pre-exponential factor [(mol m−3)^(−(𝑛−1)) s−1].
-
double B_ = {0}#
Unitless exponential factor.
-
double C_ = {0}#
Activation threshold, expected to be the negative activation energy divided by the boltzman constant [-E_a / k_b), K].
-
double D_ = {300}#
A factor that determines temperature dependence [K].
-
double E_ = {0}#
A factor that determines pressure dependence [Pa-1].
-
double A_ = {1}#
-
struct BackwardEulerSolverParameters#
- #include <micm/solver/backward_euler_solver_parameters.hpp>
BackwardEuler solver parameters.
-
template<class DenseMatrixPolicy>
class BackwardEulerTemporaryVariables : public micm::TemporaryVariables#
-
class BranchedRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/branched_rate_constant.hpp>
A Branched rate constant.
Public Functions
-
inline BranchedRateConstant()#
Default constructor.
-
inline BranchedRateConstant(const BranchedRateConstantParameters ¶meters)#
An explicit constructor.
- Parameters:
parameters – A set of branched rate constant parameters
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline double Calculate(const double &temperature, const double &air_number_density) const#
Calculate the rate constant.
- Parameters:
temperature – Temperature in [K]
air_number_density – Number density in [mol m-3]
- Returns:
-
inline double A(const double &temperature, const double &air_number_density) const#
Calculate A(T,[M],n)
- Parameters:
temperature – Temperature in [K]
air_number_density – Number density of air in [mol m-3]
-
inline BranchedRateConstant()#
-
struct BranchedRateConstantParameters#
-
class ChemicalReaction#
- #include <micm/process/chemical_reaction.hpp>
Represents a chemical reaction with reactants, products, rate constant and phase.
Public Static Functions
-
template<class DenseMatrixPolicy, class SparseMatrixPolicy, class LuDecompositionPolicy, class LMatrixPolicy, class UMatrixPolicy>
static void CalculateRateConstants(const std::vector<ChemicalReaction> &processes, State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy, LMatrixPolicy, UMatrixPolicy> &state)# Calculates the rate constants for each process for the current state.
- Parameters:
processes – The set of processes for which rate constants are to be calculated
state – The current solver state that will be modified with the updated rate constants This function is overloaded based on whether DenseMatrixPolicy is vectorizable.
-
template<class DenseMatrixPolicy, class SparseMatrixPolicy, class LuDecompositionPolicy, class LMatrixPolicy, class UMatrixPolicy>
-
class ChemicalReactionBuilder#
Public Functions
-
inline ChemicalReactionBuilder &SetAerosolScope(const std::string &scope, const Phase &phase)#
Enables aerosol scoping for reactant and product species This function must be called before setting reactants or products in order for scoping to be applied. Cannot be used together with SetPhase. They are mutually exclusive.
- Parameters:
scope – Aerosol scope prefix to apply to species names
phase – Phase object representing the reaction phase
- Throws:
std::system_error – if SetPhase, SetReactants, or SetProducts has already been called
- Returns:
Reference to the builder
-
inline ChemicalReactionBuilder &SetReactants(const std::vector<Species> &reactants)#
Sets the list of reactant species involved in the chemical reaction. When scoping is enabled, each reactant name is prefixed with the preset scope.
- Parameters:
reactants – A list of Species objects representing the reactants
- Returns:
Reference to the builder
-
inline ChemicalReactionBuilder &SetProducts(const std::vector<StoichSpecies> &products)#
Sets the list of product species and their yields for the chemical reaction. When scoping is enabled, each product name is prefixed with the preset scope.
- Parameters:
products – A list of StoichSpecies objects representing the products
- Returns:
Reference to the builder
-
inline ChemicalReactionBuilder &SetRateConstant(const RateConstant &rate_constant)#
Sets the rate constant by cloning the provided RateConstant object This method performs a deep copy of the given rate constant using its Clone() method. Useful when the original rate constant must remain unchanged.
- Parameters:
rate_constant – A reference to a RateConstant object to be cloned
- Returns:
Reference to the builder
-
inline ChemicalReactionBuilder &SetPhase(const Phase &phase)#
Sets the phase in which the chemical reaction occurs (e.g., gas, aqueous) Cannot be used together with SetAerosolScope. They are mutually exclusive.
- Parameters:
phase – Phase object representing the reaction phase
- Throws:
std::system_error – if SetAerosolScope has already been called
- Returns:
Reference to the builder
-
inline Process Build()#
Transfers ownership of all internally stored data into a ChemicalReaction, then wraps it into a Process using std::variant.
- Throws:
std::system_error – if the provided rate constant pointer is null
- Returns:
A Process containing the constructed ChemicalReaction
-
inline ChemicalReactionBuilder &SetAerosolScope(const std::string &scope, const Phase &phase)#
-
struct Conditions#
- #include <micm/system/conditions.hpp>
Environemental conditions.
-
class Constraint#
- #include <micm/constraint/constraint.hpp>
Abstract base class for algebraic constraints G(y) = 0.
Constraints define algebraic relations that must be satisfied by the species concentrations. They are used in DAE (Differential-Algebraic Equation) solvers to enforce conditions like chemical equilibrium or mass conservation.
Each constraint provides:
A residual function G(y) that should equal zero when the constraint is satisfied
Jacobian entries dG/dy for each species the constraint depends on
Subclassed by micm::EquilibriumConstraint
Public Functions
-
Constraint() = default#
Default constructor.
-
inline explicit Constraint(const std::string &name)#
Constructor with name.
- Parameters:
name – Constraint identifier
-
virtual ~Constraint() = default#
Virtual destructor.
-
virtual double Residual(const double *concentrations, const std::size_t *indices) const = 0#
Evaluate the constraint residual G(y)
- Parameters:
concentrations – Pointer to species concentrations (row of state matrix)
indices – Pointer to indices mapping species_dependencies_ to positions in concentrations
- Returns:
Residual value (should be 0 when constraint is satisfied)
-
virtual void Jacobian(const double *concentrations, const std::size_t *indices, double *jacobian) const = 0#
Compute partial derivatives dG/d[species] for each dependent species.
- Parameters:
concentrations – Pointer to species concentrations (row of state matrix)
indices – Pointer to indices mapping species_dependencies_ to positions in concentrations
jacobian – Output buffer for partial derivatives dG/d[species] (same order as species_dependencies_)
-
inline std::size_t NumberOfDependencies() const#
Get the number of species this constraint depends on.
- Returns:
Number of dependent species
-
class ConstraintSet#
- #include <micm/constraint/constraint_set.hpp>
Manages a collection of algebraic constraints for DAE solvers.
ConstraintSet handles the computation of constraint residuals (forcing terms) and Jacobian contributions for a set of constraints. It follows the same pattern as ProcessSet for integration with the Rosenbrock solver.
Public Functions
-
ConstraintSet() = default#
Default constructor.
-
inline ConstraintSet(std::vector<std::unique_ptr<Constraint>> &&constraints, const std::map<std::string, std::size_t> &variable_map, std::size_t constraint_row_offset)#
Construct a ConstraintSet from constraints and variable mapping.
- Parameters:
constraints – Vector of constraint pointers (ownership transferred)
variable_map – Map from species names to state variable indices
constraint_row_offset – Row offset for constraint equations (= number of species)
-
ConstraintSet(ConstraintSet &&other) noexcept = default#
Move constructor.
-
ConstraintSet &operator=(ConstraintSet &&other) noexcept = default#
Move assignment.
-
virtual ~ConstraintSet() = default#
Destructor.
-
inline std::size_t Size() const#
Get the number of constraints.
-
inline std::set<std::pair<std::size_t, std::size_t>> NonZeroJacobianElements() const#
Returns positions of all non-zero Jacobian elements for constraint rows.
- Returns:
Set of (row, column) index pairs
-
template<typename OrderingPolicy>
inline void SetJacobianFlatIds(const SparseMatrix<double, OrderingPolicy> &matrix)# Computes and stores flat indices for Jacobian elements.
- Parameters:
matrix – The sparse Jacobian matrix
-
template<typename DenseMatrixPolicy>
inline void AddForcingTerms(const DenseMatrixPolicy &state_variables, DenseMatrixPolicy &forcing) const# Add constraint residuals to forcing vector (constraint rows)
For each constraint G_i, adds G_i(x) to forcing[constraint_row_offset + i]
- Parameters:
state_variables – Current species concentrations (grid cell, species)
forcing – Forcing terms (grid cell, state variable) - constraint rows will be modified
-
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
inline void SubtractJacobianTerms(const DenseMatrixPolicy &state_variables, SparseMatrixPolicy &jacobian) const# Subtract constraint Jacobian terms from Jacobian matrix.
For each constraint G_i, subtracts dG_i/dx_j from jacobian[constraint_row, j] (Subtraction matches the convention used by ProcessSet)
- Parameters:
state_variables – Current species concentrations (grid cell, species)
jacobian – Sparse Jacobian matrix (grid cell, row, column)
-
ConstraintSet() = default#
-
template<class T, std::size_t L = MICM_DEFAULT_VECTOR_SIZE>
class CudaDenseMatrix : public micm::VectorMatrix<T, MICM_DEFAULT_VECTOR_SIZE># Public Functions
-
inline void Axpy(const double alpha, const CudaDenseMatrix<T, L> &x)#
For each element in the VectorMatrix x and y, perform y = alpha * x + y, where alpha is a scalar constant.
- Parameters:
alpha – The scaling scalar to apply to the VectorMatrix x
x – The input VectorMatrix
- Returns:
0 if successful, otherwise an error code
-
inline void Max(const T x)#
For each element of the VectorMatrix, perform y = max(y, x), where x is a scalar constant.
- Parameters:
x – The scalar constant to compare against
-
inline void Min(const T x)#
For each element of the VectorMatrix, perform y = min(y, x), where x is a scalar constant.
- Parameters:
x – The scalar constant to compare against
-
inline void Axpy(const double alpha, const CudaDenseMatrix<T, L> &x)#
-
template<class SparseMatrixPolicy, class LuDecompositionPolicy = CudaLuDecompositionMozartInPlace>
class CudaLinearSolverInPlace : public micm::LinearSolverInPlace<SparseMatrixPolicy, CudaLuDecompositionMozartInPlace># Public Functions
-
inline CudaLinearSolverInPlace()#
This is the default constructor, taking no arguments;.
-
inline CudaLinearSolverInPlace(const SparseMatrixPolicy &matrix, typename SparseMatrixPolicy::value_type initial_value)#
This constructor takes two arguments: a sparse matrix and its values The base class here takes three arguments: the third argument is a lamda function that creates an instance of LuDecompositionPolicy; in this case, we will use the CudaLuDecompositionInPlace specified at line 13; See line 17 of “linear_solver_in_place.inl” for more details about how this lamda function works;
-
inline ~CudaLinearSolverInPlace()#
This is the destructor that will free the device memory of the constant data from the class “CudaLinearSolverInPlace”
Public Members
-
LinearSolverInPlaceParam devstruct_#
This is an instance of struct “LinearSolverInPlaceParam” that holds the constant data of “CudaLinearSolverInPlace” class on the device
-
inline CudaLinearSolverInPlace()#
-
class CudaLuDecompositionMozartInPlace : public micm::LuDecompositionMozartInPlace#
- #include <micm/cuda/solver/cuda_lu_decomposition_mozart_in_place.hpp>
This CudaLuDecompositionMozartInPlace class inherits everything from the base class “LuDecompositionMozartInPlace”.
Public Functions
-
inline CudaLuDecompositionMozartInPlace()#
This is the default constructor, taking no arguments;.
-
template<class SparseMatrixPolicy>
inline CudaLuDecompositionMozartInPlace(const SparseMatrixPolicy &matrix)# This is the overloaded constructor that takes one argument called “matrix”; We need to specify the type (e.g., double, int, etc) and ordering (e.g., vector-stored, non-vector-stored, etc) of the “matrix”;
-
inline ~CudaLuDecompositionMozartInPlace()#
This is destructor that will free the device memory of the constant data from the class “CudaLuDecompositionMozartInPlace”
-
template<class SparseMatrixPolicy>
void Decompose(SparseMatrixPolicy &ALU) const# This is the function to perform an LU decomposition on a given A matrix on the GPU.
- Parameters:
ALU – Sparse matrix to decompose (will be overwritten with L and U matrices)
Public Members
-
LuDecomposeMozartInPlaceParam devstruct_#
This is an instance of struct “LuDecomposeMozartInPlaceParam” that holds the constant data of “CudaLuDecompositionMozartInPlace” class on the device
Public Static Functions
-
template<class SparseMatrixPolicy>
static inline CudaLuDecompositionMozartInPlace Create(const SparseMatrixPolicy &matrix)# Create an LU decomposition algorithm for a given sparse matrix policy.
- Parameters:
matrix – Sparse matrix
-
inline CudaLuDecompositionMozartInPlace()#
-
class CudaProcessSet : public micm::ProcessSet#
- #include <micm/cuda/process/cuda_process_set.hpp>
A GPU-based implementation of ProcessSet.
Public Functions
-
inline CudaProcessSet(const std::vector<Process> &processes, const std::unordered_map<std::string, std::size_t> &variable_map)#
Create a process set calculator for a given set of processes.
- Parameters:
processes – Processes to create calculator for
variable_map – A mapping of species names to concentration index
-
template<typename OrderingPolicy>
inline void SetJacobianFlatIds(const SparseMatrix<double, OrderingPolicy> &matrix)# Set the indexes for the elements of Jacobian matrix before we could copy it to the device;.
this will override the “SetJacobianFlatIds” function from the “ProcessSet” class
- Parameters:
OrderingPolicy –
matrix –
Public Members
-
ProcessSetParam devstruct_#
This is an instance of struct “ProcessSetParam” that holds the constant data of “ProcessSet” class on the device
-
inline CudaProcessSet(const std::vector<Process> &processes, const std::unordered_map<std::string, std::size_t> &variable_map)#
-
template<class RatesPolicy, class LinearSolverPolicy>
class CudaRosenbrockSolver : public micm::AbstractRosenbrockSolver<RatesPolicy, LinearSolverPolicy, CudaRosenbrockSolver<RatesPolicy, LinearSolverPolicy>># Public Types
-
using ParametersType = CudaRosenbrockSolverParameters#
Default constructor.
Solver parameters typename
Public Functions
-
inline CudaRosenbrockSolver()#
Default constructor.
-
inline CudaRosenbrockSolver(LinearSolverPolicy &&linear_solver, RatesPolicy &&rates, auto &jacobian, const size_t number_of_species)#
Builds a CUDA Rosenbrock solver for the given system and solver parameters.
- Parameters:
parameters – Solver parameters
linear_solver – Linear solver
rates – Rates calculator
jacobian – Jacobian matrix
-
inline ~CudaRosenbrockSolver()#
This is the destructor that will free the device memory of the constant data from the class “CudaRosenbrockSolver”
-
template<class SparseMatrixPolicy>
inline void AlphaMinusJacobian(auto &state, const double &alpha) const# Computes [alpha * I - jacobian] on the GPU.
- Template Parameters:
SparseMatrixPolicy –
- Parameters:
jacobian – Jacobian matrix
jacobian_diagonal_elements – Diagonal elements of the Jacobian matrix, not used
alpha –
-
template<class DenseMatrixPolicy>
inline double NormalizedError(const DenseMatrixPolicy &y_old, const DenseMatrixPolicy &y_new, const DenseMatrixPolicy &errors, auto &state) const# Computes the scaled norm of the vector errors on the GPU; assume all the data are GPU resident already.
- Template Parameters:
DenseMatrixPolicy –
- Parameters:
y_old – the original vector
y_new – the new vector
errors – The computed errors
- Returns:
The scaled norm of the errors
-
using ParametersType = CudaRosenbrockSolverParameters#
-
struct CudaRosenbrockSolverParameters : public micm::RosenbrockSolverParameters#
- #include <micm/cuda/solver/cuda_solver_parameters.hpp>
Parameters for the CUDA Rosenbrock solver.
Public Functions
-
inline CudaRosenbrockSolverParameters(const RosenbrockSolverParameters &base)#
Constructor from base class.
- Parameters:
base –
-
inline CudaRosenbrockSolverParameters(const RosenbrockSolverParameters &base)#
-
template<class T, class OrderingPolicy>
class CudaSparseMatrix : public micm::SparseMatrix<T, OrderingPolicy>#
-
template<class DenseMatrixPolicy, class SparseMatrixPolicy, class LuDecompositionPolicy>
struct CudaState : public micm::State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy># - #include <micm/cuda/solver/cuda_state.hpp>
Construct a state variable for CUDA tests.
Public Functions
-
inline CudaState(const StateParameters ¶meters, const std::size_t number_of_grid_cells)#
Constructor which takes the state dimension information as input.
- Parameters:
parameters – State dimension information
number_of_grid_cells – Number of grid cells
-
inline virtual void SetAbsoluteTolerances(const std::vector<double> &absoluteTolerance) override#
Set the absolute tolerances per species.
- Parameters:
absoluteTolerance – absolute tolerance
-
inline void SyncInputsToDevice()#
Copy input variables to the device.
-
inline void SyncOutputsToHost()#
Copy output variables to the host.
-
inline CudaState(const StateParameters ¶meters, const std::size_t number_of_grid_cells)#
-
class EquilibriumConstraint : public micm::Constraint#
- #include <micm/constraint/equilibrium_constraint.hpp>
Constraint for chemical equilibrium: K_eq = [products]^stoich / [reactants]^stoich.
For a reversible reaction: aA + bB <-> cC + dD The equilibrium constraint is: G = K_eq * [A]^a * [B]^b - [C]^c * [D]^d = 0
This can also be written in terms of forward/backward rate constants: G = k_f * [A]^a * [B]^b - k_b * [C]^c * [D]^d = 0 where K_eq = k_f / k_b
Public Functions
-
EquilibriumConstraint() = default#
Default constructor.
-
inline EquilibriumConstraint(const std::string &name, const std::vector<StoichSpecies> &reactants, const std::vector<StoichSpecies> &products, double equilibrium_constant)#
Construct an equilibrium constraint.
- Parameters:
name – Constraint identifier
reactants – Vector of StoichSpecies (species, stoichiometry) for reactants
products – Vector of StoichSpecies (species, stoichiometry) for products
equilibrium_constant – K_eq = [products]/[reactants] at equilibrium
-
inline virtual double Residual(const double *concentrations, const std::size_t *indices) const override#
Evaluate the equilibrium constraint residual.
G = K_eq * prod([reactants]^stoich) - prod([products]^stoich)
At equilibrium, G = 0
- Parameters:
concentrations – Pointer to species concentrations (row of state matrix)
indices – Pointer to indices mapping species_dependencies_ to concentrations
- Returns:
Residual value
-
inline virtual void Jacobian(const double *concentrations, const std::size_t *indices, double *jacobian) const override#
Compute Jacobian entries dG/d[species].
For reactant R with stoichiometry n: dG/d[R] = K_eq * n * [R]^(n-1) * prod([other_reactants]^stoich)
For product P with stoichiometry m: dG/d[P] = -m * [P]^(m-1) * prod([other_products]^stoich)
- Parameters:
concentrations – Pointer to species concentrations (row of state matrix)
indices – Pointer to indices mapping species_dependencies_ to concentrations
jacobian – Output buffer for partial derivatives (same order as species_dependencies_)
Public Members
-
std::vector<StoichSpecies> reactants_#
Reactant species and their stoichiometric coefficients.
-
std::vector<StoichSpecies> products_#
Product species and their stoichiometric coefficients.
-
double equilibrium_constant_#
Equilibrium constant K_eq = k_forward / k_backward.
-
EquilibriumConstraint() = default#
-
struct ExternalModel#
Public Functions
-
template<typename ModelType, typename = std::enable_if_t<!std::is_same_v<std::decay_t<ModelType>, ExternalModel>>>
inline ExternalModel(ModelType &&model)# Constructor from an external model instance.
- Template Parameters:
ModelType – Type of the external model
- Parameters:
model – Instance of the external model
-
template<typename ModelType, typename = std::enable_if_t<!std::is_same_v<std::decay_t<ModelType>, ExternalModel>>>
-
class HenrysLawConstant : public micm::TransferCoefficient#
- #include <micm/process/transfer_coefficient/henrys_law_constant.hpp>
Henry’s Law constant that accounts for temperature dependence.
Public Functions
-
inline HenrysLawConstant()#
Default constructor.
-
inline HenrysLawConstant(const HenrysLawConstantParameters ¶meters)#
Explicit constructor.
- Parameters:
parameters – A set of Henry’s Law constant parameters
-
inline virtual std::unique_ptr<TransferCoefficient> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the Henry’s Law constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
The Henry’s Law constant accounting for temperature
-
inline HenrysLawConstant()#
-
struct HenrysLawConstantParameters#
- #include <micm/process/transfer_coefficient/henrys_law_constant.hpp>
Henry’s Law constant parameters.
-
class LambdaRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/lambda_rate_constant.hpp>
A lambda-backed rate constant.
Public Functions
-
inline LambdaRateConstant()#
Default constructor.
-
inline LambdaRateConstant(const LambdaRateConstantParameters ¶meters)#
- Parameters:
parameters – The data needed to build this class
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline LambdaRateConstant()#
-
struct LambdaRateConstantParameters#
Public Members
-
std::string label_#
Label for the reaction used to identify user-defined parameters.
-
std::function<double(const Conditions&)> lambda_function_#
Lambda function for calculating the rate constant.
-
std::string label_#
-
template<class SparseMatrixPolicy, class LuDecompositionPolicy = LuDecomposition, class LMatrixPolicy = SparseMatrixPolicy, class UMatrixPolicy = SparseMatrixPolicy>
class LinearSolver# - #include <micm/solver/linear_solver.hpp>
A general-use block-diagonal sparse-matrix linear solver.
The sparsity pattern of each block in the block diagonal matrix is the same.
Public Functions
-
inline LinearSolver()#
default constructor
-
inline LinearSolver(const SparseMatrixPolicy &matrix, typename SparseMatrixPolicy::value_type initial_value)#
Constructs a linear solver for the sparsity structure of the given matrix.
- Parameters:
matrix – Sparse matrix
initial_value – Initial value for matrix elements
-
inline LinearSolver(const SparseMatrixPolicy &matrix, typename SparseMatrixPolicy::value_type initial_value, const std::function<LuDecompositionPolicy(const SparseMatrixPolicy&)> create_lu_decomp)#
Constructs a linear solver for the sparsity structure of the given matrix.
- Parameters:
matrix – Sparse matrix
initial_value – Initial value for matrix elements
create_lu_decomp – Function to create an LU Decomposition object that adheres to LuDecompositionPolicy
-
inline void Factor(const SparseMatrixPolicy &matrix, LMatrixPolicy &lower_matrix, UMatrixPolicy &upper_matrix) const#
Decompose the matrix into upper and lower triangular matrices.
- Parameters:
matrix – Matrix to decompose into lower and upper triangular matrices
-
template<class MatrixPolicy>
inline void Solve(MatrixPolicy &x, const LMatrixPolicy &lower_matrix, const UMatrixPolicy &upper_matrix) const# Solve for x in Ax = b. x should be a copy of b and after Solve finishes x will contain the result.
-
inline LinearSolver()#
-
template<class SparseMatrixPolicy, class LuDecompositionPolicy = LuDecompositionInPlace>
class LinearSolverInPlace# - #include <micm/solver/linear_solver_in_place.hpp>
A general-use block-diagonal sparse-matrix linear solver.
The sparsity pattern of each block in the block diagonal matrix is the same. The L and U matrices are decomposed in-place over the original A matrix.
Public Functions
-
inline LinearSolverInPlace()#
default constructor
-
inline LinearSolverInPlace(const SparseMatrixPolicy &matrix, typename SparseMatrixPolicy::value_type initial_value)#
Constructs a linear solver for the sparsity structure of the given matrix.
- Parameters:
matrix – Sparse matrix
initial_value – Initial value for matrix elements
-
inline LinearSolverInPlace(const SparseMatrixPolicy &matrix, typename SparseMatrixPolicy::value_type initial_value, const std::function<LuDecompositionPolicy(const SparseMatrixPolicy&)> create_lu_decomp)#
Constructs a linear solver for the sparsity structure of the given matrix.
- Parameters:
matrix – Sparse matrix
initial_value – Initial value for matrix elements
create_lu_decomp – Function to create an LU Decomposition object that adheres to LuDecompositionPolicy
-
inline void Factor(SparseMatrixPolicy &matrix) const#
Decompose the matrix into upper and lower triangular matrices (matrix will be overwritten)
- Parameters:
matrix – Matrix to decompose in-place into lower and upper triangular matrices
-
template<class MatrixPolicy>
inline void Solve(MatrixPolicy &x, const SparseMatrixPolicy &lu_matrix) const# Solve for x in Ax = b. x should be a copy of b and after Solve finishes x will contain the result.
- Parameters:
x – The solution vector
LU – The LU decomposition of the matrix as a square sparse matrix
-
inline LinearSolverInPlace()#
-
class LuDecompositionDoolittle#
- #include <micm/solver/lu_decomposition_doolittle.hpp>
LU decomposer for SparseMatrix following the Doolittle algorithm.
The LU decomposition uses the Doolittle algorithm following the naming used here: https://www.geeksforgeeks.org/doolittle-algorithm-lu-decomposition/
The sudo-code for the corresponding dense matrix algorithm for matrix A and lower (upper) triangular matrix L(U) would be:
for i = 0…n-1 // Outer loop over rows (columns) for upper (lower) triangular matrix for k = i…n-1 // Middle loop over columns for upper triangular matrix sum = 0 for j = 0…i-1 // Inner loop over columns (rows) for lower (upper) triangular matrix sum += L[i][j] * U[j][k] U[i][k] = A[i][k] - sum L[i][i] = 1 // Lower triangular matrix is 1 along the diagonal for k = i+1…n-1 // Middle loop over rows for lower triangular matrix sum = 0 for j = 0…i-1 // Inner loop over columns (rows) for lower (upper) triangular matrix sum += L[k][j] * U[j][i]; L[k][i] = (A[k][i] - sum) / U[i][i]
For the sparse matrix algorithm, the indices of non-zero terms are stored in several arrays during construction. These arrays are iterated through during calls to Decompose to do the actual decomposition. Our LU Decomposition only assigns the values of the jacobian to the LU matrices when the jacobian is nonzero. However, the sparsity pattern of the jacobian doesn’t necessarily match that of the LU matrices. There can be more nonzero elements in the LU matrices than in the jacobian. When this happens, we still need to assign the value of the jacobian matrix to the LU matrix. This value is implicitly zero when the sparsity pattern differs. The Fill values here do this implicit assignment More detail in this issue: NCAR/micm#625
Public Functions
-
inline LuDecompositionDoolittle()#
default constructor
-
template<class SparseMatrixPolicy, class LMatrixPolicy = SparseMatrixPolicy, class UMatrixPolicy = SparseMatrixPolicy>
inline LuDecompositionDoolittle(const SparseMatrixPolicy &matrix)# Construct an LU decomposition algorithm for a given sparse matrix.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy>
inline void Decompose(const SparseMatrixPolicy &A, auto &L, auto &U) const# Perform an LU decomposition on a given A matrix.
- Parameters:
A – Sparse matrix to decompose
L – The lower triangular matrix created by decomposition
U – The upper triangular matrix created by decomposition
Public Static Functions
-
template<class SparseMatrixPolicy, class LMatrixPolicy = SparseMatrixPolicy, class UMatrixPolicy = SparseMatrixPolicy>
static inline LuDecompositionDoolittle Create(const SparseMatrixPolicy &matrix)# Create an LU decomposition algorithm for a given sparse matrix policy.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy, class LMatrixPolicy = SparseMatrixPolicy, class UMatrixPolicy = SparseMatrixPolicy>
static inline std::pair<LMatrixPolicy, UMatrixPolicy> GetLUMatrices(const SparseMatrixPolicy &A, typename SparseMatrixPolicy::value_type initial_value, bool indexing_only = false)# Create sparse L and U matrices for a given A matrix.
- Parameters:
A – Sparse matrix that will be decomposed
- Returns:
L and U Sparse matrices
-
inline LuDecompositionDoolittle()#
-
class LuDecompositionDoolittleInPlace#
- #include <micm/solver/lu_decomposition_doolittle_in_place.hpp>
LU decomposer for SparseMatrix following the Doolittle algorithm.
The LU decomposition uses the Doolittle algorithm following the naming used here: https://www.geeksforgeeks.org/doolittle-algorithm-lu-decomposition/
The sudo-code for the corresponding dense matrix algorithm for matrix A (in-line) would be:
for i = 0…n-1 // Outer loop over rows (columns) for upper (lower) triangular matrix for k = i…n-1 // Middle loop over columns for upper triangular matrix for j = 0…i-1 // Inner loop over columns (rows) for lower (upper) triangular matrix A[i][k] -= A[i][j] * A[j][k] for k = i+1…n-1 // Middle loop over rows for lower triangular matrix for j = 0…i-1 // Inner loop over columns (rows) for lower (upper) triangular matrix A[k][i] -= A[k][j] * A[j][i]; A[k][i] /= A[i][i]
For the sparse matrix algorithm, the indices of non-zero terms are stored in several arrays during construction. These arrays are iterated through during calls to Decompose to do the actual decomposition. Our LU Decomposition only assigns the values of the jacobian to the LU matrices when the jacobian is nonzero. However, the sparsity pattern of the jacobian doesn’t necessarily match that of the LU matrices. There can be more nonzero elements in the LU matrices than in the jacobian. It is expected that the elements of the L and U matrices that are zero in the A matrix will be set to zero before the combined matrix is passed to the decomposition function.
Public Functions
-
inline LuDecompositionDoolittleInPlace()#
default constructor
-
template<class SparseMatrixPolicy>
inline LuDecompositionDoolittleInPlace(const SparseMatrixPolicy &matrix)# Construct an LU decomposition algorithm for a given sparse matrix.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy>
inline void Decompose(SparseMatrixPolicy &ALU) const# Perform an LU decomposition on a given A matrix.
- Parameters:
A – Sparse matrix to decompose
L – The lower triangular matrix created by decomposition
U – The upper triangular matrix created by decomposition
Public Static Functions
-
template<class SparseMatrixPolicy>
static inline LuDecompositionDoolittleInPlace Create(const SparseMatrixPolicy &matrix)# Create an LU decomposition algorithm for a given sparse matrix policy.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy>
static inline SparseMatrixPolicy GetLUMatrix(const SparseMatrixPolicy &A, typename SparseMatrixPolicy::value_type initial_value, bool indexing_only = false)# Create sparse L and U matrices for a given A matrix.
- Parameters:
A – Sparse matrix that will be decomposed
- Returns:
L and U Sparse matrices
-
inline LuDecompositionDoolittleInPlace()#
-
class LuDecompositionMozart#
- #include <micm/solver/lu_decomposition_mozart.hpp>
LU decomposer for SparseMatrix following the algorithm from the MOZART model.
This LU decomposition uses the algorithm from the MOZART chemistry preprocessor at: ESCOMP/CHEM_PREPROCESSOR
The MOZART function overwrote the A matrix with the L and U matrices. The pseudo-code in C++ for the corresponding dense matrix algorithm for matrix A (inline change) would be:
for i = 0…n-1 // Outer loop over columns of the sparse matrix A for j = i+1…n-1 // Multiply column below diagonal A[j][i] = A[j][i] / A[i][i] for k = i+1…n-1 // Modify sub-matrix for j = i+1…n-1 A[j][k] = A[j][k] – A[j][i] * A[i][k]
The pseudo-code in C++ for the corresponding dense matrix algorithm for matrix A and separate lower (upper) triangular matrix L(U) would be:
for i = 0…n-1 // Initialize U and L matrices to the A values for j = 0…i // Initialize U matrix including diagonal U[j][i] = A[j][i] L[i][i] = 1 // Lower triangular matrix is 1 along the diagonal for j = i+1…n-1 // Initialize L matrix excluding diagonal L[j][i] = A[j][i] for i = 0…n-1 for j = i+1…n-1 // Multiply column below diagonal L[j][i] = L[j][i] / U[i][i] for k = i+1…n-1 // Modify sub-matrix for j = i+1…k U[j][k] = U[j][k] - L[j][i] * U[i][k] for j = k+1…n-1 L[j][k] = L[j][k] - L[j][i] * U[i][k]
For the sparse matrix algorithm, the indices of non-zero terms are stored in several arrays during construction. These arrays are iterated through during calls to Decompose to do the actual decomposition. Our LU Decomposition only assigns the values of the jacobian to the LU matrices when the jacobian is nonzero. However, the sparsity pattern of the jacobian doesn’t necessarily match that of the LU matrices. There can be more nonzero elements in the LU matrices than in the jacobian. When this happens, we still need to assign the value of the jacobian matrix to the LU matrix. This value is implicitly zero when the sparsity pattern differs. The Fill values here do this implicit assignment More detail in this issue: NCAR/micm#625
Public Functions
-
inline LuDecompositionMozart()#
default constructor
-
template<class SparseMatrixPolicy>
LuDecompositionMozart(const SparseMatrixPolicy &matrix)# Construct an LU decomposition algorithm for a given sparse matrix.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy, class LMatrixPolicy, class UMatrixPolicy>
inline LuDecompositionMozart(const SparseMatrixPolicy &matrix)# Construct an LU decomposition algorithm for a given sparse matrix.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy>
inline void Decompose(const SparseMatrixPolicy &A, auto &L, auto &U) const# Perform an LU decomposition on a given A matrix.
- Parameters:
A – Sparse matrix to decompose
L – The lower triangular matrix created by decomposition
U – The upper triangular matrix created by decomposition
Public Static Functions
-
template<class SparseMatrixPolicy, class LMatrixPolicy, class UMatrixPolicy>
static inline LuDecompositionMozart Create(const SparseMatrixPolicy &matrix)# Create an LU decomposition algorithm for a given sparse matrix policy.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy, class LMatrixPolicy, class UMatrixPolicy>
static inline std::pair<LMatrixPolicy, UMatrixPolicy> GetLUMatrices(const SparseMatrixPolicy &A, typename SparseMatrixPolicy::value_type initial_value, bool indexing_only = false)# Create sparse L and U matrices for a given A matrix.
- Parameters:
A – Sparse matrix that will be decomposed
- Returns:
L and U Sparse matrices
-
inline LuDecompositionMozart()#
-
class LuDecompositionMozartInPlace#
- #include <micm/solver/lu_decomposition_mozart_in_place.hpp>
LU decomposer for SparseMatrix following the algorithm from the MOZART model.
This LU decomposition uses the algorithm from the MOZART chemistry preprocessor at: ESCOMP/CHEM_PREPROCESSOR
The MOZART function overwrote the A matrix with the L and U matrices. The pseudo-code in C++ for the corresponding dense matrix algorithm for matrix A (inline change) would be:
for i = 0…n-1 // Outer loop over columns of the sparse matrix A for j = i+1…n-1 // Multiply column below diagonal A[j][i] = A[j][i] / A[i][i] for k = i+1…n-1 // Modify sub-matrix for j = i+1…n-1 A[j][k] = A[j][k] – A[j][i] * A[i][k]
For the sparse matrix algorithm, the indices of non-zero terms are stored in several arrays during construction. These arrays are iterated through during calls to Decompose to do the actual decomposition.
The GetLUMatrices function creates a new sparse matrix that includes the superset of the non-zero elements in the L and U matrices. It is expected that the elements of the L and U matrices that are zero in the A matrix will be set to zero before the combined matrix is passed to the decomposition function.
Subclassed by micm::CudaLuDecompositionMozartInPlace
Public Functions
-
inline LuDecompositionMozartInPlace()#
default constructor
-
template<class SparseMatrixPolicy>
inline LuDecompositionMozartInPlace(const SparseMatrixPolicy &matrix)# Construct an LU decomposition algorithm for a given sparse matrix.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy>
inline void Decompose(SparseMatrixPolicy &ALU) const# Perform an LU decomposition on a given A matrix. All elements of L and U that are zero in A should be set to zero before calling this function.
- Parameters:
ALU – Sparse matrix to decompose (will be overwritten with L and U matrices)
Public Static Functions
-
template<class SparseMatrixPolicy>
static inline LuDecompositionMozartInPlace Create(const SparseMatrixPolicy &matrix)# Create an LU decomposition algorithm for a given sparse matrix policy.
- Parameters:
matrix – Sparse matrix
-
template<class SparseMatrixPolicy>
static inline SparseMatrixPolicy GetLUMatrix(const SparseMatrixPolicy &A, typename SparseMatrixPolicy::value_type initial_value, bool indexing_only = false)# Create a combined sparse L and U matrix for a given A matrix.
- Parameters:
A – Sparse matrix that will be decomposed
- Returns:
combined L and U Sparse matrices
-
inline LuDecompositionMozartInPlace()#
-
template<class T = double>
class Matrix# - #include <micm/util/matrix.hpp>
A 2D array class with contiguous memory.
Public Functions
-
inline std::size_t RowStride() const#
Get the number of elements in the underlying vector between adjacent rows for the same column.
- Returns:
The number of elements in the underlying vector between adjacent rows for the same column
-
inline std::size_t ColumnStride() const#
Get the number of elements in the underlying vector between adjacent columns for the same row.
- Returns:
The number of elements in the underlying vector between adjacent columns for the same row
-
inline void Fill(T val)#
Set every matrix element to a given value.
- Parameters:
val – Value to set each element to
-
inline void Axpy(const double &alpha, const Matrix &x)#
For each element in the Matrix x and y, perform y = alpha * x + y, where alpha is a scalar constant.
-
inline std::size_t RowStride() const#
-
class Phase#
- #include <micm/system/phase.hpp>
Represents a chemical phase (e.g., gaseous, aqueous) Each phase defines a set of species that participate in chemical reactions within that phase.
Public Functions
-
Phase() = default#
Defaulted constructors and assignment operators.
-
inline Phase(const std::string &name, const std::vector<PhaseSpecies> &phase_species)#
Create a phase with a name and a set of species.
-
inline std::size_t StateSize() const#
Returns the number of non-parameterized species.
-
inline std::vector<std::string> UniqueNames() const#
Returns a set of unique names for each non-parameterized species.
-
inline std::vector<std::string> SpeciesNames() const#
Returns a set of unique names for each non-parameterized species (excludes phase name prefix)
Public Members
-
std::vector<PhaseSpecies> phase_species_#
The list of phase-specific species.
-
Phase() = default#
-
class PhaseSpecies#
- #include <micm/system/phase.hpp>
Represents a chemical species within a specific phase, storing the species information and its optional diffusion coefficient.
-
class PhaseTransferProcess#
- #include <micm/process/phase_transfer_process.hpp>
Represents a phase-transfer process where species moves from one phase to another.
-
class PhaseTransferProcessBuilder#
Public Functions
-
inline PhaseTransferProcessBuilder &SetGasSpecies(const Phase &phase, const Species &species)#
Sets the species in the gas phase.
-
inline PhaseTransferProcessBuilder &SetCondensedSpecies(const Phase &phase, const Species &species)#
Sets the species in the condensed phase.
-
inline PhaseTransferProcessBuilder &SetSolvent(const Phase &phase, const Species &solvent)#
Sets the solvent involved in the phase transfer process.
-
inline PhaseTransferProcessBuilder &SetTransferCoefficient(const TransferCoefficient &coefficient)#
Sets the transfer coefficient by cloning the provided coefficient object.
- Parameters:
coefficient – A reference to a TransferCoefficient to be cloned
- Returns:
Reference to the builder
-
inline Process Build()#
Builds the PhaseTransferProcess with the configured parameters and wraps it in a Process object.
- Throws:
std::system_error – if the provided coefficient pointer is null
- Returns:
A Process object containing the constructed PhaseTransferProcess
-
inline PhaseTransferProcessBuilder &SetGasSpecies(const Phase &phase, const Species &species)#
-
class Process#
Public Static Functions
-
template<class DenseMatrixPolicy, class SparseMatrixPolicy, class LuDecompositionPolicy, class LMatrixPolicy, class UMatrixPolicy>
static inline void CalculateRateConstants(const std::vector<Process> &processes, State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy, LMatrixPolicy, UMatrixPolicy> &state)# TODO - Temporary wrapper for rate constant calculation Calls ChemicalReaction::CalculateRateConstants for all ChemicalReaction processes issue - NCAR/micm#812.
-
template<class DenseMatrixPolicy, class SparseMatrixPolicy, class LuDecompositionPolicy, class LMatrixPolicy, class UMatrixPolicy>
-
class ProcessSet#
- #include <micm/process/process_set.hpp>
Solver function calculators for a collection of processes.
Subclassed by micm::CudaProcessSet
Public Functions
-
ProcessSet() = default#
Default constructor.
-
inline ProcessSet(const std::vector<Process> &processes, const std::unordered_map<std::string, std::size_t> &variable_map)#
Constructs a ProcessSet by mapping species in each process to their corresponding indices Initializes internal data structures related to a set of processes, mapping them to variable indices using a provided variable_map. Also prepares the data needed for computing Jacobian contributions.
- Parameters:
processes – A list of processes, each with reactants and products
variable_map – A map from species names to their corresponding index in the solver’s state
- Throws:
std::system_error – If a reactant or product name in a process is not found in variable_map
-
inline std::set<std::pair<std::size_t, std::size_t>> NonZeroJacobianElements() const#
Returns the positions of all non-zero Jacobian elements.
- Returns:
A set of (row, column) index pairs, each representing a non-zero entry
-
template<typename OrderingPolicy>
inline void SetJacobianFlatIds(const SparseMatrix<double, OrderingPolicy> &matrix)# Computes and stores flat (1D) indices for non-zero Jacobian elements Stores combination of process ids and reactant ids to support column-wise Jacobian updates.
- Parameters:
matrix – The sparse Jacobian matrix used to compute flat indices.
-
template<typename DenseMatrixPolicy>
inline void AddForcingTerms(const DenseMatrixPolicy &rate_constants, const DenseMatrixPolicy &state_variables, DenseMatrixPolicy &forcing) const# Adds forcing terms for the set of processes for the current conditions.
- Parameters:
rate_constants – Current values for the process rate constants (grid cell, process)
state_variables – Current state variable values (grid cell, state variable)
forcing – Forcing terms for each state variable (grid cell, state variable)
-
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
inline void SubtractJacobianTerms(const DenseMatrixPolicy &rate_constants, const DenseMatrixPolicy &state_variables, SparseMatrixPolicy &jacobian) const# Subtracts Jacobian terms for the set of processes for the current conditions.
- Parameters:
rate_constants – Current values for the process rate constants (grid cell, process)
state_variables – Current state variable values (grid cell, state variable)
jacobian – Jacobian matrix for the system (grid cell, dependent variable, independent variable)
-
ProcessSet() = default#
-
class RateConstant#
- #include <micm/process/rate_constant/rate_constant.hpp>
A base class for any type of rate constant.
Subclassed by micm::ArrheniusRateConstant, micm::BranchedRateConstant, micm::LambdaRateConstant, micm::ReversibleRateConstant, micm::SurfaceRateConstant, micm::TaylorSeriesRateConstant, micm::TernaryChemicalActivationRateConstant, micm::TroeRateConstant, micm::TunnelingRateConstant, micm::UserDefinedRateConstant
Public Functions
-
inline virtual ~RateConstant()#
Virtual destructor.
-
virtual std::unique_ptr<RateConstant> Clone() const = 0#
Deep copy.
-
inline virtual std::vector<std::string> CustomParameters() const#
Returns a set of labels for user-defined rate constant parameters.
- Returns:
Vector of custom parameter labels
-
inline virtual std::size_t SizeCustomParameters() const#
Returns the number of custom parameters.
- Returns:
Number of custom parameters
-
inline virtual double Calculate(const Conditions &conditions) const#
Calculate the rate constant for a set of conditions.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
The reaction rate constant
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const#
Calculate the rate constant for a set of conditions.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User defined rate constant parameters
- Returns:
The reaction rate constant
-
inline virtual ~RateConstant()#
-
class ReversibleRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/reversible_rate_constant.hpp>
A reversible rate constant with temperature dependence for condensed-phase reversible reaction.
Public Functions
-
inline ReversibleRateConstant()#
Default constructor.
-
inline ReversibleRateConstant(const ReversibleRateConstantParameters ¶meters)#
An explicit constructor.
- Parameters:
parameters – A set of reversible rate constant parameters
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline double Calculate(const double temperature) const#
Calculate the rate constant.
- Parameters:
temperature – Temperature [K]
- Returns:
A rate constant based on temperature
-
inline ReversibleRateConstant()#
-
struct ReversibleRateConstantParameters#
-
template<class RatesPolicy, class LinearSolverPolicy>
class RosenbrockSolver : public micm::AbstractRosenbrockSolver<RatesPolicy, LinearSolverPolicy, RosenbrockSolver<RatesPolicy, LinearSolverPolicy>># Public Functions
-
inline RosenbrockSolver(LinearSolverPolicy &&linear_solver, RatesPolicy &&rates, auto &jacobian, const size_t number_of_species)#
Default constructor.
Note: This constructor is not intended to be used directly. Instead, use the SolverBuilder to create a solver
- Parameters:
linear_solver – Linear solver
rates – Rates calculator
jacobian – Jacobian matrix
-
inline RosenbrockSolver(LinearSolverPolicy &&linear_solver, RatesPolicy &&rates, auto &jacobian, const size_t number_of_species)#
-
struct RosenbrockSolverParameters#
- #include <micm/solver/rosenbrock_solver_parameters.hpp>
Rosenbrock solver parameters.
Subclassed by micm::CudaRosenbrockSolverParameters
Public Static Functions
-
static inline RosenbrockSolverParameters TwoStageRosenbrockParameters()#
an L-stable method, 2 stages, order 2
- Returns:
-
static inline RosenbrockSolverParameters ThreeStageRosenbrockParameters()#
an L-stable method, 3 stages, order 3, 2 function evaluations
- Parameters:
reorder_state –
- Returns:
-
static inline RosenbrockSolverParameters FourStageRosenbrockParameters()#
L-stable rosenbrock method of order 4, with 4 stages.
- Returns:
-
static inline RosenbrockSolverParameters FourStageDifferentialAlgebraicRosenbrockParameters()#
A stiffly-stable method, 4 stages, order 3.
- Returns:
-
static inline RosenbrockSolverParameters SixStageDifferentialAlgebraicRosenbrockParameters()#
stiffly-stable rosenbrock method of order 4, with 6 stages
- Returns:
-
static inline RosenbrockSolverParameters TwoStageRosenbrockParameters()#
-
template<class DenseMatrixPolicy>
class RosenbrockTemporaryVariables : public micm::TemporaryVariables#
-
template<class SolverPolicy, class StatePolicy>
class Solver# Public Functions
-
inline std::size_t MaximumNumberOfGridCells() const#
Returns the maximum number of grid cells per state.
This is the maximum number of grid cells that can fit within one group for vectorized solvers. For non-vectorized solvers, there is no limit other than the maximum size of a std::size_t.
- Returns:
Number of grid cells
-
inline std::size_t GetNumberOfSpecies() const#
Returns the number of species.
- Returns:
-
inline std::size_t MaximumNumberOfGridCells() const#
-
template<class SolverParametersPolicy, class DenseMatrixPolicy, class SparseMatrixPolicy, class RatesPolicy, class LuDecompositionPolicy, class LinearSolverPolicy, class StatePolicy>
class SolverBuilder# - #include <micm/solver/solver_builder.hpp>
Builder of general solvers.
- Template Parameters:
SolverParametersPolicy – Policy for the ODE solver
DenseMatrixPolicy – Policy for dense matrices
SparseMatrixPolicy – Policy for sparse matrices
RatesPolicy – Calculator of forcing and Jacobian terms
LinearSolverPolicy – Policy for the linear solver
Public Functions
-
inline SolverBuilder &SetSystem(const System &system)#
Set the chemical system.
- Parameters:
system – The chemical system
- Returns:
Updated SolverBuilder
-
inline SolverBuilder &SetReactions(const std::vector<Process> &reactions)#
Set the reactions.
- Parameters:
reactions – The reactions
- Returns:
Updated SolverBuilder
-
inline SolverBuilder &SetIgnoreUnusedSpecies(bool ignore_unused_species)#
Set whether to ignore unused species.
- Parameters:
ignore_unused_species – True if unused species should be ignored
- Returns:
Updated SolverBuilder
-
inline SolverBuilder &SetReorderState(bool reorder_state)#
Set whether to reorder the state to optimize the LU decomposition.
- Parameters:
reorder_state – True if the state should be reordered
- Returns:
Updated SolverBuilder
-
struct SolverResult#
Public Members
-
SolverState state_ = SolverState::NotYetCalled#
The final state the solver was in.
-
SolverStats stats_ = {}#
A collection of runtime state for this call of the solver.
-
SolverState state_ = SolverState::NotYetCalled#
-
struct SolverStats#
Public Members
-
uint64_t function_calls_ = {}#
The number of forcing function calls.
-
uint64_t jacobian_updates_ = {}#
The number of jacobian function calls.
-
uint64_t number_of_steps_ = {}#
The total number of internal time steps taken.
-
uint64_t accepted_ = {}#
The number of accepted integrations.
-
uint64_t rejected_ = {}#
The number of rejected integrations.
-
uint64_t decompositions_ = {}#
The number of LU decompositions.
-
uint64_t solves_ = {}#
The number of linear solves.
-
double final_time_ = {}#
The final time the solver iterated to.
-
uint64_t function_calls_ = {}#
-
template<class T = double, class OrderingPolicy>
class SparseMatrix : public OrderingPolicy# - #include <micm/util/sparse_matrix.hpp>
A sparse block-diagonal 2D matrix class with contiguous memory.
Each block sub-matrix is square and has the same structure of non-zero elements
The template parameters are the type of the matrix elements and a class that defines the sizing and ordering of the data elements
Public Functions
-
inline SparseMatrix(const SparseMatrixBuilder<T, OrderingPolicy> &builder, bool indexing_only = false)#
Constructs a SparseMatrix from a given builder and optional indexing mode. Initializes the SparseMatrix using the provided SparseMatrixBuilder, which defines the matrix structure, block size, and non-zero elements. Optionally, the constructor can be used in “indexing only” mode, where the data storage is not allocated.
- Template Parameters:
T – The type of the matrix elements.
OrderingPolicy – The policy class that defines the ordering and storage of elements.
- Parameters:
builder – The builder object containing matrix configuration and initial values.
indexing_only – If true, only indexing structures are initialized and data storage is omitted.
-
inline void Fill(T val)#
Set every matrix element to a given value.
- Parameters:
val – Value to set each element to
-
inline void PrintNonZeroElements(std::ostream &os) const#
Print the sparse matrix with row index, column index, and non-zero value; useful to test other linear algebra libraries.
- Parameters:
os – Output stream to print to, defaults to std::cout
-
inline SparseMatrix(const SparseMatrixBuilder<T, OrderingPolicy> &builder, bool indexing_only = false)#
-
template<class T, class OrderingPolicy = SparseMatrixStandardOrdering>
class SparseMatrixBuilder#
-
class SparseMatrixStandardOrderingCompressedSparseColumn#
- #include <micm/util/sparse_matrix_standard_ordering_compressed_sparse_column.hpp>
Defines the ordering of SparseMatrix object data in Compressed Sparse Column format.
Data is stored with blocks in the block diagonal matrix as the highest level structure, then by column, then by non-zero rows in each column.
Public Functions
-
inline bool IsZero(std::size_t row, std::size_t column) const#
Returns whether a particular element is always zero.
- Parameters:
row – Row index
column – Column index
- Returns:
true if the element is always zero, false otherwise
-
inline bool IsZero(std::size_t row, std::size_t column) const#
-
class SparseMatrixStandardOrderingCompressedSparseRow#
- #include <micm/util/sparse_matrix_standard_ordering_compressed_sparse_row.hpp>
Defines the ordering of SparseMatrix object data in Compressed Sparse Row format.
Data is stored with blocks in the block diagonal matrix as the highest level structure, then by row, then by non-zero columns in each row.
Subclassed by micm::SparseMatrix< double, SparseMatrixStandardOrdering >
Public Functions
-
inline bool IsZero(std::size_t row, std::size_t column) const#
Returns whether a particular element is always zero.
- Parameters:
row – Row index
column – Column index
- Returns:
true if the element is always zero, false otherwise
-
inline bool IsZero(std::size_t row, std::size_t column) const#
-
template<std::size_t L = MICM_DEFAULT_VECTOR_SIZE>
class SparseMatrixVectorOrderingCompressedSparseColumn# - #include <micm/util/sparse_matrix_vector_ordering_compressed_sparse_column.hpp>
Defines the ordering of SparseMatrix object data in Compressed Sparse Column format into blocks of rows to encourage vectorization.
Data is stored with sets of blocks in the block diagonal matrix as the highest level structure, then by column, then by non-zero rows in each column, then by individual blocks in the set of blocks.
The template argument is the number of blocks per set of blocks and should be approximately the size of the vector register.
Public Functions
-
inline std::size_t GroupSize() const#
Returns the size of each group of blocks in the compressed data vector.
- Parameters:
number_of_non_zero_elements – Number of non-zero elements in the matrix
- Returns:
Size of each group of blocks
-
inline std::size_t NumberOfGroups(std::size_t number_of_blocks) const#
Returns the total number of groups of blocks in the compressed data vector, including any partial groups.
- Parameters:
number_of_blocks – Total number of block sub-matrices in the overall matrix
- Returns:
Number of groups of blocks
-
inline bool IsZero(const std::size_t row, const std::size_t column) const#
Returns whether a given row and column index is a zero element.
- Parameters:
row – Index of the row
column – Index of the column
- Returns:
True if the element is zero, false otherwise
Public Static Functions
-
static inline std::size_t GroupVectorSize()#
Returns the number of blocks included in each group of blocks.
- Returns:
Number of blocks per group
-
inline std::size_t GroupSize() const#
-
template<std::size_t L = MICM_DEFAULT_VECTOR_SIZE>
class SparseMatrixVectorOrderingCompressedSparseRow# - #include <micm/util/sparse_matrix_vector_ordering_compressed_sparse_row.hpp>
Defines the ordering of SparseMatrix object data in Compressed Sparse Row format into blocks of rows to encourage vectorization.
Data is stored with sets of blocks in the block diagonal matrix as the highest level structure, then by row, then by non-zero columns in each row, then by individual blocks in the set of blocks.
The template argument is the number of blocks per set of blocks and should be approximately the size of the vector register.
Public Functions
-
inline std::size_t GroupSize() const#
Returns the size of each group of blocks in the compressed data vector.
- Parameters:
number_of_non_zero_elements – Number of non-zero elements in the matrix
- Returns:
Size of each group of blocks
-
inline std::size_t NumberOfGroups(std::size_t number_of_blocks) const#
Returns the total number of groups of blocks in the compressed data vector, including any partial groups.
- Parameters:
number_of_blocks – Total number of block sub-matrices in the overall matrix
- Returns:
Number of groups of blocks
-
inline bool IsZero(std::size_t row, std::size_t column) const#
Returns whether a particular element is always zero.
- Parameters:
row – Row index
column – Column index
- Returns:
true if the element is always zero, false otherwise
Public Static Functions
-
static inline std::size_t GroupVectorSize()#
Returns the number of blocks included in each group of blocks.
- Returns:
Number of blocks in each group
-
inline std::size_t GroupSize() const#
-
class Species#
- #include <micm/system/species.hpp>
A representation of a chemcial species.
Public Functions
-
Species() = default#
Default constructor.
-
inline Species &operator=(const Species &other)#
Copy assignment.
- Parameters:
other – species to copy
-
inline Species(const std::string &name)#
Construct a species by name only.
- Parameters:
name – The name of the species
-
inline Species(const std::string &name, const std::map<std::string, double> &properties)#
Construct a species by name and properties.
- Parameters:
name – The name of the species
properties – The properties of the species
-
inline bool IsParameterized() const#
Returns whether a species is parameterized.
Public Members
-
std::string name_#
The name of this species.
-
std::map<std::string, std::string> properties_string_#
A list of properties of this species.
-
std::function<double(const Conditions)> parameterize_ = {nullptr}#
A function that if provided will be used to parameterize the concentration of this species during solving. Species with this function defined will be excluded from the solver state.
-
Species() = default#
-
template<class DenseMatrixPolicy = StandardDenseMatrix, class SparseMatrixPolicy = StandardSparseMatrix, class LuDecompositionPolicy = LuDecomposition, class LMatrixPolicy = SparseMatrixPolicy, class UMatrixPolicy = SparseMatrixPolicy>
struct State# Subclassed by micm::CudaState< CudaDenseMatrixVector, CudaSparseMatrixVector, CudaLuDecompositionMozartInPlace >
Public Types
-
using DenseMatrixPolicyType = DenseMatrixPolicy#
Type of the DenseMatrixPolicy.
Public Functions
-
inline State()#
Default constructor Only defined to be used to create default values in types, but a default constructed state is not useable.
-
inline State(const StateParameters ¶meters, const std::size_t number_of_grid_cells)#
Constructor with parameters.
- Parameters:
parameters – State dimension information
-
inline State(const State &other)#
Copy constructor.
- Parameters:
other – The state object to be copied
-
inline State &operator=(const State &other)#
Assignment operator.
- Parameters:
other – The state object to be assigned
- Returns:
Reference to the assigned state object
-
inline State(State &&other) noexcept#
Move constructor.
- Parameters:
other – The state object to be moved
-
inline State &operator=(State &&other) noexcept#
Move assignment operator.
- Parameters:
other – The state object to be moved
- Returns:
Reference to the moved state object
-
inline std::size_t NumberOfGridCells() const#
Get the number of grid cells.
- Returns:
The number of grid cells
-
inline void SetConcentrations(const std::unordered_map<std::string, std::vector<double>> &species_to_concentration)#
Set species’ concentrations.
- Parameters:
species_to_concentration –
-
inline void SetConcentration(const Species &species, double concentration)#
Set a single species concentration.
- Parameters:
species – the species to set the concentration for
concentration – concentration [mol m-3]
-
inline void SetConcentration(const Species &species, const std::vector<double> &concentration)#
Set concentrations for a single species across multiple grid cells.
- Parameters:
species – the species to set the concentrations for
concentration – vector of concentrations [mol m-3], one per grid cell
-
inline void SetConcentration(const std::string &element, double concentration)#
Set the concentration for a named element (species or other variable)
- Parameters:
species – the name of the element (can be a non-species variable, e.g., number_concentration)
concentration – concentration value [mol m-3]
-
inline void SetConcentration(const std::string &element, const std::vector<double> &concentration)#
Set concentrations for a named element (species or other variable) across multiple grid cells.
- Parameters:
species – the name of the element (can be a non-species variable, e.g., number_concentration)
concentration – vector of concentrations [mol m-3], one per grid cell
-
inline void UnsafelySetCustomRateParameters(const std::vector<std::vector<double>> ¶meters)#
Set custom parameters assuming the values are properly ordered.
- Parameters:
parameters – map of custom rate parameters
-
inline void SetCustomRateParameters(const std::unordered_map<std::string, std::vector<double>> ¶meters)#
Set custom parameters for rate constant calculations by label.
- Parameters:
parameters – map of custom rate parameters
-
inline void SetCustomRateParameter(const std::string &label, double value)#
Set a single custom rate constant parameter.
- Parameters:
label – parameter label
value – new parameter value
-
inline void SetRelativeTolerance(double relativeTolerance)#
Set the relative tolerances.
- Parameters:
relativeTolerance – relative tolerance
-
inline virtual void SetAbsoluteTolerances(const std::vector<double> &absoluteTolerance)#
Set the absolute tolerances per species.
- Parameters:
absoluteTolerance – absolute tolerance
-
inline void PrintHeader()#
Print a header of species to display concentrations with respect to time.
-
inline void PrintState(double time)#
Print state (concentrations) at the given time.
- Parameters:
time – solving time
Public Members
-
std::size_t number_of_grid_cells_ = {1}#
The number of grid cells stored in the state.
-
DenseMatrixPolicy variables_#
The concentration of chemicals, varies through time.
-
DenseMatrixPolicy custom_rate_parameters_#
Rate paramters particular to user-defined rate constants, may vary in time.
-
DenseMatrixPolicy rate_constants_#
The reaction rates, may vary in time.
-
std::vector<Conditions> conditions_#
Atmospheric conditions, varies in time.
-
SparseMatrixPolicy jacobian_#
The jacobian structure, varies for each solve.
-
std::unordered_map<std::string, std::size_t> variable_map_#
Immutable data required for the state.
-
using DenseMatrixPolicyType = DenseMatrixPolicy#
-
struct StateParameters#
- #include <micm/solver/state.hpp>
Invariants that can be used to construct a state.
-
struct StoichSpecies#
- #include <micm/system/stoich_species.hpp>
Represents a species in a chemical reaction, defined by its stoichiometric coefficient.
-
class SurfaceRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/surface_rate_constant.hpp>
A rate constant for surface reactions.
Public Functions
-
inline SurfaceRateConstant(const SurfaceRateConstantParameters ¶meters)#
Constructs a SurfaceRateConstant by initializing the diffusion coefficient and mean free speed factor from the provided parameters.
- Throws:
std::system_error – if required properties (diffusion coefficient or molecular weight) are missing
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual std::vector<std::string> CustomParameters() const override#
Returns labels for the surface rate constant parameters: aerosol effective radius [m] aerosol number concentration [# m-3].
- Returns:
Rate constant labels
-
inline virtual std::size_t SizeCustomParameters() const override#
Returns the number of custom parameters.
- Returns:
Number of custom parameters
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline SurfaceRateConstant(const SurfaceRateConstantParameters ¶meters)#
-
struct SurfaceRateConstantParameters#
Public Members
-
std::string label_#
Label for the reaction used to identify user-defined parameters.
-
PhaseSpecies phase_species_#
Gas-phase species reacting on surface.
-
double reaction_probability_ = {1.0}#
Reaction probability (0-1) [unitless].
-
std::string label_#
-
class System#
- #include <micm/system/system.hpp>
Represents the complete chemical state of a grid cell Includes the gas phase and other associated phases, each with their own set of species.
Public Functions
-
System() = default#
Default constructor.
-
template<typename ...ExternalModels>
inline System(const Phase &gas_phase, ExternalModels&&... external_models)# Constructor with external models.
-
inline System(const SystemParameters ¶meters)#
Constructor from SystemParameters.
-
inline size_t StateSize() const#
Returns the number of doubles required to store the system state.
-
inline std::vector<std::string> UniqueNames() const#
Returns a set of unique species names.
- Returns:
vector of unique state variable names
-
inline std::vector<std::string> UniqueNames(const std::function<std::string(const std::vector<std::string> &variables, const std::size_t i)> f) const#
Returns a set of unique species names.
- Parameters:
f – Function used to apply specific order to unique names
- Returns:
vector of unique state variable names
Public Members
-
std::vector<ExternalModel> external_models_#
External models (e.g., aerosol models) that provide additional components to the system.
-
System() = default#
-
struct SystemParameters#
Public Members
-
std::vector<ExternalModel> external_models_ = {}#
External models (e.g., aerosol models) that provide additional components to the system.
-
std::vector<ExternalModel> external_models_ = {}#
-
class TaylorSeriesRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/taylor_series_rate_constant.hpp>
An taylor series rate constant dependent on temperature and pressure.
Public Functions
-
inline TaylorSeriesRateConstant()#
Default constructor.
-
inline TaylorSeriesRateConstant(const TaylorSeriesRateConstantParameters ¶meters)#
An explicit constructor where each term can be set. Set B and E to zero to get the common form of the TaylorSeries equation.
- Parameters:
parameters – A set of arrhenius rate constants
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline TaylorSeriesRateConstant()#
-
struct TaylorSeriesRateConstantParameters#
Public Members
-
double A_ = {1}#
Pre-exponential factor [(mol m−3)^(−(𝑛−1)) s−1].
-
double B_ = {0}#
Unitless exponential factor.
-
double C_ = {0}#
Activation threshold, expected to be the negative activation energy divided by the boltzman constant [-E_a / k_b), K].
-
double D_ = {300}#
A factor that determines temperature dependence [K].
-
double E_ = {0}#
A factor that determines pressure dependence [Pa-1].
-
std::vector<double> coefficients_ = {1.0}#
Taylor coefficients for the series expansion.
-
double A_ = {1}#
-
class TemporaryVariables#
- #include <micm/solver/temporary_variables.hpp>
This is the base class for temporary variables; currently it is empty and will be expanded by a specific solver later.
Subclassed by micm::BackwardEulerTemporaryVariables< DenseMatrixPolicy >, micm::RosenbrockTemporaryVariables< DenseMatrixPolicy >
-
class TernaryChemicalActivationRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/ternary_chemical_activation_rate_constant.hpp>
A TernaryChemicalActivation rate constant.
Public Functions
-
inline TernaryChemicalActivationRateConstant()#
Default constructor.
-
inline TernaryChemicalActivationRateConstant(const TernaryChemicalActivationRateConstantParameters ¶meters)#
An explicit constructor.
- Parameters:
parameters – A set of troe rate constants
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline double Calculate(const double &temperature, const double &air_number_density) const#
Calculate the rate constant.
- Parameters:
temperature – Temperature in [K]
air_number_density – Number density in [mol m-3]
- Returns:
-
inline TernaryChemicalActivationRateConstant()#
-
struct TernaryChemicalActivationRateConstantParameters#
Public Members
-
double k0_A_ = 1.0#
low-pressure pre-exponential factor
-
double k0_B_ = 0.0#
low-pressure temperature-scaling parameter
-
double k0_C_ = 0.0#
low-pressure exponential factor
-
double kinf_A_ = 1.0#
high-pressure pre-exponential factor
-
double kinf_B_ = 0.0#
high-pressure temperature-scaling parameter
-
double kinf_C_ = 0.0#
high-pressure exponential factor
-
double Fc_ = 0.6#
TernaryChemicalActivation F_c parameter.
-
double N_ = 1.0#
TernaryChemicalActivation N parameter.
-
double k0_A_ = 1.0#
-
class TransferCoefficient#
Subclassed by micm::HenrysLawConstant
Public Functions
-
inline virtual double Calculate(const Conditions &conditions) const#
Calculate the rate constant for a set of conditions.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
The reaction rate constant
-
inline virtual double Calculate(const Conditions &conditions) const#
-
class TroeRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/troe_rate_constant.hpp>
A Troe rate constant.
Public Functions
-
inline TroeRateConstant()#
Default constructor.
-
inline TroeRateConstant(const TroeRateConstantParameters ¶meters)#
An explicit constructor.
- Parameters:
parameters – A set of troe rate constants
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline double Calculate(const double &temperature, const double &air_number_density) const#
Calculate the rate constant.
- Parameters:
temperature – Temperature in [K]
air_number_density – Number density in [mol m-3]
- Returns:
-
inline TroeRateConstant()#
-
struct TroeRateConstantParameters#
Public Members
-
double k0_A_ = 1.0#
low-pressure pre-exponential factor
-
double k0_B_ = 0.0#
low-pressure temperature-scaling parameter
-
double k0_C_ = 0.0#
low-pressure exponential factor
-
double kinf_A_ = 1.0#
high-pressure pre-exponential factor
-
double kinf_B_ = 0.0#
high-pressure temperature-scaling parameter
-
double kinf_C_ = 0.0#
high-pressure exponential factor
-
double Fc_ = 0.6#
Troe F_c parameter.
-
double N_ = 1.0#
Troe N parameter.
-
double k0_A_ = 1.0#
-
class TunnelingRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/tunneling_rate_constant.hpp>
Rate constant for tunneling reactions.
Public Functions
-
inline TunnelingRateConstant()#
Default constructor.
-
inline TunnelingRateConstant(const TunnelingRateConstantParameters ¶meters)#
An explicit constructor.
- Parameters:
parameters – A set of troe rate constants
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline double Calculate(const double &temperature) const#
Calculate the rate constant.
- Parameters:
temperature – Temperature in [K]
- Returns:
the calculated rate constant
-
inline TunnelingRateConstant()#
-
struct TunnelingRateConstantParameters#
-
class UserDefinedRateConstant : public micm::RateConstant#
- #include <micm/process/rate_constant/user_defined_rate_constant.hpp>
A photolysis rate constant.
Public Functions
-
inline UserDefinedRateConstant()#
Default constructor.
-
inline UserDefinedRateConstant(const UserDefinedRateConstantParameters ¶meters)#
- Parameters:
parameters – The data needed to build this class
-
inline virtual std::unique_ptr<RateConstant> Clone() const override#
Deep copy.
-
inline virtual std::vector<std::string> CustomParameters() const override#
Returns a label for the user-defined rate constant parameter.
- Returns:
Rate constant label
-
inline virtual std::size_t SizeCustomParameters() const override#
Returns the number of custom parameters.
- Returns:
Number of custom parameters
-
inline virtual double Calculate(const Conditions &conditions, std::vector<double>::const_iterator custom_parameters) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
custom_parameters – User-defined rate constant parameters
- Returns:
A rate constant based off of the conditions in the system
-
inline virtual double Calculate(const Conditions &conditions) const override#
Calculate the rate constant.
- Parameters:
conditions – The current environmental conditions of the chemical system
- Returns:
A rate constant based off of the conditions in the system
-
inline UserDefinedRateConstant()#
-
struct UserDefinedRateConstantParameters#
-
template<class T, std::size_t L = MICM_DEFAULT_VECTOR_SIZE>
class VectorMatrix# - #include <micm/util/vector_matrix.hpp>
A 2D array class with contiguous memory structured to encourage vectorization.
The memory layout groups rows into groups whose size can be set such that for a single column, the group of rows can fit in the vector register.
The template arguments are the type of the matrix elements and the size of the number of rows per group.
Subclassed by micm::CudaDenseMatrix< double, MICM_DEFAULT_VECTOR_SIZE >
Public Functions
-
inline std::size_t RowStride() const#
Get the number of elements in the underlying vector between adjacent rows for the same column.
- Returns:
The number of elements in the underlying vector between adjacent rows for the same column
-
inline std::size_t ColumnStride() const#
Get the number of elements in the underlying vector between adjacent columns for the same row.
- Returns:
The number of elements in the underlying vector between adjacent columns for the same row
-
inline void Fill(T val)#
Set every matrix element to a given value.
- Parameters:
val – Value to set each element to
-
inline void Axpy(const double &alpha, const VectorMatrix &x)#
For each element in the VectorMatrix x and y, perform y = alpha * x + y, where alpha is a scalar constant.
- Parameters:
alpha – The scaling scalar to apply to the VectorMatrix x
x – The input VectorMatrix
-
inline void Max(const T &x)#
For each element of the VectorMatrix, perform y = max(y, x), where x is a scalar constant.
- Parameters:
x – The scalar constant to compare against
-
inline void Min(const T &x)#
For each element of the VectorMatrix, perform y = min(y, x), where x is a scalar constant.
- Parameters:
x – The scalar constant to compare against
-
inline std::size_t RowStride() const#
-
namespace constants#
Variables
-
static double BOLTZMANN_CONSTANT = 1.380649e-23#
-
static double AVOGADRO_CONSTANT = 6.02214076e23#
-
static double GAS_CONSTANT = BOLTZMANN_CONSTANT * AVOGADRO_CONSTANT#
-
static double BOLTZMANN_CONSTANT = 1.380649e-23#
-
namespace property_keys#
-
using DenseMatrixVector = VectorMatrix<double, MICM_DEFAULT_VECTOR_SIZE>#