mapPatchChange.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::mapPatchChange
26 
27 Description
28  Class containing mesh-to-mesh mapping information after a patch change
29  operation.
30 
31 SourceFiles
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef mapPatchChange_H
36 #define mapPatchChange_H
37 
38 #include "labelList.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 /*---------------------------------------------------------------------------*\
46  Class mapPatchChange Declaration
47 \*---------------------------------------------------------------------------*/
48 
49 class mapPatchChange
50 {
51  // Private Data
52 
53  //- Old patches
54  const label nOldPatches_;
55 
56  //- Patch mapping array
57  const labelList patchMap_;
58 
59 public:
60 
61  // Constructors
62 
63  //- Construct from components
65  :
66  nOldPatches_(nOldPatches),
67  patchMap_(patchMap)
68  {}
69 
70 
71  // Member Functions
72 
73  // Access
74 
75  //- Number of old patches
76  label nOldPatches() const
77  {
78  return nOldPatches_;
79  }
80 
81  //- Patch map. Size of current patches.
82  // -1 : patch was added
83  // >=0 : old position of patch
84  // any original patch which is not in the list has been deleted
85  const labelList& patchMap() const
86  {
87  return patchMap_;
88  }
89 
90 
91  // Utility functions
92 
93  //- Labels of added patches
94  labelList addedPatches() const
95  {
96  labelList added(patchMap_.size());
97 
98  label addedI = 0;
99 
100  forAll(patchMap_, patchi)
101  {
102  if (patchMap_[patchi] == -1)
103  {
104  added[addedI++] = patchi;
105  }
106  }
107  added.setSize(addedI);
108  return added;
109  }
110 
111  //- Labels (on old mesh) of deleted patches
112  labelList deletedPatches() const
113  {
114  labelList oldToNew(nOldPatches_, -1);
115 
116  // Mark all preserved patches
117  forAll(patchMap_, patchi)
118  {
119  if (patchMap_[patchi] != -1)
120  {
121  oldToNew[patchMap_[patchi]] = patchi;
122  }
123  }
124 
125  // Extract -1 elements from oldToNew. These are the deleted
126  // patches.
127  label deletedI = 0;
128 
129  forAll(oldToNew, oldPatchi)
130  {
131  if (oldToNew[oldPatchi] == -1)
132  {
133  oldToNew[deletedI++] = oldPatchi;
134  }
135  }
136 
137  oldToNew.setSize(deletedI);
138 
139  return oldToNew;
140  }
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #endif
151 
152 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Class containing mesh-to-mesh mapping information after a patch change operation. ...
labelList addedPatches() const
Labels of added patches.
label nOldPatches() const
Number of old patches.
const labelList & patchMap() const
Patch map. Size of current patches.
void setSize(const label)
Reset size of List.
Definition: List.C:281
label patchi
labelList deletedPatches() const
Labels (on old mesh) of deleted patches.
mapPatchChange(const label nOldPatches, const labelList &patchMap)
Construct from components.
Namespace for OpenFOAM.