Merge branch 'master' of github.com:OpenCFD/OpenFOAM-1.7.x
[OpenFOAM-1.7.x.git] / src / topoChangerFvMesh / linearValveFvMesh / linearValveFvMesh.C
blobeec4ca3b3da9543821d19e64700d7e793318d873
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.
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.
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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "linearValveFvMesh.H"
27 #include "Time.H"
28 #include "slidingInterface.H"
29 #include "mapPolyMesh.H"
30 #include "polyTopoChange.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(linearValveFvMesh, 0);
39     addToRunTimeSelectionTable(topoChangerFvMesh, linearValveFvMesh, IOobject);
43 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
45 void Foam::linearValveFvMesh::addZonesAndModifiers()
47     // Add zones and modifiers for motion action
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;
61         return;
62     }
64     Info<< "Time = " << time().timeName() << endl
65         << "Adding zones and modifiers to the mesh" << endl;
67     // Add zones
68     List<pointZone*> pz(1);
70     // Add an empty zone for cut points
72     pz[0] = new pointZone
73     (
74         "cutPointZone",
75         labelList(0),
76         0,
77         pointZones()
78     );
81     // Do face zones for slider
83     List<faceZone*> fz(3);
85     // Inner slider
86     const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
87     const polyPatch& innerSlider =
88         boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
90     labelList isf(innerSlider.size());
92     forAll (isf, i)
93     {
94         isf[i] = innerSlider.start() + i;
95     }
97     fz[0] = new faceZone
98     (
99         "insideSliderZone",
100         isf,
101         boolList(innerSlider.size(), false),
102         0,
103         faceZones()
104     );
106     // Outer slider
107     const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
108     const polyPatch& outerSlider =
109         boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
111     labelList osf(outerSlider.size());
113     forAll (osf, i)
114     {
115         osf[i] = outerSlider.start() + i;
116     }
118     fz[1] = new faceZone
119     (
120         "outsideSliderZone",
121         osf,
122         boolList(outerSlider.size(), false),
123         1,
124         faceZones()
125     );
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     );
137     List<cellZone*> cz(0);
139     Info << "Adding point, face and cell zones" << endl;
140     addZones(pz, fz, cz);
142     // Add a topology modifier
143     Info << "Adding topology modifiers" << endl;
144     topoChanger_.setSize(1);
145     topoChanger_.set
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,
159             slidingInterface::INTEGRAL,
160             true                          // Attach-detach action
161         )
162     );
163     topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
165     // Write mesh
166     write();
170 void Foam::linearValveFvMesh::makeSlidersDead()
172     const polyTopoChanger& topoChanges = topoChanger_;
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     }
192 void Foam::linearValveFvMesh::makeSlidersLive()
194     const polyTopoChanger& topoChanges = topoChanger_;
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     }
214 bool Foam::linearValveFvMesh::attached() const
216     const polyTopoChanger& topoChanges = topoChanger_;
218     bool result = false;
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     }
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     }
249     if (result)
250     {
251         Info << "linearValveFvMesh: attached!" << endl;
252     }
253     else
254     {
255         Info << "linearValveFvMesh: detached!" << endl;
256     }
258     return result;
262 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
264 // Construct from components
265 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
267     topoChangerFvMesh(io),
268     motionDict_
269     (
270         IOdictionary
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))
284     addZonesAndModifiers();
288 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
290 Foam::linearValveFvMesh::~linearValveFvMesh()
294 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
296 void Foam::linearValveFvMesh::update()
298     // Detaching the interface
299     if (attached())
300     {
301         Info << "Decoupling sliding interfaces" << endl;
302         makeSlidersLive();
304         // Changing topology by hand
305         resetMorph();
306         setMorphTimeIndex(3*time().timeIndex());
307         updateMesh();
309         msPtr_->updateMesh();
310     }
311     else
312     {
313         Info << "Sliding interfaces decoupled" << endl;
314     }
316     // Perform mesh motion
317     makeSlidersDead();
319     // Changing topology by hand
320     resetMorph();
321     setMorphTimeIndex(3*time().timeIndex() + 1);
322     updateMesh();
324     msPtr_->updateMesh();
326     if (topoChangeMap.valid())
327     {
328         if (topoChangeMap().hasMotionPoints())
329         {
330             Info << "Topology change; executing pre-motion" << endl;
331             movePoints(topoChangeMap().preMotionPoints());
332         }
333     }
335     // Solve for motion
336     msPtr_->solve();
338     movePoints(msPtr_->curPoints());
340     // Attach the interface
341     Info << "Coupling sliding interfaces" << endl;
342     makeSlidersLive();
343     resetMorph();
344     setMorphTimeIndex(3*time().timeIndex() + 2);
345     updateMesh();
347     Info << "Moving points post slider attach" << endl;
349     msPtr_->updateMesh();
351     Info << "Sliding interfaces coupled: " << attached() << endl;
355 // ************************************************************************* //