actuationDiskSource.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 ENERCON GmbH
10  Copyright (C) 2018-2022 OpenCFD Ltd
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 "actuationDiskSource.H"
31 #include "geometricOneField.H"
32 #include "cellSet.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace fv
40 {
41  defineTypeNameAndDebug(actuationDiskSource, 0);
42  addToRunTimeSelectionTable(option, actuationDiskSource, dictionary);
43 }
44 }
45 
46 
47 const Foam::Enum
48 <
50 >
52 ({
53  { forceMethodType::FROUDE, "Froude" },
54  { forceMethodType::VARIABLE_SCALING, "variableScaling" },
55 });
56 
57 
58 const Foam::Enum
59 <
61 >
63 ({
64  { monitorMethodType::POINTS, "points" },
65  { monitorMethodType::CELLSET, "cellSet" },
66 });
67 
68 
69 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
70 
72 {
73  writeFile::writeHeader(os, "Actuation disk source");
74  writeFile::writeCommented(os, "Time");
75  writeFile::writeCommented(os, "Uref");
76  writeFile::writeCommented(os, "Cp");
77  writeFile::writeCommented(os, "Ct");
78 
79  if (forceMethod_ == forceMethodType::FROUDE)
80  {
81  writeFile::writeCommented(os, "a");
82  writeFile::writeCommented(os, "T");
83  }
84  else if (forceMethod_ == forceMethodType::VARIABLE_SCALING)
85  {
86  writeFile::writeCommented(os, "Udisk");
87  writeFile::writeCommented(os, "CpStar");
88  writeFile::writeCommented(os, "CtStar");
89  writeFile::writeCommented(os, "T");
90  writeFile::writeCommented(os, "P");
91  }
92 
93  writeFile::writeCommented(os, "diskDir");
94 
95  os << endl;
96 }
97 
98 
99 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
100 
101 void Foam::fv::actuationDiskSource::setMonitorCells(const dictionary& dict)
102 {
103  switch (monitorMethod_)
104  {
105  case monitorMethodType::POINTS:
106  {
107  Info<< " - selecting cells using points" << endl;
108 
109  labelHashSet selectedCells;
110 
111  List<point> monitorPoints;
112 
113  const dictionary* coeffsDictPtr = dict.findDict("monitorCoeffs");
114  if (coeffsDictPtr)
115  {
116  coeffsDictPtr->readIfPresent("points", monitorPoints);
117  }
118  else
119  {
120  monitorPoints.resize(1);
121  dict.readEntry("upstreamPoint", monitorPoints.first());
122  }
123 
124  for (const point& p : monitorPoints)
125  {
126  const label celli = mesh_.findCell(p);
127 
128  const bool found = (celli >= 0);
129 
130  if (found)
131  {
132  selectedCells.insert(celli);
133  }
134 
135  if (!returnReduceOr(found))
136  {
138  << "No owner cell found for point "
139  << p << endl;
140  }
141  }
142 
143  monitorCells_ = selectedCells.sortedToc();
144  break;
145  }
146  case monitorMethodType::CELLSET:
147  {
148  Info<< " - selecting cells using cellSet "
149  << zoneName() << endl;
150 
151  monitorCells_ = cellSet(mesh_, zoneName()).sortedToc();
152  break;
153  }
154  default:
155  {
157  << "Unknown type for monitoring of incoming velocity"
158  << monitorMethodTypeNames[monitorMethod_]
159  << ". Valid monitor method types : "
160  << monitorMethodTypeNames
161  << exit(FatalError);
162  }
163  }
164 }
165 
166 
167 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
168 
170 (
171  const word& name,
172  const word& modelType,
173  const dictionary& dict,
174  const fvMesh& mesh
175 )
176 :
177  fv::cellSetOption(name, modelType, dict, mesh),
178  writeFile(mesh, name, modelType, coeffs_),
179  forceMethod_
180  (
181  forceMethodTypeNames.getOrDefault
182  (
183  "variant",
184  coeffs_,
185  forceMethodType::FROUDE
186  )
187  ),
188  monitorMethod_
189  (
190  monitorMethodTypeNames.getOrDefault
191  (
192  "monitorMethod",
193  coeffs_,
194  monitorMethodType::POINTS
195  )
196  ),
197  sink_
198  (
199  coeffs_.getOrDefault<bool>("sink", true)
200  ? 1
201  : -1
202  ),
203  writeFileStart_(coeffs_.getOrDefault<scalar>("writeFileStart", 0)),
204  writeFileEnd_(coeffs_.getOrDefault<scalar>("writeFileEnd", VGREAT)),
205  diskArea_
206  (
207  coeffs_.getCheck<scalar>
208  (
209  "diskArea",
210  scalarMinMax::ge(VSMALL)
211  )
212  ),
213  diskDir_(Function1<vector>::New("diskDir", coeffs_, &mesh)),
214  UvsCpPtr_(Function1<scalar>::New("Cp", coeffs_, &mesh)),
215  UvsCtPtr_(Function1<scalar>::New("Ct", coeffs_, &mesh)),
216  monitorCells_()
217 {
218  setMonitorCells(coeffs_);
219 
220  fieldNames_.resize(1, "U");
221 
223 
224  Info<< " - creating actuation disk zone: " << this->name() << endl;
225 
226  Info<< " - force computation method: "
230 }
231 
232 
233 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
234 
236 {
237  const scalar t = mesh_.time().timeOutputValue();
238  const vector dir(diskDir_->value(t));
239  const scalar magDir = Foam::mag(dir);
240 
241  if (magDir < SMALL)
242  {
244  << "Actuator disk surface-normal vector is zero: " << dir
245  << " at time=" << t
246  << exit(FatalError);
247  }
249  // normalised:
250  return dir/magDir;
251 }
252 
253 
255 (
256  fvMatrix<vector>& eqn,
257  const label fieldi
258 )
259 {
260  if (V() > VSMALL)
261  {
262  calc(geometricOneField(), geometricOneField(), eqn);
263  }
264 }
265 
266 
268 (
269  const volScalarField& rho,
270  fvMatrix<vector>& eqn,
271  const label fieldi
272 )
273 {
274  if (V() > VSMALL)
275  {
276  calc(geometricOneField(), rho, eqn);
277  }
278 }
279 
280 
282 (
283  const volScalarField& alpha,
284  const volScalarField& rho,
285  fvMatrix<vector>& eqn,
286  const label fieldi
287 )
288 {
289  if (V() > VSMALL)
290  {
291  calc(alpha, rho, eqn);
292  }
293 }
294 
295 
297 {
299  {
300  dict.readIfPresent("sink", sink_);
301  dict.readIfPresent("writeFileStart", writeFileStart_);
302  dict.readIfPresent("writeFileEnd", writeFileEnd_);
303  dict.readIfPresent("diskArea", diskArea_);
304  if (diskArea_ < VSMALL)
305  {
307  << "Actuator disk has zero area: "
308  << "diskArea = " << diskArea_
309  << exit(FatalIOError);
310  }
311 
312  // TBD: runTime re-reading of "diskDir" ?
313 
314  return true;
315  }
316  return false;
317 }
318 
319 
320 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:264
dictionary dict
static void writeHeader(Ostream &os, const word &fieldName)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: fvOption.H:157
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:153
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
forceMethodType
Options for the force computation method types.
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.
static const Enum< forceMethodType > forceMethodTypeNames
Names for forceMethodType.
virtual void writeFileHeader(Ostream &os)
Output file header information.
virtual bool read(const dictionary &dict)
Read source dictionary.
Macros for easy insertion into run-time selection tables.
enum forceMethodType forceMethod_
The type of the force computation method.
actuationDiskSource()=delete
No default construct.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
dynamicFvMesh & mesh
A class representing the concept of a GeometricField of 1 used to avoid unnecessary manipulations for...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
labelList fv(nPoints)
vector diskDir() const
Normal disk direction, evaluated at timeOutputValue.
virtual void addSup(fvMatrix< vector > &eqn, const label fieldi)
Source term to momentum equation.
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:64
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:24
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
static const Enum< monitorMethodType > monitorMethodTypeNames
Names for monitorMethodType.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
OBJstream os(runTime.globalPath()/outputName)
virtual bool read(const dictionary &dict)
Read dictionary.
vector point
Point is a vector.
Definition: point.H:37
#define WarningInFunction
Report a warning using Foam::Warning.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:637
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: fvOption.C:41
messageStream Info
Information stream (stdout output on master, null elsewhere)
monitorMethodType
Options for the incoming velocity monitoring method types.
volScalarField & p
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:152
bool found
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...