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  const scalarField& x1,
142  const scalarField& x2
143 ) const
144 {
145  auto tfld = tmp<Field<Type>>::New(x1.size());
146  auto& fld = tfld.ref();
147 
148  forAll(x1, i)
149  {
150  fld[i] = Function1Type::integrate(x1[i], x2[i]);
151  }
152 
153  return tfld;
154 }
155 
157 template<class Type>
159 {}
160 
161 
162 template<class Type>
164 {
165  os.writeKeyword(name_) << type();
166 }
167 
168 
169 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
170 
171 template<class Type>
172 Foam::Ostream& Foam::operator<<
173 (
174  Ostream& os,
175  const Function1<Type>& rhs
176 )
177 {
178  os.check(FUNCTION_NAME);
179 
180  os << rhs.name();
181  rhs.writeData(os);
182 
183  return os;
184 }
185 
186 
187 // ************************************************************************* //
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: Function1.C:151
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
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:156
#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:133
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:696