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 " 536 const DenseVector<Real> & mole_additions,
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);
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);
void initialize()
initialize all variables, ready for a Newton solve of the algebraic system
void computeConsistentConfiguration()
Compute a reasonably consistent configuration that can be used as an initial condition in a Newton pr...
std::vector< Real > getAlgebraicBasisValues() const
Real getTemperature() const
const unsigned _num_kin
number of kinetic species
ConstraintUserMeaningEnum
Each basis species must be provided with a constraint, that is chosen by the user from the following ...
DenseVector< Real > getBulkOldInOriginalBasis() const
std::vector< bool > _basis_activity_known
whether basis_activity[i] is fixed by the user
Real surfaceSorptionModifier(unsigned eqm_j) const
const std::vector< Real > & getKineticMoles() const
Real getIonicStrength() const
Get the ionic strength.
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...
const std::vector< Real > & getBasisActivity() const
const std::vector< std::string > _swap_in
Species to immediately add to the basis in favor of _swap_out.
void changeConstraintToBulk(unsigned basis_ind)
Changes the constraint to MOLES_BULK_SPECIES (or MOLES_BULK_WATER if basis_ind = 0) for the basis ind...
const unsigned _num_basis
number of basis species
std::vector< Real > _basis_molality
IMPORTANT: this is.
std::vector< Real > _kin_log10K
equilibrium constant of the kinetic species
const std::vector< Real > & getBulkMolesOld() const
std::string _original_redox_lhs
The left-hand-side of the redox equations in _mgd after initial swaps.
std::vector< unsigned > _algebraic_index
_algebraic_index[i] = index in the algebraic system of the basis species i. _basis_index[_algebraic_i...
void setChargeBalanceSpecies(unsigned new_charge_balance_index)
Set the charge-balance species to the basis index provided.
GeochemistryActivityCoefficients & _gac
Object to compute the activity coefficients and activity of water.
void mooseError(Args &&... args)
Real _min_initial_molality
Minimum molality ever used in an initial guess.
std::vector< Real > _basis_activity_coef
basis activity coefficients
std::vector< Real > _eqm_activity
equilibrium activities.
Real log10ActivityProduct(unsigned eqm_j) const
bool operator==(const GeochemicalSystem &rhs) const
const ModelGeochemicalDatabase mgd
void alterSystemBecauseBulkChanged()
Alter the GeochemicalSystem to reflect changes in bulk composition constraints that occur through...
void computeTransportedBulkFromMolalities(std::vector< Real > &transported_bulk) const
Computes the value of transported bulk moles for all basis species using the existing molalities...
std::vector< Real > _kin_moles_old
old mole number of kinetic 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...
Real _temperature
The temperature in degC.
const unsigned _num_redox
number of redox species
std::vector< bool > _in_algebraic_system
if _in_algebraic_system[i] == true then we need to solve for the i^th basis-species molality ...
Real surfacePotPrefactor(unsigned sp) const
Real log10KineticActivityProduct(unsigned kin) const
void computeBulk(std::vector< Real > &bulk_moles_old) const
Computes the value of bulk_moles_old for all basis species.
unsigned getChargeBalanceBasisIndex() const
return the index of the charge-balance species in the basis list
std::vector< Real > _basis_activity
values of activity (for water, minerals and aqueous basis species) or fugacity (for gases) ...
static const std::string temperature
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...
void buildTemperatureDependentQuantities(Real temperature)
Using the provided value of temperature, build _eqm_log10K for each eqm species and redox species...
GeochemicalSystem & operator=(const GeochemicalSystem &src)
Copy assignment operator.
unsigned getNumKinetic() const
returns the number of kinetic species
unsigned _charge_balance_basis_index
The index in the list of basis species corresponding to the charge-balance species. This gets altered as the simulation progresses, due to swaps, and alterChargeBalanceSpecies.
void computeSorbingSurfaceArea(std::vector< Real > &sorbing_surface_area) const
Compute sorbing_surface_area depending on the current molality of the sorbing minerals.
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 > & computeAndGetEquilibriumActivity()
Computes activity for all equilibrium species (_eqm_activity) and returns a reference to the vector...
std::vector< Real > _redox_log10K
equilibrium constant of the redox species
unsigned getNumInBasis() const
returns the number of species in the basis
const std::vector< Real > & getKineticLog10K() const
std::vector< Real > _sorbing_surface_area
surface areas of the sorbing minerals
GeochemistryIonicStrength & _is
Object that provides the ionic strengths.
std::vector< Real > _constraint_value
Numerical values of the constraints on _constraint_species. In the constructor, this is ordered to ha...
void computeFreeMineralMoles(std::vector< Real > &basis_molality) const
Compute the free mineral moles (ie, basis_molality for basis species that are minerals), using the bulk_moles_old.
unsigned _iters_to_make_consistent
Iterations to make the initial configuration consistent.
ConstraintMeaningEnum
Each basis species has one of the following constraints.
std::vector< Real > _bulk_moles_old
Number of bulk moles of basis species (this includes contributions from kinetic species, in contrast to Bethke)
Real getTotalChargeOld() const
void setKineticMoles(unsigned kin, Real moles)
Sets the current AND old mole number for a kinetic species.
Class to swap basis species with equilibrium species.
std::vector< Real > _kin_moles
mole number of kinetic species
const std::vector< Real > & getEquilibriumActivityCoefficient() const
GeochemistrySpeciesSwapper & _swapper
swapper that can swap species into and out of the basis
Real getEquilibriumActivity(unsigned eqm_ind) const
Returns the value of activity for the equilibrium species with index eqm_index.
std::string _charge_balance_species
The species used to enforce charge balance.
Real getStoichiometricIonicStrength() const
Get the stoichiometric ionic strength.
unsigned getNumInAlgebraicSystem() const
std::vector< Real > _original_constraint_value
Numerical values of the constraints on _constraint_species. In the constructor, this is ordered to ha...
std::vector< Real > _surface_pot_expr
surface potential expressions.
const std::string _original_charge_balance_species
The species used to enforce charge balance, as provided in the constructor.
const std::vector< Real > & getSorbingSurfaceArea() const
const std::vector< Real > & getBasisActivityCoefficient() const
Calculators to compute ionic strength and stoichiometric ionic strength.
Base class to compute activity coefficients for non-minerals and non-gases (since these species do no...
const ModelGeochemicalDatabase & getModelGeochemicalDatabase() 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, mole number, etc, and then, using dt, calculates the appropriate mole_additions and dmole_additions.
std::vector< GeochemistryUnitConverter::GeochemistryUnit > _constraint_unit
Units of the _constraint_value when the GeochemicalSystem is constructed. This is used during the con...
Real computeBulkFromMolalities(unsigned basis_ind) const
std::vector< ConstraintMeaningEnum > _constraint_meaning
The meaning of the values in _constraint_value. In the constructor, this is ordered to have the same ...
void enforceChargeBalance()
Enforces charge balance by altering the constraint_value and bulk_moles_old of the charge-balance spe...
const std::vector< unsigned > & getAlgebraicIndexOfBasisSystem() const
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...
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...
Real getRedoxLog10K(unsigned red) const
bool revertToOriginalChargeBalanceSpecies()
Changes the charge-balance species to the original that is specified in the constructor (this might n...
std::vector< unsigned > _basis_index
_basis_index[i] = index in the basis of the algebraic system species i, for i<num_basis_in_algebraic_...
bool alterChargeBalanceSpecies(Real threshold_molality)
If the molality of the charge-balance basis species is less than threshold molality, then attempt to change the charge-balance species, preferably to another component with opposite charge and big molality.
void setModelGeochemicalDatabase(const ModelGeochemicalDatabase &mgd)
Copies a ModelGeochemicalDatabase into our _mgd structure.
unsigned getNumRedox() const
void computeEqmMolalities(std::vector< Real > &eqm_molality) const
compute the equilibrium molalities (not for minerals or gases)
unsigned _num_in_algebraic_system
number of unknowns in the algebraic system (includes molalities and surface potentials) ...
Real getLog10K(unsigned j) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const unsigned _num_surface_pot
number of surface potentials
Real getSurfacePotential(unsigned sp) const
std::vector< Real > getAlgebraicVariableValues() const
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...
void updateBasisMolalityForKnownActivity(std::vector< Real > &basis_molality) const
For basis aqueous species (not water, minerals or gases) with activity set by the user...
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...
unsigned getNumSurfacePotentials() const
return the number of surface potentials
void setTemperature(Real temperature)
Sets the temperature to the given quantity.
const unsigned _num_eqm
number of equilibrium species
std::vector< Real > _eqm_molality
molality of equilibrium species
This class holds information about bulk composition, molalities, activities, activity coefficients...
Real getResidualComponent(unsigned algebraic_ind, const DenseVector< Real > &mole_additions) const
Return the residual of the algebraic system for the given algebraic index.
Real log10RedoxActivityProduct(unsigned red) const
std::vector< Real > _eqm_log10K
equilibrium constant of the equilibrium species
ModelGeochemicalDatabase & _mgd
The minimal geochemical database.
void setSolventMassAndFreeMolalityAndMineralMolesAndSurfacePotsAndKineticMoles(const std::vector< std::string > &names, const std::vector< Real > &values, const std::vector< bool > &constraints_from_molalities)
Sets:
void setAlgebraicVariables(const DenseVector< Real > &algebraic_var)
Set the variables in the algebraic system (molalities and potentially the mass of solvent water...
Data structure to hold all relevant information from the database file.
std::vector< Real > _eqm_activity_coef
equilibrium activity coefficients
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
void performSwapNoCheck(unsigned swap_out_of_basis, unsigned swap_into_basis)
Perform the basis swap, and ensure that the resulting system is consistent.
const std::vector< Real > & getSolventMassAndFreeMolalityAndMineralMoles() const
Real getSolventWaterMass() const
Returns the mass of solvent water.
DenseVector< Real > getTransportedBulkInOriginalBasis() 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.
const std::vector< bool > & getInAlgebraicSystem() const
const GeochemistrySpeciesSwapper & getSwapper() const
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...
const std::vector< bool > & getBasisActivityKnown() const
DenseVector< Real > getAlgebraicVariableDenseValues() const
void performSwap(unsigned swap_out_of_basis, unsigned swap_into_basis)
Perform the basis swap, and ensure that the resulting system is consistent.
void setConstraintValue(unsigned basis_ind, Real value)
Set the constraint value for the basis species.
unsigned getNumInEquilibrium() const
returns the number of species in equilibrium with the basis components
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
void closeSystem()
Changes a KG_SOLVENT_WATER constraint to MOLES_BULK_WATER (if there is such a constraint) and all FRE...
const std::vector< unsigned > & getBasisIndexOfAlgebraicSystem() const
void setMineralRelatedFreeMoles(Real value)
Set the free mole number of mineral-related species to the value provided.
const std::vector< Real > & getEquilibriumMolality() const
Real getSurfaceCharge(unsigned sp) const
const std::vector< GeochemicalSystem::ConstraintMeaningEnum > & getConstraintMeaning() const
const std::string & getOriginalRedoxLHS() const
GeochemicalSystem(ModelGeochemicalDatabase &mgd, GeochemistryActivityCoefficients &gac, GeochemistryIonicStrength &is, GeochemistrySpeciesSwapper &swapper, const std::vector< std::string > &swap_out_of_basis, const std::vector< std::string > &swap_into_basis, const std::string &charge_balance_species, const std::vector< std::string > &constrained_species, const std::vector< Real > &constraint_value, const MultiMooseEnum &constraint_unit, const MultiMooseEnum &constraint_user_meaning, Real initial_temperature, unsigned iters_to_make_consistent, Real min_initial_molality, const std::vector< std::string > &kin_name, const std::vector< Real > &kin_initial_moles, const MultiMooseEnum &kin_unit)
Construct the geochemical system, check consistency of the constructor's arguments, and initialize all internal variables (molalities, bulk compositions, equilibrium constants, activities, activity coefficients, surface potentials and kinetic mole numbers) and set up the algebraic system
unsigned _num_basis_in_algebraic_system
number of unknown molalities in the algebraic system. Note: surface potentials (if any) are extra qua...
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...
std::vector< Real > getSaturationIndices() const