All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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>
31 Foam::Function1<Type>::Function1(const word& entryName)
32 :
33  name_(entryName)
34 {}
35 
36 
37 template<class Type>
38 Foam::Function1<Type>::Function1(const Function1<Type>& de)
39 :
40  tmp<Function1<Type>>::refCount(),
41  name_(de.name_)
42 {}
43 
44 
45 template<class Type, class Function1Type>
47 (
48  const word& entryName
49 )
50 :
51  Function1<Type>(entryName)
52 {}
53 
54 
55 template<class Type, class Function1Type>
57 (
59 )
60 :
61  Function1<Type>(ff1)
62 {}
63 
64 
65 template<class Type, class Function1Type>
68 {
69  return tmp<Function1<Type>>
70  (
71  new Function1Type(refCast<const Function1Type>(*this))
72  );
73 }
74 
75 
76 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
77 
78 template<class Type>
80 {}
81 
82 
83 template<class Type, class Function1Type>
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
90 template<class Type>
92 {
93  return name_;
94 }
95 
96 
97 template<class Type>
99 {
100  writeKeyword(os, name_) << type();
101 }
102 
103 
104 template<class Type, class Function1Type>
106 (
107  const scalarField& x
108 ) const
109 {
110  tmp<Field<Type>> tfld(new Field<Type>(x.size()));
111  Field<Type>& fld = tfld.ref();
112 
113  forAll(x, i)
114  {
115  fld[i] = refCast<const Function1Type>(*this).value(x[i]);
116  }
117 
118  return tfld;
119 }
120 
121 
122 template<class Type, class Function1Type>
125 (
126  const scalarField& x1,
127  const scalarField& x2
128 ) const
129 {
130  tmp<Field<Type>> tfld(new Field<Type>(x1.size()));
131  Field<Type>& fld = tfld.ref();
132 
133  forAll(x1, i)
134  {
135  fld[i] = refCast<const Function1Type>(*this).integrate(x1[i], x2[i]);
136  }
137 
138  return tfld;
139 }
140 
141 
142 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
143 
144 template<class Type>
146 {
147  f1.writeData(os);
148 }
149 
150 
151 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
152 
153 template<class Type>
154 Foam::Ostream& Foam::operator<<
155 (
156  Ostream& os,
157  const Function1<Type>& f1
158 )
159 {
160  // Check state of Ostream
161  os.check
162  (
163  "Ostream& operator<<(Ostream&, const Function1<Type>&)"
164  );
165 
166  f1.writeData(os);
167 
168  return os;
169 }
170 
171 
172 // ************************************************************************* //
virtual Type value(const scalar x) const =0
Return value as a function of (scalar) independent variable.
virtual Type integrate(const scalar x1, const scalar x2) const =0
Integrate between two (scalar) values.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:52
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual ~FieldFunction1()
Destructor.
Definition: Function1.C:84
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
Definition: keyType.C:155
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:174
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:91
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.C:67
scalar f1
Definition: createFields.H:28
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:98
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
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual ~Function1()
Destructor.
Definition: Function1.C:79
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
FieldFunction1(const word &entryName)
Construct from entry name.
Definition: Function1.C:47
A class for managing temporary objects.
Definition: PtrList.H:53