LCOV - code coverage report
Current view: top level - src/fluidproperties - SalineMoltenSaltFluidProperties.C (source / functions) Hit Total Coverage
Test: idaholab/moose fluid_properties: #31405 (292dce) with base fef103 Lines: 74 78 94.9 %
Date: 2025-09-04 07:53:14 Functions: 16 16 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 "SalineMoltenSaltFluidProperties.h"
      11             : 
      12             : registerMooseObject("FluidPropertiesApp", SalineMoltenSaltFluidProperties);
      13             : 
      14             : InputParameters
      15          47 : SalineMoltenSaltFluidProperties::validParams()
      16             : {
      17          47 :   InputParameters params = SinglePhaseFluidProperties::validParams();
      18          47 :   const std::string description = "Molten salt fluid properties using Saline";
      19             : #ifdef SALINE_ENABLED
      20          47 :   params.addClassDescription(description);
      21             : #else
      22             :   params.addClassDescription(
      23             :       "To use this object, you need to have the `Saline` library installed. Refer to the "
      24             :       "documentation for guidance on how to enable it. (Original description: " +
      25             :       description + ")");
      26             : #endif
      27          94 :   params.addRequiredParam<std::vector<std::string>>("comp_name",
      28             :                                                     "The name of the components in the salt");
      29          94 :   params.addRequiredParam<std::vector<Real>>("comp_val",
      30             :                                              "The mole fraction of each salt component");
      31          94 :   params.addRequiredParam<std::string>(
      32             :       "prop_def_file",
      33             :       "Definition of a fluid property file, which must be a file path to the "
      34             :       "comma-separated data matching the Saline format.");
      35          47 :   return params;
      36           0 : }
      37             : 
      38          25 : SalineMoltenSaltFluidProperties::SalineMoltenSaltFluidProperties(const InputParameters & parameters)
      39          25 :   : SinglePhaseFluidProperties(parameters), _fd_size(1e-6)
      40             : {
      41             : #ifdef SALINE_ENABLED
      42          25 :   const auto & propDef = getParam<std::string>("prop_def_file");
      43          25 :   _d.load(propDef);
      44          25 :   bool success = _tp.initialize(&_d);
      45          25 :   if (!success)
      46           0 :     mooseError("The initialization of the Saline interface has failed");
      47          25 :   const auto & name = getParam<std::vector<std::string>>("comp_name");
      48          50 :   const auto & comp = getParam<std::vector<Real>>("comp_val");
      49             : 
      50             :   // Verify mole fractions
      51             :   Real mole_sum = 0.0;
      52         100 :   for (const auto val : comp)
      53          75 :     mole_sum += val;
      54          25 :   if (!MooseUtils::absoluteFuzzyEqual(mole_sum, 1.))
      55           0 :     mooseError("Mole fractions of defined salt compound do not sum to 1.0.");
      56             : 
      57          25 :   success = _tp.setComposition(name, comp);
      58          25 :   if (!success)
      59           0 :     mooseError("The composition set has failed");
      60          25 :   _fluid_name = MooseUtils::join(name, "-");
      61             : #else
      62             :   mooseError("Saline was not made available during the build and cannot be used. Make sure you "
      63             :              "have the 'modules/fluid_properties/contrib/saline' submodule checked out.");
      64             : #endif
      65          25 : }
      66             : 
      67             : #ifdef SALINE_ENABLED
      68             : 
      69             : std::string
      70           1 : SalineMoltenSaltFluidProperties::fluidName() const
      71             : {
      72           1 :   return _fluid_name;
      73             : }
      74             : 
      75             : Real
      76          38 : SalineMoltenSaltFluidProperties::rho_from_p_T(Real pressure, Real temperature) const
      77             : {
      78          38 :   return _tp.rho_kgm3(temperature, pressure * Pa_to_kPa);
      79             : }
      80             : 
      81             : void
      82           1 : SalineMoltenSaltFluidProperties::rho_from_p_T(
      83             :     Real pressure, Real temperature, Real & rho, Real & drho_dp, Real & drho_dT) const
      84             : {
      85           1 :   rho = rho_from_p_T(pressure, temperature);
      86             :   // Estimate derivatives for now because they are not provided by Saline
      87           1 :   drho_dp = 0.;
      88           1 :   drho_dT = (rho_from_p_T(pressure, temperature + 1.0) - rho) / 1.0;
      89           1 : }
      90             : 
      91             : Real
      92          10 : SalineMoltenSaltFluidProperties::cp_from_p_T(Real pressure, Real temperature) const
      93             : {
      94          10 :   return _tp.cp_kg(temperature, pressure * Pa_to_kPa); // J/kg/K
      95             : }
      96             : 
      97             : void
      98           1 : SalineMoltenSaltFluidProperties::cp_from_p_T(
      99             :     Real pressure, Real temperature, Real & cp, Real & dcp_dp, Real & dcp_dT) const
     100             : {
     101           1 :   cp = cp_from_p_T(pressure, temperature);
     102           1 :   dcp_dp = 0;
     103           1 :   dcp_dT = (cp_from_p_T(pressure, temperature + 1.0) - cp) / 1.0;
     104           1 : }
     105             : 
     106             : Real
     107          13 : SalineMoltenSaltFluidProperties::h_from_p_T(Real /*pressure*/, Real temperature) const
     108             : {
     109          13 :   return _tp.h_t_kg(temperature);
     110             : }
     111             : 
     112             : void
     113           1 : SalineMoltenSaltFluidProperties::h_from_p_T(
     114             :     Real /*pressure*/, Real temperature, Real & enthalpy, Real & dh_dp, Real & dh_dT) const
     115             : {
     116           1 :   enthalpy = h_from_p_T(0.0, temperature);
     117           1 :   dh_dp = 0.0;
     118             :   // finite difference approximation
     119           1 :   dh_dT = (h_from_p_T(0.0, temperature * (1 + _fd_size)) - enthalpy) / (temperature * _fd_size);
     120           1 : }
     121             : 
     122             : Real
     123           9 : SalineMoltenSaltFluidProperties::e_from_p_T(Real pressure, Real temperature) const
     124             : {
     125           9 :   return _tp.h_t_kg(temperature) - pressure / rho_from_p_T(pressure, temperature);
     126             : }
     127             : 
     128             : void
     129           1 : SalineMoltenSaltFluidProperties::e_from_p_T(
     130             :     Real pressure, Real temperature, Real & e, Real & de_dp, Real & de_dT) const
     131             : {
     132           1 :   const Real rho = rho_from_p_T(pressure, temperature);
     133           1 :   e = _tp.h_t_kg(temperature) - pressure / rho;
     134           1 :   de_dp = -1 / rho;
     135             :   // finite difference approximation
     136           1 :   de_dT = (e_from_p_T(pressure, temperature * (1 + _fd_size)) - e) / (temperature * _fd_size);
     137           1 : }
     138             : 
     139             : Real
     140           3 : SalineMoltenSaltFluidProperties::T_from_p_h(Real /*pressure*/, Real enthalpy) const
     141             : {
     142           3 :   return _tp.t_h_kg(enthalpy);
     143             : }
     144             : 
     145             : Real
     146           8 : SalineMoltenSaltFluidProperties::mu_from_p_T(Real pressure, Real temperature) const
     147             : {
     148           8 :   return _tp.mu(temperature, pressure * Pa_to_kPa) * mN_to_N; // Ns/m^2
     149             : }
     150             : 
     151             : void
     152           1 : SalineMoltenSaltFluidProperties::mu_from_p_T(
     153             :     Real pressure, Real temperature, Real & mu, Real & dmu_dp, Real & dmu_dT) const
     154             : {
     155           1 :   mu = _tp.mu(temperature, pressure * Pa_to_kPa) * mN_to_N;
     156           1 :   Real mu_p1 = _tp.mu(temperature, pressure * (1 + _fd_size) * Pa_to_kPa) * mN_to_N; // Ns/m^2
     157           1 :   Real mu_T1 = _tp.mu(temperature * (1 + _fd_size), pressure * Pa_to_kPa) * mN_to_N; // Ns/m^2
     158           1 :   dmu_dp = (mu_p1 - mu) / (_fd_size * pressure * Pa_to_kPa);
     159           1 :   dmu_dT = (mu_T1 - mu) / (_fd_size * temperature);
     160           1 : }
     161             : 
     162             : Real
     163           8 : SalineMoltenSaltFluidProperties::k_from_p_T(Real pressure, Real temperature) const
     164             : {
     165           8 :   return _tp.k(temperature, pressure * Pa_to_kPa); // W/m/K
     166             : }
     167             : 
     168             : void
     169           1 : SalineMoltenSaltFluidProperties::k_from_p_T(
     170             :     Real pressure, Real temperature, Real & k, Real & dk_dp, Real & dk_dT) const
     171             : {
     172           1 :   k = _tp.k(temperature, pressure * Pa_to_kPa);
     173           1 :   Real k_p1 = _tp.k(temperature, pressure * (1 + _fd_size) * Pa_to_kPa);
     174           1 :   Real k_T1 = _tp.k(temperature * (1 + _fd_size), pressure * Pa_to_kPa);
     175           1 :   dk_dp = (k_p1 - k) / (_fd_size * pressure * Pa_to_kPa);
     176           1 :   dk_dT = (k_T1 - k) / (_fd_size * temperature);
     177           1 : }
     178             : 
     179             : #endif

Generated by: LCOV version 1.14