BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / topoChangerFvMesh / linearValveFvMesh / linearValveFvMesh.C
blob19cac53913e5562bbc67d91901118f1a3cb9ca2a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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 = boundaryMesh()[innerSliderName];
89     labelList isf(innerSlider.size());
91     forAll(isf, i)
92     {
93         isf[i] = innerSlider.start() + i;
94     }
96     fz[0] = new faceZone
97     (
98         "insideSliderZone",
99         isf,
100         boolList(innerSlider.size(), false),
101         0,
102         faceZones()
103     );
105     // Outer slider
106     const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
107     const polyPatch& outerSlider = boundaryMesh()[outerSliderName];
109     labelList osf(outerSlider.size());
111     forAll(osf, i)
112     {
113         osf[i] = outerSlider.start() + i;
114     }
116     fz[1] = new faceZone
117     (
118         "outsideSliderZone",
119         osf,
120         boolList(outerSlider.size(), false),
121         1,
122         faceZones()
123     );
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     );
135     List<cellZone*> cz(0);
137     Info<< "Adding point, face and cell zones" << endl;
138     addZones(pz, fz, cz);
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,
157             slidingInterface::INTEGRAL,
158             true                          // Attach-detach action
159         )
160     );
161     topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
163     // Write mesh
164     write();
168 void Foam::linearValveFvMesh::makeSlidersDead()
170     const polyTopoChanger& topoChanges = topoChanger_;
172     // Enable layering
173     forAll(topoChanges, modI)
174     {
175         if (isA<slidingInterface>(topoChanges[modI]))
176         {
177             topoChanges[modI].disable();
178         }
179         else
180         {
181             FatalErrorIn("void Foam::linearValveFvMesh::makeSlidersDead()")
182                 << "Don't know what to do with mesh modifier "
183                 << modI << " of type " << topoChanges[modI].type()
184                 << abort(FatalError);
185         }
186     }
190 void Foam::linearValveFvMesh::makeSlidersLive()
192     const polyTopoChanger& topoChanges = topoChanger_;
194     // Enable sliding interface
195     forAll(topoChanges, modI)
196     {
197         if (isA<slidingInterface>(topoChanges[modI]))
198         {
199             topoChanges[modI].enable();
200         }
201         else
202         {
203             FatalErrorIn("void Foam::linearValveFvMesh::makeLayersLive()")
204                 << "Don't know what to do with mesh modifier "
205                 << modI << " of type " << topoChanges[modI].type()
206                 << abort(FatalError);
207         }
208     }
212 bool Foam::linearValveFvMesh::attached() const
214     const polyTopoChanger& topoChanges = topoChanger_;
216     bool result = false;
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     }
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             {
239                 FatalErrorIn("bool linearValveFvMesh::attached() const")
240                     << "Slider " << modI
241                     << " named " << topoChanges[modI].name()
242                     << " out of sync: Should be" << result
243                     << abort(FatalError);
244             }
245         }
246     }
248     if (result)
249     {
250         Info<< "linearValveFvMesh: attached!" << endl;
251     }
252     else
253     {
254         Info<< "linearValveFvMesh: detached!" << endl;
255     }
257     return result;
261 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
263 // Construct from components
264 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
266     topoChangerFvMesh(io),
267     motionDict_
268     (
269         IOdictionary
270         (
271             IOobject
272             (
273                 "dynamicMeshDict",
274                 time().constant(),
275                 *this,
276                 IOobject::MUST_READ_IF_MODIFIED,
277                 IOobject::NO_WRITE,
278                 false
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 // ************************************************************************* //