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

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