LCOV - code coverage report
Current view: top level - src/utils - EquilibriumConstantFit.C (source / functions) Hit Total Coverage
Test: idaholab/moose chemical_reactions: #31405 (292dce) with base fef103 Lines: 21 23 91.3 %
Date: 2025-09-04 07:52:33 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 "EquilibriumConstantFit.h"
      11             : #include "MooseError.h"
      12             : 
      13          24 : EquilibriumConstantFit::EquilibriumConstantFit(const std::vector<Real> & temperature,
      14          24 :                                                const std::vector<Real> & logk)
      15          24 :   : LeastSquaresFitBase(temperature, logk)
      16             : {
      17          24 :   _num_coeff = 5;
      18             : 
      19             :   // The number of temperature points and logk points must be equal
      20          24 :   if (temperature.size() != logk.size())
      21           0 :     mooseError(
      22             :         "The temperature and logk data sets must be equal in length in EquilibriumConstantFit");
      23             : 
      24             :   // At least five data points must be supplied for this functional fit
      25          24 :   if (temperature.size() < 5)
      26           0 :     mooseError("At least five data points are required in EquilibriumConstantFit");
      27          24 : }
      28             : 
      29             : void
      30          23 : EquilibriumConstantFit::fillMatrix()
      31             : {
      32          23 :   unsigned int num_rows = _x.size();
      33          23 :   unsigned int num_cols = _num_coeff;
      34          23 :   _matrix.resize(num_rows * num_cols);
      35             : 
      36         207 :   for (unsigned int row = 0; row < num_rows; ++row)
      37             :   {
      38         184 :     _matrix[row] = std::log(_x[row]);
      39         184 :     _matrix[num_rows + row] = 1.0;
      40         184 :     _matrix[(2 * num_rows) + row] = _x[row];
      41         184 :     _matrix[(3 * num_rows) + row] = 1.0 / _x[row];
      42         184 :     _matrix[(4 * num_rows) + row] = 1.0 / _x[row] / _x[row];
      43             :   }
      44          23 : }
      45             : 
      46             : Real
      47        2249 : EquilibriumConstantFit::sample(Real T)
      48             : {
      49             :   Real logK =
      50        2249 :       _coeffs[0] * std::log(T) + _coeffs[1] + _coeffs[2] * T + _coeffs[3] / T + _coeffs[4] / T / T;
      51             : 
      52        2249 :   return logK;
      53             : }

Generated by: LCOV version 1.14