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

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