mixerFvMesh.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-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "mixerFvMesh.H"
30 #include "Time.H"
31 #include "regionSplit.H"
32 #include "slidingInterface.H"
34 #include "mapPolyMesh.H"
35 #include "unitConversion.H"
36 #include "demandDrivenData.H"
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42  defineTypeNameAndDebug(mixerFvMesh, 0);
43  addToRunTimeSelectionTable(topoChangerFvMesh, mixerFvMesh, IOobject);
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::mixerFvMesh::addZonesAndModifiers()
50 {
51  // Add zones and modifiers for motion action
52 
53  if
54  (
55  pointZones().size()
56  || faceZones().size()
57  || cellZones().size()
58  || topoChanger_.size()
59  )
60  {
62  << "Zones and modifiers already present. Skipping."
63  << endl;
64 
65  return;
66  }
67 
68  Info<< "Time = " << time().timeName() << endl
69  << "Adding zones and modifiers to the mesh" << endl;
70 
71  // Add zones
72  List<pointZone*> pz(1);
73 
74  // An empty zone for cut points
75  pz[0] = new pointZone("cutPointZone", 0, pointZones());
76 
77 
78  // Do face zones for slider
79 
80  List<faceZone*> fz(3);
81 
82  // Inner slider
83  const word innerSliderName
84  (
85  motionDict_.subDict("slider").get<word>("inside")
86  );
87  const polyPatch& innerSlider = boundaryMesh()[innerSliderName];
88 
89  fz[0] = new faceZone
90  (
91  "insideSliderZone",
92  identity(innerSlider.range()),
93  false, // none are flipped
94  0,
95  faceZones()
96  );
97 
98  // Outer slider
99  const word outerSliderName
100  (
101  motionDict_.subDict("slider").get<word>("outside")
102  );
103  const polyPatch& outerSlider = boundaryMesh()[outerSliderName];
104 
105  fz[1] = new faceZone
106  (
107  "outsideSliderZone",
108  identity(outerSlider.range()),
109  false, // none are flipped
110  1,
111  faceZones()
112  );
113 
114  // An empty zone for cut faces
115  fz[2] = new faceZone("cutFaceZone", 2, faceZones());
116 
117  List<cellZone*> cz(1);
118 
119  // Mark every cell with its topological region
120  regionSplit rs(*this);
121 
122  // Get the region of the cell containing the origin.
123  const label originRegion = rs[findNearestCell(csys_.origin())];
124 
125  labelList movingCells(nCells());
126  label nMovingCells = 0;
127 
128  forAll(rs, celli)
129  {
130  if (rs[celli] == originRegion)
131  {
132  movingCells[nMovingCells] = celli;
133  ++nMovingCells;
134  }
135  }
136 
137  movingCells.resize(nMovingCells);
138  Info<< "Number of cells in the moving region: " << nMovingCells << endl;
139 
140  cz[0] = new cellZone
141  (
142  "movingCells",
143  std::move(movingCells),
144  0,
145  cellZones()
146  );
147 
148  Info<< "Adding point, face and cell zones" << endl;
149  addZones(pz, fz, cz);
150 
151  // Add a topology modifier
152  Info<< "Adding topology modifiers" << endl;
155  (
156  0,
157  new slidingInterface
158  (
159  "mixerSlider",
160  0,
161  topoChanger_,
162  outerSliderName + "Zone",
163  innerSliderName + "Zone",
164  "cutPointZone",
165  "cutFaceZone",
166  outerSliderName,
167  innerSliderName,
169  )
170  );
172 
173  write();
174 }
175 
176 
177 void Foam::mixerFvMesh::calcMovingMasks() const
178 {
179  DebugInFunction << "Calculating point and cell masks" << endl;
180 
181  if (movingPointsMaskPtr_)
182  {
184  << "point mask already calculated"
185  << abort(FatalError);
186  }
187 
188  // Set the point mask
189  movingPointsMaskPtr_ = new scalarField(points().size(), Zero);
190  scalarField& movingPointsMask = *movingPointsMaskPtr_;
191 
192  const cellList& c = cells();
193  const faceList& f = faces();
194 
195  const labelList& cellAddr = cellZones()["movingCells"];
196 
197  for (const label celli : cellAddr)
198  {
199  const cell& curCell = c[celli];
200 
201  for (const label facei : curCell)
202  {
203  // Mark all the points as moving
204  const face& curFace = f[facei];
205 
206  forAll(curFace, pointi)
207  {
208  movingPointsMask[curFace[pointi]] = 1;
209  }
210  }
211  }
212 
213  const word innerSliderZoneName
214  (
215  motionDict_.subDict("slider").get<word>("inside") + "Zone"
216  );
217 
218  const labelList& innerSliderAddr = faceZones()[innerSliderZoneName];
219 
220  for (const label facei : innerSliderAddr)
221  {
222  const face& curFace = f[facei];
223 
224  forAll(curFace, pointi)
225  {
226  movingPointsMask[curFace[pointi]] = 1;
227  }
228  }
229 
230  const word outerSliderZoneName
231  (
232  motionDict_.subDict("slider").get<word>("outside") + "Zone"
233  );
234 
235  const labelList& outerSliderAddr = faceZones()[outerSliderZoneName];
236 
237  for (const label facei : outerSliderAddr)
238  {
239  const face& curFace = f[facei];
240 
241  forAll(curFace, pointi)
242  {
243  movingPointsMask[curFace[pointi]] = 0;
244  }
245  }
246 }
247 
248 
249 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
250 
251 Foam::mixerFvMesh::mixerFvMesh
252 (
253  const IOobject& io
254 )
255 :
256  topoChangerFvMesh(io),
257  motionDict_
258  (
260  (
261  IOobject
262  (
263  "dynamicMeshDict",
264  time().constant(),
265  *this,
268  false
269  )
270  ).optionalSubDict(typeName + "Coeffs")
271  ),
272  csys_(),
273  rpm_(motionDict_.get<scalar>("rpm")),
274  movingPointsMaskPtr_(nullptr)
275 {
276  if (motionDict_.found(coordinateSystem::typeName_()))
277  {
278  // New() for access to indirect (global) coordSystem.
279  static_cast<coordinateSystem&>(csys_) =
280  *coordinateSystem::New(*this, motionDict_);
281  }
282  else
283  {
284  csys_ = coordSystem::cylindrical(motionDict_);
285  }
286 
287  addZonesAndModifiers();
288 
289  Info<< "Mixer mesh:" << nl
290  << " origin: " << csys_.origin() << nl
291  << " axis: " << csys_.e3() << nl
292  << " rpm: " << rpm_ << endl;
293 }
294 
295 
296 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
297 
299 {
300  deleteDemandDrivenData(movingPointsMaskPtr_);
301 }
302 
303 
304 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
305 
306 // Return moving points mask. Moving points marked with 1
307 const Foam::scalarField& Foam::mixerFvMesh::movingPointsMask() const
308 {
309  if (!movingPointsMaskPtr_)
310  {
311  calcMovingMasks();
312  }
313 
314  return *movingPointsMaskPtr_;
315 }
316 
317 
319 {
320  // The tangential sweep (radians)
321  const vector theta(0, rpmToRads(rpm_)*time().deltaTValue(), 0);
322 
323  movePoints
324  (
325  csys_.globalPosition
326  (
327  csys_.localPosition(points())
328  + theta
329  *movingPointsMask()
330  )
331  );
332 
333  // Make changes. Use inflation (so put new points in topoChangeMap)
334  autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
335 
336  if (topoChangeMap)
337  {
338  DebugInFunction << "Mesh topology is changing" << nl;
339 
340  deleteDemandDrivenData(movingPointsMaskPtr_);
341  }
342 
343  movePoints
344  (
345  csys_.globalPosition
346  (
347  csys_.localPosition(oldPoints())
348  + theta
349  *movingPointsMask()
350  )
351  );
352 
353  return true;
354 }
355 
356 
357 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::HashTable< regIOobject * >::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1041
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
mapPolyMesh.H
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
unitConversion.H
Unit conversion functions.
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::PtrList::set
const T * set(const label i) const
Return const pointer to element (can be nullptr),.
Definition: PtrList.H:138
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::IOobject::writeOpt
writeOption writeOpt() const noexcept
The write option.
Definition: IOobjectI.H:179
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:42
Foam::coordinateSystem::origin
virtual const point & origin() const
Return origin.
Definition: coordinateSystem.H:469
Foam::primitiveMesh::findNearestCell
label findNearestCell(const point &location) const
Find the cell with the nearest cell centre to location.
Definition: primitiveMeshFindCell.C:88
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:492
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
Definition: coordinateSystemNew.C:84
mixerFvMesh.H
regionSplit.H
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
Foam::cellList
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Foam::PtrList::setSize
void setSize(const label newLen)
Same as resize()
Definition: PtrList.H:151
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:486
Foam::coordSystem::cylindrical
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians.
Definition: cylindricalCS.H:71
Foam::FatalError
error FatalError
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::mixerFvMesh::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: mixerFvMesh.C:318
Foam::rpmToRads
constexpr scalar rpmToRads(const scalar rpm) noexcept
Conversion from revolutions/minute to radians/sec.
Definition: unitConversion.H:73
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
slidingInterface.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
f
labelList f(nPoints)
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::Vector< scalar >
Foam::topoChangerFvMesh
Abstract base class for a topology changing fvMesh.
Definition: topoChangerFvMesh.H:53
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::polyMesh::pointZones
const pointZoneMesh & pointZones() const noexcept
Return point zone mesh.
Definition: polyMesh.H:480
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::mixerFvMesh::~mixerFvMesh
virtual ~mixerFvMesh()
Destructor.
Definition: mixerFvMesh.C:298
constant
constant condensation/saturation model.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::slidingInterface::INTEGRAL
Definition: slidingInterface.H:85
Foam::polyMesh::addZones
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
Definition: polyMesh.C:999
Foam::coordinateSystem
Base class for coordinate system specification, the default coordinate system type is cartesian .
Definition: coordinateSystem.H:132
Foam::topoChangerFvMesh::topoChanger_
polyTopoChanger topoChanger_
Definition: topoChangerFvMesh.H:70