Function1.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 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 Type>
87 (
88  const scalarField& x
89 ) const
90 {
91  tmp<Field<Type>> tfld(new Field<Type>(x.size()));
92  Field<Type>& fld = tfld.ref();
93 
94  forAll(x, i)
95  {
96  fld[i] = this->value(x[i]);
97  }
98  return tfld;
99 }
100 
101 
102 template<class Type>
104 (
105  const scalarField& x1,
106  const scalarField& x2
107 ) const
108 {
109  tmp<Field<Type>> tfld(new Field<Type>(x1.size()));
110  Field<Type>& fld = tfld.ref();
111 
112  forAll(x1, i)
113  {
114  fld[i] = this->integrate(x1[i], x2[i]);
115  }
116  return tfld;
117 }
118 
119 
120 template<class Type>
122 {
123  os.writeKeyword(name_) << type();
124 }
125 
126 
127 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
128 
129 template<class Type>
130 Foam::Ostream& Foam::operator<<
131 (
132  Ostream& os,
133  const Function1<Type>& f1
134 )
135 {
136  // Check state of Ostream
137  os.check
138  (
139  "Ostream& operator<<(Ostream&, const Function1<Type>&)"
140  );
141 
142  os << f1.name_;
143  f1.writeData(os);
144 
145  return os;
146 }
147 
148 
149 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
refCount()
Construct null initializing count to 0.
Definition: refCount.H:70
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:121
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
scalar f1
Definition: createFields.H:28
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
const word name_
Name of entry.
Definition: Function1.H:76
static const zero Zero
Definition: zero.H:91
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:77
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
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
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:68
A class for managing temporary objects.
Definition: PtrList.H:54
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366