1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Post-processing mesh subset tool. Given the original mesh and the
30 list of selected cells, it creates the mesh consisting only of the
31 desired cells, with the mapping list for points, faces, and cells.
33 Puts all exposed internal faces into either
34 - a user supplied patch
35 - a newly created patch "oldInternalFaces"
37 - setCellSubset is for small subsets. Uses Maps to minimize memory.
38 - setLargeCellSubset is for largish subsets (>10% of mesh).
39 Uses labelLists instead.
41 - setLargeCellSubset does coupled patch subsetting as well. If it detects
42 a face on a coupled patch 'losing' its neighbour it will move the
43 face into the oldInternalFaces patch.
45 - if a user supplied patch is used the mapping becomes a problem.
46 Do the new faces get the value of the internal face they came from?
47 What if e.g. the user supplied patch is a fixedValue 0? So for now
48 they get the face of existing patch face 0.
53 \*---------------------------------------------------------------------------*/
55 #ifndef fvMeshSubset_H
56 #define fvMeshSubset_H
59 #include "pointMesh.H"
60 #include "fvPatchFieldMapper.H"
61 #include "PointPatchFieldMapper.H"
62 #include "GeometricField.H"
64 #include "surfaceMesh.H"
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 /*---------------------------------------------------------------------------*\
72 Class fvMeshSubset Declaration
73 \*---------------------------------------------------------------------------*/
82 //- Patch-field subset interpolation class
83 class patchFieldSubset
85 public fvPatchFieldMapper
87 label sizeBeforeMapping_;
89 labelField directAddressing_;
95 //- Construct from components
96 patchFieldSubset(const label sbm, const labelList& da)
98 sizeBeforeMapping_(sbm),
102 //- Construct given addressing
103 patchFieldSubset(const fvMeshSubset& ms, const label patchNo)
107 ms.baseMesh().boundary()[ms.patchMap()[patchNo]].size()
111 static_cast<const labelField&>
116 ms.subMesh().boundary()[patchNo].size(),
117 ms.subMesh().boundary()[patchNo].patch().start()
120 - ms.baseMesh().boundary()
121 [ms.patchMap()[patchNo]].patch().start()
124 // If patchNo supplied so exposed internal faces or uncoupled
125 // patch faces get into existing patch what to do with
126 // mapping? Truncate to 0 for now.
129 ms.baseMesh().boundary()[ms.patchMap()[patchNo]].size();
131 forAll(directAddressing_, i)
133 label& address = directAddressing_[i];
135 if (address < 0 || address >= sz)
145 virtual ~patchFieldSubset()
153 return directAddressing_.size();
156 label sizeBeforeMapping() const
158 return directAddressing_.size();
166 const unallocLabelList& directAddressing() const
168 return directAddressing_;
173 //- Patch-field subset interpolation class
174 class pointPatchFieldSubset
176 public PointPatchFieldMapper
179 const labelList& directAddressing_;
186 //- Construct given addressing
187 pointPatchFieldSubset(const labelList& directAddressing)
189 directAddressing_(directAddressing)
194 virtual ~pointPatchFieldSubset()
202 return directAddressing_.size();
205 label sizeBeforeMapping() const
207 return directAddressing_.size();
215 const unallocLabelList& directAddressing() const
217 return directAddressing_;
226 //- Reference to original mesh
227 const fvMesh& baseMesh_;
229 //- Subset fvMesh pointer
230 fvMesh* fvMeshSubsetPtr_;
232 //- Subset pointMesh pointer
233 mutable pointMesh* pointMeshSubsetPtr_;
235 //- Point mapping array
238 //- Face mapping array
241 //- Cell mapping array
244 //- Patch mapping array
248 // Private Member Functions
250 //- Disallow default bitwise copy construct
251 fvMeshSubset(const fvMeshSubset&);
253 //- Disallow default bitwise assignment
254 void operator=(const fvMeshSubset&);
257 //- Check if subset has been performed
258 bool checkCellSubset() const;
260 //- Mark points in Map
261 static void markPoints(const labelList&, Map<label>&);
263 //- Mark points (with 0) in labelList
264 static void markPoints(const labelList&, labelList&);
266 //- Adapt nCellsUsingFace for coupled faces becoming 'uncoupled'.
267 void doCoupledPatches
270 labelList& nCellsUsingFace
274 static labelList subset
277 const labelList& selectedElements,
278 const labelList& subsetMap
281 //- Create zones for submesh
284 //- Make dictionaries in case they are not present
285 // Creates fvSchemes and fvSolution copying from base
286 void makeFvDictionaries();
293 //- Construct given a mesh
294 explicit fvMeshSubset(const IOobject&, const fvMesh&);
306 //- Set the subset. Create "oldInternalFaces" patch for exposed
307 // internal faces (patchID==-1) or use supplied patch.
308 // Does not handle coupled patches correctly if only one side
312 const labelHashSet& globalCellMap,
313 const label patchID = -1
316 //- Set the subset from all cells with region == currentRegion.
317 // Create "oldInternalFaces" patch for exposed
318 // internal faces (patchID==-1) or use supplied patch.
319 // Handles coupled patches by if nessecary making coupled patch
320 // face part of patchID (so uncoupled)
321 void setLargeCellSubset
323 const labelList& region,
324 const label currentRegion,
325 const label patchID = -1,
326 const bool syncCouples = true
329 //- setLargeCellSubset but with labelHashSet.
330 void setLargeCellSubset
332 const labelHashSet& globalCellMap,
333 const label patchID = -1,
334 const bool syncPar = true
340 //- Return reference to base mesh
341 const fvMesh& baseMesh() const
346 //- Return reference to subset mesh
347 const fvMesh& subMesh() const;
351 //- Return reference to demand-driven subset pointMesh
352 const pointMesh& subPointMesh() const;
354 pointMesh& subPointMesh();
357 const labelList& pointMap() const;
360 const labelList& faceMap() const;
363 const labelList& cellMap() const;
366 const labelList& patchMap() const;
371 //- Map volume field given map addressing
372 // - it does not patch up the exposed patches with surface fields
373 // - it does not handle patch type creation correctly
374 // Please use only in dummy mapping operations
377 static tmp<GeometricField<Type, fvPatchField, volMesh> >
380 const GeometricField<Type, fvPatchField, volMesh>&,
382 const labelList& patchMap,
383 const labelList& cellMap,
384 const labelList& faceMap
389 tmp<GeometricField<Type, fvPatchField, volMesh> >
392 const GeometricField<Type, fvPatchField, volMesh>&
395 //- Map surface field
397 static tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
400 const GeometricField<Type, fvsPatchField, surfaceMesh>&,
402 const labelList& patchMap,
403 const labelList& faceMap
407 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
410 const GeometricField<Type, fvsPatchField, surfaceMesh>&
415 static tmp<GeometricField<Type, pointPatchField, pointMesh> >
418 const GeometricField<Type, pointPatchField, pointMesh>&,
419 const pointMesh& sMesh,
420 const labelList& patchMap,
421 const labelList& pointMap
425 tmp<GeometricField<Type, pointPatchField, pointMesh> >
428 const GeometricField<Type, pointPatchField, pointMesh>&
433 virtual bool writeData(Foam::Ostream&) const
441 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443 } // End namespace Foam
445 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
448 # include "fvMeshSubsetInterpolate.C"
451 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
455 // ************************************************************************* //