LCOV - code coverage report
Current view: top level - src/utils - GeochemistryUnitConverter.C (source / functions) Hit Total Coverage
Test: idaholab/moose geochemistry: 602416 Lines: 37 37 100.0 %
Date: 2025-07-18 11:37:48 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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        8193 : 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        7873 :     factor = conversionFactor(unit,
      25             :                               mgd.basis_species_index.at(species_name),
      26             :                               species_name,
      27        7873 :                               mgd.basis_species_molecular_weight,
      28        7873 :                               mgd.basis_species_molecular_volume,
      29        7873 :                               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         301 :     factor = conversionFactor(unit,
      39             :                               mgd.kin_species_index.at(species_name),
      40             :                               species_name,
      41         301 :                               mgd.kin_species_molecular_weight,
      42         301 :                               mgd.kin_species_molecular_volume,
      43         301 :                               mgd.kin_species_mineral);
      44             :   else
      45           1 :     mooseError("GeochemistryUnitConverter: ",
      46             :                species_name,
      47             :                " is not a basis, equilibrium or kinetic species");
      48        8187 :   return moles * factor;
      49             : }
      50             : 
      51             : Real
      52        8174 : toMoles(Real quantity,
      53             :         const GeochemistryUnit unit,
      54             :         const std::string & species_name,
      55             :         const ModelGeochemicalDatabase & mgd)
      56             : {
      57        8174 :   return quantity / fromMoles(1.0, unit, species_name, mgd);
      58             : }
      59             : 
      60             : Real
      61        8192 : 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        8192 :   switch (unit)
      70             :   {
      71             :     case GeochemistryUnit::DIMENSIONLESS:
      72             :     case GeochemistryUnit::MOLES:
      73             :     case GeochemistryUnit::MOLAL:
      74             :       factor = 1.0;
      75             :       break;
      76         289 :     case GeochemistryUnit::KG:
      77             :     case GeochemistryUnit::KG_PER_KG_SOLVENT:
      78         289 :       factor = 1E-3 * mol_weight[ind];
      79         289 :       break;
      80          30 :     case GeochemistryUnit::G:
      81             :     case GeochemistryUnit::G_PER_KG_SOLVENT:
      82          30 :       factor = mol_weight[ind];
      83          30 :       break;
      84         270 :     case GeochemistryUnit::MG:
      85             :     case GeochemistryUnit::MG_PER_KG_SOLVENT:
      86         270 :       factor = 1.0E3 * mol_weight[ind];
      87         270 :       break;
      88          22 :     case GeochemistryUnit::UG:
      89             :     case GeochemistryUnit::UG_PER_KG_SOLVENT:
      90          22 :       factor = 1.0E6 * mol_weight[ind];
      91          22 :       break;
      92          79 :     case GeochemistryUnit::CM3:
      93          79 :       if (!is_mineral[ind])
      94           5 :         mooseError("GeochemistryUnitConverter: Cannot use CM3 units for species ",
      95             :                    name,
      96             :                    " because it is not a mineral");
      97          74 :       factor = mol_volume[ind];
      98          74 :       break;
      99             :   }
     100        8187 :   return factor;
     101             : }
     102             : } // namespace GeochemistryUnitConverter

Generated by: LCOV version 1.14