initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicMesh / polyTopoChange / repatchPolyTopoChanger / repatchPolyTopoChanger.C
blob2cb88d9f34d625de97cee05cb0754e0d6e42759e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 Description
26     A mesh which allows changes in the patch distribution of the
27     faces.  The change in patching is set using changePatchID.  For a
28     boundary face, a new patch ID is given.  If the face is internal,
29     it will be added to the first patch and its opposite to the second
30     patch (take care with face orientation!).
32 \*---------------------------------------------------------------------------*/
34 #include "repatchPolyTopoChanger.H"
35 #include "polyTopoChanger.H"
36 #include "mapPolyMesh.H"
37 #include "polyModifyFace.H"
39 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
41 Foam::polyTopoChange& Foam::repatchPolyTopoChanger::meshMod()
43     if (meshModPtr_.empty())
44     {
45         meshModPtr_.reset(new polyTopoChange(mesh_));
46     }
47     return meshModPtr_();
51 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
53 Foam::repatchPolyTopoChanger::repatchPolyTopoChanger(polyMesh& mesh)
55     mesh_(mesh),
56     meshModPtr_(NULL)
60 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
62 void Foam::repatchPolyTopoChanger::changePatches
64     const List<polyPatch*>& patches
67     if (meshModPtr_.valid())
68     {
69         FatalErrorIn
70         (
71             "repatchPolyTopoChanger::changePatches(const List<polyPatch*>&)"
72         )   << "Cannot change patches after having changed faces. " << nl
73             << "Please call changePatches first."
74             << exit(FatalError);
75     }
76     meshModPtr_.clear();
77     mesh_.removeBoundary();
78     mesh_.addPatches(patches);
82 void Foam::repatchPolyTopoChanger::changePatchID
84     const label faceID,
85     const label patchID
88     if (polyTopoChanger::debug)
89     {
90         // Check that the request is possible
91         if
92         (
93             faceID >= mesh_.faces().size()
94          || patchID >= mesh_.boundaryMesh().size()
95          || mesh_.isInternalFace(faceID)
96         )
97         {
98             FatalErrorIn
99             (
100                 "void Foam::repatchPolyTopoChanger::changePatchID\n"
101                 "(\n"
102                 "    const label faceID,\n"
103                 "    const label patchID\n"
104                 ")\n"
105             )   << "Error in definition.  faceID: " << faceID
106                 << " patchID: " << patchID << ".  "
107                 << "Labels out of range or internal face."
108                 << abort(FatalError);
109         }
110     }
112     const label zoneID = mesh_.faceZones().whichZone(faceID);
114     bool zoneFlip = false;
116     if (zoneID >= 0)
117     {
118         const faceZone& fZone = mesh_.faceZones()[zoneID];
120         zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
121     }
123     meshMod().setAction
124     (
125         polyModifyFace
126         (
127             mesh_.faces()[faceID],              // face
128             faceID,                             // face ID
129             mesh_.faceOwner()[faceID],          // owner
130             -1,                                 // neighbour
131             false,                              // flip flux
132             patchID,                            // patch ID
133             false,                              // remove from zone
134             zoneID,                             // zone ID
135             zoneFlip                            // zone flip
136         )
137     );
141 void Foam::repatchPolyTopoChanger::setFaceZone
143     const label faceID,
144     const label zoneID,
145     const bool zoneFlip
148     if (polyTopoChanger::debug)
149     {
150         // Check that the request is possible
151         if (faceID > mesh_.faces().size())
152         {
153             FatalErrorIn
154             (
155                 "void Foam::repatchPolyTopoChanger::setFaceZone"
156                 "(\n"
157                 "    const label faceID,\n"
158                 "    const label zoneID,\n"
159                 "    const bool flip\n"
160                 ")\n"
161             )   << "Error in definition.  faceID: " << faceID
162                 << "out of range."
163                 << abort(FatalError);
164         }
165     }
167     meshMod().setAction
168     (
169         polyModifyFace
170         (
171             mesh_.faces()[faceID],              // face
172             faceID,                             // face ID
173             mesh_.faceOwner()[faceID],          // owner
174             mesh_.faceNeighbour()[faceID],      // neighbour
175             false,                              // flip flux
176             mesh_.boundaryMesh().whichPatch(faceID),  // patch ID
177             true,                               // remove from zone
178             zoneID,                             // zone ID
179             zoneFlip                            // zone flip
180         )
181     );
185 void Foam::repatchPolyTopoChanger::changeAnchorPoint
187     const label faceID,
188     const label fp
191     if (polyTopoChanger::debug)
192     {
193         // Check that the request is possible
194         if (faceID > mesh_.faces().size())
195         {
196             FatalErrorIn
197             (
198                 "void Foam::repatchPolyTopoChanger::setFaceZone"
199                 "(\n"
200                 "    const label faceID,\n"
201                 "    const label zoneID,\n"
202                 "    const bool flip\n"
203                 ")\n"
204             )   << "Error in definition.  faceID: " << faceID
205                 << "out of range."
206                 << abort(FatalError);
207         }
208     }
210     const face& f = mesh_.faces()[faceID];
212     if ((fp < 0) || (fp >= f.size()))
213     {
214         FatalErrorIn
215         (
216             "void Foam::repatchPolyTopoChanger::changeAnchorPoint"
217             "(\n"
218             "    const label faceID,\n"
219             "    const label fp\n"
220             ")\n"
221         )   << "Error in definition.  Face point: " << fp
222             << "indexes out of face " << f
223             << abort(FatalError);
224     }
226     label patchID = mesh_.boundaryMesh().whichPatch(faceID);
228     const label zoneID = mesh_.faceZones().whichZone(faceID);
230     bool zoneFlip = false;
232     if (zoneID >= 0)
233     {
234         const faceZone& fZone = mesh_.faceZones()[zoneID];
236         zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
237     }
239     if (fp == 0)
240     {
241         // Do dummy modify to keep patch ordering.
242         meshMod().setAction
243         (
244             polyModifyFace
245             (
246                 f,                                  // face
247                 faceID,                             // face ID
248                 mesh_.faceOwner()[faceID],          // owner
249                 -1,                                 // neighbour
250                 false,                              // flip flux
251                 patchID,                            // patch ID
252                 false,                              // remove from zone
253                 zoneID,                             // zone ID
254                 zoneFlip                            // zone flip
255             )
256         );
257     }
258     else
259     {
260         // Construct new face with fp as first point.
262         face newFace(f.size());
264         label fVert = fp;
266         for (label i = 0; i < f.size(); i++)
267         {
268             newFace[i] = f[fVert++];
270             if (fVert == f.size())
271             {
272                 fVert = 0;
273             }
274         }
277         meshMod().setAction
278         (
279             polyModifyFace
280             (
281                 newFace,                            // face
282                 faceID,                             // face ID
283                 mesh_.faceOwner()[faceID],          // owner
284                 -1,                                 // neighbour
285                 false,                              // flip flux
286                 patchID,                            // patch ID
287                 false,                              // remove from zone
288                 zoneID,                             // zone ID
289                 zoneFlip                            // zone flip
290             )
291         );
292     }
296 void Foam::repatchPolyTopoChanger::repatch()
298     // Change mesh, no inflation
299     meshMod().changeMesh(mesh_, false);
301     // Clear topo change for the next operation
302     meshModPtr_.clear();
306 // ************************************************************************* //