initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / meshes / polyMesh / mapPolyMesh / mapPatchChange / mapPatchChange.H
blob9dddef38c515f6a61111cdfccc41fc0983a35b67
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::mapPatchChange
28 Description
29     Class containing mesh-to-mesh mapping information after a patch change
30     operation.
32 SourceFiles
34 \*---------------------------------------------------------------------------*/
36 #ifndef mapPatchChange_H
37 #define mapPatchChange_H
39 #include "labelList.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 /*---------------------------------------------------------------------------*\
47                            Class mapPatchChange Declaration
48 \*---------------------------------------------------------------------------*/
50 class mapPatchChange
52     // Private data
54         //- Old patches
55         const label nOldPatches_;
57         //- Patch mapping array
58         const labelList patchMap_;
60 public:
62     // Constructors
64         //- Construct from components
65         mapPatchChange(const label nOldPatches, const labelList& patchMap)
66         :
67             nOldPatches_(nOldPatches),
68             patchMap_(patchMap)
69         {}
72     // Member Functions
74         // Access
76             //- Number of old patches
77             label nOldPatches() const
78             {
79                 return nOldPatches_;
80             }
82             //- Patch map. Size of current patches.
83             //  -1  : patch was added
84             //  >=0 : old position of patch
85             //  any original patch which is not in the list has been deleted
86             const labelList& patchMap() const
87             {
88                 return patchMap_;
89             }
92         // Utility functions
94             //- labels of added patches
95             labelList addedPatches() const
96             {
97                 labelList added(patchMap_.size());
99                 label addedI = 0;
101                 forAll(patchMap_, patchI)
102                 {
103                     if (patchMap_[patchI] == -1)
104                     {
105                         added[addedI++] = patchI;
106                     }
107                 }
108                 added.setSize(addedI);
109                 return added;
110             }
112             //- labels (on old mesh) of deleted patches
113             labelList deletedPatches() const
114             {
115                 labelList oldToNew(nOldPatches_, -1);
117                 // Mark all preserved patches
118                 forAll(patchMap_, patchI)
119                 {
120                     if (patchMap_[patchI] != -1)
121                     {
122                         oldToNew[patchMap_[patchI]] = patchI;
123                     }
124                 }
126                 // Extract -1 elements from oldToNew. These are the deleted
127                 // patches.
128                 label deletedI = 0;
130                 forAll(oldToNew, oldPatchI)
131                 {
132                     if (oldToNew[oldPatchI] == -1)
133                     {
134                         oldToNew[deletedI++] = oldPatchI;
135                     }
136                 }
138                 oldToNew.setSize(deletedI);
140                 return oldToNew;
141             }
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 } // End namespace Foam
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 #endif
153 // ************************************************************************* //