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 "GeochemistryQuantityAux.h" 11 : 12 : registerMooseObject("GeochemistryApp", GeochemistryQuantityAux); 13 : 14 : InputParameters 15 199282 : GeochemistryQuantityAux::validParams() 16 : { 17 199282 : InputParameters params = AuxKernel::validParams(); 18 199282 : params.addClassDescription( 19 : "Extracts information from the Reactor and records it in the AuxVariable"); 20 398564 : params.addRequiredParam<std::string>("species", "Species name"); 21 : MooseEnum quantity_choice("molal mg_per_kg free_mg free_cm3 neglog10a activity bulk_moles " 22 : "surface_charge surface_potential temperature kinetic_moles " 23 : "kinetic_additions moles_dumped transported_moles_in_original_basis", 24 398564 : "molal"); 25 398564 : params.addParam<MooseEnum>( 26 : "quantity", 27 : quantity_choice, 28 : "Type of quantity to output. These are available for non-kinetic species: activity (which " 29 : "equals " 30 : "fugacity for gases); bulk moles (this will be zero if the species is not in the basis); " 31 : "neglog10a = -log10(activity); transported_moles_in_original_basis (will throw an error if " 32 : "species is not in original basis). These are available only for non-kinetic non-minerals: " 33 : "molal = " 34 : "mol(species)/kg(solvent_water); mg_per_kg = mg(species)/kg(solvent_water). These are " 35 : "available only for minerals: " 36 : "free_mg = free mg; free_cm3 = free cubic-centimeters; moles_dumped = moles dumped when " 37 : "special dump and flow-through modes are active. These are available for minerals " 38 : "that host sorbing sites: surface_charge (C/m^2); surface_potential (V). These are " 39 : "available for kinetic species: kinetic_moles; kinetic_additions (-dt * rate = mole " 40 : "increment in kinetic species for this timestep). If " 41 : "quantity=temperature, then the 'species' is ignored and the AuxVariable will record the " 42 : "aqueous solution temperature in degC"); 43 398564 : params.addRequiredParam<UserObjectName>("reactor", 44 : "The name of the Geochemistry*Reactor user object."); 45 398564 : params.declareControllable("species"); 46 199282 : return params; 47 199282 : } 48 : 49 114866 : GeochemistryQuantityAux::GeochemistryQuantityAux(const InputParameters & parameters) 50 : : AuxKernel(parameters), 51 114866 : _species(getParam<std::string>("species")), 52 114866 : _reactor(getUserObject<GeochemistryReactorBase>("reactor")), 53 229732 : _quantity_choice(getParam<MooseEnum>("quantity").getEnum<QuantityChoiceEnum>()), 54 114866 : _surface_sorption_mineral_index(0) 55 : { 56 : const ModelGeochemicalDatabase & mgd = 57 114866 : _reactor.getPertinentGeochemicalSystem().modelGeochemicalDatabase(); 58 114866 : if (!(mgd.basis_species_index.count(_species) == 1 || 59 91582 : mgd.eqm_species_index.count(_species) == 1 || mgd.kin_species_index.count(_species) == 1)) 60 2 : paramError( 61 : "species", 62 2 : _species, 63 : " does not appear in the model's geochemical system either as a basis or equilibrium " 64 : "or kinetic species, but you requested an Aux involving it"); 65 : 66 : bool is_mineral = false; 67 114864 : if (mgd.basis_species_index.count(_species) == 1) 68 24150 : is_mineral = mgd.basis_species_mineral[mgd.basis_species_index.at(_species)]; 69 90714 : else if (mgd.eqm_species_index.count(_species) == 1) 70 89850 : is_mineral = mgd.eqm_species_mineral[mgd.eqm_species_index.at(_species)]; 71 : else 72 864 : is_mineral = mgd.kin_species_mineral[mgd.kin_species_index.at(_species)]; 73 114864 : bool is_kinetic = (mgd.kin_species_index.count(_species) == 1); 74 : 75 114864 : if (!is_mineral && (_quantity_choice == QuantityChoiceEnum::FREE_CM3 || 76 107362 : _quantity_choice == QuantityChoiceEnum::FREE_MG || 77 107356 : _quantity_choice == QuantityChoiceEnum::SURFACE_CHARGE || 78 107354 : _quantity_choice == QuantityChoiceEnum::SURFACE_POTENTIAL || 79 : _quantity_choice == QuantityChoiceEnum::MOLES_DUMPED)) 80 10 : paramError( 81 : "quantity", 82 : "the free_mg, free_cm3, moles_dumped and surface-related quantities are only available for " 83 : "mineral species"); 84 114854 : if ((is_mineral || is_kinetic) && (_quantity_choice == QuantityChoiceEnum::MOLAL || 85 : _quantity_choice == QuantityChoiceEnum::MG_PER_KG)) 86 8 : paramError("quantity", 87 : "the molal and mg_per_kg quantities are only available for " 88 : "non-kinetic, non-mineral species"); 89 114846 : if (_quantity_choice == QuantityChoiceEnum::SURFACE_CHARGE || 90 : _quantity_choice == QuantityChoiceEnum::SURFACE_POTENTIAL) 91 : { 92 260 : _surface_sorption_mineral_index = std::distance( 93 : mgd.surface_sorption_name.begin(), 94 260 : std::find(mgd.surface_sorption_name.begin(), mgd.surface_sorption_name.end(), _species)); 95 260 : if (_surface_sorption_mineral_index >= mgd.surface_sorption_name.size()) 96 4 : paramError("species", 97 : "cannot record surface charge or surface potential for a species that is not " 98 : "involved in surface sorption"); 99 : } 100 114842 : if (!is_kinetic && (_quantity_choice == QuantityChoiceEnum::KINETIC_MOLES || 101 : _quantity_choice == QuantityChoiceEnum::KINETIC_ADDITIONS)) 102 4 : paramError("quantity", 103 : "the kinetic_moles and kinetic_additions quantities are only available for kinetic " 104 : "species"); 105 860 : if (is_kinetic && (_quantity_choice == QuantityChoiceEnum::NEGLOG10A || 106 860 : _quantity_choice == QuantityChoiceEnum::ACTIVITY || 107 : _quantity_choice == QuantityChoiceEnum::BULK_MOLES)) 108 6 : paramError("species", "cannot record activity, neglog10a or bulk_moles for a kinetic species"); 109 114832 : if (_quantity_choice == QuantityChoiceEnum::TRANSPORTED_MOLES_IN_ORIGINAL_BASIS) 110 36 : _reactor.getPertinentGeochemicalSystem().getIndexOfOriginalBasisSpecies( 111 : _species); // will throw error if species not in original basis 112 114832 : } 113 : 114 : Real 115 771722 : GeochemistryQuantityAux::computeValue() 116 : { 117 : Real ret = 0.0; 118 771722 : const GeochemicalSystem & egs = _reactor.getGeochemicalSystem(_current_node->id()); 119 771722 : const ModelGeochemicalDatabase & mgd = egs.getModelGeochemicalDatabase(); 120 771722 : const PertinentGeochemicalSystem & pgs = _reactor.getPertinentGeochemicalSystem(); 121 771722 : if (_quantity_choice == QuantityChoiceEnum::SURFACE_CHARGE) 122 490 : ret = egs.getSurfaceCharge(_surface_sorption_mineral_index); 123 771232 : else if (_quantity_choice == QuantityChoiceEnum::SURFACE_POTENTIAL) 124 490 : ret = egs.getSurfacePotential(_surface_sorption_mineral_index); 125 770742 : else if (_quantity_choice == QuantityChoiceEnum::TEMPERATURE) 126 6986 : ret = egs.getTemperature(); 127 763756 : else if (_quantity_choice == QuantityChoiceEnum::MOLES_DUMPED) 128 528 : ret = _reactor.getMolesDumped(_current_node->id(), _species); 129 763228 : else if (_quantity_choice == QuantityChoiceEnum::TRANSPORTED_MOLES_IN_ORIGINAL_BASIS) 130 192 : ret = egs.getTransportedBulkInOriginalBasis()(pgs.getIndexOfOriginalBasisSpecies(_species)); 131 : else 132 : { 133 763036 : if (mgd.basis_species_index.count(_species) == 1) 134 : { 135 176856 : const unsigned basis_ind = mgd.basis_species_index.at(_species); 136 176856 : switch (_quantity_choice) 137 : { 138 30036 : case QuantityChoiceEnum::MG_PER_KG: 139 30036 : ret = egs.getSolventMassAndFreeMolalityAndMineralMoles()[basis_ind] * 140 : mgd.basis_species_molecular_weight[basis_ind] * 1000.0; 141 30036 : break; 142 7916 : case QuantityChoiceEnum::FREE_MG: 143 7916 : ret = egs.getSolventMassAndFreeMolalityAndMineralMoles()[basis_ind] * 144 : mgd.basis_species_molecular_weight[basis_ind] * 1000.0; 145 7916 : break; 146 7916 : case QuantityChoiceEnum::FREE_CM3: 147 7916 : ret = egs.getSolventMassAndFreeMolalityAndMineralMoles()[basis_ind] * 148 : mgd.basis_species_molecular_volume[basis_ind]; 149 7916 : break; 150 4186 : case QuantityChoiceEnum::NEGLOG10A: 151 4186 : ret = -std::log10(egs.getBasisActivity(basis_ind)); 152 4186 : break; 153 44902 : case QuantityChoiceEnum::ACTIVITY: 154 44902 : ret = egs.getBasisActivity(basis_ind); 155 44902 : break; 156 44902 : case QuantityChoiceEnum::BULK_MOLES: 157 44902 : ret = egs.getBulkMolesOld()[basis_ind]; 158 44902 : break; 159 36998 : default: 160 36998 : ret = egs.getSolventMassAndFreeMolalityAndMineralMoles()[basis_ind]; 161 : } 162 : } 163 586180 : else if (mgd.eqm_species_index.count(_species) == 1) 164 : { 165 577800 : const unsigned eqm_ind = mgd.eqm_species_index.at(_species); 166 577800 : switch (_quantity_choice) 167 : { 168 137834 : case QuantityChoiceEnum::MG_PER_KG: 169 137834 : ret = egs.getEquilibriumMolality(eqm_ind) * mgd.eqm_species_molecular_weight[eqm_ind] * 170 : 1000.0; 171 137834 : break; 172 6170 : case QuantityChoiceEnum::FREE_CM3: 173 6170 : ret = egs.getEquilibriumMolality(eqm_ind) * mgd.eqm_species_molecular_volume[eqm_ind]; 174 6170 : break; 175 6170 : case QuantityChoiceEnum::FREE_MG: 176 6170 : ret = egs.getEquilibriumMolality(eqm_ind) * mgd.eqm_species_molecular_weight[eqm_ind] * 177 : 1000.0; 178 6170 : break; 179 1784 : case QuantityChoiceEnum::NEGLOG10A: 180 1784 : ret = -std::log10(egs.getEquilibriumActivity(eqm_ind)); 181 1784 : break; 182 144004 : case QuantityChoiceEnum::ACTIVITY: 183 144004 : ret = egs.getEquilibriumActivity(eqm_ind); 184 144004 : break; 185 : case QuantityChoiceEnum::BULK_MOLES: 186 : ret = 0.0; 187 : break; 188 137834 : default: 189 137834 : ret = egs.getEquilibriumMolality(eqm_ind); 190 : } 191 : } 192 : else 193 : { 194 8380 : const unsigned kin_ind = mgd.kin_species_index.at(_species); 195 8380 : switch (_quantity_choice) 196 : { 197 1978 : case QuantityChoiceEnum::FREE_CM3: 198 1978 : ret = egs.getKineticMoles(kin_ind) * mgd.kin_species_molecular_volume[kin_ind]; 199 1978 : break; 200 1990 : case QuantityChoiceEnum::FREE_MG: 201 1990 : ret = egs.getKineticMoles(kin_ind) * mgd.kin_species_molecular_weight[kin_ind] * 1000.0; 202 1990 : break; 203 2110 : case QuantityChoiceEnum::KINETIC_ADDITIONS: 204 2110 : ret = _reactor.getMoleAdditions(_current_node->id())(kin_ind + egs.getNumInBasis()); 205 2110 : break; 206 2302 : default: 207 2302 : ret = egs.getKineticMoles(kin_ind); 208 : } 209 : } 210 : } 211 771722 : return ret; 212 : }