version 3.9
shomate.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
29#ifndef DUMUX_MATERIAL_COMPONENTS_SHOMATE_HH
30#define DUMUX_MATERIAL_COMPONENTS_SHOMATE_HH
31
32#include <algorithm>
33#include <array>
34#include <iostream>
35#include <type_traits>
36#include <vector>
37
38#include <dune/common/exceptions.hh>
39
40namespace Dumux {
41
48template<class Scalar, int intervals = -1>
50{
51 static_assert(intervals == -1 || intervals > 0, "Number of intervals must be -1 (dynamic) or greater than 0 (static).");
52
53public:
54 using CoefficientSet = struct { Scalar A, B, C, D, E, F, G, H; };
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)>>;
57
63 constexpr ShomateMethod(const Temperatures& temperatures, const Coefficients& coeffs)
64 : temperatures_(temperatures)
65 , coeffs_(coeffs)
66 {
67 checkInput_();
68 }
69
75 Scalar enthalpy(const Scalar temperature) const
76 {
77 const auto& p = paramsAtTemperature_(temperature);
78 const Scalar t = temperature/1000.0;
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;
81 }
82
88 Scalar heatCapacity(const Scalar temperature) const
89 {
90 const auto& p = paramsAtTemperature_(temperature);
91 const Scalar t = temperature/1000.0;
92 const Scalar heatCapacity = p.A + p.B*t + p.C*t*t + p.D*t*t*t + p.E/(t*t);
93 return heatCapacity;
94 }
95
96private:
97 const CoefficientSet& paramsAtTemperature_(const Scalar T) const
98 {
99 // check if T is smaller or higher than allowed min/max T
100 if (T < temperatures_.front() || T > temperatures_.back())
101 {
102 if (!warningPrinted_)
103 {
104 std::cout << "Temperature "<< T << " [K] is out of range. Enthalpy values are extrapolated." << std::endl;
105 warningPrinted_ = true;
106 }
107 }
108
109 // find the interval for the given temperature
110 const auto index = std::min<std::size_t>(
111 coeffs_.size()-1,
113 temperatures_.begin(),
114 std::lower_bound(temperatures_.begin(), temperatures_.end(), T)
115 )
116 );
117
118 return coeffs_[index];
119 }
120
121 void checkInput_() const
122 {
123 if constexpr (intervals == -1)
124 {
125 if (temperatures_.size() < 2)
126 DUNE_THROW(Dune::InvalidStateException, "Temperature range must have at least two entries.");
127
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.");
131
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.");
134 }
135 }
136
137 Temperatures temperatures_;
138 Coefficients coeffs_;
139 static bool warningPrinted_;
140};
141
142template<class Scalar, int intervals>
143bool ShomateMethod<Scalar, intervals>::warningPrinted_ = false;
144
145} // namespace Dumux
146
147#endif
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
Definition: adapt.hh:17