Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / topoChangerFvMesh / linearValveFvMesh / linearValveFvMesh.C
blob873c263c10f5d87441030a8ae74dc2465a6edd9e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 "volMesh.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
39     defineTypeNameAndDebug(linearValveFvMesh, 0);
41     addToRunTimeSelectionTable(topoChangerFvMesh, linearValveFvMesh, IOobject);
45 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
47 void Foam::linearValveFvMesh::addZonesAndModifiers()
49     // Add zones and modifiers for motion action
51     if
52     (
53         pointZones().size() > 0
54      || faceZones().size() > 0
55      || cellZones().size() > 0
56     )
57     {
58         Info<< "void linearValveFvMesh::addZonesAndModifiers() : "
59             << "Zones and modifiers already present.  Skipping."
60             << endl;
62         if (topoChanger_.size() == 0)
63         {
64             FatalErrorIn
65             (
66                 "void linearValveFvMesh::addZonesAndModifiers()"
67             )   << "Mesh modifiers not read properly"
68                 << abort(FatalError);
69         }
71         return;
72     }
74     Info<< "Time = " << time().timeName() << endl
75         << "Adding zones and modifiers to the mesh" << endl;
77     // Add zones
78     List<pointZone*> pz(1);
80     // Add an empty zone for cut points
82     pz[0] = new pointZone
83     (
84         "cutPointZone",
85         labelList(0),
86         0,
87         pointZones()
88     );
91     // Do face zones for slider
93     List<faceZone*> fz(3);
95     // Inner slider
96     const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
97     const polyPatch& innerSlider =
98         boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
100     labelList isf(innerSlider.size());
102     forAll (isf, i)
103     {
104         isf[i] = innerSlider.start() + i;
105     }
107     fz[0] = new faceZone
108     (
109         "insideSliderZone",
110         isf,
111         boolList(innerSlider.size(), false),
112         0,
113         faceZones()
114     );
116     // Outer slider
117     const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
118     const polyPatch& outerSlider =
119         boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
121     labelList osf(outerSlider.size());
123     forAll (osf, i)
124     {
125         osf[i] = outerSlider.start() + i;
126     }
128     fz[1] = new faceZone
129     (
130         "outsideSliderZone",
131         osf,
132         boolList(outerSlider.size(), false),
133         1,
134         faceZones()
135     );
137     // Add empty zone for cut faces
138     fz[2] = new faceZone
139     (
140         "cutFaceZone",
141         labelList(0),
142         boolList(0, false),
143         2,
144         faceZones()
145     );
147     List<cellZone*> cz(0);
149     Info << "Adding point, face and cell zones" << endl;
150     addZones(pz, fz, cz);
152     // Add a topology modifier
153     Info << "Adding topology modifiers" << endl;
154     topoChanger_.setSize(1);
155     topoChanger_.set
156     (
157         0,
158         new slidingInterface
159         (
160             "mixerSlider",
161             0,
162             topoChanger_,
163             outerSliderName + "Zone",
164             innerSliderName + "Zone",
165             "cutPointZone",
166             "cutFaceZone",
167             outerSliderName,
168             innerSliderName,
169             slidingInterface::INTEGRAL,   // Edge matching algorithm
170             true,                         // Attach-detach action
171             intersection::VISIBLE         // Projection algorithm
172         )
173     );
175     // Write mesh and modifiers
176     topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
177     topoChanger_.write();
178     write();
182 void Foam::linearValveFvMesh::makeSlidersDead()
184     const polyTopoChanger& topoChanges = topoChanger_;
186     // Enable layering
187     forAll (topoChanges, modI)
188     {
189         if (isA<slidingInterface>(topoChanges[modI]))
190         {
191             topoChanges[modI].disable();
192         }
193         else
194         {
195             FatalErrorIn("void Foam::linearValveFvMesh::makeSlidersDead()")
196                 << "Don't know what to do with mesh modifier "
197                 << modI << " of type " << topoChanges[modI].type()
198                 << abort(FatalError);
199         }
200     }
204 void Foam::linearValveFvMesh::makeSlidersLive()
206     const polyTopoChanger& topoChanges = topoChanger_;
208     // Enable sliding interface
209     forAll (topoChanges, modI)
210     {
211         if (isA<slidingInterface>(topoChanges[modI]))
212         {
213             topoChanges[modI].enable();
214         }
215         else
216         {
217             FatalErrorIn("void Foam::linearValveFvMesh::makeLayersLive()")
218                 << "Don't know what to do with mesh modifier "
219                 << modI << " of type " << topoChanges[modI].type()
220                 << abort(FatalError);
221         }
222     }
226 bool Foam::linearValveFvMesh::attached() const
228     const polyTopoChanger& topoChanges = topoChanger_;
230     bool result = false;
232     forAll (topoChanges, modI)
233     {
234         if (isA<slidingInterface>(topoChanges[modI]))
235         {
236             result =
237                 result
238              || refCast<const slidingInterface>(topoChanges[modI]).attached();
239         }
240     }
242     // Check thal all sliders are in sync (debug only)
243     forAll (topoChanges, modI)
244     {
245         if (isA<slidingInterface>(topoChanges[modI]))
246         {
247             if
248             (
249                 result 
250              != refCast<const slidingInterface>(topoChanges[modI]).attached()
251             )
252             {
253                 FatalErrorIn("bool linearValveFvMesh::attached() const")
254                     << "Slider " << modI << " named " << topoChanges[modI].name()
255                     << " out of sync: Should be" << result
256                     << abort(FatalError);
257             }
258         }
259     }
261     if (result)
262     {
263         Info << "linearValveFvMesh: attached!" << endl;
264     }
265     else
266     {
267         Info << "linearValveFvMesh: detached!" << endl;
268     }
270     return result;
274 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
276 // Construct from components
277 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
279     topoChangerFvMesh(io),
280     motionDict_
281     (
282         IOdictionary
283         (
284             IOobject
285             (
286                 "dynamicMeshDict",
287                 time().constant(),
288                 *this,
289                 IOobject::MUST_READ,
290                 IOobject::NO_WRITE
291             )
292         ).subDict(typeName + "Coeffs")
293     ),
294     msPtr_(motionSolver::New(*this))
296     addZonesAndModifiers();
300 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
302 Foam::linearValveFvMesh::~linearValveFvMesh()
306 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
308 bool Foam::linearValveFvMesh::update()
310     // Detaching the interface
311     if (attached())
312     {
313         Info << "Decoupling sliding interfaces" << endl;
314         makeSlidersLive();
316         // Changing topology by hand
317         autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
319         if (topoChangeMap1->morphing())
320         {
321             msPtr_->updateMesh(topoChangeMap1());
322         }
323     }
324     else
325     {
326         Info << "Sliding interfaces decoupled" << endl;
327     }
329     // Perform mesh motion
330     makeSlidersDead();
332     // Changing topology by hand
333     {
334         autoPtr<mapPolyMesh> topoChangeMap2 = topoChanger_.changeMesh();
336         if (topoChangeMap2->morphing())
337         {
338             msPtr_->updateMesh(topoChangeMap2());
340             if (topoChangeMap2->hasMotionPoints())
341             {
342                 Info << "Topology change; executing pre-motion" << endl;
343                 movePoints(topoChangeMap2->preMotionPoints());
344             }
345         }
346     }
348     // Solve for motion
349     msPtr_->solve();
351     movePoints(msPtr_->curPoints());
353     // Attach the interface
354     Info << "Coupling sliding interfaces" << endl;
355     makeSlidersLive();
357     // Changing topology by hand
358     {
359         // Grab old points to correct the motion
360         pointField oldPointsNew = oldAllPoints();
362         autoPtr<mapPolyMesh> topoChangeMap3 = topoChanger_.changeMesh();
364         Info << "Moving points post slider attach" << endl;
366         if (topoChangeMap3->morphing())
367         {
368             msPtr_->updateMesh(topoChangeMap3());
370             if (debug)
371             {
372                 Info << "Moving points post slider attach" << endl;
373             }
375             pointField newPoints = allPoints();
376             pointField mappedOldPointsNew(newPoints.size());
378             mappedOldPointsNew.map(oldPointsNew, topoChangeMap3->pointMap());
380             // Solve the correct mesh motion to make sure motion fluxes
381             // are solved for and not mapped
382             movePoints(mappedOldPointsNew);
383             resetMotion();
384             setV0();
385             movePoints(newPoints);
386         }
387     }
389     Info << "Sliding interfaces coupled: " << attached() << endl;
391     return true;
395 // ************************************************************************* //