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 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))
44 {
45  entry_->convertTimeBase(runTime);
46 }
47 
48 
49 template<class Type>
51 (
52  const Time& runTime,
53  const word& entryName
54 )
55 :
56  time_(runTime),
57  name_(entryName),
58  entry_(nullptr)
59 {}
60 
61 
62 template<class Type>
64 (
65  const TimeFunction1<Type>& rhs
66 )
67 :
68  time_(rhs.time_),
69  name_(rhs.name_),
70  entry_(nullptr) // steal/reuse (missing clone!)
71 {
72  if (rhs.entry_)
73  {
74  entry_.reset(rhs.entry_->clone().ptr());
75  }
76 }
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
81 template<class Type>
83 {
84  entry_ = Function1<Type>::New(name_, dict);
85  entry_->convertTimeBase(time_);
86 }
87 
88 
89 template<class Type>
91 {
92  return entry_->name();
93 }
94 
95 
96 template<class Type>
97 Type Foam::TimeFunction1<Type>::value(const scalar x) const
98 {
99  return entry_->value(x);
100 }
101 
102 
103 template<class Type>
105 (
106  const scalar x1,
107  const scalar x2
108 ) const
109 {
110  return entry_->integrate(x1, x2);
111 }
112 
113 
114 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
115 
116 template<class Type>
117 Foam::Ostream& Foam::operator<<
118 (
119  Ostream& os,
120  const TimeFunction1<Type>& rhs
121 )
122 {
123  if (rhs.entry_)
124  {
125  rhs.entry_->operator<<(os, rhs);
126  }
127  return os;
128 }
129 
130 
131 template<class Type>
133 {
134  entry_->writeData(os);
135 }
136 
137 
138 // ************************************************************************* //
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:62
Foam::TimeFunction1
Light wrapper around Function1 to provide a mechanism to update time-based entries.
Definition: ConeNozzleInjection.H:80
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:105
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:86
Foam::TimeFunction1::value
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: TimeFunction1.C:97
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:121
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:82
Foam::TimeFunction1::name
const word & name() const
Return the name of the entry.
Definition: TimeFunction1.C:90
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::TimeFunction1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: TimeFunction1.C:132
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