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