faMeshSubset.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 "boolList.H"
30 #include "BitOps.H"
31 #include "Pstream.H"
32 #include "emptyFaPatch.H"
33 #include "cyclicFaPatch.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
43 {
44  if (!subMeshPtr_)
45  {
47  << "Mesh is not subsetted!" << nl
48  << abort(FatalError);
49 
50  return false;
51  }
52 
53  return true;
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 :
61  baseMesh_(baseMesh),
62  subMeshPtr_(nullptr),
63  edgeFlipMapPtr_(nullptr),
64  pointMap_(),
65  faceMap_(),
66  cellMap_(),
67  patchMap_()
68 {}
69 
70 
72 :
73  faMeshSubset(baseMesh)
74 {
75  reset(Foam::zero{});
76 }
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 {
83  subMeshPtr_.reset(nullptr);
84  edgeFlipMapPtr_.reset(nullptr);
85 
86  pointMap_.clear();
87  faceMap_.clear();
88  cellMap_.clear();
89  patchMap_.clear();
90 }
91 
92 
94 {
95  clear();
96 }
97 
98 
100 {
101  clear();
102 
103  // Create zero-sized subMesh
104  subMeshPtr_.reset
105  (
106  new faMesh(baseMesh_, Foam::zero{})
107  );
108  auto& newSubMesh = subMeshPtr_();
109 
110 
111  // Clone non-processor patches
112  {
113  const faBoundaryMesh& oldBoundary = baseMesh_.boundary();
114  const faBoundaryMesh& newBoundary = newSubMesh.boundary();
115 
116  faPatchList newPatches(oldBoundary.nNonProcessor());
117 
118  patchMap_ = identity(newPatches.size());
119 
120  forAll(newPatches, patchi)
121  {
122  newPatches.set
123  (
124  patchi,
125  oldBoundary[patchi].clone
126  (
127  newBoundary,
128  labelList(), // edgeLabels
129  patchi,
130  oldBoundary[patchi].ngbPolyPatchIndex()
131  )
132  );
133  }
134 
135  newSubMesh.addFaPatches(newPatches);
136  }
137 }
138 
139 
140 // ************************************************************************* //
PtrList< faPatch > faPatchList
Store lists of faPatch as a PtrList.
Definition: faPatch.H:59
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
Definition: faMeshSubset.H:61
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool checkHasSubMesh() const
FatalError if subset has not been performed.
Definition: faMeshSubset.C:35
void reset()
Reset subMesh and all maps. Same as clear()
Definition: faMeshSubset.C:86
patchWriters clear()
errorManip< error > abort(error &err)
Definition: errorManip.H:139
faMeshSubset(const faMeshSubset &)=delete
No copy construct.
static word exposedPatchName
Name for exposed internal edges (default: oldInternalEdges)
Definition: faMeshSubset.H:136
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
List< label > labelList
A List of labels.
Definition: List.H:62
void clear()
Reset subMesh and all maps.
Definition: faMeshSubset.C:74