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 :
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 
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 // ************************************************************************* //
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: Function1.C:162
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
type
Types of root.
Definition: Roots.H:52
virtual tmp< Field< Type > > value(const scalarField &x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:103
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.C:132
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 void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:167
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:62
FieldFunction1(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name and dictionary.
Definition: Function1.C:120
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:81
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
virtual tmp< Field< Type > > integrate(const scalarField &x1, const scalarField &x2) const
Integrate between two (scalar) values.
Definition: Function1.C:144
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))
Base class for template-invariant parts of Function1.
Definition: function1Base.H:50
A class for managing temporary objects.
Definition: HashPtrTable.H:50
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686