Loading...
Searching...
No Matches
LookupField.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) 2024 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "volFields.H"
29#include "volMesh.H"
30#include "surfaceFields.H"
31#include "surfaceMesh.H"
32#include "pointFields.H"
33#include "pointMesh.H"
35
36// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37
38template<class Type>
40(
41 const polyPatch& pp,
42 const word& redirectType,
43 const word& entryName,
44 const dictionary& dict,
45 const bool faceValues
46)
57 const polyPatch& pp
58)
60 PatchFunction1<Type>(rhs, pp),
62{}
63
64
65template<class Type>
67(
69)
70:
71 LookupField<Type>(rhs, rhs.patch())
72{}
73
74
75// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76
77template<class Type>
80{
82
84 const label patchi = patchFunction1Base::patch().index();
85
86 if (this->faceValues())
87 {
90
91 // Try:
92 // - as volField in local scope
93 // - as surfaceField in local scope
94 // - as UniformDimensionedField recursively
95
96 const regIOobject* ptr = db.cfindIOobject(name_, false);
97
98 if (ptr)
99 {
100 const auto* vPtr = dynamic_cast<const VType*>(ptr);
101 if (vPtr)
102 {
103 return vPtr->boundaryField()[patchi];
104 }
105
106 const auto* sPtr = dynamic_cast<const SType*>(ptr);
107 if (sPtr)
108 {
109 return sPtr->boundaryField()[patchi];
110 }
111
112 const auto* uPtr = dynamic_cast<const UType*>(ptr);
113 if (uPtr)
114 {
115 return Field<Type>(this->size(), uPtr->value());
116 }
117 }
118
119 // Done db level. Try recursion
120 ptr = db.parent().cfindIOobject(name_, true);
121
122 if (ptr)
123 {
124 const auto* uPtr = dynamic_cast<const UType*>(ptr);
125 if (uPtr)
126 {
127 return Field<Type>(this->size(), uPtr->value());
128 }
129 }
130
132 << nl
133 << " failed lookup of " << name_
134 << " (objectRegistry "
135 << db.name()
136 << ")\n available objects of type " << VType::typeName
137 << ':' << nl
138 << db.names<VType>() << nl
139 << " available objects of type " << SType::typeName
140 << ':' << nl
141 << db.names<SType>() << nl
142 << " available objects of type " << UType::typeName
143 << ':' << nl
144 << db.names<UType>() << nl
145 << exit(FatalError);
146 return Field<Type>::null();
147 }
148 else
149 {
150 // Assume pointField
151 typedef GeometricField<Type, pointPatchField, pointMesh> PType;
152
153 const regIOobject* ptr = db.cfindIOobject(name_, false);
154
155 if (ptr)
156 {
157 const auto* pPtr = dynamic_cast<const PType*>(ptr);
158 if (pPtr)
159 {
160 return pPtr->boundaryField()[patchi].patchInternalField();
161 }
162 }
163
164 // Re-do as uniform field. Note: could repeat logic above
165 const auto& obj = db.lookupObject<UType>(name_, true);
166
167 return Field<Type>(this->size(), obj.value());
168 }
169}
170
171
172template<class Type>
175(
176 const scalar x1,
177 const scalar x2
178) const
179{
180 return (x2-x1)*value(0.5*(x1+x2));
181}
182
183
184template<class Type>
186(
187 Ostream& os
188) const
189{
191 os.writeEntry(this->name(), type());
192 os.beginBlock(word(this->name() + "Coeffs"));
193 writeEntries(os);
194 os.endBlock();
195}
196
197
198// ************************************************************************* //
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
static const Field< Type > & null() noexcept
Return a null Field (reference to a nullObject). Behaves like an empty Field.
Definition Field.H:192
Generic GeometricField class.
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition Ostream.C:90
PatchFunction1 to lookup volField/surfaceField or pointField from an objectregistry and return its va...
Definition LookupField.H:89
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual tmp< Field< Type > > value(const scalar x) const
Return Lookup value.
Definition LookupField.C:72
LookupField(const polyPatch &pp, const word &redirectType, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from entry name, dictionary and optional registry.
Definition LookupField.C:33
const polyPatch const word const word & entryName
virtual void writeData(Ostream &os) const
Write in dictionary format.
const polyPatch const word const word const dictionary & dict
const polyPatch & pp
const polyPatch const word const word const dictionary const bool faceValues
Dimensioned<Type> registered with the database as a registered IOobject which has the functionality o...
word name_
Key of object.
Definition lookupBase.H:55
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition lookupBase.C:39
lookupBase(const dictionary &dict)
Construct from dictionary.
Definition lookupBase.C:25
Registry of regIOobjects.
const objectRegistry & parent() const noexcept
Return the parent objectRegistry.
const regIOobject * cfindIOobject(const word &name, const bool recursive=false) const
Return const pointer to the regIOobject.
wordList names() const
The unsorted names of all objects.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
const polyPatch & patch() const noexcept
Reference to the patch.
const objectRegistry & obr() const
Return the object registry (ie, the mesh).
label size() const
Number of faces or points on the patch.
label index() const noexcept
The index of this patch in the boundaryMesh.
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
auto & name
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
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::surfaceFields.