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

mapDistributePolyMesh.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 "mapDistributePolyMesh.H"
00028 #include "polyMesh.H"
00029 
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 void Foam::mapDistributePolyMesh::calcPatchSizes()
00034 {
00035     oldPatchSizes_.setSize(oldPatchStarts_.size());
00036 
00037     // Calculate old patch sizes
00038     for (label patchI = 0; patchI < oldPatchStarts_.size() - 1; patchI++)
00039     {
00040         oldPatchSizes_[patchI] =
00041             oldPatchStarts_[patchI + 1] - oldPatchStarts_[patchI];
00042     }
00043 
00044     // Set the last one by hand
00045     const label lastPatchID = oldPatchStarts_.size() - 1;
00046 
00047     oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID];
00048 
00049     if (min(oldPatchSizes_) < 0)
00050     {
00051         FatalErrorIn("mapDistributePolyMesh::calcPatchSizes()")
00052             << "Calculated negative old patch size:" << oldPatchSizes_ << nl
00053             << "Error in mapping data" << abort(FatalError);
00054     }
00055 }
00056 
00057 
00058 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00059 
00060 //- Construct from components
00061 Foam::mapDistributePolyMesh::mapDistributePolyMesh
00062 (
00063     const polyMesh& mesh,
00064 
00065     // mesh before changes
00066     const label nOldPoints,
00067     const label nOldFaces,
00068     const label nOldCells,
00069     const labelList& oldPatchStarts,
00070     const labelList& oldPatchNMeshPoints,
00071 
00072     // how to subset pieces of mesh to send across
00073     const labelListList& subPointMap,
00074     const labelListList& subFaceMap,
00075     const labelListList& subCellMap,
00076     const labelListList& subPatchMap,
00077 
00078     // how to reconstruct received mesh
00079     const labelListList& constructPointMap,
00080     const labelListList& constructFaceMap,
00081     const labelListList& constructCellMap,
00082     const labelListList& constructPatchMap
00083 )
00084 :
00085     mesh_(mesh),
00086     nOldPoints_(nOldPoints),
00087     nOldFaces_(nOldFaces),
00088     nOldCells_(nOldCells),
00089     oldPatchSizes_(oldPatchStarts.size()),
00090     oldPatchStarts_(oldPatchStarts),
00091     oldPatchNMeshPoints_(oldPatchNMeshPoints),
00092     pointMap_(mesh.nPoints(), subPointMap, constructPointMap),
00093     faceMap_(mesh.nFaces(), subFaceMap, constructFaceMap),
00094     cellMap_(mesh.nCells(), subCellMap, constructCellMap),
00095     patchMap_(mesh.boundaryMesh().size(), subPatchMap, constructPatchMap)
00096 {
00097     calcPatchSizes();
00098 }
00099 
00100 
00101 //- (optionally destructively) construct from components
00102 Foam::mapDistributePolyMesh::mapDistributePolyMesh
00103 (
00104     const polyMesh& mesh,
00105     const label nOldPoints,
00106     const label nOldFaces,
00107     const label nOldCells,
00108     labelList& oldPatchStarts,
00109     labelList& oldPatchNMeshPoints,
00110 
00111     labelListList& subPointMap,
00112     labelListList& subFaceMap,
00113     labelListList& subCellMap,
00114     labelListList& subPatchMap,
00115     labelListList& constructPointMap,
00116     labelListList& constructFaceMap,
00117     labelListList& constructCellMap,
00118     labelListList& constructPatchMap,
00119     const bool reUse                // clone or reuse
00120 )
00121 :
00122     mesh_(mesh),
00123     nOldPoints_(nOldPoints),
00124     nOldFaces_(nOldFaces),
00125     nOldCells_(nOldCells),
00126     oldPatchSizes_(oldPatchStarts.size()),
00127     oldPatchStarts_(oldPatchStarts, reUse),
00128     oldPatchNMeshPoints_(oldPatchNMeshPoints, reUse),
00129 
00130     pointMap_(mesh.nPoints(), subPointMap, constructPointMap, reUse),
00131     faceMap_(mesh.nFaces(), subFaceMap, constructFaceMap, reUse),
00132     cellMap_(mesh.nCells(), subCellMap, constructCellMap, reUse),
00133     patchMap_(mesh.boundaryMesh().size(), subPatchMap, constructPatchMap, reUse)
00134 {
00135     calcPatchSizes();
00136 }
00137 
00138 
00139 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00140 
00141 void Foam::mapDistributePolyMesh::distributePointIndices(labelList& lst) const
00142 {
00143     // Construct boolList from selected elements
00144     boolList isSelected
00145     (
00146         createWithValues<boolList>
00147         (
00148             nOldPoints(),
00149             false,
00150             lst,
00151             true
00152         )
00153     );
00154 
00155     // Distribute
00156     distributePointData(isSelected);
00157 
00158     // Collect selected elements
00159     lst = findIndices(isSelected, true);
00160 }
00161 
00162 
00163 void Foam::mapDistributePolyMesh::distributeFaceIndices(labelList& lst) const
00164 {
00165     // Construct boolList from selected elements
00166     boolList isSelected
00167     (
00168         createWithValues<boolList>
00169         (
00170             nOldFaces(),
00171             false,
00172             lst,
00173             true
00174         )
00175     );
00176 
00177     // Distribute
00178     distributeFaceData(isSelected);
00179 
00180     // Collect selected elements
00181     lst = findIndices(isSelected, true);
00182 }
00183 
00184 
00185 void Foam::mapDistributePolyMesh::distributeCellIndices(labelList& lst) const
00186 {
00187     // Construct boolList from selected elements
00188     boolList isSelected
00189     (
00190         createWithValues<boolList>
00191         (
00192             nOldCells(),
00193             false,
00194             lst,
00195             true
00196         )
00197     );
00198 
00199     // Distribute
00200     distributeCellData(isSelected);
00201 
00202     // Collect selected elements
00203     lst = findIndices(isSelected, true);
00204 }
00205 
00206 
00207 void Foam::mapDistributePolyMesh::distributePatchIndices(labelList& lst) const
00208 {
00209     // Construct boolList from selected elements
00210     boolList isSelected
00211     (
00212         createWithValues<boolList>
00213         (
00214             oldPatchStarts().size(),    // nOldPatches
00215             false,
00216             lst,
00217             true
00218         )
00219     );
00220 
00221     // Distribute
00222     distributePatchData(isSelected);
00223 
00224     // Collect selected elements
00225     lst = findIndices(isSelected, true);
00226 }
00227 
00228 
00229 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00230 
00231 
00232 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00233 
00234 
00235 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd