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>
83 void Foam::TimeFunction1<Type>::reset(const dictionary& dict)
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>
133 void Foam::TimeFunction1<Type>::writeData(Ostream& os) const
134 {
135  entry_->writeData(os);
136 }
137 
138 
139 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
autoPtr< Function1< Type > > entry_
The underlying Function1.
Definition: TimeFunction1.H:75
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
engineTime & runTime
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TimeFunction1.C:99
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
A class for handling words, derived from Foam::string.
Definition: word.H:63
Light wrapper around Function1 to provide a mechanism to update time-based entries.
Definition: TimeFunction1.H:46
void reset(const dictionary &dict)
Reset entry by re-reading from dictionary.
Definition: TimeFunction1.C:76
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const word & name() const
Return the name of the entry.
Definition: TimeFunction1.C:84
OBJstream os(runTime.globalPath()/outputName)
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: TimeFunction1.C:91
virtual void writeData(Ostream &os) const
Write in dictionary format.
TimeFunction1(const Time &runTime, const word &name, const dictionary &dict)
Construct from entry name and dictionary.
Definition: TimeFunction1.C:28