1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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 "thoboisMesh.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"
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::thoboisMesh::makeLayersLive()
62 forAll (topoChanger_, modI)
64 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
66 topoChanger_[modI].enable();
68 else if (isA<slidingInterface>(topoChanger_[modI]))
70 topoChanger_[modI].disable();
72 else if (isA<attachDetach>(topoChanger_[modI]))
74 topoChanger_[modI].enable();
78 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
79 << "Don't know what to do with mesh modifier "
80 << modI << " of type " << topoChanger_[modI].type()
88 void Foam::thoboisMesh::valveDetach()
90 // Enable sliding interface
91 forAll (topoChanger_, modI)
93 if (isA<attachDetach>(topoChanger_[modI]))
95 const attachDetach& ad =
96 refCast<const attachDetach>(topoChanger_[modI]);
98 const word masterName = ad.masterPatchID().name();
100 // Find the valve with that name
101 label valveIndex = -1;
103 forAll (valves_, valveI)
107 valves_[valveI].detachInCylinderPatchID().name()
120 "void Foam::engineTopoFvMesh::prepareValveDetach()"
121 ) << "Cannot match patch for attach/detach " << modI
122 << abort(FatalError);
127 Info<< " valveI: " << valveIndex << " attached: "
129 << " valve open: " << valves_[valveIndex].isOpen()
139 void Foam::thoboisMesh::valveAttach()
141 // Enable sliding interface
142 forAll (topoChanger_, modI)
144 if (isA<attachDetach>(topoChanger_[modI]))
146 const attachDetach& ad =
147 refCast<const attachDetach>(topoChanger_[modI]);
149 const word masterName = ad.masterPatchID().name();
151 // Find the valve with that name
152 label valveIndex = -1;
154 forAll (valves_, valveI)
158 valves_[valveI].detachInCylinderPatchID().name()
171 "void Foam::engineTopoFvMesh::prepareValveDetach()"
172 ) << "Cannot match patch for attach/detach " << modI
173 << abort(FatalError);
178 Info<< " valveI: " << valveIndex << " attached: "
180 << " valve open: " << valves_[valveIndex].isOpen()
191 void Foam::thoboisMesh::prepareValveDetach()
193 // Enable sliding interface
194 forAll (topoChanger_, modI)
196 if (isA<attachDetach>(topoChanger_[modI]))
198 const attachDetach& ad =
199 refCast<const attachDetach>(topoChanger_[modI]);
201 const word masterName = ad.masterPatchID().name();
203 // Find the valve with that name
204 label valveIndex = -1;
206 forAll (valves_, valveI)
210 valves_[valveI].detachInCylinderPatchID().name()
223 "void Foam::engineTopoFvMesh::prepareValveDetach()"
224 ) << "Cannot match patch for attach/detach " << modI
225 << abort(FatalError);
230 Info<< " valveI: " << valveIndex << " attached: "
232 << " valve open: " << valves_[valveIndex].isOpen()
236 if (valves_[valveIndex].isOpen())
249 bool Foam::thoboisMesh::update()
251 Info << "bool Foam::layerSmooth::update()" << endl;
252 tetDecompositionMotionSolver& mSolver =
253 refCast<tetDecompositionMotionSolver>(msPtr_());
255 tetPointVectorField& motionU = mSolver.motionU();
257 // Find piston mesh modifier
259 const label pistonLayerID =
260 topoChanger_.findModifierID("pistonLayer");
265 topoChanger_[pistonLayerID].disable();
267 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
269 if (topoChangeMap->morphing())
271 mSolver.updateMesh(topoChangeMap());
272 Info << "mSolver.updateMesh(topoChangeMap())" << endl;
277 scalar deltaZ = engTime().pistonDisplacement().value();
279 // deltaZ set to zero, FIXED PISTON POSITION
282 Info<< "deltaZ = " << deltaZ << " Piston at:" << pistonPosition()
284 virtualPistonPosition() += deltaZ;
286 Info << "pistonLayerID: " << pistonLayerID << endl;
288 bool realDeformation = deformation();
292 virtualPistonPosition() + deltaZ
293 > deckHeight() - engTime().clearance().value() - SMALL
296 realDeformation = true;
301 // Disable layer addition
302 Info << "**Mesh deformation mode" << endl;
303 topoChanger_[pistonLayerID].disable();
307 // Enable layer addition
308 Info << "**Piston layering mode" << endl;
309 topoChanger_[pistonLayerID].enable();
312 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
314 bool meshChanged = topoChangeMap->morphing();
316 pointField newPoints = allPoints();
320 mSolver.updateMesh(topoChangeMap());
322 if (topoChangeMap().hasMotionPoints())
324 movePoints(topoChangeMap().preMotionPoints());
325 newPoints = topoChangeMap().preMotionPoints();
333 //# include "movePistonPointsLayering.H"
334 movePoints(newPoints);
336 # include "setValveMotionBoundaryConditionThobois.H"
338 // Set piston velocity
339 if (piston().patchID().active())
342 componentMixedTetPolyPatchVectorField& pp =
343 refCast<componentMixedTetPolyPatchVectorField>
345 motionU.boundaryField()[piston().patchID().index()]
348 pp.refValue() = vector::zero;
351 motionU.correctBoundaryConditions();
354 DynamicList<label> constrainedPoints(mSolver.curPoints()().size()/100);
355 DynamicList<vector> constrainedVelocity
357 mSolver.curPoints()().size()/100
360 # include "setThoboisMeshConstraintsNoDeformation.H"
363 // Set piston velocity
364 if (piston().patchID().active())
366 componentMixedTetPolyPatchVectorField& pp =
367 refCast<componentMixedTetPolyPatchVectorField>
369 motionU.boundaryField()[piston().patchID().index()]
372 pp.refValue() = vector::zero;
375 motionU.correctBoundaryConditions();
377 labelList constrainedPointsList(constrainedPoints.shrink());
378 vectorField constrainedVelocityField(constrainedVelocity.shrink());
380 forAll (constrainedPointsList, i)
382 mSolver.setConstraint
384 constrainedPointsList[i],
385 constrainedVelocityField[i]
391 // labelList(constrainedPoints.shrink()),
392 // constrainedVelocity.shrink()
397 //set to zero the motion U along the x and y directions
399 newPoints = mSolver.curPoints();
400 movePoints(newPoints);
401 setVirtualPositions();
402 mSolver.clearConstraints();
406 # include "setValveMotionBoundaryConditionThobois.H"
407 # include "setPistonMotionBoundaryConditionThobois.H"
408 DynamicList<label> constrainedPoints(mSolver.curPoints()().size()/100);
409 DynamicList<vector> constrainedVelocity
411 mSolver.curPoints()().size()/100
414 # include "setThoboisMeshConstraints.H"
416 // Set piston velocity
417 if (piston().patchID().active())
420 componentMixedTetPolyPatchVectorField& pp =
421 refCast<componentMixedTetPolyPatchVectorField>
423 motionU.boundaryField()[piston().patchID().index()]
426 pp.refValue() = vector::zero;
429 // motionU.correctBoundaryConditions();
431 labelList constrainedPointsList(constrainedPoints.shrink());
432 vectorField constrainedVelocityField(constrainedVelocity.shrink());
434 forAll (constrainedPointsList, i)
436 mSolver.setConstraint
438 constrainedPointsList[i],
439 constrainedVelocityField[i]
445 // labelList(constrainedPoints.shrink()),
446 // constrainedVelocity.shrink()
451 //set to zero the motion U along the x and y directions
453 newPoints = mSolver.curPoints();
454 movePoints(newPoints);
455 setVirtualPositions();
456 mSolver.clearConstraints();
460 pointField oldPointsNew = oldPoints();
461 pointField newPointsNew = points();
463 prepareValveDetach();
464 topoChanger_[pistonLayerID].disable();
465 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
467 // Info << motionU << endl;
469 if (topoChangeMap->morphing())
471 mSolver.updateMesh(topoChangeMap());
474 // correct the motion after attaching the sliding interface
476 pointField mappedOldPointsNew(allPoints().size());
478 mappedOldPointsNew.map(oldPointsNew, topoChangeMap->pointMap());
479 pointField newPoints = allPoints();
481 movePoints(mappedOldPointsNew);
484 movePoints(newPoints);
489 Info << "CHANGED LAST" << endl;
492 if(moving() && meshChanged)
494 Info << "MOOOOOOOOOOVING!!!!!!!" << endl;
495 Info << "min V0() post motion = " << min(V0()) << endl;
498 Info << "min V() post-motion = " << min(V()) << endl;
499 Info << "max phi() post-motion = " << max(phi()) << endl;
500 Info << "min phi() post-motion = " << min(phi()) << endl;
503 Info<< "Total cylinder volume at CA " << engTime().timeName() << " = "