1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "thoboisMesh.H"
27 #include "slidingInterface.H"
28 #include "layerAdditionRemoval.H"
29 #include "attachDetach.H"
30 #include "surfaceFields.H"
31 #include "regionSplit.H"
32 #include "componentMixedTetPolyPatchVectorField.H"
33 #include "mapPolyMesh.H"
35 #include "tetPolyMesh.H"
36 #include "tetPointFields.H"
37 #include "elementFields.H"
38 #include "fixedValueTetPolyPatchFields.H"
39 #include "slipTetPolyPatchFields.H"
40 #include "symmetryTetPolyPatch.H"
44 #include "symmetryFvPatch.H"
45 #include "wedgeFvPatch.H"
46 #include "emptyFvPatch.H"
47 #include "zeroGradientTetPolyPatchFields.H"
48 #include "tetMotionSolver.H"
50 #include "fixedValueTetPolyPatchFields.H"
51 #include "mixedTetPolyPatchFields.H"
52 #include "slipTetPolyPatchFields.H"
53 #include "zeroGradientTetPolyPatchFields.H"
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 void Foam::thoboisMesh::makeLayersLive()
61 forAll (topoChanger_, modI)
63 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
65 topoChanger_[modI].enable();
67 else if (isA<slidingInterface>(topoChanger_[modI]))
69 topoChanger_[modI].disable();
71 else if (isA<attachDetach>(topoChanger_[modI]))
73 topoChanger_[modI].enable();
77 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
78 << "Don't know what to do with mesh modifier "
79 << modI << " of type " << topoChanger_[modI].type()
87 void Foam::thoboisMesh::valveDetach()
89 // Enable sliding interface
90 forAll (topoChanger_, modI)
92 if (isA<attachDetach>(topoChanger_[modI]))
94 const attachDetach& ad =
95 refCast<const attachDetach>(topoChanger_[modI]);
97 const word masterName = ad.masterPatchID().name();
99 // Find the valve with that name
100 label valveIndex = -1;
102 forAll (valves_, valveI)
106 valves_[valveI].detachInCylinderPatchID().name()
119 "void Foam::engineTopoFvMesh::prepareValveDetach()"
120 ) << "Cannot match patch for attach/detach " << modI
121 << abort(FatalError);
126 Info<< " valveI: " << valveIndex << " attached: "
128 << " valve open: " << valves_[valveIndex].isOpen()
138 void Foam::thoboisMesh::valveAttach()
140 // Enable sliding interface
141 forAll (topoChanger_, modI)
143 if (isA<attachDetach>(topoChanger_[modI]))
145 const attachDetach& ad =
146 refCast<const attachDetach>(topoChanger_[modI]);
148 const word masterName = ad.masterPatchID().name();
150 // Find the valve with that name
151 label valveIndex = -1;
153 forAll (valves_, valveI)
157 valves_[valveI].detachInCylinderPatchID().name()
170 "void Foam::engineTopoFvMesh::prepareValveDetach()"
171 ) << "Cannot match patch for attach/detach " << modI
172 << abort(FatalError);
177 Info<< " valveI: " << valveIndex << " attached: "
179 << " valve open: " << valves_[valveIndex].isOpen()
190 void Foam::thoboisMesh::prepareValveDetach()
192 // Enable sliding interface
193 forAll (topoChanger_, modI)
195 if (isA<attachDetach>(topoChanger_[modI]))
197 const attachDetach& ad =
198 refCast<const attachDetach>(topoChanger_[modI]);
200 const word masterName = ad.masterPatchID().name();
202 // Find the valve with that name
203 label valveIndex = -1;
205 forAll (valves_, valveI)
209 valves_[valveI].detachInCylinderPatchID().name()
222 "void Foam::engineTopoFvMesh::prepareValveDetach()"
223 ) << "Cannot match patch for attach/detach " << modI
224 << abort(FatalError);
229 Info<< " valveI: " << valveIndex << " attached: "
231 << " valve open: " << valves_[valveIndex].isOpen()
235 if (valves_[valveIndex].isOpen())
248 bool Foam::thoboisMesh::update()
250 Info << "bool Foam::layerSmooth::update()" << endl;
251 tetMotionSolver& mSolver =
252 refCast<tetMotionSolver>(msPtr_());
254 tetPointVectorField& motionU = mSolver.motionU();
256 // Find piston mesh modifier
258 const label pistonLayerID =
259 topoChanger_.findModifierID("pistonLayer");
264 topoChanger_[pistonLayerID].disable();
266 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
268 if (topoChangeMap->morphing())
270 mSolver.updateMesh(topoChangeMap());
271 Info << "mSolver.updateMesh(topoChangeMap())" << endl;
276 scalar deltaZ = engTime().pistonDisplacement().value();
278 // deltaZ set to zero, FIXED PISTON POSITION
281 Info<< "deltaZ = " << deltaZ << " Piston at:" << pistonPosition()
283 virtualPistonPosition() += deltaZ;
285 Info << "pistonLayerID: " << pistonLayerID << endl;
287 bool realDeformation = deformation();
291 virtualPistonPosition() + deltaZ
292 > deckHeight() - engTime().clearance().value() - SMALL
295 realDeformation = true;
300 // Disable layer addition
301 Info << "**Mesh deformation mode" << endl;
302 topoChanger_[pistonLayerID].disable();
306 // Enable layer addition
307 Info << "**Piston layering mode" << endl;
308 topoChanger_[pistonLayerID].enable();
311 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
313 bool meshChanged = topoChangeMap->morphing();
315 pointField newPoints = allPoints();
319 mSolver.updateMesh(topoChangeMap());
321 if (topoChangeMap().hasMotionPoints())
323 movePoints(topoChangeMap().preMotionPoints());
324 newPoints = topoChangeMap().preMotionPoints();
332 //# include "movePistonPointsLayering.H"
333 movePoints(newPoints);
335 # include "setValveMotionBoundaryConditionThobois.H"
337 // Set piston velocity
338 if (piston().patchID().active())
341 componentMixedTetPolyPatchVectorField& pp =
342 refCast<componentMixedTetPolyPatchVectorField>
344 motionU.boundaryField()[piston().patchID().index()]
347 pp.refValue() = vector::zero;
350 motionU.correctBoundaryConditions();
353 DynamicList<label> constrainedPoints(mSolver.curPoints()().size()/100);
354 DynamicList<vector> constrainedVelocity
356 mSolver.curPoints()().size()/100
359 # include "setThoboisMeshConstraintsNoDeformation.H"
362 // Set piston velocity
363 if (piston().patchID().active())
365 componentMixedTetPolyPatchVectorField& pp =
366 refCast<componentMixedTetPolyPatchVectorField>
368 motionU.boundaryField()[piston().patchID().index()]
371 pp.refValue() = vector::zero;
374 motionU.correctBoundaryConditions();
376 labelList constrainedPointsList(constrainedPoints.shrink());
377 vectorField constrainedVelocityField(constrainedVelocity.shrink());
379 forAll (constrainedPointsList, i)
381 mSolver.setConstraint
383 constrainedPointsList[i],
384 constrainedVelocityField[i]
390 // labelList(constrainedPoints.shrink()),
391 // constrainedVelocity.shrink()
396 //set to zero the motion U along the x and y directions
398 newPoints = mSolver.curPoints();
399 movePoints(newPoints);
400 setVirtualPositions();
401 mSolver.clearConstraints();
405 # include "setValveMotionBoundaryConditionThobois.H"
406 # include "setPistonMotionBoundaryConditionThobois.H"
407 DynamicList<label> constrainedPoints(mSolver.curPoints()().size()/100);
408 DynamicList<vector> constrainedVelocity
410 mSolver.curPoints()().size()/100
413 # include "setThoboisMeshConstraints.H"
415 // Set piston velocity
416 if (piston().patchID().active())
419 componentMixedTetPolyPatchVectorField& pp =
420 refCast<componentMixedTetPolyPatchVectorField>
422 motionU.boundaryField()[piston().patchID().index()]
425 pp.refValue() = vector::zero;
428 // motionU.correctBoundaryConditions();
430 labelList constrainedPointsList(constrainedPoints.shrink());
431 vectorField constrainedVelocityField(constrainedVelocity.shrink());
433 forAll (constrainedPointsList, i)
435 mSolver.setConstraint
437 constrainedPointsList[i],
438 constrainedVelocityField[i]
444 // labelList(constrainedPoints.shrink()),
445 // constrainedVelocity.shrink()
450 //set to zero the motion U along the x and y directions
452 newPoints = mSolver.curPoints();
453 movePoints(newPoints);
454 setVirtualPositions();
455 mSolver.clearConstraints();
459 pointField oldPointsNew = oldPoints();
460 pointField newPointsNew = points();
462 prepareValveDetach();
463 topoChanger_[pistonLayerID].disable();
464 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
466 // Info << motionU << endl;
468 if (topoChangeMap->morphing())
470 mSolver.updateMesh(topoChangeMap());
473 // correct the motion after attaching the sliding interface
475 pointField mappedOldPointsNew(allPoints().size());
477 mappedOldPointsNew.map(oldPointsNew, topoChangeMap->pointMap());
478 pointField newPoints = allPoints();
480 movePoints(mappedOldPointsNew);
483 movePoints(newPoints);
488 Info << "CHANGED LAST" << endl;
491 if(moving() && meshChanged)
493 Info << "MOOOOOOOOOOVING!!!!!!!" << endl;
494 Info << "min V0() post motion = " << min(V0()) << endl;
497 Info << "min V() post-motion = " << min(V()) << endl;
498 Info << "max phi() post-motion = " << max(phi()) << endl;
499 Info << "min phi() post-motion = " << min(phi()) << endl;
502 Info<< "Total cylinder volume at CA " << engTime().timeName() << " = "