Function1.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) 2011-2017 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 "Function1.H"
30 #include "Time.H"
31 // Required by clang 5 for correct instantiation of Function1::New
32 #include "Constant.H"
33 
34 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
35 
36 template<class Type>
37 Foam::Function1<Type>::Function1(const word& entryName)
38 :
39  function1Base(entryName)
40 {}
41 
42 
43 template<class Type>
44 Foam::Function1<Type>::Function1(const word& entryName, const dictionary& dict)
45 :
46  function1Base(entryName, dict)
47 {}
48 
49 
50 template<class Type>
51 Foam::Function1<Type>::Function1(const Function1<Type>& rhs)
52 :
53  function1Base(rhs)
54 {}
55 
56 
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 
59 template<class Type>
60 Type Foam::Function1<Type>::value(const scalar x) const
61 {
63  return Zero;
64 }
65 
66 
67 template<class Type>
70 (
71  const scalarField& x
72 ) const
73 {
75  return nullptr;
76 }
77 
78 
79 template<class Type>
80 Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
81 {
83  return Zero;
84 }
85 
86 
87 template<class Type>
90 (
91  const scalarField& x1,
92  const scalarField& x2
93 ) const
94 {
96  return nullptr;
97 }
98 
99 
100 template<class Function1Type>
103 (
104  const scalarField& x
105 ) const
106 {
107  auto tfld = tmp<Field<Type>>::New(x.size());
108  auto& fld = tfld.ref();
109 
110  forAll(x, i)
111  {
112  fld[i] = Function1Type::value(x[i]);
113  }
114  return tfld;
115 }
116 
117 
118 template<class Function1Type>
120 (
121  const word& entryName,
122  const dictionary& dict
123 )
124 :
125  Function1Type(entryName, dict)
126 {}
127 
128 
129 template<class Function1Type>
132 {
133  return tmp<Function1<Type>>
134  (
136  );
137 }
138 
139 
140 template<class Function1Type>
143 (
144  const scalarField& x1,
145  const scalarField& x2
146 ) const
147 {
148  auto tfld = tmp<Field<Type>>::New(x1.size());
149  auto& fld = tfld.ref();
150 
151  forAll(x1, i)
152  {
153  fld[i] = Function1Type::integrate(x1[i], x2[i]);
154  }
155 
156  return tfld;
157 }
158 
159 
160 template<class Type>
162 {}
163 
164 
165 template<class Type>
167 {
168  os.writeKeyword(name_) << type();
169 }
170 
171 
172 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
173 
174 template<class Type>
175 Foam::Ostream& Foam::operator<<
176 (
177  Ostream& os,
178  const Function1<Type>& rhs
179 )
180 {
181  os.check(FUNCTION_NAME);
182 
183  os << rhs.name();
184  rhs.writeData(os);
185 
186  return os;
187 }
188 
189 
190 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::Function1::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: Function1.C:161
Function1.H
Foam::FieldFunction1::FieldFunction1
FieldFunction1(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
Definition: Function1.C:120
Foam::Function1::Function1
Function1
Definition: Function1.H:130
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::FieldFunction1
Definition: Function1.H:242
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:445
Foam::Field< scalar >
Foam::Function1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:166
Foam::FieldFunction1::integrate
virtual tmp< Field< Type > > integrate(const scalarField &x1, const scalarField &x2) const
Integrate between two (scalar) values.
Definition: Function1.C:143
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::Function1::value
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:60
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::Ostream::writeKeyword
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:57
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
Time.H
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::FieldFunction1::clone
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.C:131
x
x
Definition: LISASMDCalcMethod2.H:52
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Constant.H
Foam::Function1::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:80
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::FieldFunction1::value
virtual tmp< Field< Type > > value(const scalarField &x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:103