TimeFunction1.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "TimeFunction1.H"
30 
31 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const Time& runTime,
37  const word& entryName,
38  const dictionary& dict
39 )
40 :
41  time_(runTime),
42  name_(entryName),
43  entry_(Function1<Type>::New(entryName, dict, &runTime))
44 {
45  // Time conversion now handled by Function1 directly
46  // entry_->userTimeToTime(runTime);
47 }
48 
49 
50 template<class Type>
52 (
53  const Time& runTime,
54  const word& entryName
55 )
56 :
57  time_(runTime),
58  name_(entryName),
59  entry_(nullptr)
60 {}
61 
62 
63 template<class Type>
65 (
66  const TimeFunction1<Type>& rhs
67 )
68 :
69  time_(rhs.time_),
70  name_(rhs.name_),
71  entry_(nullptr) // steal/reuse (missing clone!)
72 {
73  if (rhs.entry_)
74  {
75  entry_.reset(rhs.entry_->clone().ptr());
76  }
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
82 template<class Type>
84 {
85  entry_ = Function1<Type>::New(name_, dict, &time_);
86  entry_->userTimeToTime(time_);
87 }
88 
89 
90 template<class Type>
92 {
93  return entry_->name();
94 }
95 
96 
97 template<class Type>
98 Type Foam::TimeFunction1<Type>::value(const scalar x) const
99 {
100  return entry_->value(x);
101 }
102 
103 
104 template<class Type>
106 (
107  const scalar x1,
108  const scalar x2
109 ) const
110 {
111  return entry_->integrate(x1, x2);
112 }
113 
114 
115 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
116 
117 template<class Type>
118 Foam::Ostream& Foam::operator<<
119 (
120  Ostream& os,
121  const TimeFunction1<Type>& rhs
122 )
123 {
124  if (rhs.entry_)
125  {
126  rhs.entry_->operator<<(os, rhs);
127  }
128  return os;
129 }
130 
131 
132 template<class Type>
134 {
135  entry_->writeData(os);
136 }
137 
138 
139 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::TimeFunction1::TimeFunction1
TimeFunction1(const Time &runTime, const word &name, const dictionary &dict)
Construct from entry name and dictionary.
Definition: TimeFunction1.C:35
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::TimeFunction1
Light wrapper around Function1 to provide a mechanism to update time-based entries.
Definition: TimeFunction1.H:50
Foam::TimeFunction1::name_
const word name_
Name of the data entry.
Definition: TimeFunction1.H:70
Foam::TimeFunction1::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TimeFunction1.C:106
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::TimeFunction1::value
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: TimeFunction1.C:98
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::TimeFunction1::time_
const Time & time_
Reference to the time database.
Definition: TimeFunction1.H:67
Foam::TimeFunction1::reset
void reset(const dictionary &dict)
Reset entry by re-reading from dictionary.
Definition: TimeFunction1.C:83
Foam::TimeFunction1::name
const word & name() const
Return the name of the entry.
Definition: TimeFunction1.C:91
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::TimeFunction1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: TimeFunction1.C:133
Foam::TimeFunction1::entry_
autoPtr< Function1< Type > > entry_
The underlying Function1.
Definition: TimeFunction1.H:73
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
TimeFunction1.H