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

enrichedPatchMasterPoints.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 
00026 \*---------------------------------------------------------------------------*/
00027 
00028 #include "enrichedPatch.H"
00029 #include <OpenFOAM/primitiveMesh.H>
00030 #include <OpenFOAM/demandDrivenData.H>
00031 #include <OpenFOAM/DynamicList.H>
00032 
00033 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00034 
00035 const Foam::label Foam::enrichedPatch::nFaceHits_ = 4;
00036 
00037 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00038 
00039 void Foam::enrichedPatch::calcMasterPointFaces() const
00040 {
00041     if (masterPointFacesPtr_)
00042     {
00043         FatalErrorIn("void enrichedPatch::calcMasterPointFaces() const")
00044             << "Master point face addressing already calculated."
00045             << abort(FatalError);
00046     }
00047 
00048     // Note:
00049     // Master point face addressing lists the master faces for all points
00050     // in the enriched patch support (if there are no master faces, which is
00051     // normal, the list will be empty).  The index represents the index of
00052     // the master face rather than the index from the enriched patch
00053     // Master face points lists the points of the enriched master face plus
00054     // points projected into the master face
00055 
00056     Map<DynamicList<label> > mpf(meshPoints().size());
00057 
00058     const faceList& ef = enrichedFaces();
00059 
00060     // Add the original face points
00061     forAll (masterPatch_, faceI)
00062     {
00063         const face& curFace = ef[faceI + slavePatch_.size()];
00064 //         Pout << "Cur face in pfAddr: " << curFace << endl;
00065         forAll (curFace, pointI)
00066         {
00067             Map<DynamicList<label> >::iterator mpfIter =
00068                 mpf.find(curFace[pointI]);
00069 
00070             if (mpfIter == mpf.end())
00071             {
00072                 // Not found, add new dynamic list
00073                 // Work-around for compiler bug
00074                 DynamicList<label> fpp(primitiveMesh::facesPerPoint_);
00075                 mpf.insert
00076                 (
00077                     curFace[pointI],
00078                     fpp
00079                 );
00080 
00081                 // Iterator is invalidated - have to find again
00082                 mpf.find(curFace[pointI])().append(faceI);
00083             }
00084             else
00085             {
00086                 mpfIter().append(faceI);
00087             }
00088         }
00089     }
00090 
00091     // Add the projected points which hit the face
00092     const labelList& slaveMeshPoints = slavePatch_.meshPoints();
00093 
00094     forAll (slavePointFaceHits_, pointI)
00095     {
00096         if
00097         (
00098             slavePointPointHits_[pointI] < 0
00099          && slavePointEdgeHits_[pointI] < 0
00100          && slavePointFaceHits_[pointI].hit()
00101         )
00102         {
00103             // Get the index of projected point corresponding to this slave
00104             // point
00105             const label mergedSmp =
00106                 pointMergeMap().find(slaveMeshPoints[pointI])();
00107 
00108             Map<DynamicList<label> >::iterator mpfIter =
00109                 mpf.find(mergedSmp);
00110 
00111             if (mpfIter == mpf.end())
00112             {
00113                 // Not found, add new dynamic list
00114                 // Work-around for compiler bug
00115                 DynamicList<label> fpp(primitiveMesh::facesPerPoint_);
00116                 mpf.insert
00117                 (
00118                     mergedSmp,
00119                     fpp
00120                 );
00121 
00122                 // Iterator is invalidated - have to find again
00123                 mpf.find(mergedSmp)().append
00124                 (
00125                     slavePointFaceHits_[pointI].hitObject()
00126                 );
00127             }
00128             else
00129             {
00130                 mpfIter().append(slavePointFaceHits_[pointI].hitObject());
00131             }
00132         }
00133     }
00134 
00135     // Re-pack dynamic lists into normal lists
00136     const labelList mpfToc = mpf.toc();
00137 
00138     masterPointFacesPtr_ = new Map<labelList>(2*mpfToc.size());
00139     Map<labelList>& masterPointFaceAddr = *masterPointFacesPtr_;
00140 
00141     forAll (mpfToc, mpfTocI)
00142     {
00143         labelList l;
00144         l.transfer(mpf.find(mpfToc[mpfTocI])());
00145 
00146         masterPointFaceAddr.insert(mpfToc[mpfTocI], l);
00147     }
00148     // Pout<< "masterPointFaceAddr: " << masterPointFaceAddr << endl;
00149 }
00150 
00151 
00152 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00153 
00154 const Foam::Map<Foam::labelList>& Foam::enrichedPatch::masterPointFaces() const
00155 {
00156     if (!masterPointFacesPtr_)
00157     {
00158         calcMasterPointFaces();
00159     }
00160 
00161     return *masterPointFacesPtr_;
00162 }
00163 
00164 
00165 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines