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

duplicatePoints.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "duplicatePoints.H"
00028 #include "localPointRegion.H"
00029 #include "polyTopoChange.H"
00030 #include "polyAddPoint.H"
00031 #include "polyModifyFace.H"
00032 #include "polyMesh.H"
00033 #include "OFstream.H"
00034 #include "meshTools.H"
00035 #include "Time.H"
00036 
00037 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00038 
00039 namespace Foam
00040 {
00041 
00042 defineTypeNameAndDebug(duplicatePoints, 0);
00043 
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 // Construct from mesh
00050 Foam::duplicatePoints::duplicatePoints(const polyMesh& mesh)
00051 :
00052     mesh_(mesh),
00053     duplicates_(0)
00054 {}
00055 
00056 
00057 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00058 
00059 void Foam::duplicatePoints::setRefinement
00060 (
00061     const localPointRegion& regionSide,
00062     polyTopoChange& meshMod
00063 )
00064 {
00065     const Map<label>& meshPointMap = regionSide.meshPointMap();
00066     const labelListList& pointRegions = regionSide.pointRegions();
00067     const Map<label>& meshFaceMap = regionSide.meshFaceMap();
00068     const faceList& faceRegions = regionSide.faceRegions();
00069     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00070 
00071     // Create duplicates for points. One for each region.
00072     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00073 
00074     // Per point-to-be-duplicated, in order of the regions the point added.
00075     duplicates_.setSize(meshPointMap.size());
00076 
00077     forAllConstIter(Map<label>, meshPointMap, iter)
00078     {
00079         label pointI = iter.key();
00080         label localI = iter();
00081         const labelList& regions = pointRegions[localI];
00082 
00083         duplicates_[localI].setSize(regions.size());
00084         duplicates_[localI][0] = pointI;
00085         for (label i = 1; i < regions.size(); i++)
00086         {
00087             duplicates_[localI][i] = meshMod.addPoint
00088             (
00089                 mesh_.points()[pointI],  // point
00090                 pointI,                 // master point
00091                 -1,                     // zone for point
00092                 true                    // supports a cell
00093             );
00094         }
00095 
00096         //Pout<< "For point:" << pointI << " coord:" << mesh_.points()[pointI]
00097         //    << endl;
00098         //forAll(duplicates_[localI], i)
00099         //{
00100         //    Pout<< "    region:" << regions[i]
00101         //        << "  addedpoint:" << duplicates_[localI][i]
00102         //        << endl;
00103         //}
00104     }
00105 
00106 
00107 
00108     // Modfify faces according to face region
00109     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00110 
00111     face newFace;
00112 
00113     forAllConstIter(Map<label>, meshFaceMap, iter)
00114     {
00115         label faceI = iter.key();
00116         label localI = iter();
00117 
00118         // Replace points with duplicated ones.
00119         const face& fRegion = faceRegions[localI];
00120         const face& f = mesh_.faces()[faceI];
00121 
00122         newFace.setSize(f.size());
00123         forAll(f, fp)
00124         {
00125             label pointI = f[fp];
00126 
00127             Map<label>::const_iterator iter = meshPointMap.find(pointI);
00128 
00129             if (iter != meshPointMap.end())
00130             {
00131                 // Point has been duplicated. Find correct one for my
00132                 // region.
00133 
00134                 // Get the regions and added points for this point
00135                 const labelList& regions = pointRegions[iter()];
00136                 const labelList& dupPoints = duplicates_[iter()];
00137 
00138                 // Look up index of my region in the regions for this point
00139                 label index = findIndex(regions, fRegion[fp]);
00140                 // Get the corresponding added point
00141                 newFace[fp] = dupPoints[index];
00142             }
00143             else
00144             {
00145                 newFace[fp] = pointI;
00146             }
00147         }
00148 
00149         // Get current zone info
00150         label zoneID = mesh_.faceZones().whichZone(faceI);
00151         bool zoneFlip = false;
00152         if (zoneID >= 0)
00153         {
00154             const faceZone& fZone = mesh_.faceZones()[zoneID];
00155             zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00156         }
00157 
00158 
00159         if (mesh_.isInternalFace(faceI))
00160         {
00161             meshMod.modifyFace
00162             (
00163                 newFace,                    // modified face
00164                 faceI,                      // label of face being modified
00165                 mesh_.faceOwner()[faceI],   // owner
00166                 mesh_.faceNeighbour()[faceI],   // neighbour
00167                 false,                      // face flip
00168                 -1,                         // patch for face
00169                 zoneID,                     // zone for face
00170                 zoneFlip                    // face flip in zone
00171             );
00172         }
00173         else
00174         {
00175             meshMod.modifyFace
00176             (
00177                 newFace,                    // modified face
00178                 faceI,                      // label of face being modified
00179                 mesh_.faceOwner()[faceI],   // owner
00180                 -1,                         // neighbour
00181                 false,                      // face flip
00182                 patches.whichPatch(faceI),  // patch for face
00183                 zoneID,                     // zone for face
00184                 zoneFlip                    // face flip in zone
00185             );
00186         }
00187     }
00188 
00189 
00190     if (debug)
00191     {
00192         // Output duplicated points
00193         {
00194             OFstream str(mesh_.time().path()/"duplicatedPoints.obj");
00195             forAllConstIter(Map<label>, meshPointMap, iter)
00196             {
00197                 label localI = iter();
00198                 const labelList& dups = duplicates_[localI];
00199 
00200                 forAll(dups, i)
00201                 {
00202                     meshTools::writeOBJ(str, meshMod.points()[dups[i]]);
00203                 }
00204             }
00205         }
00206     }
00207 }
00208 
00209 
00210 void Foam::duplicatePoints::updateMesh(const mapPolyMesh& map)
00211 {
00212     forAll(duplicates_, masterI)
00213     {
00214         inplaceRenumber(map.reversePointMap(), duplicates_[masterI]);
00215     }
00216 }
00217 
00218 
00219 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd