Function2.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) 2020 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 "Function2.H"
27 
28 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 :
33  name_(name)
34 {}
35 
36 
37 template<class Type>
39 :
40  tmp<Function2<Type>>::refCount(),
41  name_(de.name_)
42 {}
43 
44 
45 template<class Type, class Function2Type>
47 (
48  const word& name
49 )
50 :
52 {}
53 
54 
55 template<class Type, class Function2Type>
58 {
59  return tmp<Function2<Type>>
60  (
61  new Function2Type(refCast<const Function2Type>(*this))
62  );
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
68 template<class Type>
70 {}
71 
72 
73 template<class Type, class Function2Type>
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
80 template<class Type>
82 {
83  return name_;
84 }
85 
86 
87 template<class Type, class Function2Type>
89 (
90  const scalarField& x,
91  const scalarField& y
92 ) const
93 {
94  tmp<Field<Type>> tfld(new Field<Type>(x.size()));
95  Field<Type>& fld = tfld.ref();
96 
97  forAll(x, i)
98  {
99  fld[i] = refCast<const Function2Type>(*this).value(x[i], y[i]);
100  }
101 
102  return tfld;
103 }
104 
105 
106 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
107 
108 template<class Type>
110 {
111  if (this == &f)
112  {
114  << "attempted assignment to self"
115  << abort(FatalError);
116  }
117 }
118 
119 
120 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
121 
122 template<class Type>
124 {
125  writeKeyword(os, f2.name())
126  << nl << indent << token::BEGIN_BLOCK << nl << incrIndent;
127 
128  writeEntry(os, "type", f2.type());
129 
130  f2.write(os);
131 
132  os << decrIndent << indent << token::END_BLOCK << endl;
133 }
134 
135 
136 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
137 
138 template<class Type>
139 Foam::Ostream& Foam::operator<<
140 (
141  Ostream& os,
142  const Function2<Type>& f2
143 )
144 {
145  // Check state of Ostream
146  os.check
147  (
148  "Ostream& operator<<(Ostream&, const Function2<Type>&)"
149  );
150 
151  f2.write(os);
152 
153  return os;
154 }
155 
156 
157 // ************************************************************************* //
virtual void write(Ostream &os) const =0
Write in dictionary format.
void operator=(const Function2< Type > &)
Assignment.
Definition: Function2.C:109
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual tmp< Function2< Type > > clone() const
Construct and return a clone.
Definition: Function2.C:57
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
Definition: keyType.C:155
Reference counter for various OpenFOAM components.
Definition: refCount.H:49
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
FieldFunction2(const word &name)
Construct from name.
Definition: Function2.C:47
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A class for handling words, derived from string.
Definition: word.H:59
errorManip< error > abort(error &err)
Definition: errorManip.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
labelList f(nPoints)
virtual ~Function2()
Destructor.
Definition: Function2.C:69
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
virtual Type value(const scalar x, const scalar y) const =0
Return value as a function of two scalars.
Run-time selectable function of two variables.
Definition: Function2.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
virtual ~FieldFunction2()
Destructor.
Definition: Function2.C:74
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
Function2(const word &name)
Construct from name.
Definition: Function2.C:31
const word & name() const
Return the name of the entry.
Definition: Function2.C:81