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-2023 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 Function1<Type>& function
49 )
50 :
51  time_(time),
52  name_(function.name()),
53  function_(function.clone().ptr())
54 {}
55 
56 
57 template<class Type>
59 (
60  const Time& time,
61  const word& name
62 )
63 :
64  time_(time),
65  name_(name),
66  function_(nullptr)
67 {}
68 
69 
70 template<class Type>
72 (
73  const TimeFunction1<Type>& tf
74 )
75 :
76  time_(tf.time_),
77  name_(tf.name_),
78  function_(tf.function_, false)
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
83 
84 template<class Type>
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
91 template<class Type>
93 {
94  function_.reset(Function1<Type>::New(name_, dict).ptr());
95 }
96 
97 
98 template<class Type>
99 Type Foam::TimeFunction1<Type>::value(const scalar x) const
100 {
101  return function_->value(time_.timeToUserTime(x));
102 }
103 
104 
105 template<class Type>
107 (
108  const scalar x1,
109  const scalar x2
110 ) const
111 {
112  return
113  time_.userTimeToTime(1)
114  *function_->integral
115  (
116  time_.timeToUserTime(x1),
117  time_.timeToUserTime(x2)
118  );
119 }
120 
121 
122 template<class Type>
124 {
125  writeEntry(os, function_());
126 }
127 
128 
129 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
130 
131 template<class Type>
132 Foam::Ostream& Foam::operator<<
133 (
134  Ostream& os,
135  const TimeFunction1<Type>& tf
136 )
137 {
138  return os << tf.function_();
139 }
140 
141 
142 // ************************************************************************* //
Run-time selectable general function of one variable.
Definition: Function1.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Light wrapper around Function1 to provide a mechanism to update time-based entries.
Definition: TimeFunction1.H:61
void reset(const dictionary &dict)
Reset entry by re-reading from dictionary.
Definition: TimeFunction1.C:92
virtual ~TimeFunction1()
Destructor.
Definition: TimeFunction1.C:85
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalars.
virtual void write(Ostream &os) const
Write in dictionary format.
virtual Type value(const scalar x) const
Return value as a function of scalar x.
Definition: TimeFunction1.C:99
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:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for handling words, derived from string.
Definition: word.H:62
const tensorField & tf
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
T clone(const T &t)
Definition: List.H:55
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict