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-2019 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& entryName,
35  const dictionary& dict
36 )
37 :
38  time_(time),
39  name_(entryName),
40  function_(Function1<Type>::New(entryName, dict))
41 {}
42 
43 
44 template<class Type>
46 (
47  const Time& time,
48  const word& entryName
49 )
50 :
51  time_(time),
52  name_(entryName),
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_->integrate
102  (
103  time_.userTimeToTime(x1),
104  time_.userTimeToTime(x2)
105  );
106 }
107 
108 
109 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
110 
111 template<class Type>
112 Foam::Ostream& Foam::operator<<
113 (
114  Ostream& os,
115  const TimeFunction1<Type>& tf
116 )
117 {
118  return os << tf.function_();
119 }
120 
121 
122 template<class Type>
124 {
125  function_->writeData(os);
126 }
127 
128 
129 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:52
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TimeFunction1.C:94
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) independent variable.
Definition: TimeFunction1.C:86
virtual void writeData(Ostream &os) const
Write in dictionary format.
TimeFunction1(const Time &time, const word &entryName, const dictionary &dict)
Construct from time, entry name and dictionary.
Definition: TimeFunction1.C:32
const word name_
Name of the data entry.
Definition: TimeFunction1.H:70
const Time & time_
Reference to the time database.
Definition: TimeFunction1.H:67