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

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