1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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
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())
45 meshModPtr_.reset(new polyTopoChange(mesh_));
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 Foam::repatchPolyTopoChanger::repatchPolyTopoChanger(polyMesh& mesh)
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 void Foam::repatchPolyTopoChanger::changePatches
64 const List<polyPatch*>& patches
67 if (meshModPtr_.valid())
71 "repatchPolyTopoChanger::changePatches(const List<polyPatch*>&)"
72 ) << "Cannot change patches after having changed faces. " << nl
73 << "Please call changePatches first."
77 mesh_.removeBoundary();
78 mesh_.addPatches(patches);
82 void Foam::repatchPolyTopoChanger::changePatchID
88 if (polyTopoChanger::debug)
90 // Check that the request is possible
93 faceID >= mesh_.faces().size()
94 || patchID >= mesh_.boundaryMesh().size()
95 || mesh_.isInternalFace(faceID)
100 "void Foam::repatchPolyTopoChanger::changePatchID\n"
102 " const label faceID,\n"
103 " const label patchID\n"
105 ) << "Error in definition. faceID: " << faceID
106 << " patchID: " << patchID << ". "
107 << "Labels out of range or internal face."
108 << abort(FatalError);
112 const label zoneID = mesh_.faceZones().whichZone(faceID);
114 bool zoneFlip = false;
118 const faceZone& fZone = mesh_.faceZones()[zoneID];
120 zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
127 mesh_.faces()[faceID], // face
129 mesh_.faceOwner()[faceID], // owner
133 false, // remove from zone
135 zoneFlip // zone flip
141 void Foam::repatchPolyTopoChanger::setFaceZone
148 if (polyTopoChanger::debug)
150 // Check that the request is possible
151 if (faceID > mesh_.faces().size())
155 "void Foam::repatchPolyTopoChanger::setFaceZone"
157 " const label faceID,\n"
158 " const label zoneID,\n"
161 ) << "Error in definition. faceID: " << faceID
163 << abort(FatalError);
171 mesh_.faces()[faceID], // face
173 mesh_.faceOwner()[faceID], // owner
174 mesh_.faceNeighbour()[faceID], // neighbour
176 mesh_.boundaryMesh().whichPatch(faceID), // patch ID
177 true, // remove from zone
179 zoneFlip // zone flip
185 void Foam::repatchPolyTopoChanger::changeAnchorPoint
191 if (polyTopoChanger::debug)
193 // Check that the request is possible
194 if (faceID > mesh_.faces().size())
198 "void Foam::repatchPolyTopoChanger::setFaceZone"
200 " const label faceID,\n"
201 " const label zoneID,\n"
204 ) << "Error in definition. faceID: " << faceID
206 << abort(FatalError);
210 const face& f = mesh_.faces()[faceID];
212 if ((fp < 0) || (fp >= f.size()))
216 "void Foam::repatchPolyTopoChanger::changeAnchorPoint"
218 " const label faceID,\n"
221 ) << "Error in definition. Face point: " << fp
222 << "indexes out of face " << f
223 << abort(FatalError);
226 label patchID = mesh_.boundaryMesh().whichPatch(faceID);
228 const label zoneID = mesh_.faceZones().whichZone(faceID);
230 bool zoneFlip = false;
234 const faceZone& fZone = mesh_.faceZones()[zoneID];
236 zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
241 // Do dummy modify to keep patch ordering.
248 mesh_.faceOwner()[faceID], // owner
252 false, // remove from zone
254 zoneFlip // zone flip
260 // Construct new face with fp as first point.
262 face newFace(f.size());
266 for (label i = 0; i < f.size(); i++)
268 newFace[i] = f[fVert++];
270 if (fVert == f.size())
283 mesh_.faceOwner()[faceID], // owner
287 false, // remove from zone
289 zoneFlip // zone flip
296 void Foam::repatchPolyTopoChanger::repatch()
298 // Change mesh, no inflation
299 meshMod().changeMesh(mesh_, false);
301 // Clear topo change for the next operation
306 // ************************************************************************* //