FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/Time.H>
29 #include <OpenFOAM/mapPolyMesh.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  {
57  Info<< "void linearValveFvMesh::addZonesAndModifiers() : "
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 =
88  boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
89 
90  labelList isf(innerSlider.size());
91 
92  forAll (isf, i)
93  {
94  isf[i] = innerSlider.start() + i;
95  }
96 
97  fz[0] = new faceZone
98  (
99  "insideSliderZone",
100  isf,
101  boolList(innerSlider.size(), false),
102  0,
103  faceZones()
104  );
105 
106  // Outer slider
107  const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
108  const polyPatch& outerSlider =
109  boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
110 
111  labelList osf(outerSlider.size());
112 
113  forAll (osf, i)
114  {
115  osf[i] = outerSlider.start() + i;
116  }
117 
118  fz[1] = new faceZone
119  (
120  "outsideSliderZone",
121  osf,
122  boolList(outerSlider.size(), false),
123  1,
124  faceZones()
125  );
126 
127  // Add empty zone for cut faces
128  fz[2] = new faceZone
129  (
130  "cutFaceZone",
131  labelList(0),
132  boolList(0, false),
133  2,
134  faceZones()
135  );
136 
137  List<cellZone*> cz(0);
138 
139  Info << "Adding point, face and cell zones" << endl;
140  addZones(pz, fz, cz);
141 
142  // Add a topology modifier
143  Info << "Adding topology modifiers" << endl;
146  (
147  0,
148  new slidingInterface
149  (
150  "mixerSlider",
151  0,
152  topoChanger_,
153  outerSliderName + "Zone",
154  innerSliderName + "Zone",
155  "cutPointZone",
156  "cutFaceZone",
157  outerSliderName,
158  innerSliderName,
160  true // Attach-detach action
161  )
162  );
164 
165  // Write mesh
166  write();
167 }
168 
169 
170 void Foam::linearValveFvMesh::makeSlidersDead()
171 {
172  const polyTopoChanger& topoChanges = topoChanger_;
173 
174  // Enable layering
175  forAll (topoChanges, modI)
176  {
177  if (isA<slidingInterface>(topoChanges[modI]))
178  {
179  topoChanges[modI].disable();
180  }
181  else
182  {
183  FatalErrorIn("void Foam::linearValveFvMesh::makeSlidersDead()")
184  << "Don't know what to do with mesh modifier "
185  << modI << " of type " << topoChanges[modI].type()
186  << abort(FatalError);
187  }
188  }
189 }
190 
191 
192 void Foam::linearValveFvMesh::makeSlidersLive()
193 {
194  const polyTopoChanger& topoChanges = topoChanger_;
195 
196  // Enable sliding interface
197  forAll (topoChanges, modI)
198  {
199  if (isA<slidingInterface>(topoChanges[modI]))
200  {
201  topoChanges[modI].enable();
202  }
203  else
204  {
205  FatalErrorIn("void Foam::linearValveFvMesh::makeLayersLive()")
206  << "Don't know what to do with mesh modifier "
207  << modI << " of type " << topoChanges[modI].type()
208  << abort(FatalError);
209  }
210  }
211 }
212 
213 
214 bool Foam::linearValveFvMesh::attached() const
215 {
216  const polyTopoChanger& topoChanges = topoChanger_;
217 
218  bool result = false;
219 
220  forAll (topoChanges, modI)
221  {
222  if (isA<slidingInterface>(topoChanges[modI]))
223  {
224  result =
225  result
226  || refCast<const slidingInterface>(topoChanges[modI]).attached();
227  }
228  }
229 
230  // Check thal all sliders are in sync (debug only)
231  forAll (topoChanges, modI)
232  {
233  if (isA<slidingInterface>(topoChanges[modI]))
234  {
235  if
236  (
237  result
238  != refCast<const slidingInterface>(topoChanges[modI]).attached()
239  )
240  {
241  FatalErrorIn("bool linearValveFvMesh::attached() const")
242  << "Slider " << modI << " named " << topoChanges[modI].name()
243  << " out of sync: Should be" << result
244  << abort(FatalError);
245  }
246  }
247  }
248 
249  if (result)
250  {
251  Info << "linearValveFvMesh: attached!" << endl;
252  }
253  else
254  {
255  Info << "linearValveFvMesh: detached!" << endl;
256  }
257 
258  return result;
259 }
260 
261 
262 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
263 
264 // Construct from components
265 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
266 :
267  topoChangerFvMesh(io),
268  motionDict_
269  (
271  (
272  IOobject
273  (
274  "dynamicMeshDict",
275  time().constant(),
276  *this,
277  IOobject::MUST_READ,
278  IOobject::NO_WRITE
279  )
280  ).subDict(typeName + "Coeffs")
281  ),
282  msPtr_(motionSolver::New(*this))
283 {
284  addZonesAndModifiers();
285 }
286 
287 
288 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
289 
291 {}
292 
293 
294 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
295 
297 {
298  // Detaching the interface
299  if (attached())
300  {
301  Info << "Decoupling sliding interfaces" << endl;
302  makeSlidersLive();
303 
304  // Changing topology by hand
305  resetMorph();
306  setMorphTimeIndex(3*time().timeIndex());
307  updateMesh();
308 
309  msPtr_->updateMesh();
310  }
311  else
312  {
313  Info << "Sliding interfaces decoupled" << endl;
314  }
315 
316  // Perform mesh motion
317  makeSlidersDead();
318 
319  // Changing topology by hand
320  resetMorph();
321  setMorphTimeIndex(3*time().timeIndex() + 1);
322  updateMesh();
323 
324  msPtr_->updateMesh();
325 
326  if (topoChangeMap.valid())
327  {
328  if (topoChangeMap().hasMotionPoints())
329  {
330  Info << "Topology change; executing pre-motion" << endl;
331  movePoints(topoChangeMap().preMotionPoints());
332  }
333  }
334 
335  // Solve for motion
336  msPtr_->solve();
337 
338  movePoints(msPtr_->curPoints());
339 
340  // Attach the interface
341  Info << "Coupling sliding interfaces" << endl;
342  makeSlidersLive();
343  resetMorph();
344  setMorphTimeIndex(3*time().timeIndex() + 2);
345  updateMesh();
346 
347  Info << "Moving points post slider attach" << endl;
348 
349  msPtr_->updateMesh();
350 
351  Info << "Sliding interfaces coupled: " << attached() << endl;
352 }
353 
354 
355 // ************************ vim: set sw=4 sts=4 et: ************************ //