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-2021 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"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace fv
39 {
40  defineTypeNameAndDebug(actuationDiskSource, 0);
41  addToRunTimeSelectionTable(option, actuationDiskSource, dictionary);
42 }
43 }
44 
45 
46 const Foam::Enum
47 <
49 >
51 ({
52  { forceMethodType::FROUDE, "Froude" },
53  { forceMethodType::VARIABLE_SCALING, "variableScaling" },
54 });
55 
56 
57 const Foam::Enum
58 <
60 >
62 ({
63  { monitorMethodType::POINTS, "points" },
64  { monitorMethodType::CELLSET, "cellSet" },
65 });
66 
67 
68 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
69 
71 {
72  writeFile::writeHeader(os, "Actuation disk source");
73  writeFile::writeCommented(os, "Time");
74  writeFile::writeCommented(os, "Uref");
75  writeFile::writeCommented(os, "Cp");
76  writeFile::writeCommented(os, "Ct");
77 
78  if (forceMethod_ == forceMethodType::FROUDE)
79  {
80  writeFile::writeCommented(os, "a");
81  writeFile::writeCommented(os, "T");
82  }
83  else if (forceMethod_ == forceMethodType::VARIABLE_SCALING)
84  {
85  writeFile::writeCommented(os, "Udisk");
86  writeFile::writeCommented(os, "CpStar");
87  writeFile::writeCommented(os, "CtStar");
88  writeFile::writeCommented(os, "T");
89  writeFile::writeCommented(os, "P");
90  }
91 
92  os << endl;
93 }
94 
95 
96 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
97 
98 void Foam::fv::actuationDiskSource::setMonitorCells(const dictionary& dict)
99 {
100  switch (monitorMethod_)
101  {
102  case monitorMethodType::POINTS:
103  {
104  Info<< " - selecting cells using points" << endl;
105 
106  labelHashSet selectedCells;
107 
108  List<point> monitorPoints;
109 
110  const dictionary* coeffsDictPtr = dict.findDict("monitorCoeffs");
111  if (coeffsDictPtr)
112  {
113  coeffsDictPtr->readIfPresent("points", monitorPoints);
114  }
115  else
116  {
117  monitorPoints.resize(1);
118  dict.readEntry("upstreamPoint", monitorPoints.first());
119  }
120 
121  for (const auto& monitorPoint : monitorPoints)
122  {
123  const label celli = mesh_.findCell(monitorPoint);
124  if (celli >= 0)
125  {
126  selectedCells.insert(celli);
127  }
128 
129  const label globalCelli = returnReduce(celli, maxOp<label>());
130  if (globalCelli < 0)
131  {
133  << "Unable to find owner cell for point "
134  << monitorPoint << endl;
135  }
136  }
137 
138  monitorCells_ = selectedCells.sortedToc();
139  break;
140  }
141  case monitorMethodType::CELLSET:
142  {
143  Info<< " - selecting cells using cellSet "
144  << cellSetName_ << endl;
145 
146  monitorCells_ = cellSet(mesh_, cellSetName_).sortedToc();
147  break;
148  }
149  default:
150  {
152  << "Unknown type for monitoring of incoming velocity"
153  << monitorMethodTypeNames[monitorMethod_]
154  << ". Valid monitor method types : "
155  << monitorMethodTypeNames
156  << exit(FatalError);
157  }
158  }
159 }
160 
161 
162 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
163 
165 (
166  const word& name,
167  const word& modelType,
168  const dictionary& dict,
169  const fvMesh& mesh
170 )
171 :
172  fv::cellSetOption(name, modelType, dict, mesh),
173  writeFile(mesh, name, modelType, coeffs_),
174  forceMethod_
175  (
176  forceMethodTypeNames.getOrDefault
177  (
178  "variant",
179  coeffs_,
180  forceMethodType::FROUDE
181  )
182  ),
183  monitorMethod_
184  (
185  monitorMethodTypeNames.getOrDefault
186  (
187  "monitorMethod",
188  coeffs_,
189  monitorMethodType::POINTS
190  )
191  ),
192  sink_
193  (
194  coeffs_.getOrDefault<bool>("sink", true)
195  ? 1
196  : -1
197  ),
198  writeFileStart_(coeffs_.getOrDefault<scalar>("writeFileStart", 0)),
199  writeFileEnd_(coeffs_.getOrDefault<scalar>("writeFileEnd", VGREAT)),
200  diskArea_
201  (
202  coeffs_.getCheck<scalar>
203  (
204  "diskArea",
205  scalarMinMax::ge(VSMALL)
206  )
207  ),
208  diskDir_
209  (
210  coeffs_.getCheck<vector>
211  (
212  "diskDir",
213  [&](const vector& vec){ return mag(vec) > VSMALL; }
214  ).normalise()
215  ),
216  UvsCpPtr_(Function1<scalar>::New("Cp", coeffs_, &mesh)),
217  UvsCtPtr_(Function1<scalar>::New("Ct", coeffs_, &mesh)),
218  monitorCells_()
219 {
220  setMonitorCells(coeffs_);
221 
222  fieldNames_.resize(1, "U");
223 
225 
226  Info<< " - creating actuation disk zone: " << this->name() << endl;
227 
228  Info<< " - force computation method: "
229  << forceMethodTypeNames[forceMethod_] << endl;
230 
231  writeFileHeader(file());
232 }
233 
234 
235 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
236 
238 (
239  fvMatrix<vector>& eqn,
240  const label fieldi
241 )
242 {
243  if (V() > VSMALL)
244  {
245  calc(geometricOneField(), geometricOneField(), eqn);
246  }
247 }
248 
249 
251 (
252  const volScalarField& rho,
253  fvMatrix<vector>& eqn,
254  const label fieldi
255 )
256 {
257  if (V() > VSMALL)
258  {
259  calc(geometricOneField(), rho, eqn);
260  }
261 }
262 
263 
265 (
266  const volScalarField& alpha,
267  const volScalarField& rho,
268  fvMatrix<vector>& eqn,
269  const label fieldi
270 )
271 {
272  if (V() > VSMALL)
273  {
274  calc(alpha, rho, eqn);
275  }
276 }
277 
278 
280 {
282  {
283  dict.readIfPresent("sink", sink_);
284  dict.readIfPresent("writeFileStart", writeFileStart_);
285  dict.readIfPresent("writeFileEnd", writeFileEnd_);
286  dict.readIfPresent("diskArea", diskArea_);
287  if (diskArea_ < VSMALL)
288  {
290  << "Actuator disk has zero area: "
291  << "diskArea = " << diskArea_
292  << exit(FatalIOError);
293  }
294 
295  dict.readIfPresent("diskDir", diskDir_);
296  diskDir_.normalise();
297  if (mag(diskDir_) < VSMALL)
298  {
300  << "Actuator disk surface-normal vector is zero: "
301  << "diskDir = " << diskDir_
302  << exit(FatalIOError);
303  }
304 
305  return true;
306  }
307 
308  return false;
309 }
310 
311 
312 // ************************************************************************* //
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::fv::actuationDiskSource::monitorMethodType
monitorMethodType
Options for the incoming velocity monitoring method types.
Definition: actuationDiskSource.H:385
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:163
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::fv::option::resetApplied
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: fvOption.C:48
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:212
Foam::geometricOneField
A class representing the concept of a GeometricField of 1 used to avoid unnecessary manipulations for...
Definition: geometricOneField.H:55
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::fv::actuationDiskSource::monitorMethodTypeNames
static const Enum< monitorMethodType > monitorMethodTypeNames
Names for monitorMethodType.
Definition: actuationDiskSource.H:392
Foam::writeHeader
static void writeHeader(Ostream &os, const word &fieldName)
Definition: rawSurfaceWriterImpl.C:66
Foam::Vector::normalise
Vector< Cmpt > & normalise()
Normalise the vector by its magnitude.
Definition: VectorI.H:123
Foam::HashSet< label, Hash< label > >
rho
rho
Definition: readInitialConditions.H:88
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::fv::actuationDiskSource::actuationDiskSource
actuationDiskSource()=delete
No default construct.
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::fv::cellSetOption::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: cellSetOption.C:255
Foam::fv::actuationDiskSource::forceMethod_
enum forceMethodType forceMethod_
The type of the force computation method.
Definition: actuationDiskSource.H:398
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:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fv::actuationDiskSource::forceMethodTypeNames
static const Enum< forceMethodType > forceMethodTypeNames
Names for forceMethodType.
Definition: actuationDiskSource.H:382
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::fv::actuationDiskSource::writeFileHeader
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: actuationDiskSource.C:70
fv
labelList fv(nPoints)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
geometricOneField.H
Foam::MinMax::ge
static MinMax< T > ge(const T &minVal)
A semi-infinite range from minVal to the type max.
Definition: MinMaxI.H:31
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
Foam::fv::actuationDiskSource::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: actuationDiskSource.C:279
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fv::actuationDiskSource::addSup
virtual void addSup(fvMatrix< vector > &eqn, const label fieldi)
Source term to momentum equation.
Definition: actuationDiskSource.C:238
Foam::fv::actuationDiskSource::forceMethodType
forceMethodType
Options for the force computation method types.
Definition: actuationDiskSource.H:375
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< scalar, fvPatchField, volMesh >
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405
actuationDiskSource.H