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 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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"
34 
35 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace fv
40 {
41  defineTypeNameAndDebug(viscousDissipation, 0);
42 
44  (
45  option,
46  viscousDissipation,
47  dictionary
48  );
49 }
50 }
51 
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 
54 Foam::tmp<Foam::volScalarField> Foam::fv::viscousDissipation::rho() const
55 {
57  (
58  IOobject
59  (
60  "trho",
61  mesh_.time().timeName(),
62  mesh_,
65  ),
66  mesh_,
67  rho_
68  );
69 
70  if (rho_.value() > 0)
71  {
72  return trho;
73  }
74  else if (rhoName_ != "none")
75  {
76  trho.ref() = mesh_.lookupObject<volScalarField>(rhoName_);
77  return trho;
78  }
79 
81  << "Neither rhoName nor rho are specified."
82  << exit(FatalError);
83 
84  return nullptr;
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89 
90 Foam::fv::viscousDissipation::viscousDissipation
91 (
92  const word& sourceName,
93  const word& modelType,
94  const dictionary& dict,
95  const fvMesh& mesh
96 )
97 :
98  option(sourceName, modelType, dict, mesh),
99  UName_(coeffs_.lookupOrDefault<word>("U", "U")),
100  rhoName_(coeffs_.lookupOrDefault<word>("rho", "none")),
101  rho_
102  (
103  coeffs_.lookupOrDefault
104  (
105  "rhoInf",
106  dimensionedScalar("rho", dimDensity, 0)
107  )
108  )
109 {
110  const basicThermo* thermoPtr =
111  mesh_.findObject<basicThermo>(basicThermo::dictName);
112 
113  if (thermoPtr)
114  {
115  fieldNames_.setSize(1, thermoPtr->he().name());
116  }
117 
118  if (fieldNames_.empty())
119  {
120  coeffs_.readEntry("fields", fieldNames_);
121  }
122 
123  if (fieldNames_.size() != 1)
124  {
126  << "settings are:" << fieldNames_ << exit(FatalError);
127  }
128 
129  applied_.setSize(fieldNames_.size(), false);
130 }
131 
132 
133 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 
136 Foam::fv::viscousDissipation::devRhoReff() const
137 {
138  // Incompressible
139  {
140  const auto* turbPtr =
141  mesh_.findObject<incompressible::turbulenceModel>
142  (
144  );
145 
146  if (turbPtr)
147  {
148  return tmp<volSymmTensorField>(rho()*turbPtr->devRhoReff());
149  }
150  }
151 
152  // Compressible
153  {
154  const auto* turbPtr =
155  mesh_.findObject<compressible::turbulenceModel>
156  (
158  );
159 
160  if (turbPtr)
161  {
162  return tmp<volSymmTensorField>(turbPtr->devRhoReff());
163  }
164  }
165 
167  << " The turbulence model is not found in the database."
168  << exit(FatalError);
169 
170  return nullptr;
171 }
172 
173 
175 (
176  const volScalarField& rho,
177  fvMatrix<scalar>& eqn,
178  const label fieldi
179 )
180 {
181  typedef typename outerProduct<vector, vector>::type GradType;
183 
184  const word gradUName("grad(" + UName_ + ')');
185 
186  auto tgradU = tmp<GradFieldType>::New
187  (
188  IOobject
189  (
190  "gradU",
191  mesh_.time().timeName(),
192  mesh_.time(),
195  ),
196  mesh_,
198  );
199 
200  // Cached?
201  const GradFieldType* gradUPtr = mesh_.findObject<GradFieldType>(gradUName);
202 
203  if (gradUPtr)
204  {
205  tgradU.ref() = *gradUPtr;
206  }
207  else
208  {
209  const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
210  tgradU.ref() = fvc::grad(U);
211  }
212 
213  const volScalarField D("D", devRhoReff() && tgradU.ref());
214 
215  eqn -= D;
216 }
217 
218 
219 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
basicThermo.H
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:54
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::dimDensity
const dimensionSet dimDensity
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:764
turbulentTransportModel.H
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:100
Foam::basicThermo
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:63
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:404
rho
rho
Definition: readInitialConditions.H:96
Foam::fv::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:82
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
trho
tmp< volScalarField > trho
Definition: setRegionSolidFields.H:4
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::fv::option
Finite volume options abstract base class. Provides a base set of controls, e.g.:
Definition: fvOption.H:69
Foam::compressible::turbulenceModel
ThermalDiffusivity< CompressibleTurbulenceModel< fluidThermo > > turbulenceModel
Definition: turbulentFluidThermoModel.H:63
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
viscousDissipation.H
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionary.H:458
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::dimensioned< scalar >
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(option, 0)
U
U
Definition: pEqn.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, fixedTemperatureConstraint, dictionary)
Foam::GeometricField::ref
Internal & ref(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
Definition: GeometricField.C:718
Foam::fv::viscousDissipation::addSup
virtual void addSup(const volScalarField &rho, fvMatrix< scalar > &eqn, const label fieldi)
Add explicit contribution to compressible energy equation.
Definition: viscousDissipation.C:175
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
D
const dimensionedScalar & D
Definition: solveBulkSurfactant.H:4
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:246
Foam::IncompressibleTurbulenceModel
Templated abstract base class for single-phase incompressible turbulence models.
Definition: IncompressibleTurbulenceModel.H:55
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::basicThermo::he
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
Foam::dimensionedTensor
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
Definition: dimensionedTensor.H:51
turbulentFluidThermoModel.H