Function1.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) 2011-2019 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 "Function1.H"
27 #include "Time.H"
28 
29 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
30 
31 template<class Type>
32 Foam::Function1<Type>::Function1(const word& entryName)
33 :
34  name_(entryName)
35 {}
36 
37 
38 template<class Type>
39 Foam::Function1<Type>::Function1(const Function1<Type>& de)
40 :
41  tmp<Function1<Type>>::refCount(),
42  name_(de.name_)
43 {}
44 
45 
46 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
47 
48 template<class Type>
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
55 template<class Type>
57 {
58  return name_;
59 }
60 
61 
62 template<class Type>
64 {}
65 
66 
67 template<class Type>
68 Type Foam::Function1<Type>::value(const scalar x) const
69 {
71  << "Evaluation is not defined for " << type() << " functions"
72  << exit(FatalError);
73 
74  return Zero;
75 }
76 
77 
78 template<class Type>
79 Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
80 {
82  << "Integration is not defined for " << type() << " functions"
83  << exit(FatalError);
84 
85  return Zero;
86 }
87 
88 
89 template<class Function1Type>
92 (
93  const scalarField& x
94 ) const
95 {
96  tmp<Field<Type>> tfld(new Field<Type>(x.size()));
97  Field<Type>& fld = tfld.ref();
98 
99  forAll(x, i)
100  {
101  fld[i] = Function1Type::value(x[i]);
102  }
103  return tfld;
104 }
105 
106 
107 template<class Function1Type>
109 (
110  const word& entryName,
111  const dictionary& dict
112 )
113 :
114  Function1Type(entryName, dict)
115 {}
116 
117 
118 template<class Function1Type>
121 {
122  return tmp<Function1<Type>>
123  (
125  );
126 }
127 
128 
129 template<class Function1Type>
132 (
133  const scalarField& x1,
134  const scalarField& x2
135 ) const
136 {
137  tmp<Field<Type>> tfld(new Field<Type>(x1.size()));
138  Field<Type>& fld = tfld.ref();
139 
140  forAll(x1, i)
141  {
142  fld[i] = Function1Type::integrate(x1[i], x2[i]);
143  }
144 
145  return tfld;
146 }
147 
148 
149 template<class Type>
151 {
152  os.writeKeyword(name_) << type();
153 }
154 
155 
156 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
157 
158 template<class Type>
160 {
161  f1.writeData(os);
162 }
163 
164 
165 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
166 
167 template<class Type>
168 Foam::Ostream& Foam::operator<<
169 (
170  Ostream& os,
171  const Function1<Type>& f1
172 )
173 {
174  // Check state of Ostream
175  os.check
176  (
177  "Ostream& operator<<(Ostream&, const Function1<Type>&)"
178  );
179 
180  f1.writeData(os);
181 
182  return os;
183 }
184 
185 
186 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual tmp< Field< Type > > value(const scalarField &x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:92
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.C:120
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
scalar f1
Definition: createFields.H:28
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:150
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:68
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A class for handling words, derived from string.
Definition: word.H:59
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:79
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
virtual ~Function1()
Destructor.
Definition: Function1.C:49
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: Function1.C:63
virtual tmp< Field< Type > > integrate(const scalarField &x1, const scalarField &x2) const
Integrate between two (scalar) values.
Definition: Function1.C:132
FieldFunction1(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
Definition: Function1.C:109
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
A class for managing temporary objects.
Definition: PtrList.H:53