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

decompositionMethod.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 InClass
00026     decompositionMethod
00027 
00028 Description
00029 
00030 \*---------------------------------------------------------------------------*/
00031 
00032 #include "decompositionMethod.H"
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038     defineTypeNameAndDebug(decompositionMethod, 0);
00039     defineRunTimeSelectionTable(decompositionMethod, dictionary);
00040     defineRunTimeSelectionTable(decompositionMethod, dictionaryMesh);
00041 }
00042 
00043 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00044 
00045 Foam::autoPtr<Foam::decompositionMethod> Foam::decompositionMethod::New
00046 (
00047     const dictionary& decompositionDict
00048 )
00049 {
00050     word decompositionMethodTypeName(decompositionDict.lookup("method"));
00051 
00052     Info<< "Selecting decompositionMethod "
00053         << decompositionMethodTypeName << endl;
00054 
00055     dictionaryConstructorTable::iterator cstrIter =
00056         dictionaryConstructorTablePtr_->find(decompositionMethodTypeName);
00057 
00058     if (cstrIter == dictionaryConstructorTablePtr_->end())
00059     {
00060         FatalErrorIn
00061         (
00062             "decompositionMethod::New"
00063             "(const dictionary& decompositionDict)"
00064         )   << "Unknown decompositionMethod "
00065             << decompositionMethodTypeName << endl << endl
00066             << "Valid decompositionMethods are : " << endl
00067             << dictionaryConstructorTablePtr_->toc()
00068             << exit(FatalError);
00069     }
00070 
00071     return autoPtr<decompositionMethod>(cstrIter()(decompositionDict));
00072 }
00073 
00074 
00075 Foam::autoPtr<Foam::decompositionMethod> Foam::decompositionMethod::New
00076 (
00077     const dictionary& decompositionDict,
00078     const polyMesh& mesh
00079 )
00080 {
00081     word decompositionMethodTypeName(decompositionDict.lookup("method"));
00082 
00083     Info<< "Selecting decompositionMethod "
00084         << decompositionMethodTypeName << endl;
00085 
00086     dictionaryMeshConstructorTable::iterator cstrIter =
00087         dictionaryMeshConstructorTablePtr_->find(decompositionMethodTypeName);
00088 
00089     if (cstrIter == dictionaryMeshConstructorTablePtr_->end())
00090     {
00091         FatalErrorIn
00092         (
00093             "decompositionMethod::New"
00094             "(const dictionary& decompositionDict, "
00095             "const polyMesh& mesh)"
00096         )   << "Unknown decompositionMethod "
00097             << decompositionMethodTypeName << endl << endl
00098             << "Valid decompositionMethods are : " << endl
00099             << dictionaryMeshConstructorTablePtr_->toc()
00100             << exit(FatalError);
00101     }
00102 
00103     return autoPtr<decompositionMethod>(cstrIter()(decompositionDict, mesh));
00104 }
00105 
00106 
00107 Foam::labelList Foam::decompositionMethod::decompose
00108 (
00109     const labelList& fineToCoarse,
00110     const pointField& coarsePoints
00111 )
00112 {
00113     // Decompose based on agglomerated points
00114     labelList coarseDistribution(decompose(coarsePoints));
00115 
00116     // Rework back into decomposition for original mesh_
00117     labelList fineDistribution(fineToCoarse.size());
00118 
00119     forAll(fineDistribution, i)
00120     {
00121         fineDistribution[i] = coarseDistribution[fineToCoarse[i]];
00122     }
00123 
00124     return fineDistribution;
00125 }
00126 
00127 
00128 void Foam::decompositionMethod::calcCellCells
00129 (
00130     const polyMesh& mesh,
00131     const labelList& fineToCoarse,
00132     const label nCoarse,
00133     labelListList& cellCells
00134 )
00135 {
00136     if (fineToCoarse.size() != mesh.nCells())
00137     {
00138         FatalErrorIn
00139         (
00140             "decompositionMethod::calcCellCells"
00141             "(const labelList&, labelListList&) const"
00142         )   << "Only valid for mesh agglomeration." << exit(FatalError);
00143     }
00144 
00145     List<DynamicList<label> > dynCellCells(nCoarse);
00146 
00147     forAll(mesh.faceNeighbour(), faceI)
00148     {
00149         label own = fineToCoarse[mesh.faceOwner()[faceI]];
00150         label nei = fineToCoarse[mesh.faceNeighbour()[faceI]];
00151 
00152         if (own != nei)
00153         {
00154             if (findIndex(dynCellCells[own], nei) == -1)
00155             {
00156                 dynCellCells[own].append(nei);
00157             }
00158             if (findIndex(dynCellCells[nei], own) == -1)
00159             {
00160                 dynCellCells[nei].append(own);
00161             }
00162         }
00163     }
00164 
00165     cellCells.setSize(dynCellCells.size());
00166     forAll(dynCellCells, coarseI)
00167     {
00168         cellCells[coarseI].transfer(dynCellCells[coarseI]);
00169     }
00170 }
00171 
00172 
00173 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd