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

meshRefinementTemplates.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 "meshRefinement.H"
00028 #include "fvMesh.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00036 
00037 // Add a T entry
00038 template<class T> void meshRefinement::updateList
00039 (
00040     const labelList& newToOld,
00041     const T& nullValue,
00042     List<T>& elems
00043 )
00044 {
00045     List<T> newElems(newToOld.size(), nullValue);
00046 
00047     forAll(newElems, i)
00048     {
00049         label oldI = newToOld[i];
00050 
00051         if (oldI >= 0)
00052         {
00053             newElems[i] = elems[oldI];
00054         }
00055     }
00056 
00057     elems.transfer(newElems);
00058 }
00059 
00060 
00061 // Compare two lists over all boundary faces
00062 template<class T>
00063 void meshRefinement::testSyncBoundaryFaceList
00064 (
00065     const scalar tol,
00066     const string& msg,
00067     const UList<T>& faceData,
00068     const UList<T>& syncedFaceData
00069 ) const
00070 {
00071     label nBFaces = mesh_.nFaces() - mesh_.nInternalFaces();
00072 
00073     if (faceData.size() != nBFaces || syncedFaceData.size() != nBFaces)
00074     {
00075         FatalErrorIn
00076         (
00077             "meshRefinement::testSyncBoundaryFaceList"
00078             "(const scalar, const string&, const List<T>&, const List<T>&)"
00079         )   << "Boundary faces:" << nBFaces
00080             << " faceData:" << faceData.size()
00081             << " syncedFaceData:" << syncedFaceData.size()
00082             << abort(FatalError);
00083     }
00084 
00085     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00086 
00087     forAll(patches, patchI)
00088     {
00089         const polyPatch& pp = patches[patchI];
00090 
00091         label bFaceI = pp.start() - mesh_.nInternalFaces();
00092 
00093         forAll(pp, i)
00094         {
00095             const T& data = faceData[bFaceI];
00096             const T& syncData = syncedFaceData[bFaceI];
00097 
00098             if (mag(data - syncData) > tol)
00099             {
00100                 label faceI = pp.start()+i;
00101 
00102                 FatalErrorIn("testSyncFaces")
00103                     << msg
00104                     << "patchFace:" << i
00105                     << " face:" << faceI
00106                     << " fc:" << mesh_.faceCentres()[faceI]
00107                     << " patch:" << pp.name()
00108                     << " faceData:" << data
00109                     << " syncedFaceData:" << syncData
00110                     << " diff:" << mag(data - syncData)
00111                     << abort(FatalError);
00112             }
00113 
00114             bFaceI++;
00115         }
00116     }
00117 }
00118 
00119 
00120 //template <class T, class Mesh>
00121 template<class GeoField>
00122 void meshRefinement::addPatchFields(fvMesh& mesh, const word& patchFieldType)
00123 {
00124     HashTable<const GeoField*> flds
00125     (
00126         mesh.objectRegistry::lookupClass<GeoField>()
00127     );
00128 
00129     for
00130     (
00131         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
00132         iter != flds.end();
00133         ++iter
00134     )
00135     {
00136         const GeoField& fld = *iter();
00137 
00138         typename GeoField::GeometricBoundaryField& bfld =
00139             const_cast<typename GeoField::GeometricBoundaryField&>
00140             (
00141                 fld.boundaryField()
00142             );
00143 
00144         label sz = bfld.size();
00145         bfld.setSize(sz+1);
00146         bfld.set
00147         (
00148             sz,
00149             GeoField::PatchFieldType::New
00150             (
00151                 patchFieldType,
00152                 mesh.boundary()[sz],
00153                 fld.dimensionedInternalField()
00154             )
00155         );
00156     }
00157 }
00158 
00159 
00160 // Reorder patch field
00161 template<class GeoField>
00162 void meshRefinement::reorderPatchFields(fvMesh& mesh, const labelList& oldToNew)
00163 {
00164     HashTable<const GeoField*> flds
00165     (
00166         mesh.objectRegistry::lookupClass<GeoField>()
00167     );
00168 
00169     for
00170     (
00171         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
00172         iter != flds.end();
00173         ++iter
00174     )
00175     {
00176         const GeoField& fld = *iter();
00177 
00178         typename GeoField::GeometricBoundaryField& bfld =
00179             const_cast<typename GeoField::GeometricBoundaryField&>
00180             (
00181                 fld.boundaryField()
00182             );
00183 
00184         bfld.reorder(oldToNew);
00185     }
00186 }
00187 
00188 
00189 
00190 
00191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00192 
00193 } // End namespace Foam
00194 
00195 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd