faMeshSubsetTemplates.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) 2022 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 "faMeshSubset.H"
29#include "areaFaMesh.H"
30#include "edgeFaMesh.H"
31#include "areaFields.H"
32#include "edgeFields.H"
33#include "emptyFaPatchFields.H"
35#include "flipOp.H"
36
37// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
38
39template<class Type>
41<
43>
45(
47 const faMesh& sMesh,
48 const bool allowUnmapped
49)
50{
51 // 1. Create the complete field with dummy patch fields
52 PtrList<faPatchField<Type>> patchFields(sMesh.boundary().size());
53
54 forAll(patchFields, patchi)
55 {
56 patchFields.set
57 (
58 patchi,
60 (
62 sMesh.boundary()[patchi],
64 )
65 );
66 }
67
69 (
71 (
72 "subset"+vf.name(),
73 sMesh.time().timeName(),
74 sMesh.thisDb(),
77 ),
78 sMesh,
79 vf.dimensions(),
81 // Field<Type>(vf.primitiveField(), cellMap),
82 patchFields
83 );
84 auto& result = tresult.ref();
85 result.oriented() = vf.oriented();
86
87
88 // 2. Change the faPatchFields to the correct type using a mapper
89 // constructor (with reference to the now correct internal field)
90
91 auto& bf = result.boundaryFieldRef();
92
93 forAll(bf, patchi)
94 {
95 // Construct addressing
96 const faPatch& subPatch = sMesh.boundary()[patchi];
97
98 labelList directAddressing;
99 directFaPatchFieldMapper mapper(directAddressing);
100
101 // allowUnmapped : special mode for if we do not want to be
102 // warned for unmapped faces (e.g. from faMeshDistribute).
103 const bool hasUnmapped = mapper.hasUnmapped();
104 if (allowUnmapped)
105 {
106 mapper.hasUnmapped() = false;
107 }
108
109 bf.set
110 (
111 patchi,
113 (
114 vf.boundaryField()[patchi],
115 subPatch,
116 result(),
117 mapper
118 )
119 );
120
121 if (allowUnmapped && hasUnmapped)
122 {
123 // Set unmapped values to zeroGradient. This is the default
124 // action for unmapped faPatchFields. Note that this bypasses
125 // any special logic for handling unmapped faPatchFields but
126 // since this is only used inside faMeshDistribute ...
127
128 tmp<Field<Type>> tfld(bf[patchi].patchInternalField());
129 const Field<Type>& fld = tfld();
130
131 Field<Type> value(bf[patchi]);
132 forAll(directAddressing, i)
133 {
134 if (directAddressing[i] == -1)
135 {
136 value[i] = fld[i];
137 }
138 }
139 bf[patchi].faPatchField<Type>::operator=(value);
140 }
141 }
142
143 return tresult;
144}
145
146
147template<class Type>
149<
151>
153(
155 const faMesh& sMesh
156)
157{
158 // 1. Create the complete field with dummy patch fields
159 PtrList<faePatchField<Type>> patchFields(sMesh.boundary().size());
160
161 forAll(patchFields, patchi)
162 {
163 patchFields.set
164 (
165 patchi,
167 (
169 sMesh.boundary()[patchi],
171 )
172 );
173 }
174
176 (
178 (
179 "subset"+vf.name(),
180 sMesh.time().timeName(),
181 sMesh.thisDb(),
184 ),
185 sMesh,
186 vf.dimensions(),
187 Field<Type>(),
188 // Field<Type>
189 // (
190 // vf.primitiveField(),
191 // SubList<label>(edgeMap, sMesh.nInternalEdges())
192 // ),
193 patchFields
194 );
195 auto& result = tresult.ref();
196 result.oriented() = vf.oriented();
197
198
199 // 2. Change the faePatchFields to the correct type using a mapper
200 // constructor (with reference to the now correct internal field)
201
202 auto& bf = result.boundaryFieldRef();
203
204 forAll(bf, patchi)
205 {
206 // Construct addressing
207 const faPatch& subPatch = sMesh.boundary()[patchi];
208
209 labelList directAddressing;
210 directFaPatchFieldMapper mapper(directAddressing);
211
212 bf.set
213 (
214 patchi,
216 (
217 vf.boundaryField()[patchi],
218 subPatch,
219 result(),
220 mapper
221 )
222 );
223 }
224
225 return tresult;
226}
227
228
229// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
230
231template<class Type>
233<
235>
237(
239 const bool allowUnmapped
240) const
241{
242 if (subMeshPtr_)
243 {
244 return interpolate(vf, *subMeshPtr_);
245 }
246
247 return vf;
248}
249
250
251template<class Type>
253<
255>
257(
259 const bool allowUnmapped
260) const
261{
262 if (subMeshPtr_)
263 {
264 return interpolate(vf, *subMeshPtr_);
265 }
266
267 return vf;
268}
269
270
271// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
const dimensionSet & dimensions() const
Return dimensions.
const orientedType & oriented() const noexcept
Return oriented type.
A templated direct mapper for the given FieldMapper type.
virtual bool hasUnmapped() const
Any unmapped values?
Generic templated field type.
Definition: Field.H:82
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
const T * set(const label i) const
Definition: PtrList.H:138
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:100
const Time & time() const
Return reference to time.
Definition: faMesh.C:673
const faBoundaryMesh & boundary() const noexcept
Return constant reference to boundary mesh.
Definition: faMeshI.H:38
virtual const objectRegistry & thisDb() const
Return reference to the mesh database.
Definition: faMesh.C:697
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: faPatchField.H:82
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:78
faePatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cove...
Definition: faePatchField.H:83
bool interpolate() const noexcept
Same as isPointData()
A class for managing temporary objects.
Definition: tmp.H:65
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333