damping.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "damping.H"
27 #include "fvMatrix.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace fv
35 {
36  defineTypeNameAndDebug(damping, 0);
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
42 
44 {
45  UName_ = coeffs().lookupOrDefault<word>("U", "U");
46 
47  lambda_ =
49  (
50  lambda_.name(),
51  lambda_.dimensions(),
52  coeffs().lookup(lambda_.name())
53  );
54 
55  const bool foundScale = coeffs().found("scale");
56  const bool foundOgn = coeffs().found("origin");
57  const bool foundDir = coeffs().found("direction");
58  const bool foundOgns = coeffs().found("origins");
59  const bool foundDirs = coeffs().found("directions");
60  const bool foundAll =
61  foundScale
62  && (
63  (foundOgn && foundDir && !foundOgns && !foundDirs)
64  || (!foundOgn && !foundDir && foundOgns && foundDirs)
65  );
66  const bool foundAny =
67  foundScale || foundOgn || foundDir || foundOgns || foundDirs;
68 
69  if (!foundAll)
70  {
71  scale_ = autoPtr<Function1<scalar>>();
72  origins_.clear();
73  directions_.clear();
74  }
75 
76  if (foundAll)
77  {
78  scale_ = Function1<scalar>::New("scale", coeffs());
79  if (foundOgn)
80  {
81  origins_.setSize(1);
82  directions_.setSize(1);
83  coeffs().lookup("origin") >> origins_.last();
84  coeffs().lookup("direction") >> directions_.last();
85  }
86  else
87  {
88  coeffs().lookup("origins") >> origins_;
89  coeffs().lookup("directions") >> directions_;
90 
91  if
92  (
93  origins_.size() == 0
94  || directions_.size() == 0
95  || origins_.size() != directions_.size()
96  )
97  {
99  << "The same, non-zero number of origins and "
100  << "directions must be provided" << exit(FatalError);
101  }
102  }
103  forAll(directions_, i)
104  {
105  directions_[i] /= mag(directions_[i]);
106  }
107  }
108 
109  if (!foundAll && foundAny)
110  {
112  << "The scaling specification is incomplete. \"scale\", "
113  << "\"origin\" and \"direction\" (or \"origins\" and "
114  << "\"directions\"), must all be specified in order to scale "
115  << "the damping. The damping will be applied uniformly across "
116  << "the cell set." << endl << endl;
117  }
118 }
119 
120 
122 {
124  (
126  (
127  IOobject
128  (
129  type() + ":forceCoeff",
130  mesh().time().timeName(),
131  mesh()
132  ),
133  mesh(),
134  dimensionedScalar(lambda_.dimensions(), scale_.valid() ? 0 : 1)
135  )
136  );
137  scalarField& forceCoeff = tforceCoeff.ref();
138 
139  forAll(origins_, i)
140  {
141  const vectorField& c = mesh().cellCentres();
142  const scalarField x((c - origins_[i]) & directions_[i]);
143  forceCoeff = max(forceCoeff, scale_->value(x));
144  }
145 
146  forceCoeff *= lambda_.value();
147 
148  // Write out the force coefficient for debugging
149  if (debug && mesh().time().writeTime())
150  {
151  volScalarField vForceCoeff
152  (
153  IOobject
154  (
155  type() + ":forceCoeff",
156  mesh().time().timeName(),
157  mesh()
158  ),
159  mesh(),
160  lambda_.dimensions(),
162  );
163  vForceCoeff.primitiveFieldRef() = forceCoeff;
164  vForceCoeff.correctBoundaryConditions();
165  vForceCoeff.write();
166  }
167 
168  return tforceCoeff;
169 }
170 
171 
172 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
173 
175 (
176  const word& name,
177  const word& modelType,
178  const dictionary& dict,
179  const fvMesh& mesh
180 )
181 :
182  fvModel(name, modelType, dict, mesh),
183  UName_(word::null),
184  lambda_("lambda", dimless/dimTime, NaN),
185  scale_(nullptr),
186  origins_(),
187  directions_()
188 {
189  readCoeffs();
190 }
191 
192 
193 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
194 
196 {
197  return wordList(1, UName_);
198 }
199 
200 
202 {
203  if (fvModel::read(dict))
204  {
205  readCoeffs();
206  return true;
207  }
208  else
209  {
210  return false;
211  }
212 }
213 
214 
215 // ************************************************************************* //
defineTypeNameAndDebug(fixedTemperatureConstraint, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:158
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void readCoeffs()
Non-virtual read.
Definition: damping.C:43
Finite volume model abstract base class.
Definition: fvModel.H:55
damping(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: damping.C:175
const dimensionSet dimless
const dimensionedScalar c
Speed of light in a vacuum.
void clear()
Delete object (if the pointer is valid) and set pointer to.
Definition: autoPtrI.H:126
const dimensionSet dimTime
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: damping.C:201
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
static const word null
An empty word.
Definition: word.H:77
virtual wordList addSupFields() const
Return the list of fields for which the fvModel adds source term.
Definition: damping.C:195
word timeName
Definition: getTimeIndex.H:3
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
This boundary condition applies a zero-gradient condition from the patch internal field onto the patc...
List< word > wordList
A List of words.
Definition: fileName.H:54
#define WarningInFunction
Report a warning using Foam::Warning.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensioned< scalar > mag(const dimensioned< Type > &)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
tmp< volScalarField::Internal > forceCoeff() const
Return the force coefficient.
Definition: damping.C:121
Namespace for OpenFOAM.
static autoPtr< Function1< Type > > New(const word &name, const dictionary &dict)
Selector.
Definition: Function1New.C:32