Loading...
Searching...
No Matches
viscousDissipation.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2017-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "viscousDissipation.H"
29#include "fvMatrices.H"
32#include "basicThermo.H"
35// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
36
37namespace Foam
38{
39namespace fv
40{
43}
44}
45
46// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47
48Foam::tmp<Foam::volScalarField> Foam::fv::viscousDissipation::rho() const
49{
51 (
52 "trho",
54 mesh_,
55 rho_
56 );
57
58 if (rho_.value() > 0)
59 {
60 return trho;
61 }
62 else if (rhoName_ != "none")
63 {
64 trho.ref() = mesh_.lookupObject<volScalarField>(rhoName_);
65 return trho;
66 }
67
69 << "Neither rhoName nor rho are specified."
70 << exit(FatalError);
72 return nullptr;
73}
74
75
76// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
77
79(
80 const word& sourceName,
81 const word& modelType,
82 const dictionary& dict,
83 const fvMesh& mesh
84)
85:
86 fv::option(sourceName, modelType, dict, mesh),
87 UName_(coeffs_.getOrDefault<word>("U", "U")),
88 rhoName_(coeffs_.getOrDefault<word>("rho", "none")),
89 rho_
90 (
91 coeffs_.getOrDefault
92 (
93 "rhoInf",
95 )
96 )
97{
98 const auto* thermoPtr =
100
101 if (thermoPtr)
102 {
103 fieldNames_.resize(1, thermoPtr->he().name());
104 }
105
106 if (fieldNames_.empty())
107 {
108 coeffs_.readEntry("fields", fieldNames_);
109 }
110
111 if (fieldNames_.size() != 1)
112 {
113 FatalErrorInFunction
114 << "settings are:" << fieldNames_ << exit(FatalError);
115 }
116
118}
119
120
121// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122
124Foam::fv::viscousDissipation::devRhoReff() const
125{
126 // Incompressible
127 {
128 const auto* turbPtr =
129 mesh_.findObject<incompressible::turbulenceModel>
130 (
132 );
133
134 if (turbPtr)
135 {
136 return tmp<volSymmTensorField>(rho()*turbPtr->devRhoReff());
137 }
138 }
139
140 // Compressible
141 {
142 const auto* turbPtr =
143 mesh_.findObject<compressible::turbulenceModel>
144 (
146 );
147
148 if (turbPtr)
149 {
150 return tmp<volSymmTensorField>(turbPtr->devRhoReff());
151 }
152 }
153
155 << " The turbulence model is not found in the database."
156 << exit(FatalError);
157
158 return nullptr;
159}
160
161
163(
164 const volScalarField& rho,
165 fvMatrix<scalar>& eqn,
166 const label fieldi
167)
168{
169 typedef typename outerProduct<vector, vector>::type GradType;
171
172 const word gradUName("grad(" + UName_ + ')');
173
174 auto tgradU = GradFieldType::New
175 (
176 "gradU",
178 mesh_,
180 );
181
182 // Cached?
183 const auto* gradUPtr = mesh_.findObject<GradFieldType>(gradUName);
184
185 if (gradUPtr)
186 {
187 tgradU.ref() = *gradUPtr;
188 }
189 else
190 {
191 const auto& U = mesh_.lookupObject<volVectorField>(UName_);
192 tgradU.ref() = fvc::grad(U);
193 }
194
195 const volScalarField D("D", devRhoReff() && tgradU.ref());
196
197 eqn -= D;
198}
199
200
201// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
if(patchID !=-1)
Generic GeometricField class.
static tmp< GeometricField< scalar, fvPatchField, volMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=fvPatchField< scalar >::calculatedType())
@ NO_REGISTER
Do not request registration (bool: false).
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Abstract base-class for fluid and solid thermodynamic properties.
Definition basicThermo.H:62
static const word dictName
The dictionary name ("thermophysicalProperties").
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const Type & value() const noexcept
Return const reference to value.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition fvMatrix.H:118
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Base abstract class for handling finite volume options (i.e. fvOption).
Definition fvOption.H:124
const fvMesh & mesh_
Reference to the mesh database.
Definition fvOption.H:142
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition fvOption.H:157
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition fvOption.C:51
dictionary coeffs_
Dictionary containing source coefficients.
Definition fvOption.H:152
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition fvOption.C:41
const fvMesh & mesh() const noexcept
Return const access to the mesh database.
Definition fvOptionI.H:30
Applies a viscous dissipation energy source to the energy equation.
virtual void addSup(const volScalarField &rho, fvMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to compressible energy equation.
viscousDissipation(const word &sourceName, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from explicit source name and mesh.
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
Definition products.H:118
A class for managing temporary objects.
Definition tmp.H:75
static const word propertiesName
Default name of the turbulence properties dictionary.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
U
Definition pEqn.H:72
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
A special matrix type and solver, designed for finite volume solutions of scalar equations.
ThermalDiffusivity< CompressibleTurbulenceModel< fluidThermo > > turbulenceModel
Namespace for finite-volume.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition fvcGrad.C:47
IncompressibleTurbulenceModel< transportModel > turbulenceModel
Namespace for OpenFOAM.
GeometricField< vector, fvPatchField, volMesh > volVectorField
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionSet dimDensity
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
dictionary dict
tmp< volScalarField > trho
const dimensionedScalar & D