Class to swap basis species with equilibrium species. More...
#include <GeochemistrySpeciesSwapper.h>
Public Member Functions | |
GeochemistrySpeciesSwapper (unsigned basis_size, Real stoi_tol) | |
bool | operator== (const GeochemistrySpeciesSwapper &rhs) const |
void | checkSwap (const ModelGeochemicalDatabase &mgd, const std::string &replace_this, const std::string &with_this) |
Check that replacing the named basis species with the named equilibrium species is valid. More... | |
void | checkSwap (const ModelGeochemicalDatabase &mgd, unsigned basis_index_to_replace, unsigned eqm_index_to_insert) |
Check that replacing the indexed basis species with the indexed equilibrium species is valid. More... | |
void | performSwap (ModelGeochemicalDatabase &mgd, const std::string &replace_this, const std::string &with_this) |
Check that replacing the named basis species with the named equilibrium species is valid, and then perform this swap by altering the mgd data structure. More... | |
void | performSwap (ModelGeochemicalDatabase &mgd, unsigned basis_index_to_replace, unsigned eqm_index_to_insert) |
Check that replacing the indexed basis species with the indexed equilibrium species is valid, and then perform this swap by altering the mgd data structure. More... | |
void | performSwap (ModelGeochemicalDatabase &mgd, DenseVector< Real > &bulk_composition, const std::string &replace_this, const std::string &with_this) |
Check that replacing the named basis species with the named equilibrium species is valid, and then perform this swap by altering the mgd data structure, and calculate the bulk composition of the new system. More... | |
void | performSwap (ModelGeochemicalDatabase &mgd, DenseVector< Real > &bulk_composition, unsigned basis_index_to_replace, unsigned eqm_index_to_insert) |
Check that replacing the indexed basis species with the indexed equilibrium species is valid, and then perform this swap by altering the mgd data structure, and calculate the bulk composition of the new system. More... | |
bool | findBestEqmSwap (unsigned basis_ind, const ModelGeochemicalDatabase &mgd, const std::vector< Real > &eqm_molality, bool minerals_allowed, bool gas_allowed, bool sorption_allowed, unsigned &best_eqm_species) const |
For the the given basis index, find the equilibrium index that it should be swapped with. More... | |
Private Member Functions | |
void | constructInverseMatrix (const ModelGeochemicalDatabase &mgd, unsigned basis_index_to_replace, unsigned eqm_index_to_insert) |
Construct the swap matrix, and its inverse, that describes the swap between the indexed basis species and the indexed equilibrium index. More... | |
void | alterMGD (ModelGeochemicalDatabase &mgd, unsigned basis_index_to_replace, unsigned eqm_index_to_insert) |
Modify the ModelGeochemicalDatabase mgd to swap the indexed basis species and the indexed equilibrium index. More... | |
void | alterBulkComposition (unsigned basis_size, DenseVector< Real > &bulk_composition) const |
Calculate the bulk composition in the new basis based on the bulk composition in the original basis. More... | |
Private Attributes | |
Real | _stoi_tol |
tolerance for matrix inversion and stoichiometric coefficients More... | |
DenseMatrix< Real > | _swap_matrix |
swap matrix More... | |
DenseMatrix< Real > | _true_swap_matrix |
Before _swap_matrix.svd (a non-const method) is called, we copy _true_swap_matrix = _swap_matrix. More... | |
DenseMatrix< Real > | _inv_swap_matrix |
inverse of swap matrix More... | |
DenseVector< Real > | _swap_sigma |
used in SVD decomposition of swap matrix More... | |
DenseMatrix< Real > | _swap_U |
used in SVD decomposition of swap matrix More... | |
DenseMatrix< Real > | _swap_VT |
used in SVD decomposition of swap matrix More... | |
Class to swap basis species with equilibrium species.
Definition at line 19 of file GeochemistrySpeciesSwapper.h.
GeochemistrySpeciesSwapper::GeochemistrySpeciesSwapper | ( | unsigned | basis_size, |
Real | stoi_tol | ||
) |
basis_size | Number of basis species in the geochemical model |
stoi_tol | Swapping involves inverting matrices via a singular value decomposition. During this process: (1) if abs(singular value) < stoi_tol * L1norm(singular values), then the matrix is deemed singular (so the basis swap is deemed invalid); (2) if abs(any stoichiometric coefficient) < stoi_tol then it is set to zero. A suggested reasonable value is stoi_tol=1E-6 |
Definition at line 12 of file GeochemistrySpeciesSwapper.C.
|
private |
Calculate the bulk composition in the new basis based on the bulk composition in the original basis.
basis_size | Size of basis, which is only used for error checking |
[in/out] | bulk_composition Upon entry, the bulk composition in the original basis. Upon exit, the bulk composition in the basis after the swap |
Definition at line 355 of file GeochemistrySpeciesSwapper.C.
Referenced by performSwap().
|
private |
Modify the ModelGeochemicalDatabase mgd to swap the indexed basis species and the indexed equilibrium index.
mgd | The ModelGeochemicalDatabase that holds all information regarding basis components, equilibrium species, stoichiometries, etc |
basis_index_to_replace | The index of the basis component that will be removed from the basis and added to the equilibrium species list |
eqm_index_to_insert | The index of the equilibrium species that will be removed from the equilibrium species list and added to the basis component list |
Definition at line 162 of file GeochemistrySpeciesSwapper.C.
Referenced by performSwap().
void GeochemistrySpeciesSwapper::checkSwap | ( | const ModelGeochemicalDatabase & | mgd, |
const std::string & | replace_this, | ||
const std::string & | with_this | ||
) |
Check that replacing the named basis species with the named equilibrium species is valid.
In performing this check, the "swap" matrix is inverted, so the check is somewhat expensive. Therefore, if the swap will be performed, assuming it's valid, the performSwap method should be used instead. A mooseError or mooseException will result if the swap is invalid
mgd | The ModelGeochemicalDatabase that holds all information regarding basis components, equilibrium species, stoichiometries, etc |
replace_this | The basis component that will be removed from the basis and added to the equilibrium species list |
with_this | The equilibrium species that will be removed from the equilibrium species list and added to the basis component list |
Definition at line 24 of file GeochemistrySpeciesSwapper.C.
Referenced by performSwap(), and TEST().
void GeochemistrySpeciesSwapper::checkSwap | ( | const ModelGeochemicalDatabase & | mgd, |
unsigned | basis_index_to_replace, | ||
unsigned | eqm_index_to_insert | ||
) |
Check that replacing the indexed basis species with the indexed equilibrium species is valid.
In performing this check, the "swap" matrix is inverted, so the check is somewhat expensive. Therefore, if the swap will be performed, assuming it's valid, the performSwap method should be used instead. A mooseError or mooseException will result if the swap is invalid
mgd | The ModelGeochemicalDatabase that holds all information regarding basis components, equilibrium species, stoichiometries, etc |
basis_index_to_replace | The index of the basis component that will be removed from the basis and added to the equilibrium species list |
eqm_index_to_insert | The index of the equilibrium species that will be removed from the equilibrium species list and added to the basis component list |
Definition at line 40 of file GeochemistrySpeciesSwapper.C.
|
private |
Construct the swap matrix, and its inverse, that describes the swap between the indexed basis species and the indexed equilibrium index.
The inverse of the swap matrix is used in alterMGD to modify its datastructures to implement the swap. A mooseError or mooseException will result if the swap is invalid
mgd | The ModelGeochemicalDatabase that holds all information regarding basis components, equilibrium species, stoichiometries, etc |
basis_index_to_replace | The index of the basis component that will be removed from the basis and added to the equilibrium species list |
eqm_index_to_insert | The index of the equilibrium species that will be removed from the equilibrium species list and added to the basis component list |
Definition at line 65 of file GeochemistrySpeciesSwapper.C.
Referenced by checkSwap().
bool GeochemistrySpeciesSwapper::findBestEqmSwap | ( | unsigned | basis_ind, |
const ModelGeochemicalDatabase & | mgd, | ||
const std::vector< Real > & | eqm_molality, | ||
bool | minerals_allowed, | ||
bool | gas_allowed, | ||
bool | sorption_allowed, | ||
unsigned & | best_eqm_species | ||
) | const |
For the the given basis index, find the equilibrium index that it should be swapped with.
basis_ind | index of basis species in mgd that we'd like to swap out of the basis | |
mgd | the model's geochemical databgase | |
eqm_molality | the molality of all the equilibrium species | |
minerals_allowed | if false, best_eqm_species will not correspond to a mineral. Since equilibrium minerals have molality=0 it is very unlikely that best_eqm_species will correspond to a mineral, even if this flag is true. | |
gases_allowed | if false, best_eqm_species will not correspond to a gas. Since equilibrium gases have molality=0 it is very unlikely that best_eqm_species will correspond to a gas, even if this flag is true. | |
sorption_allowed | if false, best_eqm_species will not be involved in sorption | |
[out] | best_eqm_species | the index of the equilibrium species that should be swapped with basis_ind |
Definition at line 368 of file GeochemistrySpeciesSwapper.C.
Referenced by GeochemistryTimeDependentReactor::preSolveDump(), GeochemicalSolver::swapNeeded(), and TEST().
|
inline |
Definition at line 31 of file GeochemistrySpeciesSwapper.h.
void GeochemistrySpeciesSwapper::performSwap | ( | ModelGeochemicalDatabase & | mgd, |
const std::string & | replace_this, | ||
const std::string & | with_this | ||
) |
Check that replacing the named basis species with the named equilibrium species is valid, and then perform this swap by altering the mgd data structure.
A mooseError or mooseException will result if the swap is invalid
mgd | The ModelGeochemicalDatabase that holds all information regarding basis components, equilibrium species, stoichiometries, etc |
replace_this | The basis component that will be removed from the basis and added to the equilibrium species list |
with_this | The equilibrium species that will be removed from the equilibrium species list and added to the basis component list |
Definition at line 114 of file GeochemistrySpeciesSwapper.C.
Referenced by GeochemicalSystem::checkAndInitialize(), GeochemicalModelInterrogator::output(), performSwap(), GeochemicalSystem::performSwapNoCheck(), and TEST().
void GeochemistrySpeciesSwapper::performSwap | ( | ModelGeochemicalDatabase & | mgd, |
unsigned | basis_index_to_replace, | ||
unsigned | eqm_index_to_insert | ||
) |
Check that replacing the indexed basis species with the indexed equilibrium species is valid, and then perform this swap by altering the mgd data structure.
A mooseError or mooseException will result if the swap is invalid
mgd | The ModelGeochemicalDatabase that holds all information regarding basis components, equilibrium species, stoichiometries, etc |
basis_index_to_replace | The index of the basis component that will be removed from the basis and added to the equilibrium species list |
eqm_index_to_insert | The index of the equilibrium species that will be removed from the equilibrium species list and added to the basis component list |
Definition at line 127 of file GeochemistrySpeciesSwapper.C.
void GeochemistrySpeciesSwapper::performSwap | ( | ModelGeochemicalDatabase & | mgd, |
DenseVector< Real > & | bulk_composition, | ||
const std::string & | replace_this, | ||
const std::string & | with_this | ||
) |
Check that replacing the named basis species with the named equilibrium species is valid, and then perform this swap by altering the mgd data structure, and calculate the bulk composition of the new system.
A mooseError or mooseException will result if the swap is invalid
mgd | The ModelGeochemicalDatabase that holds all information regarding basis components, equilibrium species, stoichiometries, etc |
[in/out] | bulk_composition Upon entry, the bulk composition in the original basis. Upon exit, the bulk composition in the basis after the swap |
replace_this | The basis component that will be removed from the basis and added to the equilibrium species list |
with_this | The equilibrium species that will be removed from the equilibrium species list and added to the basis component list |
Definition at line 140 of file GeochemistrySpeciesSwapper.C.
void GeochemistrySpeciesSwapper::performSwap | ( | ModelGeochemicalDatabase & | mgd, |
DenseVector< Real > & | bulk_composition, | ||
unsigned | basis_index_to_replace, | ||
unsigned | eqm_index_to_insert | ||
) |
Check that replacing the indexed basis species with the indexed equilibrium species is valid, and then perform this swap by altering the mgd data structure, and calculate the bulk composition of the new system.
A mooseError or mooseException will result if the swap is invalid
mgd | The ModelGeochemicalDatabase that holds all information regarding basis components, equilibrium species, stoichiometries, etc |
[in/out] | bulk_composition Upon entry, the bulk composition in the original basis. Upon exit, the bulk composition in the basis after the swap |
basis_index_to_replace | The index of the basis component that will be removed from the basis and added to the equilibrium species list |
eqm_index_to_insert | The index of the equilibrium species that will be removed from the equilibrium species list and added to the basis component list |
Definition at line 151 of file GeochemistrySpeciesSwapper.C.
|
private |
inverse of swap matrix
Definition at line 216 of file GeochemistrySpeciesSwapper.h.
Referenced by alterBulkComposition(), alterMGD(), and constructInverseMatrix().
|
private |
tolerance for matrix inversion and stoichiometric coefficients
Definition at line 203 of file GeochemistrySpeciesSwapper.h.
Referenced by alterMGD(), constructInverseMatrix(), and operator==().
|
private |
swap matrix
Definition at line 206 of file GeochemistrySpeciesSwapper.h.
Referenced by constructInverseMatrix(), and operator==().
|
private |
used in SVD decomposition of swap matrix
Definition at line 219 of file GeochemistrySpeciesSwapper.h.
Referenced by constructInverseMatrix().
|
private |
used in SVD decomposition of swap matrix
Definition at line 222 of file GeochemistrySpeciesSwapper.h.
Referenced by constructInverseMatrix().
|
private |
used in SVD decomposition of swap matrix
Definition at line 225 of file GeochemistrySpeciesSwapper.h.
Referenced by constructInverseMatrix().
|
private |
Before _swap_matrix.svd (a non-const method) is called, we copy _true_swap_matrix = _swap_matrix.
It is necessary to record _swap_matrix in this fashion so that mgd.swap_to_original_basis can be modified using it
Definition at line 213 of file GeochemistrySpeciesSwapper.h.
Referenced by alterMGD(), and constructInverseMatrix().