initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / topoChangerFvMesh / linearValveFvMesh / linearValveFvMesh.C
blobbef2864e3e2fff4b669618b1432cac616b783fdf
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "linearValveFvMesh.H"
28 #include "Time.H"
29 #include "slidingInterface.H"
30 #include "mapPolyMesh.H"
31 #include "polyTopoChange.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
38     defineTypeNameAndDebug(linearValveFvMesh, 0);
40     addToRunTimeSelectionTable(topoChangerFvMesh, linearValveFvMesh, IOobject);
44 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
46 void Foam::linearValveFvMesh::addZonesAndModifiers()
48     // Add zones and modifiers for motion action
50     if
51     (
52         pointZones().size()
53      || faceZones().size()
54      || cellZones().size()
55      || topoChanger_.size()
56     )
57     {
58         Info<< "void linearValveFvMesh::addZonesAndModifiers() : "
59             << "Zones and modifiers already present.  Skipping."
60             << endl;
62         return;
63     }
65     Info<< "Time = " << time().timeName() << endl
66         << "Adding zones and modifiers to the mesh" << endl;
68     // Add zones
69     List<pointZone*> pz(1);
71     // Add an empty zone for cut points
73     pz[0] = new pointZone
74     (
75         "cutPointZone",
76         labelList(0),
77         0,
78         pointZones()
79     );
82     // Do face zones for slider
84     List<faceZone*> fz(3);
86     // Inner slider
87     const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
88     const polyPatch& innerSlider =
89         boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
91     labelList isf(innerSlider.size());
93     forAll (isf, i)
94     {
95         isf[i] = innerSlider.start() + i;
96     }
98     fz[0] = new faceZone
99     (
100         "insideSliderZone",
101         isf,
102         boolList(innerSlider.size(), false),
103         0,
104         faceZones()
105     );
107     // Outer slider
108     const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
109     const polyPatch& outerSlider =
110         boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
112     labelList osf(outerSlider.size());
114     forAll (osf, i)
115     {
116         osf[i] = outerSlider.start() + i;
117     }
119     fz[1] = new faceZone
120     (
121         "outsideSliderZone",
122         osf,
123         boolList(outerSlider.size(), false),
124         1,
125         faceZones()
126     );
128     // Add empty zone for cut faces
129     fz[2] = new faceZone
130     (
131         "cutFaceZone",
132         labelList(0),
133         boolList(0, false),
134         2,
135         faceZones()
136     );
138     List<cellZone*> cz(0);
140     Info << "Adding point, face and cell zones" << endl;
141     addZones(pz, fz, cz);
143     // Add a topology modifier
144     Info << "Adding topology modifiers" << endl;
145     topoChanger_.setSize(1);
146     topoChanger_.set
147     (
148         0,
149         new slidingInterface
150         (
151             "mixerSlider",
152             0,
153             topoChanger_,
154             outerSliderName + "Zone",
155             innerSliderName + "Zone",
156             "cutPointZone",
157             "cutFaceZone",
158             outerSliderName,
159             innerSliderName,
160             slidingInterface::INTEGRAL,
161             true                          // Attach-detach action
162         )
163     );
164     topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
166     // Write mesh
167     write();
171 void Foam::linearValveFvMesh::makeSlidersDead()
173     const polyTopoChanger& topoChanges = topoChanger_;
175     // Enable layering
176     forAll (topoChanges, modI)
177     {
178         if (typeid(topoChanges[modI]) == typeid(slidingInterface))
179         {
180             topoChanges[modI].disable();
181         }
182         else
183         {
184             FatalErrorIn("void Foam::linearValveFvMesh::makeSlidersDead()")
185                 << "Don't know what to do with mesh modifier "
186                 << modI << " of type " << topoChanges[modI].type()
187                 << abort(FatalError);
188         }
189     }
193 void Foam::linearValveFvMesh::makeSlidersLive()
195     const polyTopoChanger& topoChanges = topoChanger_;
197     // Enable sliding interface
198     forAll (topoChanges, modI)
199     {
200         if (typeid(topoChanges[modI]) == typeid(slidingInterface))
201         {
202             topoChanges[modI].enable();
203         }
204         else
205         {
206             FatalErrorIn("void Foam::linearValveFvMesh::makeLayersLive()")
207                 << "Don't know what to do with mesh modifier "
208                 << modI << " of type " << topoChanges[modI].type()
209                 << abort(FatalError);
210         }
211     }
215 bool Foam::linearValveFvMesh::attached() const
217     const polyTopoChanger& topoChanges = topoChanger_;
219     bool result = false;
221     forAll (topoChanges, modI)
222     {
223         if (typeid(topoChanges[modI]) == typeid(slidingInterface))
224         {
225             result =
226                 result
227              || refCast<const slidingInterface>(topoChanges[modI]).attached();
228         }
229     }
231     // Check thal all sliders are in sync (debug only)
232     forAll (topoChanges, modI)
233     {
234         if (typeid(topoChanges[modI]) == typeid(slidingInterface))
235         {
236             if
237             (
238                 result
239              != refCast<const slidingInterface>(topoChanges[modI]).attached()
240             )
241             {
242                 FatalErrorIn("bool linearValveFvMesh::attached() const")
243                     << "Slider " << modI << " named " << topoChanges[modI].name()
244                     << " out of sync: Should be" << result
245                     << abort(FatalError);
246             }
247         }
248     }
250     if (result)
251     {
252         Info << "linearValveFvMesh: attached!" << endl;
253     }
254     else
255     {
256         Info << "linearValveFvMesh: detached!" << endl;
257     }
259     return result;
263 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
265 // Construct from components
266 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
268     topoChangerFvMesh(io),
269     motionDict_
270     (
271         IOdictionary
272         (
273             IOobject
274             (
275                 "dynamicMeshDict",
276                 time().constant(),
277                 *this,
278                 IOobject::MUST_READ,
279                 IOobject::NO_WRITE
280             )
281         ).subDict(typeName + "Coeffs")
282     ),
283     msPtr_(motionSolver::New(*this))
285     addZonesAndModifiers();
289 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
291 Foam::linearValveFvMesh::~linearValveFvMesh()
295 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
297 void Foam::linearValveFvMesh::update()
299     // Detaching the interface
300     if (attached())
301     {
302         Info << "Decoupling sliding interfaces" << endl;
303         makeSlidersLive();
305         // Changing topology by hand
306         resetMorph();
307         setMorphTimeIndex(3*time().timeIndex());
308         updateMesh();
310         msPtr_->updateMesh();
311     }
312     else
313     {
314         Info << "Sliding interfaces decoupled" << endl;
315     }
317     // Perform mesh motion
318     makeSlidersDead();
320     // Changing topology by hand
321     resetMorph();
322     setMorphTimeIndex(3*time().timeIndex() + 1);
323     updateMesh();
325     msPtr_->updateMesh();
327     if (topoChangeMap.valid())
328     {
329         if (topoChangeMap().hasMotionPoints())
330         {
331             Info << "Topology change; executing pre-motion" << endl;
332             movePoints(topoChangeMap().preMotionPoints());
333         }
334     }
336     // Solve for motion
337     msPtr_->solve();
339     movePoints(msPtr_->curPoints());
341     // Attach the interface
342     Info << "Coupling sliding interfaces" << endl;
343     makeSlidersLive();
344     resetMorph();
345     setMorphTimeIndex(3*time().timeIndex() + 2);
346     updateMesh();
348     Info << "Moving points post slider attach" << endl;
350     msPtr_->updateMesh();
352     Info << "Sliding interfaces coupled: " << attached() << endl;
356 // ************************************************************************* //