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-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 "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>
38 (
39  const word& entryName,
40  const objectRegistry* obrPtr
41 )
42 :
43  function1Base(entryName, obrPtr)
44 {}
45 
46 
47 template<class Type>
49 (
50  const word& entryName,
51  const dictionary& dict,
52  const objectRegistry* obrPtr
53 )
54 :
55  function1Base(entryName, dict, obrPtr)
56 {}
57 
58 
59 template<class Type>
60 Foam::Function1<Type>::Function1(const Function1<Type>& rhs)
61 :
62  function1Base(rhs)
63 {}
64 
65 
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 
68 template<class Type>
69 Type Foam::Function1<Type>::value(const scalar x) const
70 {
72  return Type();
73 }
74 
75 
76 template<class Type>
78 (
79  const scalarField& x
80 ) const
81 {
83  return nullptr;
84 }
85 
86 
87 template<class Type>
88 Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
89 {
91  return Type();
92 }
93 
94 
95 template<class Type>
97 (
98  const scalarField& x1,
99  const scalarField& x2
100 ) const
101 {
103  return nullptr;
104 }
105 
106 
107 template<class Function1Type>
110 (
111  const scalarField& x
112 ) const
113 {
114  auto tfld = tmp<Field<Type>>::New(x.size());
115  auto& fld = tfld.ref();
116 
117  forAll(x, i)
118  {
119  fld[i] = Function1Type::value(x[i]);
120  }
121  return tfld;
122 }
123 
124 
125 template<class Function1Type>
127 (
128  const word& entryName,
129  const dictionary& dict,
130  const objectRegistry* obrPtr
131 )
132 :
133  Function1Type(entryName, dict, obrPtr)
134 {}
135 
136 
137 template<class Function1Type>
140 {
141  return tmp<Function1<Type>>
142  (
144  );
145 }
146 
147 
148 template<class Function1Type>
151 (
152  const scalarField& x1,
153  const scalarField& x2
154 ) const
155 {
156  auto tfld = tmp<Field<Type>>::New(x1.size());
157  auto& fld = tfld.ref();
158 
159  forAll(x1, i)
160  {
161  fld[i] = Function1Type::integrate(x1[i], x2[i]);
162  }
163 
164  return tfld;
165 }
166 
167 
168 template<class Type>
170 {}
171 
172 
173 template<class Type>
175 {
176  os.writeKeyword(name_) << type();
177 }
178 
179 
180 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
181 
182 template<class Type>
183 Foam::Ostream& Foam::operator<<
184 (
185  Ostream& os,
186  const Function1<Type>& rhs
187 )
188 {
189  os.check(FUNCTION_NAME);
190 
191  os << rhs.name();
192  rhs.writeData(os);
193 
194  return os;
195 }
196 
197 
198 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Function1::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: Function1.C:169
Function1.H
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: propellerInfo.H:291
Foam::FieldFunction1
Definition: Function1.H:292
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
Foam::Field< scalar >
Foam::Function1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:174
Foam::FieldFunction1::integrate
virtual tmp< Field< Type > > integrate(const scalarField &x1, const scalarField &x2) const
Integrate between two (scalar) values.
Definition: Function1.C:151
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:69
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:123
os
OBJstream os(runTime.globalPath()/outputName)
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:139
x
x
Definition: LISASMDCalcMethod2.H:52
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
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:88
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:110
Foam::FieldFunction1::FieldFunction1
FieldFunction1(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name and dictionary.
Definition: Function1.C:127