OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

repatchPolyTopoChanger.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     A mesh which allows changes in the patch distribution of the
00027     faces.  The change in patching is set using changePatchID.  For a
00028     boundary face, a new patch ID is given.  If the face is internal,
00029     it will be added to the first patch and its opposite to the second
00030     patch (take care with face orientation!).
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 #include "repatchPolyTopoChanger.H"
00035 #include "polyTopoChanger.H"
00036 #include "mapPolyMesh.H"
00037 #include "polyModifyFace.H"
00038 
00039 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00040 
00041 Foam::polyTopoChange& Foam::repatchPolyTopoChanger::meshMod()
00042 {
00043     if (meshModPtr_.empty())
00044     {
00045         meshModPtr_.reset(new polyTopoChange(mesh_));
00046     }
00047     return meshModPtr_();
00048 }
00049 
00050 
00051 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00052 
00053 Foam::repatchPolyTopoChanger::repatchPolyTopoChanger(polyMesh& mesh)
00054 :
00055     mesh_(mesh),
00056     meshModPtr_(NULL)
00057 {}
00058 
00059 
00060 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00061 
00062 void Foam::repatchPolyTopoChanger::changePatches
00063 (
00064     const List<polyPatch*>& patches
00065 )
00066 {
00067     if (meshModPtr_.valid())
00068     {
00069         FatalErrorIn
00070         (
00071             "repatchPolyTopoChanger::changePatches(const List<polyPatch*>&)"
00072         )   << "Cannot change patches after having changed faces. " << nl
00073             << "Please call changePatches first."
00074             << exit(FatalError);
00075     }
00076     meshModPtr_.clear();
00077     mesh_.removeBoundary();
00078     mesh_.addPatches(patches);
00079 }
00080 
00081 
00082 void Foam::repatchPolyTopoChanger::changePatchID
00083 (
00084     const label faceID,
00085     const label patchID
00086 )
00087 {
00088     if (polyTopoChanger::debug)
00089     {
00090         // Check that the request is possible
00091         if
00092         (
00093             faceID >= mesh_.faces().size()
00094          || patchID >= mesh_.boundaryMesh().size()
00095          || mesh_.isInternalFace(faceID)
00096         )
00097         {
00098             FatalErrorIn
00099             (
00100                 "void Foam::repatchPolyTopoChanger::changePatchID\n"
00101                 "(\n"
00102                 "    const label faceID,\n"
00103                 "    const label patchID\n"
00104                 ")\n"
00105             )   << "Error in definition.  faceID: " << faceID
00106                 << " patchID: " << patchID << ".  "
00107                 << "Labels out of range or internal face."
00108                 << abort(FatalError);
00109         }
00110     }
00111 
00112     const label zoneID = mesh_.faceZones().whichZone(faceID);
00113 
00114     bool zoneFlip = false;
00115 
00116     if (zoneID >= 0)
00117     {
00118         const faceZone& fZone = mesh_.faceZones()[zoneID];
00119 
00120         zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
00121     }
00122 
00123     meshMod().setAction
00124     (
00125         polyModifyFace
00126         (
00127             mesh_.faces()[faceID],              // face
00128             faceID,                             // face ID
00129             mesh_.faceOwner()[faceID],          // owner
00130             -1,                                 // neighbour
00131             false,                              // flip flux
00132             patchID,                            // patch ID
00133             false,                              // remove from zone
00134             zoneID,                             // zone ID
00135             zoneFlip                            // zone flip
00136         )
00137     );
00138 }
00139 
00140 
00141 void Foam::repatchPolyTopoChanger::setFaceZone
00142 (
00143     const label faceID,
00144     const label zoneID,
00145     const bool zoneFlip
00146 )
00147 {
00148     if (polyTopoChanger::debug)
00149     {
00150         // Check that the request is possible
00151         if (faceID > mesh_.faces().size())
00152         {
00153             FatalErrorIn
00154             (
00155                 "void Foam::repatchPolyTopoChanger::setFaceZone"
00156                 "(\n"
00157                 "    const label faceID,\n"
00158                 "    const label zoneID,\n"
00159                 "    const bool flip\n"
00160                 ")\n"
00161             )   << "Error in definition.  faceID: " << faceID
00162                 << "out of range."
00163                 << abort(FatalError);
00164         }
00165     }
00166 
00167     meshMod().setAction
00168     (
00169         polyModifyFace
00170         (
00171             mesh_.faces()[faceID],              // face
00172             faceID,                             // face ID
00173             mesh_.faceOwner()[faceID],          // owner
00174             mesh_.faceNeighbour()[faceID],      // neighbour
00175             false,                              // flip flux
00176             mesh_.boundaryMesh().whichPatch(faceID),  // patch ID
00177             true,                               // remove from zone
00178             zoneID,                             // zone ID
00179             zoneFlip                            // zone flip
00180         )
00181     );
00182 }
00183 
00184 
00185 void Foam::repatchPolyTopoChanger::changeAnchorPoint
00186 (
00187     const label faceID,
00188     const label fp
00189 )
00190 {
00191     if (polyTopoChanger::debug)
00192     {
00193         // Check that the request is possible
00194         if (faceID > mesh_.faces().size())
00195         {
00196             FatalErrorIn
00197             (
00198                 "void Foam::repatchPolyTopoChanger::setFaceZone"
00199                 "(\n"
00200                 "    const label faceID,\n"
00201                 "    const label zoneID,\n"
00202                 "    const bool flip\n"
00203                 ")\n"
00204             )   << "Error in definition.  faceID: " << faceID
00205                 << "out of range."
00206                 << abort(FatalError);
00207         }
00208     }
00209 
00210     const face& f = mesh_.faces()[faceID];
00211 
00212     if ((fp < 0) || (fp >= f.size()))
00213     {
00214         FatalErrorIn
00215         (
00216             "void Foam::repatchPolyTopoChanger::changeAnchorPoint"
00217             "(\n"
00218             "    const label faceID,\n"
00219             "    const label fp\n"
00220             ")\n"
00221         )   << "Error in definition.  Face point: " << fp
00222             << "indexes out of face " << f
00223             << abort(FatalError);
00224     }
00225 
00226     label patchID = mesh_.boundaryMesh().whichPatch(faceID);
00227 
00228     const label zoneID = mesh_.faceZones().whichZone(faceID);
00229 
00230     bool zoneFlip = false;
00231 
00232     if (zoneID >= 0)
00233     {
00234         const faceZone& fZone = mesh_.faceZones()[zoneID];
00235 
00236         zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
00237     }
00238 
00239     if (fp == 0)
00240     {
00241         // Do dummy modify to keep patch ordering.
00242         meshMod().setAction
00243         (
00244             polyModifyFace
00245             (
00246                 f,                                  // face
00247                 faceID,                             // face ID
00248                 mesh_.faceOwner()[faceID],          // owner
00249                 -1,                                 // neighbour
00250                 false,                              // flip flux
00251                 patchID,                            // patch ID
00252                 false,                              // remove from zone
00253                 zoneID,                             // zone ID
00254                 zoneFlip                            // zone flip
00255             )
00256         );
00257     }
00258     else
00259     {
00260         // Construct new face with fp as first point.
00261 
00262         face newFace(f.size());
00263 
00264         label fVert = fp;
00265 
00266         for (label i = 0; i < f.size(); i++)
00267         {
00268             newFace[i] = f[fVert++];
00269 
00270             if (fVert == f.size())
00271             {
00272                 fVert = 0;
00273             }
00274         }
00275 
00276 
00277         meshMod().setAction
00278         (
00279             polyModifyFace
00280             (
00281                 newFace,                            // face
00282                 faceID,                             // face ID
00283                 mesh_.faceOwner()[faceID],          // owner
00284                 -1,                                 // neighbour
00285                 false,                              // flip flux
00286                 patchID,                            // patch ID
00287                 false,                              // remove from zone
00288                 zoneID,                             // zone ID
00289                 zoneFlip                            // zone flip
00290             )
00291         );
00292     }
00293 }
00294 
00295 
00296 void Foam::repatchPolyTopoChanger::repatch()
00297 {
00298     // Change mesh, no inflation
00299     meshMod().changeMesh(mesh_, false);
00300 
00301     // Clear topo change for the next operation
00302     meshModPtr_.clear();
00303 }
00304 
00305 
00306 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd