116 const std::vector<std::string> & swap_out_of_basis,
117 const std::vector<std::string> & swap_into_basis,
118 const std::string & charge_balance_species,
119 const std::vector<std::string> & constrained_species,
120 const std::vector<Real> & constraint_value,
123 Real initial_temperature,
124 unsigned iters_to_make_consistent,
125 Real min_initial_molality,
126 const std::vector<std::string> & kin_name,
127 const std::vector<Real> & kin_initial_moles,
135 const std::vector<std::string> & swap_out_of_basis,
136 const std::vector<std::string> & swap_into_basis,
137 const std::string & charge_balance_species,
138 const std::vector<std::string> & constrained_species,
139 const std::vector<Real> & constraint_value,
140 const std::vector<GeochemistryUnitConverter::GeochemistryUnit> & constraint_unit,
141 const std::vector<ConstraintUserMeaningEnum> & constraint_user_meaning,
142 Real initial_temperature,
143 unsigned iters_to_make_consistent,
144 Real min_initial_molality,
145 const std::vector<std::string> & kin_name,
146 const std::vector<Real> & kin_initial,
147 const std::vector<GeochemistryUnitConverter::GeochemistryUnit> & kin_unit);
166 mooseError(
"GeochemicalSystem: copy assigment operator called with inconsistent fundamental "
513 Real
getResidualComponent(
unsigned algebraic_ind,
const DenseVector<Real> & mole_additions)
const;
535 DenseMatrix<Real> & jac,
536 const DenseVector<Real> & mole_additions,
537 const DenseMatrix<Real> & dmole_additions)
const;
577 void performSwap(
unsigned swap_out_of_basis,
unsigned swap_into_basis);
672 const std::vector<std::string> & names,
673 const std::vector<Real> & values,
674 const std::vector<bool> & constraints_from_molalities);
834 addKineticRates(Real dt, DenseVector<Real> & mole_additions, DenseMatrix<Real> & dmole_additions);
956 unsigned & num_basis_in_algebraic_system,
957 unsigned & num_in_algebraic_system,
958 std::vector<unsigned> & algebraic_index,
959 std::vector<unsigned> & basis_index)
const;
971 std::vector<Real> & basis_molality)
const;
979 std::vector<Real> & basis_activity)
const;
1011 std::vector<Real> & bulk_moles_old)
const;
1018 void computeBulk(std::vector<Real> & bulk_moles_old)
const;
1026 std::vector<Real> & bulk_moles_old)
const;
1045 const std::vector<Real> & kin_initial,
1046 const std::vector<GeochemistryUnitConverter::GeochemistryUnit> & kin_unit);
const ModelGeochemicalDatabase mgd
void mooseError(Args &&... args)
This class holds information about bulk composition, molalities, activities, activity coefficients,...
Real log10KineticActivityProduct(unsigned kin) const
Real computeBulkFromMolalities(unsigned basis_ind) const
std::vector< Real > getSaturationIndices() const
GeochemicalSystem & operator=(const GeochemicalSystem &src)
Copy assignment operator.
Real getResidualComponent(unsigned algebraic_ind, const DenseVector< Real > &mole_additions) const
Return the residual of the algebraic system for the given algebraic index.
std::string _original_redox_lhs
The left-hand-side of the redox equations in _mgd after initial swaps.
std::vector< Real > getAlgebraicBasisValues() const
Real getEquilibriumActivity(unsigned eqm_ind) const
Returns the value of activity for the equilibrium species with index eqm_index.
std::vector< Real > _eqm_activity_coef
equilibrium activity coefficients
const std::vector< unsigned > & getAlgebraicIndexOfBasisSystem() const
const std::vector< GeochemicalSystem::ConstraintMeaningEnum > & getConstraintMeaning() const
std::vector< Real > _bulk_moles_old
Number of bulk moles of basis species (this includes contributions from kinetic species,...
void enforceChargeBalance()
Enforces charge balance by altering the constraint_value and bulk_moles_old of the charge-balance spe...
std::vector< Real > _sorbing_surface_area
surface areas of the sorbing minerals
Real _temperature
The temperature in degC.
void setAlgebraicVariables(const DenseVector< Real > &algebraic_var)
Set the variables in the algebraic system (molalities and potentially the mass of solvent water,...
Real surfacePotPrefactor(unsigned sp) const
const std::vector< std::string > _swap_out
Species to immediately remove from the basis in favor of _swap_in.
unsigned getNumBasisInAlgebraicSystem() const
return the number of basis species in the algebraic system
std::vector< unsigned > _algebraic_index
_algebraic_index[i] = index in the algebraic system of the basis species i. _basis_index[_algebraic_i...
unsigned getNumKinetic() const
returns the number of kinetic species
std::vector< Real > _constraint_value
Numerical values of the constraints on _constraint_species. In the constructor, this is ordered to ha...
DenseVector< Real > getAlgebraicVariableDenseValues() const
Real getLog10K(unsigned j) const
void addKineticRates(Real dt, DenseVector< Real > &mole_additions, DenseMatrix< Real > &dmole_additions)
Computes the kinetic rates and their derivatives based on the current values of molality,...
const GeochemistrySpeciesSwapper & getSwapper() const
GeochemicalSystem(const GeochemicalSystem &src)=default
Copy constructor.
bool operator==(const GeochemicalSystem &rhs) const
const unsigned _num_kin
number of kinetic species
const unsigned _num_surface_pot
number of surface potentials
void computeEqmMolalities(std::vector< Real > &eqm_molality) const
compute the equilibrium molalities (not for minerals or gases)
void setChargeBalanceSpecies(unsigned new_charge_balance_index)
Set the charge-balance species to the basis index provided.
std::vector< bool > _in_algebraic_system
if _in_algebraic_system[i] == true then we need to solve for the i^th basis-species molality
unsigned _iters_to_make_consistent
Iterations to make the initial configuration consistent.
unsigned _num_basis_in_algebraic_system
number of unknown molalities in the algebraic system. Note: surface potentials (if any) are extra qua...
bool revertToOriginalChargeBalanceSpecies()
Changes the charge-balance species to the original that is specified in the constructor (this might n...
GeochemistryActivityCoefficients & _gac
Object to compute the activity coefficients and activity of water.
Real log10ActivityProduct(unsigned eqm_j) const
const std::vector< Real > & getSorbingSurfaceArea() const
const std::string & getOriginalRedoxLHS() const
void setMineralRelatedFreeMoles(Real value)
Set the free mole number of mineral-related species to the value provided.
void initBulkAndFree(std::vector< Real > &bulk_moles_old, std::vector< Real > &basis_molality) const
based on _constrained_value and _constraint_meaning, populate nw, bulk_moles_old and basis_molality w...
std::vector< ConstraintMeaningEnum > _constraint_meaning
The meaning of the values in _constraint_value. In the constructor, this is ordered to have the same ...
void updateOldWithCurrent(const DenseVector< Real > &mole_additions)
Usually used at the end of a solve, to provide correct initial conditions to the next time-step,...
Real log10RedoxActivityProduct(unsigned red) const
Real getRedoxLog10K(unsigned red) const
const unsigned _num_redox
number of redox species
void setKineticMoles(unsigned kin, Real moles)
Sets the current AND old mole number for a kinetic species.
void computeSorbingSurfaceArea(std::vector< Real > &sorbing_surface_area) const
Compute sorbing_surface_area depending on the current molality of the sorbing minerals.
void alterSystemBecauseBulkChanged()
Alter the GeochemicalSystem to reflect changes in bulk composition constraints that occur through,...
void computeConsistentConfiguration()
Compute a reasonably consistent configuration that can be used as an initial condition in a Newton pr...
std::vector< std::string > _constrained_species
Names of the species in that have their values fixed to _constraint_value with meanings _constraint_m...
const std::vector< Real > & getEquilibriumMolality() const
const std::vector< Real > & getBasisActivityCoefficient() const
const std::vector< Real > & computeAndGetEquilibriumActivity()
Computes activity for all equilibrium species (_eqm_activity) and returns a reference to the vector.
std::vector< Real > _eqm_log10K
equilibrium constant of the equilibrium species
Real _min_initial_molality
Minimum molality ever used in an initial guess.
const unsigned _num_eqm
number of equilibrium species
unsigned _num_in_algebraic_system
number of unknowns in the algebraic system (includes molalities and surface potentials)
void changeConstraintToBulk(unsigned basis_ind)
Changes the constraint to MOLES_BULK_SPECIES (or MOLES_BULK_WATER if basis_ind = 0) for the basis ind...
std::vector< Real > _original_constraint_value
Numerical values of the constraints on _constraint_species. In the constructor, this is ordered to ha...
Real getSurfacePotential(unsigned sp) const
std::vector< Real > _surface_pot_expr
surface potential expressions.
void performSwap(unsigned swap_out_of_basis, unsigned swap_into_basis)
Perform the basis swap, and ensure that the resulting system is consistent.
unsigned getNumSurfacePotentials() const
return the number of surface potentials
unsigned getNumInBasis() const
returns the number of species in the basis
void computeTransportedBulkFromMolalities(std::vector< Real > &transported_bulk) const
Computes the value of transported bulk moles for all basis species using the existing molalities.
void buildTemperatureDependentQuantities(Real temperature)
Using the provided value of temperature, build _eqm_log10K for each eqm species and redox species.
std::vector< ConstraintUserMeaningEnum > _constraint_user_meaning
The user-defined meaning of the values in _constraint_value. In the constructor, this is ordered to h...
void checkAndInitialize(const std::vector< std::string > &kin_name, const std::vector< Real > &kin_initial, const std::vector< GeochemistryUnitConverter::GeochemistryUnit > &kin_unit)
Used during construction: checks for sane inputs and initializes molalities, etc, using the initializ...
unsigned getNumInEquilibrium() const
returns the number of species in equilibrium with the basis components
const std::vector< bool > & getBasisActivityKnown() const
unsigned getChargeBalanceBasisIndex() const
return the index of the charge-balance species in the basis list
Real getTotalChargeOld() const
std::vector< GeochemistryUnitConverter::GeochemistryUnit > _constraint_unit
Units of the _constraint_value when the GeochemicalSystem is constructed. This is used during the con...
void computeRemainingBasisActivities(std::vector< Real > &basis_activity) const
Compute the activity of water and put in basis_activity[0], and use the _basis_activity_coef and _bas...
void setSolventMassAndFreeMolalityAndMineralMolesAndSurfacePotsAndKineticMoles(const std::vector< std::string > &names, const std::vector< Real > &values, const std::vector< bool > &constraints_from_molalities)
Sets:
const std::string _original_charge_balance_species
The species used to enforce charge balance, as provided in the constructor.
GeochemistryIonicStrength & _is
Object that provides the ionic strengths.
const std::vector< bool > & getInAlgebraicSystem() const
DenseVector< Real > getTransportedBulkInOriginalBasis() const
const std::vector< Real > & getEquilibriumActivityCoefficient() const
Real getSolventWaterMass() const
Returns the mass of solvent water.
void enforceChargeBalanceIfSimple(std::vector< Real > &constraint_value, std::vector< Real > &bulk_moles_old) const
If all non-charged basis species are provided with a bulk number of moles, alter the bulk number of m...
GeochemistrySpeciesSwapper & _swapper
swapper that can swap species into and out of the basis
const std::vector< Real > & getKineticLog10K() const
unsigned getNumRedox() const
const std::vector< unsigned > & getBasisIndexOfAlgebraicSystem() const
std::vector< Real > _eqm_molality
molality of equilibrium species
Real getStoichiometricIonicStrength() const
Get the stoichiometric ionic strength.
void addToBulkMoles(unsigned basis_ind, Real value)
Add to the MOLES_BULK_SPECIES (or MOLES_BULK_WATER if basis_ind = 0) for the basis species.
void setConstraintValue(unsigned basis_ind, Real value)
Set the constraint value for the basis species.
ConstraintUserMeaningEnum
Each basis species must be provided with a constraint, that is chosen by the user from the following ...
@ BULK_COMPOSITION_WITH_KINETIC
const std::vector< Real > & getBulkMolesOld() const
bool alterChargeBalanceSpecies(Real threshold_molality)
If the molality of the charge-balance basis species is less than threshold molality,...
std::vector< Real > _basis_molality
IMPORTANT: this is.
const ModelGeochemicalDatabase & getModelGeochemicalDatabase() const
const std::vector< std::string > _swap_in
Species to immediately add to the basis in favor of _swap_out.
std::vector< bool > _basis_activity_known
whether basis_activity[i] is fixed by the user
Real getIonicStrength() const
Get the ionic strength.
std::string _charge_balance_species
The species used to enforce charge balance.
const std::vector< Real > & getSolventMassAndFreeMolalityAndMineralMoles() const
void updateBasisMolalityForKnownActivity(std::vector< Real > &basis_molality) const
For basis aqueous species (not water, minerals or gases) with activity set by the user,...
unsigned getNumInAlgebraicSystem() const
std::vector< unsigned > _basis_index
_basis_index[i] = index in the basis of the algebraic system species i, for i<num_basis_in_algebraic_...
void performSwapNoCheck(unsigned swap_out_of_basis, unsigned swap_into_basis)
Perform the basis swap, and ensure that the resulting system is consistent.
void initialize()
initialize all variables, ready for a Newton solve of the algebraic system
std::vector< Real > _redox_log10K
equilibrium constant of the redox species
std::vector< Real > getAlgebraicVariableValues() const
std::vector< Real > _kin_log10K
equilibrium constant of the kinetic species
DenseVector< Real > getBulkOldInOriginalBasis() const
Real getSurfaceCharge(unsigned sp) const
void computeJacobian(const DenseVector< Real > &res, DenseMatrix< Real > &jac, const DenseVector< Real > &mole_additions, const DenseMatrix< Real > &dmole_additions) const
Compute the Jacobian for the algebraic system and put it in jac.
std::vector< Real > _eqm_activity
equilibrium activities.
const unsigned _num_basis
number of basis species
unsigned _charge_balance_basis_index
The index in the list of basis species corresponding to the charge-balance species....
const std::vector< Real > & getKineticMoles() const
const std::vector< Real > & getBasisActivity() const
std::vector< Real > _basis_activity_coef
basis activity coefficients
void computeFreeMineralMoles(std::vector< Real > &basis_molality) const
Compute the free mineral moles (ie, basis_molality for basis species that are minerals),...
std::vector< Real > _kin_moles
mole number of kinetic species
void computeBulk(std::vector< Real > &bulk_moles_old) const
Computes the value of bulk_moles_old for all basis species.
ModelGeochemicalDatabase & _mgd
The minimal geochemical database.
ConstraintMeaningEnum
Each basis species has one of the following constraints.
@ FREE_MOLES_MINERAL_SPECIES
void buildAlgebraicInfo(std::vector< bool > &in_algebraic_system, unsigned &num_basis_in_algebraic_system, unsigned &num_in_algebraic_system, std::vector< unsigned > &algebraic_index, std::vector< unsigned > &basis_index) const
Builds in_algebraic_system, algebraic_index and basis_index, and sets num_basis_in_algebraic_system a...
void closeSystem()
Changes a KG_SOLVENT_WATER constraint to MOLES_BULK_WATER (if there is such a constraint) and all FRE...
Real surfaceSorptionModifier(unsigned eqm_j) const
void buildKnownBasisActivities(std::vector< bool > &basis_activity_known, std::vector< Real > &basis_activity) const
Fully populates basis_activity_known, which is true if activity has been set by the user,...
std::vector< Real > _kin_moles_old
old mole number of kinetic species
void setTemperature(Real temperature)
Sets the temperature to the given quantity.
void setModelGeochemicalDatabase(const ModelGeochemicalDatabase &mgd)
Copies a ModelGeochemicalDatabase into our _mgd structure.
Real getTemperature() const
std::vector< Real > _basis_activity
values of activity (for water, minerals and aqueous basis species) or fugacity (for gases)
Base class to compute activity coefficients for non-minerals and non-gases (since these species do no...
Calculators to compute ionic strength and stoichiometric ionic strength.
Class to swap basis species with equilibrium species.
Data structure to hold all relevant information from the database file.