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

setLayerPairing.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     Remove a layer of cells and prepare addressing data
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "layerAdditionRemoval.H"
00031 #include "polyMesh.H"
00032 #include "primitiveMesh.H"
00033 #include "polyTopoChange.H"
00034 #include "oppositeFace.H"
00035 #include "polyTopoChanger.H"
00036 
00037 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00038 
00039 bool Foam::layerAdditionRemoval::setLayerPairing() const
00040 {
00041     // Note:
00042     // This is also the most complex part of the topological change.
00043     // Therefore it will be calculated here and stored as temporary
00044     // data until the actual topological change, after which it will
00045     // be cleared.  
00046 
00047     // Algorithm for point collapse
00048     // 1)  Go through the master cell layer and for every face of
00049     //     the face zone find the opposite face in the master cell.
00050     //     Check the direction of the opposite face and adjust as
00051     //     necessary.  Check other faces to find an edge defining
00052     //     relative orientation of the two faces and adjust the face
00053     //     as necessary.  Once the face is adjusted, record the
00054     //     addressing between the master and slave vertex layer.
00055 
00056     const polyMesh& mesh = topoChanger().mesh();
00057 
00058     const labelList& mc =
00059         mesh.faceZones()[faceZoneID_.index()].masterCells();
00060 
00061     const labelList& mf = mesh.faceZones()[faceZoneID_.index()];
00062 
00063     const boolList& mfFlip =
00064         mesh.faceZones()[faceZoneID_.index()].flipMap();
00065 
00066     const faceList& faces = mesh.faces();
00067     const cellList& cells = mesh.cells();
00068 
00069     // Grab the local faces from the master zone
00070     const faceList& mlf =
00071         mesh.faceZones()[faceZoneID_.index()]().localFaces();
00072 
00073     const labelList& meshPoints =
00074         mesh.faceZones()[faceZoneID_.index()]().meshPoints();
00075 
00076     // Create a list of points to collapse for every point of
00077     // the master patch
00078     if (pointsPairingPtr_ || facesPairingPtr_)
00079     {
00080         FatalErrorIn
00081         (
00082             "void Foam::layerAdditionRemoval::setLayerPairing() const"
00083         )   << "Problem with layer pairing data"
00084             << abort(FatalError);
00085     }
00086 
00087     pointsPairingPtr_ = new labelList(meshPoints.size(), -1);
00088     labelList& ptc = *pointsPairingPtr_;
00089 
00090     facesPairingPtr_ = new labelList(mf.size(), -1);
00091     labelList& ftc = *facesPairingPtr_;
00092 //     Pout << "meshPoints: " << meshPoints << nl
00093 //          << "localPoints: " << mesh.faceZones()[faceZoneID_.index()]().localPoints() << endl;
00094 
00095     // For all faces, create the mapping
00096     label nPointErrors = 0;
00097     label nFaceErrors = 0;
00098 
00099     forAll (mf, faceI)
00100     {
00101         // Get the local master face
00102         face curLocalFace = mlf[faceI];
00103 
00104         // Flip face based on flip index to recover original orientation
00105         if (mfFlip[faceI])
00106         {
00107             curLocalFace = curLocalFace.reverseFace();
00108         }
00109 
00110         // Get the opposing face from the master cell
00111         oppositeFace lidFace =
00112             cells[mc[faceI]].opposingFace(mf[faceI], faces);
00113 
00114         if (!lidFace.found())
00115         {
00116             // This is not a valid layer; cannot continue
00117             nFaceErrors++;
00118             continue;
00119         }
00120 
00121 // Pout<< "curMasterFace: " << faces[mf[faceI]] << nl
00122 //     << "cell shape: " << mesh.cellShapes()[mc[faceI]] << nl
00123 //     << "curLocalFace: " << curLocalFace << nl
00124 //     << "lidFace: " << lidFace
00125 //     << " master index: " << lidFace.masterIndex()
00126 //     << " oppositeIndex: " << lidFace.oppositeIndex() << endl;
00127 
00128         // Grab the opposite face for face collapse addressing
00129         ftc[faceI] = lidFace.oppositeIndex();
00130 
00131         // Using the local face insert the points into the lid list
00132         forAll (curLocalFace, pointI)
00133         {
00134             const label clp = curLocalFace[pointI];
00135 
00136             if (ptc[clp] == -1)
00137             {
00138                 // Point not mapped yet.  Insert the label
00139                 ptc[clp] = lidFace[pointI];
00140             }
00141             else
00142             {
00143                 // Point mapped from some other face.  Check the label
00144                 if (ptc[clp] != lidFace[pointI])
00145                 {
00146                     nPointErrors++;
00147 //                     Pout<< "Topological error in cell layer pairing.  "
00148 //                         << "This mesh is either topologically incorrect "
00149 //                         << "or the master afce layer is not defined "
00150 //                         << "consistently.  Please check the "
00151 //                         << "face zone flip map." << nl
00152 //                         << "First index: " << ptc[clp]
00153 //                         << " new index: " << lidFace[pointI] << endl;
00154                 }
00155             }
00156         }
00157 //         Pout << "ptc: " << ptc << endl;
00158     }
00159 
00160     reduce(nPointErrors, sumOp<label>());
00161     reduce(nFaceErrors, sumOp<label>());
00162 
00163     if (nPointErrors > 0 || nFaceErrors > 0)
00164     {
00165         clearAddressing();
00166 
00167         return false;
00168     }
00169     else
00170     {
00171         // Valid layer
00172         return true;
00173     }
00174 }
00175 
00176 
00177 const Foam::labelList& Foam::layerAdditionRemoval::pointsPairing() const
00178 {
00179     if (!pointsPairingPtr_)
00180     {
00181         FatalErrorIn
00182         (
00183             "const labelList& layerAdditionRemoval::pointsPairing() const"
00184         )   << "Problem with layer pairing data for object " << name()
00185             << abort(FatalError);
00186     }
00187 
00188     return *pointsPairingPtr_;
00189 }
00190 
00191 const Foam::labelList& Foam::layerAdditionRemoval::facesPairing() const
00192 {
00193     if (!facesPairingPtr_)
00194     {
00195         FatalErrorIn
00196         (
00197             "const labelList& layerAdditionRemoval::facesPairing() const"
00198         )   << "Problem with layer pairing data for object " << name()
00199             << abort(FatalError);
00200     }
00201 
00202     return *facesPairingPtr_;
00203 }
00204 
00205 
00206 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00207 
00208 void Foam::layerAdditionRemoval::modifyMotionPoints
00209 (
00210     pointField& motionPoints
00211 ) const
00212 {
00213     if (debug)
00214     {
00215         Pout<< "void layerAdditionRemoval::modifyMotionPoints(" 
00216             << "pointField& motionPoints) const for object "
00217             << name() << " : ";
00218     }
00219 
00220     if (debug)
00221     {
00222         Pout << "No motion point adjustment" << endl;
00223     }
00224 }
00225 
00226 
00227 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd