fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / accordionEngineMesh / accordionEngineMeshMove.C
blobfefdc62650b177a3bcc20bf8f422e8e255cd985b
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 "accordionEngineMesh.H"
28 #include "slidingInterface.H"
29 #include "layerAdditionRemoval.H"
30 #include "attachDetach.H"
31 #include "surfaceFields.H"
32 #include "regionSplit.H"
33 #include "componentMixedTetPolyPatchVectorField.H"
34 #include "mapPolyMesh.H"
36 #include "tetPolyMesh.H"
37 #include "tetPointFields.H"
38 #include "elementFields.H"
39 #include "fixedValueTetPolyPatchFields.H"
40 #include "slipTetPolyPatchFields.H"
41 #include "symmetryTetPolyPatch.H"
43 #include "tetFem.H"
45 #include "symmetryFvPatch.H"
46 #include "wedgeFvPatch.H"
47 #include "emptyFvPatch.H"
48 #include "zeroGradientTetPolyPatchFields.H"
49 #include "tetDecompositionMotionSolver.H"
51 #include "fixedValueTetPolyPatchFields.H"
52 #include "mixedTetPolyPatchFields.H"
53 #include "slipTetPolyPatchFields.H"
54 #include "zeroGradientTetPolyPatchFields.H"
58 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
59 void Foam::accordionEngineMesh::makeLayersLive()
61     // Enable layering
62     forAll (topoChanger_, modI)
63     {
64         if (isA<layerAdditionRemoval>(topoChanger_[modI]))
65         {
66             topoChanger_[modI].enable();
67         }
68         else if (isA<slidingInterface>(topoChanger_[modI]))
69         {
70             topoChanger_[modI].disable();
71         }
72         else if (isA<attachDetach>(topoChanger_[modI]))
73         {
74             topoChanger_[modI].enable();
75         }
76         else
77         {
78             FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
79                 << "Don't know what to do with mesh modifier "
80                 << modI << " of type " << topoChanger_[modI].type()
81                 << abort(FatalError);
82         }
83     }
86 void Foam::accordionEngineMesh::makeDetachLive()
88     // Enable sliding interface
89     forAll (topoChanger_, modI)
90     {
91         if (isA<attachDetach>(topoChanger_[modI]))
92         {
93             topoChanger_[modI].enable();
94         }
95         else
96         {
97             FatalErrorIn("void Foam::accordionEngineMesh::makeDetachLive()")
98                 << "Don't know what to do with mesh modifier "
99                 << modI << " of type " << topoChanger_[modI].type()
100                 << abort(FatalError);
101         }
102     }
106 void Foam::accordionEngineMesh::valveDetach()
108     // Enable sliding interface
109     forAll (topoChanger_, modI)
110     {
111         if (isA<attachDetach>(topoChanger_[modI]))
112         {
113             const attachDetach& ad =
114                 refCast<const attachDetach>(topoChanger_[modI]);
116             const word masterName = ad.masterPatchID().name();
118             // Find the valve with that name
119             label valveIndex = -1;
121             forAll (valves_, valveI)
122             {
123                 if
124                 (
125                     valves_[valveI].detachInCylinderPatchID().name()
126                  == masterName
127                 )
128                 {
129                     valveIndex = valveI;
130                     break;
131                 }
132             }
134             if (valveIndex < 0)
135             {
136                 FatalErrorIn
137                 (
138                     "void Foam::engineTopoFvMesh::prepareValveDetach()"
139                 )   << "Cannot match patch for attach/detach " << modI
140                     << abort(FatalError);
141             }
143             if (debug)
144             {
145                 Info<< " valveI: " << valveIndex << " attached: "
146                     << ad.attached()
147                     << " valve open: " << valves_[valveIndex].isOpen()
148                     << endl;
149             }
151             ad.setDetach();
152         }
153     }
156 void Foam::accordionEngineMesh::valveAttach()
158     // Enable sliding interface
159     forAll (topoChanger_, modI)
160     {
161         if (isA<attachDetach>(topoChanger_[modI]))
162         {
163             const attachDetach& ad =
164                 refCast<const attachDetach>(topoChanger_[modI]);
166             const word masterName = ad.masterPatchID().name();
168             // Find the valve with that name
169             label valveIndex = -1;
171             forAll (valves_, valveI)
172             {
173                 if
174                 (
175                     valves_[valveI].detachInCylinderPatchID().name()
176                  == masterName
177                 )
178                 {
179                     valveIndex = valveI;
180                     break;
181                 }
182             }
184             if (valveIndex < 0)
185             {
186                 FatalErrorIn
187                 (
188                     "void Foam::engineTopoFvMesh::prepareValveDetach()"
189                 )   << "Cannot match patch for attach/detach " << modI
190                     << abort(FatalError);
191             }
193             if (debug)
194             {
195                 Info<< " valveI: " << valveIndex << " attached: "
196                     << ad.attached()
197                     << " valve open: " << valves_[valveIndex].isOpen()
198                     << endl;
199             }
201             ad.setAttach();
202         }
203     }
207 void Foam::accordionEngineMesh::prepareValveDetach()
209     // Enable sliding interface
210     forAll (topoChanger_, modI)
211     {
212         if (isA<attachDetach>(topoChanger_[modI]))
213         {
214             const attachDetach& ad =
215                 refCast<const attachDetach>(topoChanger_[modI]);
217             const word masterName = ad.masterPatchID().name();
219             // Find the valve with that name
220             label valveIndex = -1;
222             forAll (valves_, valveI)
223             {
224                 if
225                 (
226                     valves_[valveI].detachInCylinderPatchID().name()
227                  == masterName
228                 )
229                 {
230                     valveIndex = valveI;
231                     break;
232                 }
233             }
235             if (valveIndex < 0)
236             {
237                 FatalErrorIn
238                 (
239                     "void Foam::engineTopoFvMesh::prepareValveDetach()"
240                 )   << "Cannot match patch for attach/detach " << modI
241                     << abort(FatalError);
242             }
244             if (debug)
245             {
246                 Info<< " valveI: " << valveIndex << " attached: "
247                     << ad.attached()
248                     << " valve open: " << valves_[valveIndex].isOpen()
249                     << endl;
250             }
252             if (valves_[valveIndex].isOpen())
253             {
254                 ad.setAttach();
255             }
256             else
257             {
258                 ad.setDetach();
259             }
260         }
261     }
265 bool Foam::accordionEngineMesh::update()
267     tetDecompositionMotionSolver& mSolver =
268         refCast<tetDecompositionMotionSolver>(msPtr_());
270     tetPointVectorField& motionU = mSolver.motionU();
272     Info << "motioU.size() = " << motionU.internalField().size() << endl;
274     scalar deltaZ = engTime().pistonDisplacement().value();
276     // deltaZ set to zero, FIXED PISTON POSITION
277     deltaZ = 0.0;
279     virtualPistonPosition() += deltaZ;
281     makeDetachLive();
283 //    valveDetach();
285     autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
287     if (topoChangeMap->morphing())
288     {
289         mSolver.updateMesh(topoChangeMap());
290         Info << "mSolver.updateMesh(topoChangeMap())" << endl;
292         if (topoChangeMap->hasMotionPoints())
293         {
294             movePoints(topoChangeMap->preMotionPoints());
295             resetMotion();
296             setV0();
297         }
298     }
300     pointField newPoints = points();
302     {
303 #       include "setValveMotionBoundaryConditionAccordionEngineMesh.H"
304 #       include "setPistonMotionBoundaryConditionAccordionEngineMesh.H"
307         DynamicList<label> constrainedPoints(mSolver.curPoints()().size()/100);
308         DynamicList<vector> constrainedVelocity
309         (
310             mSolver.curPoints()().size()/100
311         );
313 #       include "setAccordionEngineMeshConstraints.H"
316         labelList constrainedPointsList(constrainedPoints.shrink());
317         vectorField constrainedVelocityField(constrainedVelocity.shrink());
319         forAll (constrainedPointsList, i)
320         {
321             mSolver.setConstraint
322             (
323                 constrainedPointsList[i],
324                 constrainedVelocityField[i]
325             );
326         }
328         mSolver.solve();
330         //set to zero the motion U along the x and y directions
332         newPoints = mSolver.curPoints();
333         movePoints(newPoints);
334         setVirtualPositions();
335         mSolver.clearConstraints();
336     }
338 //    pointField oldPointsNew = oldPoints();
339     pointField oldPointsNew = oldAllPoints();
340     newPoints = points();
342     Info << "max mesh phi before = " << max((phi())) << endl;
343     Info << "min mesh phi before = " << min((phi())) << endl;
345 //    makeDetachLive();
346     prepareValveDetach();
348     autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
350     if (topoChangeMap1->morphing())
351     {
352         mSolver.updateMesh(topoChangeMap1());
354         if (topoChangeMap1->hasMotionPoints())
355         {
356 //              movePoints(topoChangeMap1->preMotionPoints());
357 //              resetMotion();
358 //              setV0();
360             // correct the motion after attaching the sliding interface
361             pointField mappedOldPointsNew(allPoints().size());
363             mappedOldPointsNew.map(oldPointsNew, topoChangeMap1->pointMap());
364             pointField newPoints = allPoints();
366             movePoints(mappedOldPointsNew);
367             resetMotion();
368             setV0();
369             movePoints(newPoints);
371         }
372     }
374     Info << "max mesh phi after = " << max((phi())) << endl;
375     Info << "min mesh phi after = " << min((phi())) << endl;
377 /*         if(correctPointsMotion_)
378         {
379             // correct the motion after attaching the sliding interface
380             pointField mappedOldPointsNew(allPoints().size());
382             mappedOldPointsNew.map(oldPointsNew, topoChangeMap3->pointMap());
383             pointField newPoints = allPoints();
385             movePoints(mappedOldPointsNew);
386             resetMotion();
387             setV0();
388             movePoints(newPoints);
389         }
391 //    Info << motionU << endl;
393     if (meshChanged1)
394     {
395             Info << "meshChanged1" << endl;
397         mSolver.updateMesh(topoChangeMap1());
399        {
400            pointField mappedOldPointsNew(allPoints().size());
402            mappedOldPointsNew.map(oldPointsNew, topoChangeMap1->pointMap());
403            pointField newPoints = allPoints();
405            movePoints(mappedOldPointsNew);
406            resetMotion();
407            setV0();
408            movePoints(newPoints);
409        }
410     }
412     Info<< "Total cylinder volume at CA " << engTime().timeName() << " = "
413         << sum(V()) << endl;
415     return false;