29#ifndef DUMUX_MATERIAL_COMPONENTS_SHOMATE_HH
30#define DUMUX_MATERIAL_COMPONENTS_SHOMATE_HH
38#include <dune/common/exceptions.hh>
48template<
class Scalar,
int intervals = -1>
51 static_assert(intervals == -1 || intervals > 0,
"Number of intervals must be -1 (dynamic) or greater than 0 (static).");
55 using Temperatures = std::conditional_t<intervals == -1, std::vector<Scalar>, std::array<Scalar, std::size_t(intervals+1)>>;
56 using Coefficients = std::conditional_t<intervals == -1, std::vector<CoefficientSet>, std::array<
CoefficientSet, std::size_t(intervals)>>;
64 : temperatures_(temperatures)
79 const Scalar standardEnthalpyDiff = p.A*t + p.B*t*t/2.0 + p.C*t*t*t/3.0 + p.D*t*t*t*t/4.0 - p.E/t + p.F - p.H;
80 return standardEnthalpyDiff;
92 const Scalar
heatCapacity = p.A + p.B*t + p.C*t*t + p.D*t*t*t + p.E/(t*t);
100 if (T < temperatures_.front() || T > temperatures_.back())
102 if (!warningPrinted_)
104 std::cout <<
"Temperature "<< T <<
" [K] is out of range. Enthalpy values are extrapolated." << std::endl;
105 warningPrinted_ =
true;
110 const auto index = std::min<std::size_t>(
113 temperatures_.begin(),
114 std::lower_bound(temperatures_.begin(), temperatures_.end(), T)
118 return coeffs_[index];
121 void checkInput_()
const
123 if constexpr (intervals == -1)
125 if (temperatures_.size() < 2)
126 DUNE_THROW(Dune::InvalidStateException,
"Temperature range must have at least two entries.");
128 for (
size_t i = 0; i < temperatures_.size()-1; i++)
129 if (temperatures_[i] >= temperatures_[i+1])
130 DUNE_THROW(Dune::InvalidStateException,
"Temperature range must be strictly increasing.");
132 if (temperatures_.size()-1 != coeffs_.size())
133 DUNE_THROW(Dune::InvalidStateException,
"If temperature vector is size n+1, there must be n coefficient sets.");
139 static bool warningPrinted_;
142template<
class Scalar,
int intervals>
143bool ShomateMethod<Scalar, intervals>::warningPrinted_ =
false;
The Shomate method to compute enthalpy and heat capacity.
Definition: shomate.hh:50
Scalar heatCapacity(const Scalar temperature) const
Return heat capacity in J/(mol*K)
Definition: shomate.hh:88
std::conditional_t< intervals==-1, std::vector< Scalar >, std::array< Scalar, std::size_t(intervals+1)> > Temperatures
Definition: shomate.hh:55
std::conditional_t< intervals==-1, std::vector< CoefficientSet >, std::array< CoefficientSet, std::size_t(intervals)> > Coefficients
Definition: shomate.hh:56
{ Scalar A, B, C, D, E, F, G, H CoefficientSet
Definition: shomate.hh:54
constexpr ShomateMethod(const Temperatures &temperatures, const Coefficients &coeffs)
Constructor for Shomate method class.
Definition: shomate.hh:63
Scalar enthalpy(const Scalar temperature) const
Return enthalpy in kJ/mol.
Definition: shomate.hh:75
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:282
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:39