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-2018 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& t,
34  const word& name,
35  const dictionary& dict
36 )
37 :
38  time_(t),
39  name_(name),
40  entry_(Function1<Type>::New(name, dict))
41 {
42  entry_->convertTimeBase(t);
43 }
44 
45 
46 template<class Type>
48 :
49  time_(t),
50  name_(name),
51  entry_(nullptr)
52 {}
53 
54 
55 template<class Type>
57 (
58  const TimeFunction1<Type>& tde
59 )
60 :
61  time_(tde.time_),
62  name_(tde.name_),
63  entry_()
64 {
65  if (tde.entry_.valid())
66  {
67  entry_.reset(tde.entry_->clone().ptr());
68  }
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73 
74 template<class Type>
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
81 template<class Type>
83 {
84  entry_.reset
85  (
87  (
88  name_,
89  dict
90  ).ptr()
91  );
92 
93  entry_->convertTimeBase(time_);
94 }
95 
96 
97 template<class Type>
99 {
100  return entry_->name();
101 }
102 
103 
104 template<class Type>
105 Type Foam::TimeFunction1<Type>::value(const scalar x) const
106 {
107  return entry_->value(x);
108 }
109 
110 
111 template<class Type>
113 (
114  const scalar x1,
115  const scalar x2
116 ) const
117 {
118  return entry_->integrate(x1, x2);
119 }
120 
121 
122 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
123 
124 template<class Type>
125 Foam::Ostream& Foam::operator<<
126 (
127  Ostream& os,
128  const TimeFunction1<Type>& de
129 )
130 {
131  return de.entry_->operator<<(os, de);
132 }
133 
134 
135 template<class Type>
137 {
138  entry_->writeData(os);
139 }
140 
141 
142 // ************************************************************************* //
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:74
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
TimeFunction1(const Time &t, const word &name, const dictionary &dict)
Construct from entry name.
Definition: TimeFunction1.C:32
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual ~TimeFunction1()
Destructor.
Definition: TimeFunction1.C:75
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:82
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const word & name() const
Return the name of the entry.
Definition: TimeFunction1.C:98
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
virtual void writeData(Ostream &os) const
Write in dictionary format.
const word name_
Name of the data entry.
Definition: TimeFunction1.H:71
const Time & time_
Reference to the time database.
Definition: TimeFunction1.H:68