linearValveFvMesh.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 "linearValveFvMesh.H"
30 #include "Time.H"
31 #include "slidingInterface.H"
32 #include "mapPolyMesh.H"
33 #include "polyTopoChange.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(linearValveFvMesh, 0);
41 
42  addToRunTimeSelectionTable(topoChangerFvMesh, linearValveFvMesh, IOobject);
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::linearValveFvMesh::addZonesAndModifiers()
49 {
50  // Add zones and modifiers for motion action
51 
52  if
53  (
54  pointZones().size()
55  || faceZones().size()
56  || cellZones().size()
57  || topoChanger_.size()
58  )
59  {
61  << "Zones and modifiers already present. Skipping."
62  << endl;
63 
64  return;
65  }
66 
67  Info<< "Time = " << time().timeName() << endl
68  << "Adding zones and modifiers to the mesh" << endl;
69 
70  // Add zones
71  List<pointZone*> pz(1);
72 
73  // An empty zone for cut points
74  pz[0] = new pointZone("cutPointZone", 0, pointZones());
75 
76 
77  // Do face zones for slider
78 
79  List<faceZone*> fz(3);
80 
81  // Inner slider
82  const word innerSliderName
83  (
84  motionDict_.subDict("slider").get<word>("inside")
85  );
86  const polyPatch& innerSlider = boundaryMesh()[innerSliderName];
87 
88  fz[0] = new faceZone
89  (
90  "insideSliderZone",
91  identity(innerSlider.range()),
92  false, // none are flipped
93  0,
94  faceZones()
95  );
96 
97  // Outer slider
98  const word outerSliderName
99  (
100  motionDict_.subDict("slider").get<word>("outside")
101  );
102  const polyPatch& outerSlider = boundaryMesh()[outerSliderName];
103 
104  fz[1] = new faceZone
105  (
106  "outsideSliderZone",
107  identity(outerSlider.range()),
108  false, // none are flipped
109  1,
110  faceZones()
111  );
112 
113  // An empty zone for cut faces
114  fz[2] = new faceZone("cutFaceZone", 2, faceZones());
115 
116  List<cellZone*> cz(0);
117 
118  Info<< "Adding point, face and cell zones" << endl;
119  addZones(pz, fz, cz);
120 
121  // Add a topology modifier
122  Info<< "Adding topology modifiers" << endl;
125  (
126  0,
127  new slidingInterface
128  (
129  "mixerSlider",
130  0,
131  topoChanger_,
132  outerSliderName + "Zone",
133  innerSliderName + "Zone",
134  "cutPointZone",
135  "cutFaceZone",
136  outerSliderName,
137  innerSliderName,
139  true // Attach-detach action
140  )
141  );
143 
144  // Write mesh
145  write();
146 }
147 
148 
149 void Foam::linearValveFvMesh::makeSlidersDead()
150 {
151  const polyTopoChanger& topoChanges = topoChanger_;
152 
153  // Enable layering
154  forAll(topoChanges, modI)
155  {
156  if (isA<slidingInterface>(topoChanges[modI]))
157  {
158  topoChanges[modI].disable();
159  }
160  else
161  {
163  << "Don't know what to do with mesh modifier "
164  << modI << " of type " << topoChanges[modI].type()
165  << abort(FatalError);
166  }
167  }
168 }
169 
170 
171 void Foam::linearValveFvMesh::makeSlidersLive()
172 {
173  const polyTopoChanger& topoChanges = topoChanger_;
174 
175  // Enable sliding interface
176  forAll(topoChanges, modI)
177  {
178  if (isA<slidingInterface>(topoChanges[modI]))
179  {
180  topoChanges[modI].enable();
181  }
182  else
183  {
185  << "Don't know what to do with mesh modifier "
186  << modI << " of type " << topoChanges[modI].type()
187  << abort(FatalError);
188  }
189  }
190 }
191 
192 
193 bool Foam::linearValveFvMesh::attached() const
194 {
195  const polyTopoChanger& topoChanges = topoChanger_;
196 
197  bool result = false;
198 
199  forAll(topoChanges, modI)
200  {
201  if (isA<slidingInterface>(topoChanges[modI]))
202  {
203  result =
204  result
205  || refCast<const slidingInterface>(topoChanges[modI]).attached();
206  }
207  }
208 
209  // Check thal all sliders are in sync (debug only)
210  forAll(topoChanges, modI)
211  {
212  if (isA<slidingInterface>(topoChanges[modI]))
213  {
214  if
215  (
216  result
217  != refCast<const slidingInterface>(topoChanges[modI]).attached()
218  )
219  {
221  << "Slider " << modI
222  << " named " << topoChanges[modI].name()
223  << " out of sync: Should be" << result
224  << abort(FatalError);
225  }
226  }
227  }
228 
229  if (result)
230  {
231  Info<< "linearValveFvMesh: attached!" << endl;
232  }
233  else
234  {
235  Info<< "linearValveFvMesh: detached!" << endl;
236  }
237 
238  return result;
239 }
240 
241 
242 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
243 
244 // Construct from components
245 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
246 :
247  topoChangerFvMesh(io),
248  motionDict_
249  (
251  (
252  IOobject
253  (
254  "dynamicMeshDict",
255  time().constant(),
256  *this,
257  IOobject::MUST_READ_IF_MODIFIED,
258  IOobject::NO_WRITE,
259  false
260  )
261  ).optionalSubDict(typeName + "Coeffs")
262  ),
263  msPtr_(motionSolver::New(*this))
264 {
265  addZonesAndModifiers();
266 }
267 
268 
269 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
270 
272 {}
273 
274 
275 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
276 
278 {
279  // Detaching the interface
280  if (attached())
281  {
282  Info<< "Decoupling sliding interfaces" << endl;
283  makeSlidersLive();
284 
285  // Changing topology by hand
286  resetMorph();
287  setMorphTimeIndex(3*time().timeIndex());
288  updateMesh();
289 
290  msPtr_->updateMesh();
291  }
292  else
293  {
294  Info<< "Sliding interfaces decoupled" << endl;
295  }
296 
297  // Perform mesh motion
298  makeSlidersDead();
299 
300  // Changing topology by hand
301  resetMorph();
302  setMorphTimeIndex(3*time().timeIndex() + 1);
303  updateMesh();
304 
305  msPtr_->updateMesh();
306 
307  if (topoChangeMap)
308  {
309  if (topoChangeMap().hasMotionPoints())
310  {
311  Info<< "Topology change; executing pre-motion" << endl;
312  movePoints(topoChangeMap().preMotionPoints());
313  }
314  }
315 
316  // Solve for motion
317  msPtr_->solve();
318 
319  movePoints(msPtr_->curPoints());
320 
321  // Attach the interface
322  Info<< "Coupling sliding interfaces" << endl;
323  makeSlidersLive();
324  resetMorph();
325  setMorphTimeIndex(3*time().timeIndex() + 2);
326  updateMesh();
327 
328  Info<< "Moving points post slider attach" << endl;
329 
330  msPtr_->updateMesh();
331 
332  Info<< "Sliding interfaces coupled: " << attached() << endl;
333 }
334 
335 
336 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
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::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
linearValveFvMesh.H
mapPolyMesh.H
polyTopoChange.H
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
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::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:492
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::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::FatalError
error FatalError
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::linearValveFvMesh::~linearValveFvMesh
virtual ~linearValveFvMesh()
Destructor.
Definition: linearValveFvMesh.C:271
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::motionSolver
Virtual base class for mesh motion solver.
Definition: motionSolver.H:58
slidingInterface.H
Foam::topoChangerFvMesh
Abstract base class for a topology changing fvMesh.
Definition: topoChangerFvMesh.H:53
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::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
timeIndex
label timeIndex
Definition: getTimeIndex.H:30
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::linearValveFvMesh::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: linearValveFvMesh.C:277
Foam::topoChangerFvMesh::topoChanger_
polyTopoChanger topoChanger_
Definition: topoChangerFvMesh.H:70