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-2024 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 
28 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 :
33  name_(name)
34 {}
35 
36 
37 template<class Type>
39 :
40  tmp<Function1<Type>>::refCount(),
41  name_(f1.name_)
42 {}
43 
44 
45 template<class Type, class Function1Type>
47 :
48  Function1<Type>(name)
49 {}
50 
51 
52 template<class Type, class Function1Type>
55 {
56  return tmp<Function1<Type>>
57  (
58  new Function1Type(static_cast<const Function1Type&>(*this))
59  );
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64 
65 template<class Type>
67 {}
68 
69 
70 template<class Type, class Function1Type>
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 template<class Type>
79 {
80  return name_;
81 }
82 
83 
84 template<class Type>
86 {
87  return false;
88 }
89 
90 
91 template<class Type, class Function1Type>
93 (
94  const scalarField& x
95 ) const
96 {
97  tmp<Field<Type>> tfld(new Field<Type>(x.size()));
98  Field<Type>& fld = tfld.ref();
99 
100  forAll(x, i)
101  {
102  fld[i] = static_cast<const Function1Type&>(*this).value(x[i]);
103  }
104 
105  return tfld;
106 }
107 
108 
109 template<class Type, class Function1Type>
112 (
113  const scalarField& x1,
114  const scalarField& x2
115 ) const
116 {
117  tmp<Field<Type>> tfld(new Field<Type>(x1.size()));
118  Field<Type>& fld = tfld.ref();
119 
120  forAll(x1, i)
121  {
122  fld[i] =
123  static_cast<const Function1Type&>(*this).integral(x1[i], x2[i]);
124  }
125 
126  return tfld;
127 }
128 
129 
130 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
131 
132 template<class Type>
134 {
135  if (this == &f)
136  {
138  << "attempted assignment to self"
139  << abort(FatalError);
140  }
141 }
142 
143 
144 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
145 
146 template<class Type>
148 {
149  writeEntry(os, {unitAny, unitAny}, f1);
150 }
151 
152 
153 template<class Type>
155 (
156  Ostream& os,
158  const Function1<Type>& f1
159 )
160 {
161  writeKeyword(os, f1.name())
162  << nl << indent << token::BEGIN_BLOCK << nl << incrIndent;
163 
164  writeEntry(os, "type", f1.type());
165 
166  f1.write(os, units);
167 
168  os << decrIndent << indent << token::END_BLOCK << endl;
169 }
170 
171 
172 template<class Type>
174 (
175  Ostream& os,
176  const unitConversion& xUnits,
177  const unitConversion& valueUnits,
178  const Function1<Type>& f1
179 )
180 {
181  writeEntry(os, {xUnits, valueUnits}, f1);
182 }
183 
184 
185 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
186 
187 template<class Type>
189 {
190  f1.write(os, {unitAny, unitAny});
191 
192  // Check state of Ostream
193  os.check("Ostream& operator<<(Ostream&, const Function1<Type>&)");
194 
195  return os;
196 }
197 
198 
199 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual Type integral(const scalar x1, const scalar x2) const =0
Integrate between two scalar values.
FieldFunction1(const word &name)
Construct from name.
Definition: Function1.C:46
virtual Type value(const scalar x) const =0
Return value as a function of one scalars.
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.C:54
virtual ~FieldFunction1()
Destructor.
Definition: Function1.C:71
Run-time selectable general function of one variable.
Definition: Function1.H:125
virtual ~Function1()
Destructor.
Definition: Function1.C:66
Function1(const word &name)
Construct from name.
Definition: Function1.C:31
void operator=(const Function1< Type > &)
Assignment.
Definition: Function1.C:133
virtual bool constant() const
Is this function guaranteed to be constant?
Definition: Function1.C:85
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
virtual void write(Ostream &os, const Function1s::unitConversions &) const =0
Write data to dictionary stream.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
@ BEGIN_BLOCK
Definition: token.H:113
@ END_BLOCK
Definition: token.H:114
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:241
const unitConversion unitAny
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:234
const HashTable< unitConversion > & units()
Get the table of unit conversions.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
error FatalError
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
Definition: keyType.C:155
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
static const char nl
Definition: Ostream.H:266
labelList f(nPoints)