Changed the coeffs dictionary construction to allow better error messages.
[OpenFOAM-1.6.x.git] / src / turbulenceModels / compressible / LES / LESModel / LESModel.C
blob7964ae56cbddfa27752be501076d23cb82bdd2c4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "LESModel.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
34 namespace compressible
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(LESModel, 0);
40 defineRunTimeSelectionTable(LESModel, dictionary);
41 addToRunTimeSelectionTable(turbulenceModel, LESModel, turbulenceModel);
43 // * * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * //
45 void LESModel::printCoeffs()
47     if (printCoeffs_)
48     {
49         Info<< type() << "Coeffs" << coeffDict_ << endl;
50     }
54 // * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * * //
56 LESModel::LESModel
58     const word& type,
59     const volScalarField& rho,
60     const volVectorField& U,
61     const surfaceScalarField& phi,
62     const basicThermo& thermoPhysicalModel
65     turbulenceModel(rho, U, phi, thermoPhysicalModel),
67     IOdictionary
68     (
69         IOobject
70         (
71             "LESProperties",
72             U.time().constant(),
73             U.db(),
74             IOobject::MUST_READ,
75             IOobject::NO_WRITE
76         )
77     ),
79     printCoeffs_(lookupOrDefault<Switch>("printCoeffs", false)),
80     coeffDict_(subOrEmptyDict(type + "Coeffs")),
82     k0_("k0", dimVelocity*dimVelocity, SMALL),
84     delta_(LESdelta::New("delta", U.mesh(), *this))
86     readIfPresent("k0", k0_);
88     // Force the construction of the mesh deltaCoeffs which may be needed
89     // for the construction of the derived models and BCs
90     mesh_.deltaCoeffs();
94 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
96 autoPtr<LESModel> LESModel::New
98     const volScalarField& rho,
99     const volVectorField& U,
100     const surfaceScalarField& phi,
101     const basicThermo& thermoPhysicalModel
104     word modelName;
106     // Enclose the creation of the dictionary to ensure it is deleted
107     // before the turbulenceModel is created otherwise the dictionary is
108     // entered in the database twice
109     {
110         IOdictionary dict
111         (
112             IOobject
113             (
114                 "LESProperties",
115                 U.time().constant(),
116                 U.db(),
117                 IOobject::MUST_READ,
118                 IOobject::NO_WRITE
119             )
120         );
122         dict.lookup("LESModel") >> modelName;
123     }
125     Info<< "Selecting LES turbulence model " << modelName << endl;
127     dictionaryConstructorTable::iterator cstrIter =
128         dictionaryConstructorTablePtr_->find(modelName);
130     if (cstrIter == dictionaryConstructorTablePtr_->end())
131     {
132         FatalErrorIn
133         (
134             "LESModel::New(const volVectorField& U, const "
135             "surfaceScalarField& phi, const basicThermo&)"
136         )   << "Unknown LESModel type " << modelName
137             << endl << endl
138             << "Valid LESModel types are :" << endl
139             << dictionaryConstructorTablePtr_->toc()
140             << exit(FatalError);
141     }
143     return autoPtr<LESModel>(cstrIter()(rho, U, phi, thermoPhysicalModel));
147 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
149 void LESModel::correct(const tmp<volTensorField>&)
151     delta_().correct();
155 void LESModel::correct()
157     correct(fvc::grad(U_));
161 bool LESModel::read()
163     if (regIOobject::read())
164     {
165         if (const dictionary* dictPtr = subDictPtr(type() + "Coeffs"))
166         {
167             coeffDict_ <<= *dictPtr;
168         }
170         readIfPresent("k0", k0_);
172         delta_().read(*this);
174         return true;
175     }
176     else
177     {
178         return false;
179     }
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 } // End namespace compressible
186 } // End namespace Foam
188 // ************************************************************************* //