Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "GeochemistryIonicStrength.h" 11 : #include "libmesh/utility.h" 12 : 13 1220 : GeochemistryIonicStrength::GeochemistryIonicStrength(Real max_ionic_strength, 14 : Real max_stoichiometric_ionic_strength, 15 : bool use_only_basis_molality, 16 1220 : bool use_only_Cl_molality) 17 1220 : : _max_ionic_strength(max_ionic_strength), 18 1220 : _max_stoichiometric_ionic_strength(max_stoichiometric_ionic_strength), 19 1220 : _use_only_basis_molality(use_only_basis_molality), 20 1220 : _use_only_Cl_molality(use_only_Cl_molality) 21 : { 22 1220 : } 23 : 24 : Real 25 55806 : GeochemistryIonicStrength::ionicStrength(const ModelGeochemicalDatabase & mgd, 26 : const std::vector<Real> & basis_species_molality, 27 : const std::vector<Real> & eqm_species_molality, 28 : const std::vector<Real> & kin_species_molality) const 29 : { 30 55806 : const unsigned num_basis = mgd.basis_species_charge.size(); 31 55806 : const unsigned num_eqm = mgd.eqm_species_charge.size(); 32 55806 : const unsigned num_kin = mgd.kin_species_charge.size(); 33 55806 : if (num_basis != basis_species_molality.size()) 34 1 : mooseError("Ionic strength calculation: Number of basis species in mgd not equal to the size " 35 : "of basis_species_molality"); 36 55805 : if (num_eqm != eqm_species_molality.size()) 37 1 : mooseError("Ionic strength calculation: Number of equilibrium species in mgd not equal to the " 38 : "size of eqm_species_molality"); 39 55804 : if (num_kin != kin_species_molality.size()) 40 1 : mooseError("Ionic strength calculation: Number of kinetic species in mgd not equal to the size " 41 : "of kin_species_molality"); 42 : 43 : Real ionic_strength = 0.0; 44 434609 : for (unsigned i = 0; i < num_basis; ++i) 45 378806 : ionic_strength += Utility::pow<2>(mgd.basis_species_charge[i]) * basis_species_molality[i]; 46 55803 : if (!_use_only_basis_molality) 47 : { 48 1584702 : for (unsigned i = 0; i < num_eqm; ++i) 49 1528903 : if (!mgd.surface_sorption_related[i]) 50 1473311 : ionic_strength += Utility::pow<2>(mgd.eqm_species_charge[i]) * eqm_species_molality[i]; 51 63155 : for (unsigned i = 0; i < num_kin; ++i) 52 7356 : ionic_strength += Utility::pow<2>(mgd.kin_species_charge[i]) * kin_species_molality[i] / 53 : basis_species_molality[0]; // kin_species_molality is actually the number of 54 : // moles of the kinetic species 55 : } 56 : 57 104702 : return std::max(0.0, std::min(_max_ionic_strength, 0.5 * ionic_strength)); 58 : } 59 : 60 : Real 61 48783 : GeochemistryIonicStrength::stoichiometricIonicStrength( 62 : const ModelGeochemicalDatabase & mgd, 63 : const std::vector<Real> & basis_species_molality, 64 : const std::vector<Real> & eqm_species_molality, 65 : const std::vector<Real> & kin_species_molality) const 66 : { 67 48783 : const unsigned num_basis = mgd.basis_species_charge.size(); 68 48783 : const unsigned num_eqm = mgd.eqm_species_charge.size(); 69 48783 : const unsigned num_kin = mgd.kin_species_charge.size(); 70 48783 : if (num_basis != basis_species_molality.size()) 71 1 : mooseError("Stoichiometric ionic strength calculation: Number of basis species in mgd not " 72 : "equal to the size of basis_species_molality"); 73 48782 : if (num_eqm != eqm_species_molality.size()) 74 1 : mooseError("Stoichiometric ionic strength calculation: Number of equilibrium species in mgd " 75 : "not equal to the size of eqm_species_molality"); 76 48781 : if (num_kin != kin_species_molality.size()) 77 1 : mooseError("Stoichiometric ionic strength calculation: Number of kinetic species in mgd not " 78 : "equal to the size of kin_species_molality"); 79 : 80 48780 : Real ionic_strength = 0.0; 81 48780 : if (_use_only_Cl_molality) 82 : { 83 48700 : if (mgd.basis_species_index.count("Cl-")) 84 48694 : ionic_strength = basis_species_molality[mgd.basis_species_index.at("Cl-")]; 85 6 : else if (mgd.eqm_species_index.count("Cl-")) 86 2 : ionic_strength = eqm_species_molality[mgd.eqm_species_index.at("Cl-")]; 87 4 : else if (mgd.kin_species_index.count("Cl-")) 88 2 : ionic_strength = kin_species_molality[mgd.kin_species_index.at("Cl-")]; 89 : else 90 1 : mooseError("GeochemistryIonicStrength: attempting to compute stoichiometric ionic strength " 91 : "using only the Cl- molality, but Cl- does not appear in the geochemical system"); 92 71209 : return std::max(0.0, std::min(_max_stoichiometric_ionic_strength, ionic_strength)); 93 : } 94 : 95 109035 : for (unsigned i = 0; i < num_basis; ++i) 96 84605 : ionic_strength += Utility::pow<2>(mgd.basis_species_charge[i]) * basis_species_molality[i]; 97 24430 : if (!_use_only_basis_molality) 98 : { 99 122480 : for (unsigned i = 0; i < num_eqm; ++i) 100 98054 : if (!mgd.surface_sorption_related[i]) 101 : { 102 : 103 91974 : if (mgd.eqm_species_charge[i] != 0.0) 104 50184 : ionic_strength += Utility::pow<2>(mgd.eqm_species_charge[i]) * eqm_species_molality[i]; 105 : else 106 : { 107 336231 : for (unsigned j = 0; j < num_basis; ++j) 108 294441 : ionic_strength += Utility::pow<2>(mgd.basis_species_charge[j]) * 109 294441 : eqm_species_molality[i] * mgd.eqm_stoichiometry(i, j); 110 : } 111 : } 112 26240 : for (unsigned i = 0; i < num_kin; 113 : ++i) // kin_species_molality is actually the number of moles, not molality 114 1814 : if (mgd.kin_species_charge[i] != 0.0) 115 7 : ionic_strength += Utility::pow<2>(mgd.kin_species_charge[i]) * kin_species_molality[i] / 116 : basis_species_molality[0]; 117 : } 118 : 119 71531 : return std::max(0.0, std::min(_max_stoichiometric_ionic_strength, 0.5 * ionic_strength)); 120 : } 121 : 122 : void 123 45459 : GeochemistryIonicStrength::setMaxIonicStrength(Real max_ionic_strength) 124 : { 125 45459 : _max_ionic_strength = max_ionic_strength; 126 45459 : } 127 : 128 : Real 129 2 : GeochemistryIonicStrength::getMaxIonicStrength() const 130 : { 131 2 : return _max_ionic_strength; 132 : } 133 : 134 : void 135 45460 : GeochemistryIonicStrength::setMaxStoichiometricIonicStrength(Real max_stoichiometric_ionic_strength) 136 : { 137 45460 : _max_stoichiometric_ionic_strength = max_stoichiometric_ionic_strength; 138 45460 : } 139 : 140 : Real 141 2 : GeochemistryIonicStrength::getMaxStoichiometricIonicStrength() const 142 : { 143 2 : return _max_stoichiometric_ionic_strength; 144 : } 145 : 146 : void 147 3 : GeochemistryIonicStrength::setUseOnlyBasisMolality(bool use_only_basis_molality) 148 : { 149 3 : _use_only_basis_molality = use_only_basis_molality; 150 3 : } 151 : 152 : Real 153 7 : GeochemistryIonicStrength::getUseOnlyBasisMolality() const 154 : { 155 7 : return _use_only_basis_molality; 156 : } 157 : 158 : void 159 1 : GeochemistryIonicStrength::setUseOnlyClMolality(bool use_only_Cl_molality) 160 : { 161 1 : _use_only_Cl_molality = use_only_Cl_molality; 162 1 : } 163 : 164 : Real 165 7 : GeochemistryIonicStrength::getUseOnlyClMolality() const 166 : { 167 7 : return _use_only_Cl_molality; 168 : }