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

smoothDelta.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 "smoothDelta.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "FaceCellWave.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 defineTypeNameAndDebug(smoothDelta, 0);
00039 addToRunTimeSelectionTable(LESdelta, smoothDelta, dictionary);
00040 
00041 scalar smoothDelta::deltaData::maxDeltaRatio = 1.2;
00042 
00043 
00044 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00045 
00046 // Fill changedFaces (with face labels) and changedFacesInfo (with delta)
00047 // This is the initial set of faces from which to start the waves.
00048 // Since there might be lots of places with delta jumps we can follow various
00049 // strategies for this initial 'seed'.
00050 // - start from single cell/face and let FaceCellWave pick up all others
00051 //   from there. might be quite a few waves before everything settles.
00052 // - start from all faces. Lots of initial transfers.
00053 // We do something inbetween:
00054 // - start from all faces where there is a jump. Since we cannot easily
00055 //   determine this across coupled patches (cyclic, processor) introduce
00056 //   all faces of these and let FaceCellWave sort it out.
00057 void smoothDelta::setChangedFaces
00058 (
00059     const polyMesh& mesh,
00060     const volScalarField& delta,
00061     DynamicList<label>& changedFaces,
00062     DynamicList<deltaData>& changedFacesInfo
00063 )
00064 {
00065     for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
00066     {
00067         scalar ownDelta = delta[mesh.faceOwner()[faceI]];
00068 
00069         scalar neiDelta = delta[mesh.faceNeighbour()[faceI]];
00070 
00071         // Check if owner delta much larger than neighbour delta or vice versa
00072 
00073         if (ownDelta > deltaData::maxDeltaRatio * neiDelta)
00074         {
00075             changedFaces.append(faceI);
00076             changedFacesInfo.append(deltaData(ownDelta));
00077         }
00078         else if (neiDelta > deltaData::maxDeltaRatio * ownDelta)
00079         {
00080             changedFaces.append(faceI);
00081             changedFacesInfo.append(deltaData(neiDelta));
00082         }
00083     }
00084 
00085     // Insert all faces of coupled patches no matter what. Let FaceCellWave
00086     // sort it out.
00087     forAll(mesh.boundaryMesh(), patchI) 
00088     {
00089         const polyPatch& patch = mesh.boundaryMesh()[patchI];
00090 
00091         if (patch.coupled())
00092         {
00093             forAll(patch, patchFaceI)
00094             {
00095                 label meshFaceI = patch.start() + patchFaceI;
00096 
00097                 scalar ownDelta = delta[mesh.faceOwner()[meshFaceI]];
00098 
00099                 changedFaces.append(meshFaceI);
00100                 changedFacesInfo.append(deltaData(ownDelta));
00101             }
00102         }
00103     }
00104 
00105     changedFaces.shrink();
00106     changedFacesInfo.shrink();
00107 }
00108 
00109 
00110 void smoothDelta::calcDelta()
00111 {
00112     deltaData::maxDeltaRatio = maxDeltaRatio_;
00113     const volScalarField& geometricDelta = geometricDelta_();
00114 
00115     // Fill changed faces with info
00116     DynamicList<label> changedFaces(mesh_.nFaces()/100 + 100);
00117     DynamicList<deltaData> changedFacesInfo(changedFaces.size());
00118 
00119     setChangedFaces(mesh_, geometricDelta, changedFaces, changedFacesInfo);
00120 
00121     // Set initial field on cells.
00122     List<deltaData> cellDeltaData(mesh_.nCells());
00123 
00124     forAll(geometricDelta, cellI)
00125     {
00126         cellDeltaData[cellI] = geometricDelta[cellI];
00127     }
00128 
00129     // Set initial field on faces.
00130     List<deltaData> faceDeltaData(mesh_.nFaces());
00131 
00132 
00133     // Propagate information over whole domain.
00134     FaceCellWave<deltaData> deltaCalc
00135     (
00136         mesh_,
00137         changedFaces,
00138         changedFacesInfo,
00139         faceDeltaData,
00140         cellDeltaData,
00141         mesh_.globalData().nTotalCells()    // max iterations
00142     );
00143 
00144     forAll(delta_, cellI)
00145     {
00146         delta_[cellI] = cellDeltaData[cellI].delta();
00147     }
00148 }
00149 
00150 
00151 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00152 
00153 smoothDelta::smoothDelta
00154 (
00155     const word& name,
00156     const fvMesh& mesh,
00157     const dictionary& dd
00158 )
00159 :
00160     LESdelta(name, mesh),
00161     geometricDelta_
00162     (
00163         LESdelta::New("geometricDelta", mesh, dd.subDict(type() + "Coeffs"))
00164     ),
00165     maxDeltaRatio_
00166     (
00167         readScalar(dd.subDict(type() + "Coeffs").lookup("maxDeltaRatio"))
00168     )
00169 {
00170     calcDelta();
00171 }
00172 
00173 
00174 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00175 
00176 void smoothDelta::read(const dictionary& d)
00177 {
00178     const dictionary& dd(d.subDict(type() + "Coeffs"));
00179 
00180     geometricDelta_().read(dd);
00181     dd.lookup("maxDeltaRatio") >> maxDeltaRatio_;
00182     calcDelta();
00183 }
00184 
00185 
00186 void smoothDelta::correct()
00187 {
00188     geometricDelta_().correct();
00189 
00190     if (mesh_.changing())
00191     {
00192         calcDelta();
00193     }
00194 }
00195 
00196 
00197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00198 
00199 } // End namespace Foam
00200 
00201 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd