acousticDampingSource.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-2021 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 "acousticDampingSource.H"
29 #include "fvMesh.H"
30 #include "fvMatrices.H"
31 #include "fvmSup.H"
33 #include "mathematicalConstants.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace fv
41 {
42  defineTypeNameAndDebug(acousticDampingSource, 0);
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
49 
51 {
53 
54  const vectorField& Cf = mesh_.C();
55 
56  const scalar pi = constant::mathematical::pi;
57 
58  forAll(cells_, i)
59  {
60  label celli = cells_[i];
61  scalar d = mag(Cf[celli] - x0_);
62 
63  if (d < r1_)
64  {
65  blendFactor_[celli] = 0.0;
66  }
67  else if ((d >= r1_) && (d <= r2_))
68  {
69  blendFactor_[celli] = (1.0 - cos(pi*mag(d - r1_)/(r2_ - r1_)))/2.0;
70  }
71  }
72 
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
80 (
81  const word& name,
82  const word& modelType,
83  const dictionary& dict,
84  const fvMesh& mesh
85 )
86 :
87  fv::cellSetOption(name, modelType, dict, mesh),
88  blendFactor_
89  (
91  (
92  IOobject
93  (
94  name_ + ":blend",
95  mesh_.time().timeName(),
96  mesh_,
97  IOobject::NO_READ,
98  IOobject::NO_WRITE
99  ),
100  mesh_,
101  dimensionedScalar("blend0", dimless, 1.0),
103  )
104  ),
105  frequency_("frequency", dimless/dimTime, 0),
106  x0_(Zero),
107  r1_(0),
108  r2_(0),
109  URefName_("unknown-URef"),
110  w_(20)
111 {
113 }
114 
115 
116 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117 
119 (
120  fvMatrix<vector>& eqn,
121  const label fieldI
122 )
123 {
124  const volVectorField& U = eqn.psi();
125  const volScalarField coeff(name_ + ":coeff", w_*frequency_*blendFactor_);
126  const auto& URef = mesh().lookupObject<volVectorField>(URefName_);
127 
128  fvMatrix<vector> dampingEqn
129  (
130  fvm::Sp(coeff, U) - coeff*URef
131  );
132  eqn -= dampingEqn;
133 }
134 
135 
137 (
138  const volScalarField& rho,
139  fvMatrix<vector>& eqn,
140  const label fieldI
141 )
142 {
143  const volVectorField& U = eqn.psi();
144  const volScalarField coeff(name_ + ":coeff", w_*frequency_*blendFactor_);
145  const auto& URef = mesh().lookupObject<volVectorField>(URefName_);
146 
147  fvMatrix<vector> dampingEqn
148  (
149  fvm::Sp(rho*coeff, U) - rho*coeff*URef
150  );
151  eqn -= dampingEqn;
152 }
153 
154 
156 (
157  const volScalarField& alpha,
158  const volScalarField& rho,
159  fvMatrix<vector>& eqn,
160  const label fieldI
161 )
162 {
163  const volVectorField& U = eqn.psi();
164  const volScalarField coeff(name_ + ":coeff", w_*frequency_*blendFactor_);
165  const auto& URef = mesh().lookupObject<volVectorField>(URefName_);
166 
167  fvMatrix<vector> dampingEqn
168  (
169  fvm::Sp(alpha*rho*coeff, U) - alpha*rho*coeff*URef
170  );
171  eqn -= dampingEqn;
172 }
173 
174 
176 {
178  {
179  if (!coeffs_.readIfPresent("UNames", fieldNames_))
180  {
181  fieldNames_.resize(1);
182  fieldNames_.first() = coeffs_.getOrDefault<word>("U", "U");
183  }
184 
186 
187  coeffs_.readEntry("frequency", frequency_.value());
188  coeffs_.readEntry("URef", URefName_);
189  coeffs_.readCompat<vector>("origin", {{"centre", -1806}}, x0_);
190  coeffs_.readEntry("radius1", r1_);
191  coeffs_.readEntry("radius2", r2_);
192 
193  if (coeffs_.readIfPresent("w", w_))
194  {
195  Info<< name_ << ": Setting stencil width to " << w_ << endl;
196  }
197 
198  setBlendingFactor();
199 
200  return true;
201  }
202 
203  return false;
204 }
205 
206 
207 // ************************************************************************* //
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:191
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:165
mathematicalConstants.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:159
Foam::fv::acousticDampingSource::addSup
virtual void addSup(fvMatrix< vector > &eqn, const label fieldI)
Definition: acousticDampingSource.C:112
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::fv::option::resetApplied
void resetApplied()
Definition: fvOption.C:41
Foam::fv::acousticDampingSource::r2_
scalar r2_
Definition: acousticDampingSource.H:197
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Definition: readThermalProperties.H:212
Foam::fv::acousticDampingSource::setBlendingFactor
void setBlendingFactor()
Definition: acousticDampingSource.C:43
Foam::read
bool read(const char *buf, int32_t &val)
Definition: int32.H:125
Foam::fv::acousticDampingSource::x0_
point x0_
Definition: acousticDampingSource.H:191
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::fv::acousticDampingSource::r1_
scalar r1_
Definition: acousticDampingSource.H:194
Foam::fv::option::mesh_
const fvMesh & mesh_
Definition: fvOption.H:135
Foam::zeroGradientFvPatchField
This boundary condition applies a zero-gradient condition from the patch internal field onto the patc...
Definition: zeroGradientFvPatchField.H:60
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::fv::acousticDampingSource::read
virtual bool read(const dictionary &dict)
Definition: acousticDampingSource.C:168
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
Foam::fvm::Sp
tmp< fvMatrix< Type > > Sp(const volScalarField::Internal &, const GeometricField< Type, fvPatchField, volMesh > &)
Foam::fv::option
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:122
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::Info
messageStream Info
rho
rho
Definition: readInitialConditions.H:88
Foam::fv::cellSetOption::read
virtual bool read(const dictionary &dict)
Definition: cellSetOption.C:248
Foam::fv::acousticDampingSource
Applies sources on velocity (i.e. U) within a specified region to enable acoustic damping.
Definition: acousticDampingSource.H:176
Foam::fv::cellSetOption::cells_
labelList cells_
Definition: cellSetOption.H:200
Foam::fvMesh::C
const volVectorField & C() const
Definition: fvMeshGeometry.C:334
timeName
word timeName
Definition: getTimeIndex.H:3
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fvMatrix::psi
const GeometricField< Type, fvPatchField, volMesh > & psi(const label i=0) const
Definition: fvMatrix.H:395
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:36
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:81
fvMesh.H
Foam
Definition: atmBoundaryLayer.C:26
fvmSup.H
Calculate the matrix for implicit and explicit sources.
Foam::GeometricField::primitiveFieldRef
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Definition: GeometricField.C:759
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Definition: GeometricField.C:933
acousticDampingSource.H
fv
labelList fv(nPoints)
U
U
Definition: pEqn.H:72
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::fv::acousticDampingSource::acousticDampingSource
acousticDampingSource(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Definition: acousticDampingSource.C:73
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::fv::acousticDampingSource::blendFactor_
volScalarField blendFactor_
Definition: acousticDampingSource.H:185
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:64
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:49
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:184
zeroGradientFvPatchFields.H
Foam::dimless
const dimensionSet dimless
Definition: dimensionSets.C:182
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:258