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-2023 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 :
52  Function1<Type>(name)
53 {}
54 
55 
56 template<class Type, class Function1Type>
59 {
60  return tmp<Function1<Type>>
61  (
62  new Function1Type(static_cast<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] = static_cast<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] =
120  static_cast<const Function1Type&>(*this).integral(x1[i], x2[i]);
121  }
122 
123  return tfld;
124 }
125 
126 
127 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
128 
129 template<class Type>
131 {
132  if (this == &f)
133  {
135  << "attempted assignment to self"
136  << abort(FatalError);
137  }
138 }
139 
140 
141 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
142 
143 template<class Type>
145 {
146  writeKeyword(os, f1.name())
147  << nl << indent << token::BEGIN_BLOCK << nl << incrIndent;
148 
149  writeEntry(os, "type", f1.type());
150 
151  f1.write(os);
152 
153  os << decrIndent << indent << token::END_BLOCK << endl;
154 }
155 
156 
157 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
158 
159 template<class Type>
160 Foam::Ostream& Foam::operator<<
161 (
162  Ostream& os,
163  const Function1<Type>& f1
164 )
165 {
166  // Check state of Ostream
167  os.check
168  (
169  "Ostream& operator<<(Ostream&, const Function1<Type>&)"
170  );
171 
172  f1.write(os);
173 
174  return os;
175 }
176 
177 
178 // ************************************************************************* //
#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:48
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:58
virtual ~FieldFunction1()
Destructor.
Definition: Function1.C:75
Run-time selectable general function of one variable.
Definition: Function1.H:64
virtual ~Function1()
Destructor.
Definition: Function1.C:70
Function1(const word &name)
Construct from name.
Definition: Function1.C:32
void operator=(const Function1< Type > &)
Assignment.
Definition: Function1.C:130
const word & name() const
Return the name of the entry.
Definition: Function1.C:82
virtual void write(Ostream &os) 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:110
@ END_BLOCK
Definition: token.H:111
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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:235
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
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
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
static const char nl
Definition: Ostream.H:260
labelList f(nPoints)