initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / topoChangerFvMesh / linearValveLayersFvMesh / linearValveLayersFvMesh.C
blob9dd4c56c2f74d6a780108d60830da31e5f829329
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 "linearValveLayersFvMesh.H"
28 #include "Time.H"
29 #include "slidingInterface.H"
30 #include "layerAdditionRemoval.H"
31 #include "pointField.H"
32 #include "mapPolyMesh.H"
33 #include "polyTopoChange.H"
34 #include "addToRunTimeSelectionTable.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 namespace Foam
40     defineTypeNameAndDebug(linearValveLayersFvMesh, 0);
42     addToRunTimeSelectionTable(topoChangerFvMesh, linearValveLayersFvMesh, IOobject);
46 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
48 void Foam::linearValveLayersFvMesh::addZonesAndModifiers()
50     // Add zones and modifiers for motion action
52     if
53     (
54         pointZones().size()
55      || faceZones().size()
56      || cellZones().size()
57      || topoChanger_.size()
58     )
59     {
60         Info<< "void linearValveLayersFvMesh::addZonesAndModifiers() : "
61             << "Zones and modifiers already present.  Skipping."
62             << endl;
64         return;
65     }
67     Info<< "Time = " << time().timeName() << endl
68         << "Adding zones and modifiers to the mesh" << endl;
70     // Add zones
71     List<pointZone*> pz(1);
72     List<faceZone*> fz(4);
73     List<cellZone*> cz(0);
76     // Add an empty zone for cut points
78     pz[0] = new pointZone
79     (
80         "cutPointZone",
81         labelList(0),
82         0,
83         pointZones()
84     );
87     // Do face zones for slider
89     // Inner slider
90     const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
91     const polyPatch& innerSlider =
92         boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
94     labelList isf(innerSlider.size());
96     forAll (isf, i)
97     {
98         isf[i] = innerSlider.start() + i;
99     }
101     fz[0] = new faceZone
102     (
103         "insideSliderZone",
104         isf,
105         boolList(innerSlider.size(), false),
106         0,
107         faceZones()
108     );
110     // Outer slider
111     const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
112     const polyPatch& outerSlider =
113         boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
115     labelList osf(outerSlider.size());
117     forAll (osf, i)
118     {
119         osf[i] = outerSlider.start() + i;
120     }
122     fz[1] = new faceZone
123     (
124         "outsideSliderZone",
125         osf,
126         boolList(outerSlider.size(), false),
127         1,
128         faceZones()
129     );
131     // Add empty zone for cut faces
132     fz[2] = new faceZone
133     (
134         "cutFaceZone",
135         labelList(0),
136         boolList(0, false),
137         2,
138         faceZones()
139     );
141     // Add face zone for layer addition
142     const word layerPatchName
143     (
144         motionDict_.subDict("layer").lookup("patch")
145     );
147     const polyPatch& layerPatch =
148         boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
150     labelList lpf(layerPatch.size());
152     forAll (lpf, i)
153     {
154         lpf[i] = layerPatch.start() + i;
155     }
157     fz[3] = new faceZone
158     (
159         "valveLayerZone",
160         lpf,
161         boolList(layerPatch.size(), true),
162         0,
163         faceZones()
164     );
167     Info << "Adding point and face zones" << endl;
168     addZones(pz, fz, cz);
170     // Add a topology modifier
172     List<polyMeshModifier*> tm(2);
174     tm[0] = new slidingInterface
175     (
176         "valveSlider",
177         0,
178         topoChanger_,
179         outerSliderName + "Zone",
180         innerSliderName + "Zone",
181         "cutPointZone",
182         "cutFaceZone",
183         outerSliderName,
184         innerSliderName,
185         slidingInterface::INTEGRAL,
186         true                          // Attach-detach action
187     );
189     tm[1] =
190         new layerAdditionRemoval
191         (
192             "valveLayer",
193             1,
194             topoChanger_,
195             "valveLayerZone",
196             readScalar
197             (
198                 motionDict_.subDict("layer").lookup("minThickness")
199             ),
200             readScalar
201             (
202                 motionDict_.subDict("layer").lookup("maxThickness")
203             )
204         );
207     Info << "Adding topology modifiers" << endl;
208     addTopologyModifiers(tm);
210     // Write mesh
211     write();
215 void Foam::linearValveLayersFvMesh::makeLayersLive()
217     const polyTopoChanger& topoChanges = topoChanger_;
219     // Enable layering
220     forAll (topoChanges, modI)
221     {
222         if (typeid(topoChanges[modI]) == typeid(layerAdditionRemoval))
223         {
224             topoChanges[modI].enable();
225         }
226         else if (typeid(topoChanges[modI]) == typeid(slidingInterface))
227         {
228             topoChanges[modI].disable();
229         }
230         else
231         {
232             FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
233                 << "Don't know what to do with mesh modifier "
234                 << modI << " of type " << topoChanges[modI].type()
235                 << abort(FatalError);
236         }
237     }
241 void Foam::linearValveLayersFvMesh::makeSlidersLive()
243     const polyTopoChanger& topoChanges = topoChanger_;
245     // Enable sliding interface
246     forAll (topoChanges, modI)
247     {
248         if (typeid(topoChanges[modI]) == typeid(layerAdditionRemoval))
249         {
250             topoChanges[modI].disable();
251         }
252         else if (typeid(topoChanges[modI]) == typeid(slidingInterface))
253         {
254             topoChanges[modI].enable();
255         }
256         else
257         {
258             FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
259                 << "Don't know what to do with mesh modifier "
260                 << modI << " of type " << topoChanges[modI].type()
261                 << abort(FatalError);
262         }
263     }
267 bool Foam::linearValveLayersFvMesh::attached() const
269     const polyTopoChanger& topoChanges = topoChanger_;
271     bool result = false;
273     forAll (topoChanges, modI)
274     {
275         if (typeid(topoChanges[modI]) == typeid(slidingInterface))
276         {
277             result =
278                 result
279              || refCast<const slidingInterface>(topoChanges[modI]).attached();
280         }
281     }
283     // Check thal all sliders are in sync (debug only)
284     forAll (topoChanges, modI)
285     {
286         if (typeid(topoChanges[modI]) == typeid(slidingInterface))
287         {
288             if
289             (
290                 result
291              != refCast<const slidingInterface>(topoChanges[modI]).attached()
292             )
293             {
294                 FatalErrorIn("bool linearValveLayersFvMesh::attached() const")
295                     << "Slider " << modI << " named "
296                     << topoChanges[modI].name()
297                     << " out of sync: Should be" << result
298                     << abort(FatalError);
299             }
300         }
301     }
303     return result;
307 Foam::tmp<Foam::pointField> Foam::linearValveLayersFvMesh::newPoints() const
309     tmp<pointField> tnewPoints
310     (
311         new pointField(points())
312     );
314     pointField& np = tnewPoints();
316     const word layerPatchName
317     (
318         motionDict_.subDict("layer").lookup("patch")
319     );
321     const polyPatch& layerPatch =
322         boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
324     const labelList& patchPoints = layerPatch.meshPoints();
326     const vector vel
327     (
328         motionDict_.lookup("pistonVelocity")
329     );
331     forAll (patchPoints, ppI)
332     {
333         np[patchPoints[ppI]] += vel*time().deltaT().value();
334     }
336     return tnewPoints;
341 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
343 // Construct from components
344 Foam::linearValveLayersFvMesh::linearValveLayersFvMesh(const IOobject& io)
346     topoChangerFvMesh(io),
347     motionDict_
348     (
349         IOdictionary
350         (
351             IOobject
352             (
353                 "dynamicMeshDict",
354                 time().constant(),
355                 *this,
356                 IOobject::MUST_READ,
357                 IOobject::NO_WRITE
358             )
359         ).subDict(typeName + "Coeffs")
360     )
362     addZonesAndModifiers();
366 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
368 Foam::linearValveLayersFvMesh::~linearValveLayersFvMesh()
371 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
373 void Foam::linearValveLayersFvMesh::update()
375     // Detaching the interface
376     if (attached())
377     {
378         Info << "Decoupling sliding interfaces" << endl;
379         makeSlidersLive();
381         // Changing topology
382         resetMorph();
383         setMorphTimeIndex(3*time().timeIndex());
384         updateMesh();
385     }
386     else
387     {
388         Info << "Sliding interfaces decoupled" << endl;
389     }
391     // Perform layer action and mesh motion
392     makeLayersLive();
394     // Changing topology
395     resetMorph();
396     setMorphTimeIndex(3*time().timeIndex() + 1);
397     updateMesh();
399     if (topoChangeMap.valid())
400     {
401         if (topoChangeMap().hasMotionPoints())
402         {
403             Info << "Topology change; executing pre-motion" << endl;
404             movePoints(topoChangeMap().preMotionPoints());
405         }
406     }
408     // Move points
409     movePoints(newPoints());
411     // Attach the interface
412     Info << "Coupling sliding interfaces" << endl;
413     makeSlidersLive();
415     // Changing topology
416     resetMorph();
417     setMorphTimeIndex(3*time().timeIndex() + 2);
418     updateMesh();
420     Info << "Moving points post slider attach" << endl;
421 //     const pointField p = allPoints();
422 //     movePoints(p);
424     Info << "Sliding interfaces coupled: " << attached() << endl;
428 // ************************************************************************* //