TimeFunction1.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) 2012-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 "TimeFunction1.H"
27 
28 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const Time& time,
34  const word& name,
35  const dictionary& dict
36 )
37 :
38  time_(time),
39  name_(name),
40  function_(Function1<Type>::New(name, dict))
41 {}
42 
43 
44 template<class Type>
46 (
47  const Time& time,
48  const word& name
49 )
50 :
51  time_(time),
52  name_(name),
53  function_(nullptr)
54 {}
55 
56 
57 template<class Type>
59 (
60  const TimeFunction1<Type>& tf
61 )
62 :
63  time_(tf.time_),
64  name_(tf.name_),
65  function_(tf.function_, false)
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
71 template<class Type>
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
78 template<class Type>
80 {
81  function_.reset(Function1<Type>::New(name_, dict).ptr());
82 }
83 
84 
85 template<class Type>
86 Type Foam::TimeFunction1<Type>::value(const scalar x) const
87 {
88  return function_->value(time_.userTimeToTime(x));
89 }
90 
91 
92 template<class Type>
94 (
95  const scalar x1,
96  const scalar x2
97 ) const
98 {
99  return
100  time_.timeToUserTimeRatio()
101  *function_->integral
102  (
103  time_.userTimeToTime(x1),
104  time_.userTimeToTime(x2)
105  );
106 }
107 
108 
109 template<class Type>
111 {
112  writeEntry(os, function_());
113 }
114 
115 
116 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
117 
118 template<class Type>
119 Foam::Ostream& Foam::operator<<
120 (
121  Ostream& os,
122  const TimeFunction1<Type>& tf
123 )
124 {
125  return os << tf.function_();
126 }
127 
128 
129 // ************************************************************************* //
Run-time selectable general function of one variable.
Definition: Function1.H:52
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
TimeFunction1(const Time &time, const word &name, const dictionary &dict)
Construct from time, name and dictionary.
Definition: TimeFunction1.C:32
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
const tensorField & tf
virtual ~TimeFunction1()
Destructor.
Definition: TimeFunction1.C:72
A class for handling words, derived from string.
Definition: word.H:59
Light wrapper around Function1 to provide a mechanism to update time-based entries.
void reset(const dictionary &dict)
Reset entry by re-reading from dictionary.
Definition: TimeFunction1.C:79
autoPtr< Function1< Type > > function_
The function.
Definition: TimeFunction1.H:73
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual Type value(const scalar x) const
Return value as a function of scalar x.
Definition: TimeFunction1.C:86
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalars.
Definition: TimeFunction1.C:94
virtual void write(Ostream &os) const
Write in dictionary format.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
const word name_
Name of the data entry.
Definition: TimeFunction1.H:70
const Time & time_
Reference to the time database.
Definition: TimeFunction1.H:67