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 "GeochemistryUnitConverter.h" 11 : #include "GeochemistryConstants.h" 12 : 13 : namespace GeochemistryUnitConverter 14 : { 15 : 16 : Real 17 8751 : fromMoles(Real moles, 18 : const GeochemistryUnit unit, 19 : const std::string & species_name, 20 : const ModelGeochemicalDatabase & mgd) 21 : { 22 : Real factor = 0.0; // return moles * factor 23 : if (mgd.basis_species_index.count(species_name) != 0) 24 8419 : factor = conversionFactor(unit, 25 : mgd.basis_species_index.at(species_name), 26 : species_name, 27 8419 : mgd.basis_species_molecular_weight, 28 8419 : mgd.basis_species_molecular_volume, 29 8419 : mgd.basis_species_mineral); 30 : else if (mgd.eqm_species_index.count(species_name) != 0) 31 18 : factor = conversionFactor(unit, 32 : mgd.eqm_species_index.at(species_name), 33 : species_name, 34 18 : mgd.eqm_species_molecular_weight, 35 18 : mgd.eqm_species_molecular_volume, 36 18 : mgd.eqm_species_mineral); 37 : else if (mgd.kin_species_index.count(species_name) != 0) 38 313 : factor = conversionFactor(unit, 39 : mgd.kin_species_index.at(species_name), 40 : species_name, 41 313 : mgd.kin_species_molecular_weight, 42 313 : mgd.kin_species_molecular_volume, 43 313 : mgd.kin_species_mineral); 44 : else 45 1 : mooseError("GeochemistryUnitConverter: ", 46 : species_name, 47 : " is not a basis, equilibrium or kinetic species"); 48 8745 : return moles * factor; 49 : } 50 : 51 : Real 52 8732 : toMoles(Real quantity, 53 : const GeochemistryUnit unit, 54 : const std::string & species_name, 55 : const ModelGeochemicalDatabase & mgd) 56 : { 57 8732 : return quantity / fromMoles(1.0, unit, species_name, mgd); 58 : } 59 : 60 : Real 61 8750 : conversionFactor(const GeochemistryUnit unit, 62 : unsigned ind, 63 : const std::string & name, 64 : const std::vector<Real> & mol_weight, 65 : const std::vector<Real> & mol_volume, 66 : const std::vector<bool> & is_mineral) 67 : { 68 : Real factor = 1.0; 69 8750 : switch (unit) 70 : { 71 : case GeochemistryUnit::DIMENSIONLESS: 72 : case GeochemistryUnit::MOLES: 73 : case GeochemistryUnit::MOLAL: 74 : factor = 1.0; 75 : break; 76 302 : case GeochemistryUnit::KG: 77 : case GeochemistryUnit::KG_PER_KG_SOLVENT: 78 302 : factor = 1E-3 * mol_weight[ind]; 79 302 : break; 80 32 : case GeochemistryUnit::G: 81 : case GeochemistryUnit::G_PER_KG_SOLVENT: 82 32 : factor = mol_weight[ind]; 83 32 : break; 84 294 : case GeochemistryUnit::MG: 85 : case GeochemistryUnit::MG_PER_KG_SOLVENT: 86 294 : factor = 1.0E3 * mol_weight[ind]; 87 294 : break; 88 23 : case GeochemistryUnit::UG: 89 : case GeochemistryUnit::UG_PER_KG_SOLVENT: 90 23 : factor = 1.0E6 * mol_weight[ind]; 91 23 : break; 92 85 : case GeochemistryUnit::CM3: 93 85 : if (!is_mineral[ind]) 94 5 : mooseError("GeochemistryUnitConverter: Cannot use CM3 units for species ", 95 : name, 96 : " because it is not a mineral"); 97 80 : factor = mol_volume[ind]; 98 80 : break; 99 : } 100 8745 : return factor; 101 : } 102 : } // namespace GeochemistryUnitConverter