UniformTable1.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "UniformTable1.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const word& name,
34  const dictionary& dict
35 )
36 :
38  dictName_(dict.name()),
39  low_(dict.lookup<scalar>("low")),
40  high_(dict.lookup<scalar>("high")),
41  values_(dict.lookup("values"))
42 {
43  if (values_.size() < 2)
44  {
46  << "Table " << nl
47  << " " << dictName_ << nl
48  << " has less than 2 entries."
49  << exit(FatalError);
50  }
51  else
52  {
53  delta_ = (high_ - low_)/(values_.size() - 1);
54  }
55 }
56 
57 
58 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59 
60 template<class Type>
62 {
63  const scalar nd = (x - low_)/delta_;
64  const label i = nd;
65 
66  if (nd < 0 || i > values_.size() - 2)
67  {
69  << x << " out of range "
70  << low_ << " to " << high_ << nl
71  << " of table " << dictName_
72  << exit(FatalError);
73  }
74 
75  const scalar xi = low_ + i*delta_;
76  const scalar lambda = (x - xi)/delta_;
77 
78  return values_[i] + lambda*(values_[i + 1] - values_[i]);
79 }
80 
81 
82 template<class Type>
84 (
85  const scalar x1,
86  const scalar x2
87 ) const
88 {
90  return Zero;
91 }
92 
93 
94 template<class Type>
96 {
97  writeEntry(os, "low", low_);
98  writeEntry(os, "high", high_);
99  writeEntry(os, "values", values_);
100 }
101 
102 
103 // ************************************************************************* //
UniformTable(const word &name, const dictionary &dict)
Construct from name and dictionary.
Definition: UniformTable1.C:32
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
virtual Type value(scalar x) const
Evaluate the function and return the result.
Definition: UniformTable1.C:61
dimensionedScalar lambda(viscosity->lookup("lambda"))
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalar values.
Definition: UniformTable1.C:84
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:109
A class for handling words, derived from string.
Definition: word.H:59
void write(Ostream &os) const
Write the function coefficients.
Definition: UniformTable1.C:95
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864