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-2018 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 #include "Time.H"
28 
29 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
30 
31 template<class Type>
32 Foam::Function1<Type>::Function1(const word& entryName)
33 :
34  name_(entryName)
35 {}
36 
37 
38 template<class Type>
39 Foam::Function1<Type>::Function1(const Function1<Type>& de)
40 :
41  tmp<Function1<Type>>::refCount(),
42  name_(de.name_)
43 {}
44 
45 
46 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
47 
48 template<class Type>
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
55 template<class Type>
57 {
58  return name_;
59 }
60 
61 
62 template<class Type>
64 {}
65 
66 
67 template<class Type>
68 Type Foam::Function1<Type>::value(const scalar x) const
69 {
71 
72  return Zero;
73 }
74 
75 
76 template<class Type>
77 Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
78 {
80 
81  return Zero;
82 }
83 
84 
85 template<class Function1Type>
88 (
89  const scalarField& x
90 ) const
91 {
92  tmp<Field<Type>> tfld(new Field<Type>(x.size()));
93  Field<Type>& fld = tfld.ref();
94 
95  forAll(x, i)
96  {
97  fld[i] = Function1Type::value(x[i]);
98  }
99  return tfld;
100 }
101 
102 
103 template<class Function1Type>
105 (
106  const word& entryName,
107  const dictionary& dict
108 )
109 :
110  Function1Type(entryName, dict)
111 {}
112 
113 
114 template<class Function1Type>
117 {
118  return tmp<Function1<Type>>
119  (
121  );
122 }
123 
124 
125 template<class Function1Type>
128 (
129  const scalarField& x1,
130  const scalarField& x2
131 ) const
132 {
133  tmp<Field<Type>> tfld(new Field<Type>(x1.size()));
134  Field<Type>& fld = tfld.ref();
135 
136  forAll(x1, i)
137  {
138  fld[i] = Function1Type::integrate(x1[i], x2[i]);
139  }
140 
141  return tfld;
142 }
143 
144 
145 template<class Type>
147 {
148  os.writeKeyword(name_) << type();
149 }
150 
151 
152 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
153 
154 template<class Type>
155 Foam::Ostream& Foam::operator<<
156 (
157  Ostream& os,
158  const Function1<Type>& f1
159 )
160 {
161  // Check state of Ostream
162  os.check
163  (
164  "Ostream& operator<<(Ostream&, const Function1<Type>&)"
165  );
166 
167  os << f1.name_;
168  f1.writeData(os);
169 
170  return os;
171 }
172 
173 
174 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
type
Types of root.
Definition: Roots.H:52
virtual tmp< Field< Type > > value(const scalarField &x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:88
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.C:116
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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:163
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
scalar f1
Definition: createFields.H:28
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:146
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:68
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
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:77
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
virtual ~Function1()
Destructor.
Definition: Function1.C:49
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: Function1.C:63
virtual tmp< Field< Type > > integrate(const scalarField &x1, const scalarField &x2) const
Integrate between two (scalar) values.
Definition: Function1.C:128
FieldFunction1(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
Definition: Function1.C:105
A class for managing temporary objects.
Definition: PtrList.H:53
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366