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 -------------------------------------------------------------------------------
10 License
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 
39 template<class Type>
41 <
43 >
45 (
46  const GeometricField<Type, faPatchField, areaMesh>& vf,
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 
68  auto tresult = tmp<GeometricField<Type, faPatchField, areaMesh>>::New
69  (
70  IOobject
71  (
72  "subset"+vf.name(),
73  sMesh.time().timeName(),
74  sMesh.thisDb(),
77  ),
78  sMesh,
79  vf.dimensions(),
80  Field<Type>(),
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 
147 template<class Type>
148 Foam::tmp
149 <
151 >
153 (
154  const GeometricField<Type, faePatchField, edgeMesh>& vf,
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 
175  auto tresult = tmp<GeometricField<Type, faePatchField, edgeMesh>>::New
176  (
177  IOobject
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 
231 template<class Type>
232 Foam::tmp
233 <
235 >
237 (
238  const GeometricField<Type, faPatchField, areaMesh>& vf,
239  const bool allowUnmapped
240 ) const
241 {
242  if (subMeshPtr_)
243  {
244  return interpolate(vf, *subMeshPtr_);
245  }
246 
247  return vf;
248 }
249 
250 
251 template<class Type>
252 Foam::tmp
253 <
255 >
257 (
258  const GeometricField<Type, faePatchField, edgeMesh>& vf,
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 // ************************************************************************* //
static tmp< faPatchField< Type > > New(const word &patchFieldType, const word &actualPatchType, const faPatch &, const DimensionedField< Type, areaMesh > &)
Return a pointer to a new patchField created on freestore given patch and internal field...
static const word & calculatedType() noexcept
The type name for calculated patch fields.
static const DimensionedField< Type, GeoMesh > & null() noexcept
Return a null DimensionedField (reference to a nullObject).
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 >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Generic GeometricField class.
Ignore writing from objectRegistry::writeObject()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
static tmp< GeometricField< Type, faPatchField, areaMesh > > interpolate(const GeometricField< Type, faPatchField, areaMesh > &, const faMesh &sMesh, const bool allowUnmapped=false)
Map area field.
DirectFieldMapper< faPatchFieldMapper > directFaPatchFieldMapper
A direct faPatchFieldMapper.
static const word & calculatedType() noexcept
The type name for calculated patch fields.
Definition: faPatchField.H:174
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Nothing to be read.
static tmp< faePatchField< Type > > New(const word &patchFieldType, const faPatch &, const DimensionedField< Type, edgeMesh > &)
Return a pointer to a new patchField created on freestore given.
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50