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

GAMGSolverAgglomerateMatrix.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 "GAMGSolver.H"
00028 #include "GAMGInterfaceField.H"
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 void Foam::GAMGSolver::agglomerateMatrix(const label fineLevelIndex)
00033 {
00034     // Get fine matrix
00035     const lduMatrix& fineMatrix = matrixLevel(fineLevelIndex);
00036 
00037     // Set the coarse level matrix
00038     matrixLevels_.set
00039     (
00040         fineLevelIndex,
00041         new lduMatrix(agglomeration_.meshLevel(fineLevelIndex + 1))
00042     );
00043     lduMatrix& coarseMatrix = matrixLevels_[fineLevelIndex];
00044 
00045     // Get face restriction map for current level
00046     const labelList& faceRestrictAddr =
00047         agglomeration_.faceRestrictAddressing(fineLevelIndex);
00048 
00049     // Coarse matrix diagonal initialised by restricting the finer mesh diagonal
00050     scalarField& coarseDiag = coarseMatrix.diag();
00051     agglomeration_.restrictField(coarseDiag, fineMatrix.diag(), fineLevelIndex);
00052 
00053     // Get reference to fine-level interfaces
00054     const lduInterfaceFieldPtrsList& fineInterfaces =
00055         interfaceLevel(fineLevelIndex);
00056 
00057     // Get reference to fine-level boundary coefficients
00058     const FieldField<Field, scalar>& fineInterfaceBouCoeffs =
00059         interfaceBouCoeffsLevel(fineLevelIndex);
00060 
00061     // Get reference to fine-level internal coefficients
00062     const FieldField<Field, scalar>& fineInterfaceIntCoeffs =
00063         interfaceIntCoeffsLevel(fineLevelIndex);
00064 
00065 
00066     // Create coarse-level interfaces
00067     interfaceLevels_.set
00068     (
00069         fineLevelIndex,
00070         new lduInterfaceFieldPtrsList(fineInterfaces.size())
00071     );
00072 
00073     lduInterfaceFieldPtrsList& coarseInterfaces =
00074         interfaceLevels_[fineLevelIndex];
00075 
00076     // Set coarse-level boundary coefficients
00077     interfaceLevelsBouCoeffs_.set
00078     (
00079         fineLevelIndex,
00080         new FieldField<Field, scalar>(fineInterfaces.size())
00081     );
00082     FieldField<Field, scalar>& coarseInterfaceBouCoeffs =
00083         interfaceLevelsBouCoeffs_[fineLevelIndex];
00084 
00085     // Set coarse-level internal coefficients
00086     interfaceLevelsIntCoeffs_.set
00087     (
00088         fineLevelIndex,
00089         new FieldField<Field, scalar>(fineInterfaces.size())
00090     );
00091     FieldField<Field, scalar>& coarseInterfaceIntCoeffs =
00092         interfaceLevelsIntCoeffs_[fineLevelIndex];
00093 
00094     // Add the coarse level
00095     forAll (fineInterfaces, inti)
00096     {
00097         if (fineInterfaces.set(inti))
00098         {
00099             const GAMGInterface& coarseInterface = 
00100                 refCast<const GAMGInterface>
00101                 (
00102                     agglomeration_.interfaceLevel(fineLevelIndex + 1)[inti]
00103                 );
00104 
00105             coarseInterfaces.set
00106             (
00107                 inti,
00108                 GAMGInterfaceField::New
00109                 (
00110                     coarseInterface,
00111                     fineInterfaces[inti]
00112                 ).ptr()
00113             );
00114 
00115             coarseInterfaceBouCoeffs.set
00116             (
00117                 inti,
00118                 coarseInterface.agglomerateCoeffs(fineInterfaceBouCoeffs[inti])
00119             );
00120 
00121             coarseInterfaceIntCoeffs.set
00122             (
00123                 inti,
00124                 coarseInterface.agglomerateCoeffs(fineInterfaceIntCoeffs[inti])
00125             );
00126         }
00127     }
00128 
00129 
00130     // Check if matrix is assymetric and if so agglomerate both upper and lower
00131     // coefficients ...
00132     if (fineMatrix.hasLower())
00133     {
00134         // Get off-diagonal matrix coefficients
00135         const scalarField& fineUpper = fineMatrix.upper();
00136         const scalarField& fineLower = fineMatrix.lower();
00137 
00138         // Coarse matrix upper coefficients
00139         scalarField& coarseUpper = coarseMatrix.upper();
00140         scalarField& coarseLower = coarseMatrix.lower();
00141 
00142         const labelList& restrictAddr =
00143             agglomeration_.restrictAddressing(fineLevelIndex);
00144 
00145         const unallocLabelList& l = fineMatrix.lduAddr().lowerAddr();
00146         const unallocLabelList& cl = coarseMatrix.lduAddr().lowerAddr();
00147         const unallocLabelList& cu = coarseMatrix.lduAddr().upperAddr();
00148 
00149         forAll(faceRestrictAddr, fineFacei)
00150         {
00151             label cFace = faceRestrictAddr[fineFacei];
00152 
00153             if (cFace >= 0)
00154             {
00155                 // Check the orientation of the fine-face relative to the
00156                 // coarse face it is being agglomerated into
00157                 if (cl[cFace] == restrictAddr[l[fineFacei]])
00158                 {
00159                     coarseUpper[cFace] += fineUpper[fineFacei];
00160                     coarseLower[cFace] += fineLower[fineFacei];
00161                 }
00162                 else if (cu[cFace] == restrictAddr[l[fineFacei]])
00163                 {
00164                     coarseUpper[cFace] += fineLower[fineFacei];
00165                     coarseLower[cFace] += fineUpper[fineFacei];
00166                 }
00167                 else
00168                 {
00169                     FatalErrorIn
00170                     (
00171                         "GAMGSolver::agglomerateMatrix(const label)"
00172                     )   << "Inconsistent addressing between "
00173                            "fine and coarse grids"
00174                         << exit(FatalError);
00175                 }
00176             }
00177             else
00178             {
00179                 // Add the fine face coefficients into the diagonal.
00180                 coarseDiag[-1 - cFace] +=
00181                     fineUpper[fineFacei] + fineLower[fineFacei];
00182             }
00183         }
00184     }
00185     else // ... Otherwise it is symmetric so agglomerate just the upper 
00186     {
00187         // Get off-diagonal matrix coefficients
00188         const scalarField& fineUpper = fineMatrix.upper();
00189 
00190         // Coarse matrix upper coefficients
00191         scalarField& coarseUpper = coarseMatrix.upper();
00192 
00193         forAll(faceRestrictAddr, fineFacei)
00194         {
00195             label cFace = faceRestrictAddr[fineFacei];
00196 
00197             if (cFace >= 0)
00198             {
00199                 coarseUpper[cFace] += fineUpper[fineFacei];
00200             }
00201             else
00202             {
00203                 // Add the fine face coefficient into the diagonal.
00204                 coarseDiag[-1 - cFace] += 2*fineUpper[fineFacei];
00205             }
00206         }
00207     }
00208 }
00209 
00210 
00211 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd