FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     A mesh which allows changes in the patch distribution of the
00026     faces.  The change in patching is set using changePatchID.  For a
00027     boundary face, a new patch ID is given.  If the face is internal,
00028     it will be added to the first patch and its opposite to the second
00029     patch (take care with face orientation!).
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "repatchPolyTopoChanger.H"
00034 #include <dynamicMesh/polyTopoChanger.H>
00035 #include <OpenFOAM/mapPolyMesh.H>
00036 #include <dynamicMesh/polyModifyFace.H>
00037 
00038 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00039 
00040 Foam::polyTopoChange& Foam::repatchPolyTopoChanger::meshMod()
00041 {
00042     if (meshModPtr_.empty())
00043     {
00044         meshModPtr_.reset(new polyTopoChange(mesh_));
00045     }
00046     return meshModPtr_();
00047 }
00048 
00049 
00050 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00051 
00052 Foam::repatchPolyTopoChanger::repatchPolyTopoChanger(polyMesh& mesh)
00053 :
00054     mesh_(mesh),
00055     meshModPtr_(NULL)
00056 {}
00057 
00058 
00059 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00060 
00061 void Foam::repatchPolyTopoChanger::changePatches
00062 (
00063     const List<polyPatch*>& patches
00064 )
00065 {
00066     if (meshModPtr_.valid())
00067     {
00068         FatalErrorIn
00069         (
00070             "repatchPolyTopoChanger::changePatches(const List<polyPatch*>&)"
00071         )   << "Cannot change patches after having changed faces. " << nl
00072             << "Please call changePatches first."
00073             << exit(FatalError);
00074     }
00075     meshModPtr_.clear();
00076     mesh_.removeBoundary();
00077     mesh_.addPatches(patches);
00078 }
00079 
00080 
00081 void Foam::repatchPolyTopoChanger::changePatchID
00082 (
00083     const label faceID,
00084     const label patchID
00085 )
00086 {
00087     if (polyTopoChanger::debug)
00088     {
00089         // Check that the request is possible
00090         if
00091         (
00092             faceID >= mesh_.faces().size()
00093          || patchID >= mesh_.boundaryMesh().size()
00094          || mesh_.isInternalFace(faceID)
00095         )
00096         {
00097             FatalErrorIn
00098             (
00099                 "void Foam::repatchPolyTopoChanger::changePatchID\n"
00100                 "(\n"
00101                 "    const label faceID,\n"
00102                 "    const label patchID\n"
00103                 ")\n"
00104             )   << "Error in definition.  faceID: " << faceID
00105                 << " patchID: " << patchID << ".  "
00106                 << "Labels out of range or internal face."
00107                 << abort(FatalError);
00108         }
00109     }
00110 
00111     const label zoneID = mesh_.faceZones().whichZone(faceID);
00112 
00113     bool zoneFlip = false;
00114 
00115     if (zoneID >= 0)
00116     {
00117         const faceZone& fZone = mesh_.faceZones()[zoneID];
00118 
00119         zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
00120     }
00121 
00122     meshMod().setAction
00123     (
00124         polyModifyFace
00125         (
00126             mesh_.faces()[faceID],              // face
00127             faceID,                             // face ID
00128             mesh_.faceOwner()[faceID],          // owner
00129             -1,                                 // neighbour
00130             false,                              // flip flux
00131             patchID,                            // patch ID
00132             false,                              // remove from zone
00133             zoneID,                             // zone ID
00134             zoneFlip                            // zone flip
00135         )
00136     );
00137 }
00138 
00139 
00140 void Foam::repatchPolyTopoChanger::setFaceZone
00141 (
00142     const label faceID,
00143     const label zoneID,
00144     const bool zoneFlip
00145 )
00146 {
00147     if (polyTopoChanger::debug)
00148     {
00149         // Check that the request is possible
00150         if (faceID > mesh_.faces().size())
00151         {
00152             FatalErrorIn
00153             (
00154                 "void Foam::repatchPolyTopoChanger::setFaceZone"
00155                 "(\n"
00156                 "    const label faceID,\n"
00157                 "    const label zoneID,\n"
00158                 "    const bool flip\n"
00159                 ")\n"
00160             )   << "Error in definition.  faceID: " << faceID
00161                 << "out of range."
00162                 << abort(FatalError);
00163         }
00164     }
00165 
00166     meshMod().setAction
00167     (
00168         polyModifyFace
00169         (
00170             mesh_.faces()[faceID],              // face
00171             faceID,                             // face ID
00172             mesh_.faceOwner()[faceID],          // owner
00173             mesh_.faceNeighbour()[faceID],      // neighbour
00174             false,                              // flip flux
00175             mesh_.boundaryMesh().whichPatch(faceID),  // patch ID
00176             true,                               // remove from zone
00177             zoneID,                             // zone ID
00178             zoneFlip                            // zone flip
00179         )
00180     );
00181 }
00182 
00183 
00184 void Foam::repatchPolyTopoChanger::changeAnchorPoint
00185 (
00186     const label faceID,
00187     const label fp
00188 )
00189 {
00190     if (polyTopoChanger::debug)
00191     {
00192         // Check that the request is possible
00193         if (faceID > mesh_.faces().size())
00194         {
00195             FatalErrorIn
00196             (
00197                 "void Foam::repatchPolyTopoChanger::setFaceZone"
00198                 "(\n"
00199                 "    const label faceID,\n"
00200                 "    const label zoneID,\n"
00201                 "    const bool flip\n"
00202                 ")\n"
00203             )   << "Error in definition.  faceID: " << faceID
00204                 << "out of range."
00205                 << abort(FatalError);
00206         }
00207     }
00208 
00209     const face& f = mesh_.faces()[faceID];
00210 
00211     if ((fp < 0) || (fp >= f.size()))
00212     {
00213         FatalErrorIn
00214         (
00215             "void Foam::repatchPolyTopoChanger::changeAnchorPoint"
00216             "(\n"
00217             "    const label faceID,\n"
00218             "    const label fp\n"
00219             ")\n"
00220         )   << "Error in definition.  Face point: " << fp
00221             << "indexes out of face " << f
00222             << abort(FatalError);
00223     }
00224 
00225     label patchID = mesh_.boundaryMesh().whichPatch(faceID);
00226 
00227     const label zoneID = mesh_.faceZones().whichZone(faceID);
00228 
00229     bool zoneFlip = false;
00230 
00231     if (zoneID >= 0)
00232     {
00233         const faceZone& fZone = mesh_.faceZones()[zoneID];
00234 
00235         zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
00236     }
00237 
00238     if (fp == 0)
00239     {
00240         // Do dummy modify to keep patch ordering.
00241         meshMod().setAction
00242         (
00243             polyModifyFace
00244             (
00245                 f,                                  // face
00246                 faceID,                             // face ID
00247                 mesh_.faceOwner()[faceID],          // owner
00248                 -1,                                 // neighbour
00249                 false,                              // flip flux
00250                 patchID,                            // patch ID
00251                 false,                              // remove from zone
00252                 zoneID,                             // zone ID
00253                 zoneFlip                            // zone flip
00254             )
00255         );
00256     }
00257     else
00258     {
00259         // Construct new face with fp as first point.
00260 
00261         face newFace(f.size());
00262 
00263         label fVert = fp;
00264 
00265         for (label i = 0; i < f.size(); i++)
00266         {
00267             newFace[i] = f[fVert++];
00268 
00269             if (fVert == f.size())
00270             {
00271                 fVert = 0;
00272             }
00273         }
00274 
00275 
00276         meshMod().setAction
00277         (
00278             polyModifyFace
00279             (
00280                 newFace,                            // face
00281                 faceID,                             // face ID
00282                 mesh_.faceOwner()[faceID],          // owner
00283                 -1,                                 // neighbour
00284                 false,                              // flip flux
00285                 patchID,                            // patch ID
00286                 false,                              // remove from zone
00287                 zoneID,                             // zone ID
00288                 zoneFlip                            // zone flip
00289             )
00290         );
00291     }
00292 }
00293 
00294 
00295 void Foam::repatchPolyTopoChanger::repatch()
00296 {
00297     // Change mesh, no inflation
00298     meshMod().changeMesh(mesh_, false);
00299 
00300     // Clear topo change for the next operation
00301     meshModPtr_.clear();
00302 }
00303 
00304 
00305 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines