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-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 "Function1.H"
27 
28 
29 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 :
34  name_(name)
35 {}
36 
37 
38 template<class Type>
40 :
41  tmp<Function1<Type>>::refCount(),
42  name_(de.name_)
43 {}
44 
45 
46 template<class Type, class Function1Type>
48 (
49  const word& name
50 )
51 :
53 {}
54 
55 
56 template<class Type, class Function1Type>
59 {
60  return tmp<Function1<Type>>
61  (
62  new Function1Type(refCast<const Function1Type>(*this))
63  );
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
68 
69 template<class Type>
71 {}
72 
73 
74 template<class Type, class Function1Type>
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
81 template<class Type>
83 {
84  return name_;
85 }
86 
87 
88 template<class Type, class Function1Type>
90 (
91  const scalarField& x
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 Function1Type>(*this).value(x[i]);
100  }
101 
102  return tfld;
103 }
104 
105 
106 template<class Type, class Function1Type>
109 (
110  const scalarField& x1,
111  const scalarField& x2
112 ) const
113 {
114  tmp<Field<Type>> tfld(new Field<Type>(x1.size()));
115  Field<Type>& fld = tfld.ref();
116 
117  forAll(x1, i)
118  {
119  fld[i] = refCast<const Function1Type>(*this).integral(x1[i], x2[i]);
120  }
121 
122  return tfld;
123 }
124 
125 
126 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
127 
128 template<class Type>
130 {
131  if (this == &f)
132  {
134  << "attempted assignment to self"
135  << abort(FatalError);
136  }
137 }
138 
139 
140 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
141 
142 template<class Type>
144 {
145  writeKeyword(os, f1.name())
146  << nl << indent << token::BEGIN_BLOCK << nl << incrIndent;
147 
148  writeEntry(os, "type", f1.type());
149 
150  f1.write(os);
151 
152  os << decrIndent << indent << token::END_BLOCK << endl;
153 }
154 
155 
156 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
157 
158 template<class Type>
159 Foam::Ostream& Foam::operator<<
160 (
161  Ostream& os,
162  const Function1<Type>& f1
163 )
164 {
165  // Check state of Ostream
166  os.check
167  (
168  "Ostream& operator<<(Ostream&, const Function1<Type>&)"
169  );
170 
171  f1.write(os);
172 
173  return os;
174 }
175 
176 
177 // ************************************************************************* //
virtual Type value(const scalar x) const =0
Return value as a function of one scalars.
Run-time selectable general function of one variable.
Definition: Function1.H:52
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual ~FieldFunction1()
Destructor.
Definition: Function1.C:75
virtual void write(Ostream &os) const =0
Write data to dictionary stream.
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
const word & name() const
Return the name of the entry.
Definition: Function1.C:82
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.C:58
scalar f1
Definition: createFields.H:15
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
void operator=(const Function1< Type > &)
Assignment.
Definition: Function1.C:129
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
virtual ~Function1()
Destructor.
Definition: Function1.C:70
labelList f(nPoints)
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
FieldFunction1(const word &name)
Construct from name.
Definition: Function1.C:48
A class for managing temporary objects.
Definition: PtrList.H:53
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
virtual Type integral(const scalar x1, const scalar x2) const =0
Integrate between two scalar values.
Function1(const word &name)
Construct from name.
Definition: Function1.C:32