strainRateFunction.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) 2016-2017 OpenFOAM Foundation
9  Copyright (C) 2017-2021 OpenCFD Ltd.
10  Copyright (C) 2026 Keysight Technologies
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "strainRateFunction.H"
32 #include "surfaceFields.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace viscosityModels
39 {
40  defineTypeNameAndDebug(strainRateFunction, 0);
41 
43  (
44  viscosityModel,
45  strainRateFunction,
46  dictionary
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
53 
56 {
58  const volScalarField& sigma = tsigma();
59 
60  auto tnu = tmp<volScalarField>::New
61  (
62  U_.mesh().newIOobject("nu"),
63  U_.mesh(),
65  );
66  scalarField& nu = tnu.ref().primitiveFieldRef();
67 
68  nu = strainRateFunction_->value(sigma());
69 
70  volScalarField::Boundary& nuBf = tnu.ref().boundaryFieldRef();
71  const volScalarField::Boundary& sigmaBf = sigma.boundaryField();
72 
73  forAll(nuBf, patchi)
74  {
75  nuBf[patchi] = strainRateFunction_->value(sigmaBf[patchi]);
76  }
77 
78  return tnu;
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
83 
85 (
86  const word& name,
87  const dictionary& viscosityProperties,
88  const volVectorField& U,
89  const surfaceScalarField& phi
90 )
91 :
92  viscosityModel(name, viscosityProperties, U, phi),
93  strainRateFunctionCoeffs_
94  (
95  viscosityProperties.optionalSubDict(typeName + "Coeffs")
96  ),
97  strainRateFunction_
98  (
99  Function1<scalar>::New
100  (
101  "function",
102  strainRateFunctionCoeffs_,
103  &U_.db()
104  )
105  ),
106  nu_
107  (
108  IOobject
109  (
110  name,
111  U_.time().timeName(),
112  U_.db(),
113  IOobject::NO_READ,
114  IOobject::AUTO_WRITE
115  ),
116  U_.mesh(),
118  )
119 {
121 }
122 
123 
124 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
125 
128 {
129  return nu_;
130 }
131 
132 
134 Foam::viscosityModels::strainRateFunction::nu(const label patchi) const
135 {
136  return nu_.boundaryField()[patchi];
137 }
138 
139 
141 {
142  nu_ = calcNu();
143 }
144 
145 
147 (
148  const dictionary& viscosityProperties
149 )
150 {
151  viscosityModel::read(viscosityProperties);
152 
153  strainRateFunctionCoeffs_ = viscosityProperties.optionalSubDict
154  (
155  typeName + "Coeffs"
156  );
157 
158  strainRateFunction_.clear();
159  strainRateFunction_ = Function1<scalar>::New
160  (
161  "function",
162  strainRateFunctionCoeffs_,
163  &U_.db()
164  );
165 
166  return true;
167 }
168 
169 
170 // ************************************************************************* //
Foam::surfaceFields.
virtual bool read(const dictionary &viscosityProperties)
Read transportProperties dictionary.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
virtual tmp< volScalarField > nu() const
Return the laminar viscosity.
const dimensionSet dimViscosity
tmp< volScalarField > strainRate() const
Return the strain rate.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
const volVectorField & U_
An abstract base class for incompressible viscosityModels.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:400
word timeName
Definition: getTimeIndex.H:3
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:560
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
addToRunTimeSelectionTable(viscosityModel, BirdCarreau, dictionary)
virtual bool read(const dictionary &viscosityProperties)=0
Read transportProperties dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:63
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:217
defineTypeNameAndDebug(BirdCarreau, 0)
strainRateFunction(const word &name, const dictionary &viscosityProperties, const volVectorField &U, const surfaceScalarField &phi)
Construct from components.
U
Definition: pEqn.H:72
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const Mesh & mesh() const noexcept
Return const reference to mesh.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
void clear()
Clear the dictionary.
Definition: dictionary.C:862
virtual void correct()
Correct the laminar viscosity.
tmp< volScalarField > calcNu() const
Calculate and return the laminar viscosity.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:188
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127