Loading...
Searching...
No Matches
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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2020-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "Function1.H"
30#include "Time.H"
31// Required by clang 5 for correct instantiation of Function1::New
32#include "Constant.H"
33
34// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
35
36template<class Type>
38(
39 const word& entryName,
40 const objectRegistry* obrPtr
42:
43 function1Base(entryName, obrPtr)
44{}
45
46
47template<class Type>
49(
50 const word& entryName,
51 const dictionary& dict,
52 const objectRegistry* obrPtr
54:
55 function1Base(entryName, dict, obrPtr)
56{}
57
58
59template<class Type>
61:
63{}
64
65
66// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67
68template<class Type>
69Type Foam::Function1<Type>::value(const scalar x) const
72 return Type();
73}
74
75
76template<class Type>
78(
79 const scalarField& x
80) const
83 return nullptr;
84}
85
86
87template<class Type>
88Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
91 return Type();
92}
93
94
95template<class Type>
97(
98 const scalarField& x1,
99 const scalarField& x2
100) const
101{
103 return nullptr;
104}
105
106
107template<class Function1Type>
110(
111 const scalarField& x
112) const
113{
114 auto tfld = tmp<Field<Type>>::New(x.size());
115 auto& fld = tfld.ref();
116
117 forAll(x, i)
118 {
119 fld[i] = Function1Type::value(x[i]);
120 }
121 return tfld;
122}
123
124
125template<class Function1Type>
127(
128 const word& entryName,
129 const dictionary& dict,
130 const objectRegistry* obrPtr
131)
133 Function1Type(entryName, dict, obrPtr)
134{}
135
136
137template<class Function1Type>
140(
141 const scalarField& x1,
142 const scalarField& x2
143) const
144{
145 auto tfld = tmp<Field<Type>>::New(x1.size());
146 auto& fld = tfld.ref();
147
148 forAll(x1, i)
149 {
150 fld[i] = Function1Type::integrate(x1[i], x2[i]);
152
153 return tfld;
154}
155
157template<class Type>
159{}
160
161
162template<class Type>
164{
165 os.writeKeyword(name_) << type();
166}
167
168
169// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
170
171template<class Type>
172Foam::Ostream& Foam::operator<<
173(
174 Ostream& os,
175 const Function1<Type>& rhs
176)
177{
178 os.check(FUNCTION_NAME);
179
180 os << rhs.name();
181 rhs.writeData(os);
182
183 return os;
184}
185
186
187// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
virtual tmp< Field< Type > > integrate(const scalarField &x1, const scalarField &x2) const
Integrate between two (scalar) values.
Definition Function1.C:133
virtual tmp< Field< Type > > value(const scalarField &x) const
Return value as a function of (scalar) independent variable.
Definition Function1.C:103
FieldFunction1(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name and dictionary.
Definition Function1.C:120
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition Function1.H:92
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition Function1.C:156
Function1(const word &entryName, const objectRegistry *obrPtr=nullptr)
Construct from entry name.
Definition Function1.C:31
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition Function1.C:151
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition Function1.C:62
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition Function1.C:81
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
function1Base(const word &entryName, const objectRegistry *obrPtr=nullptr)
Construct from entry name and optional registry.
const word name_
Name of entry.
Registry of regIOobjects.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299