1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | 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/>.
27 \*---------------------------------------------------------------------------*/
29 #include "thoboisSliding.H"
30 #include "slidingInterface.H"
31 #include "layerAdditionRemoval.H"
32 #include "attachDetach.H"
33 #include "surfaceFields.H"
34 #include "regionSplit.H"
35 #include "componentMixedTetPolyPatchVectorField.H"
36 #include "mapPolyMesh.H"
38 #include "tetPolyMesh.H"
39 #include "tetPointFields.H"
40 #include "elementFields.H"
41 #include "fixedValueTetPolyPatchFields.H"
42 #include "slipTetPolyPatchFields.H"
46 #include "symmetryFvPatch.H"
47 #include "wedgeFvPatch.H"
48 #include "emptyFvPatch.H"
49 #include "zeroGradientTetPolyPatchFields.H"
50 #include "tetMotionSolver.H"
52 #include "fixedValueTetPolyPatchFields.H"
53 #include "mixedTetPolyPatchFields.H"
54 #include "slipTetPolyPatchFields.H"
55 #include "zeroGradientTetPolyPatchFields.H"
57 #include "zeroGradientFvPatchFields.H"
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 void Foam::thoboisSliding::makeLayersLive()
65 forAll (topoChanger_, modI)
67 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
69 topoChanger_[modI].enable();
71 else if (isA<slidingInterface>(topoChanger_[modI]))
73 topoChanger_[modI].disable();
75 else if (isA<attachDetach>(topoChanger_[modI]))
77 topoChanger_[modI].enable();
81 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
82 << "Don't know what to do with mesh modifier "
83 << modI << " of type " << topoChanger_[modI].type()
89 void Foam::thoboisSliding::makeSlidersLive()
91 // Enable sliding interface
92 forAll (topoChanger_, modI)
94 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
96 topoChanger_[modI].disable();
98 else if (isA<slidingInterface>(topoChanger_[modI]))
100 topoChanger_[modI].enable();
102 else if (isA<attachDetach>(topoChanger_[modI]))
104 topoChanger_[modI].enable();
108 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
109 << "Don't know what to do with mesh modifier "
110 << modI << " of type " << topoChanger_[modI].type()
111 << abort(FatalError);
117 bool Foam::thoboisSliding::attached() const
119 const polyTopoChanger& morphs = topoChanger_;
123 forAll (morphs, modI)
125 if (typeid(morphs[modI]) == typeid(slidingInterface))
129 || refCast<const slidingInterface>(morphs[modI]).attached();
133 // Check thal all sliders are in sync (debug only)
134 forAll (morphs, modI)
136 if (typeid(morphs[modI]) == typeid(slidingInterface))
141 != refCast<const slidingInterface>(morphs[modI]).attached()
144 FatalErrorIn("bool movingSquaresTM::attached() const")
145 << "Slider " << modI << " named " << morphs[modI].name()
146 << " out of sync: Should be" << result
147 << abort(FatalError);
156 void Foam::thoboisSliding::valveDetach()
158 // Enable sliding interface
159 forAll (topoChanger_, modI)
161 if (isA<attachDetach>(topoChanger_[modI]))
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)
175 valves_[valveI].detachInCylinderPatchID().name()
188 "void Foam::engineTopoFvMesh::prepareValveDetach()"
189 ) << "Cannot match patch for attach/detach " << modI
190 << abort(FatalError);
195 Info<< " valveI: " << valveIndex << " attached: "
197 << " valve open: " << valves_[valveIndex].isOpen()
206 void Foam::thoboisSliding::valveAttach()
208 // Enable sliding interface
209 forAll (topoChanger_, modI)
211 if (isA<attachDetach>(topoChanger_[modI]))
213 const attachDetach& ad =
214 refCast<const attachDetach>(topoChanger_[modI]);
216 const word masterName = ad.masterPatchID().name();
218 // Find the valve with that name
219 label valveIndex = -1;
221 forAll (valves_, valveI)
225 valves_[valveI].detachInCylinderPatchID().name()
238 "void Foam::engineTopoFvMesh::prepareValveDetach()"
239 ) << "Cannot match patch for attach/detach " << modI
240 << abort(FatalError);
245 Info<< " valveI: " << valveIndex << " attached: "
247 << " valve open: " << valves_[valveIndex].isOpen()
257 void Foam::thoboisSliding::prepareValveDetach()
259 // Enable sliding interface
260 forAll (topoChanger_, modI)
262 if (isA<attachDetach>(topoChanger_[modI]))
264 const attachDetach& ad =
265 refCast<const attachDetach>(topoChanger_[modI]);
267 const word masterName = ad.masterPatchID().name();
269 // Find the valve with that name
270 label valveIndex = -1;
272 forAll (valves_, valveI)
276 valves_[valveI].detachInCylinderPatchID().name()
289 "void Foam::engineTopoFvMesh::prepareValveDetach()"
290 ) << "Cannot match patch for attach/detach " << modI
291 << abort(FatalError);
296 Info<< " valveI: " << valveIndex << " attached: "
298 << " valve open: " << valves_[valveIndex].isOpen()
302 if (valves_[valveIndex].isOpen())
315 bool Foam::thoboisSliding::update()
317 tetMotionSolver& mSolver =
318 refCast<tetMotionSolver>(msPtr_());
320 // Detaching the interfacethobois2DSlidingDeform
323 Info << "Decoupling sliding interfaces" << endl;
326 autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
328 Info << "sliding interfaces successfully decoupled!!!" << endl;
330 if (topoChangeMap1->morphing())
332 mSolver.updateMesh(topoChangeMap1());
337 Info << "Sliding interfaces decoupled" << endl;
341 Info << "Executing layer action" << endl;
343 scalar deltaZ = engTime().pistonDisplacement().value();
350 // Activate bottom layer
351 Info << "Valve layering mode" << endl;
352 forAll(valves_, valveI)
354 if(valves_[valveI].bottomPatchID().active())
356 // Find piston mesh modifier
357 const label valveLayerID2 =
358 topoChanger_.findModifierID
361 + Foam::name(valveI + 1)
364 topoChanger_[valveLayerID2].enable();
369 virtualPistonPosition() += deltaZ;
372 forAll(valves_, valveI)
374 if(!realDeformation())
376 scalar valveDisplacement =
377 valves_[valveI].curVelocity()*
378 valves_[valveI].cs().axis().z()*engTime().deltaT().value();
380 Info<< "valveDisplacement = " << valveDisplacement << nl
381 << "valve velocity =" << valves_[valveI].curVelocity()
384 valveTopPosition_[valveI] += valveDisplacement;
385 valveBottomPosition_[valveI] += valveDisplacement;
386 valvePistonPosition_[valveI] += deltaZ;
391 forAll(valves_,valveI)
393 if(valves_[valveI].curLift() > valves_[valveI].deformationLift())
395 if(valves_[valveI].poppetPatchID().active())
397 // Find valve layer mesh modifier
398 const label valveLayerID =
399 topoChanger_.findModifierID
402 + Foam::name(valveI + 1)
405 if (valveLayerID < 0)
407 FatalErrorIn("void engineFvMesh::moveAndMorph()")
408 << "valve modifier not found."
409 << abort(FatalError);
412 topoChanger_[valveLayerID].enable();
417 if(valves_[valveI].poppetPatchID().active())
419 // Find valve layer mesh modifier
420 const label valveLayerID =
421 topoChanger_.findModifierID
424 + Foam::name(valveI + 1)
427 if (valveLayerID < 0)
429 FatalErrorIn("void engineFvMesh::moveAndMorph()")
430 << "valve modifier not found."
431 << abort(FatalError);
434 topoChanger_[valveLayerID].disable();
439 pointField newPoints = points();
441 // pointField newPoints = allPoints();
443 autoPtr<mapPolyMesh> topoChangeMap2 = topoChanger_.changeMesh();
445 // Changing topology by hand
446 if (topoChangeMap2->morphing())
448 mSolver.updateMesh(topoChangeMap2());
450 if (topoChangeMap2->hasMotionPoints())
452 movePoints(topoChangeMap2->preMotionPoints());
453 newPoints = topoChangeMap2->preMotionPoints();
459 // Work array for new points position.
463 // Reset the position of layered interfaces
467 # include "setValveMotionBoundaryConditionThoboisSliding.H"
469 dynamicLabelList constrainedPoints(mSolver.curPoints()().size()/100);
470 DynamicList<vector> constrainedVelocity
472 mSolver.curPoints()().size()/100
474 # include "setThoboisSlidingConstraint.H"
476 forAll (constrainedPoints, i)
478 mSolver.setConstraint
480 constrainedPoints[i],
481 constrainedVelocity[i]
487 newPoints = mSolver.curPoints();
488 movePoints(newPoints);
490 setVirtualPositions();
491 mSolver.clearConstraints();
495 # include "moveValvePointsThoboisSliding.H"
496 movePoints(newPoints);
497 // newPoints = points();
498 newPoints = allPoints();
499 setVirtualPositions();
503 forAll(valves(), valveI)
505 Info << "Valve Top Position for valve n. " << valveI + 1 << " = " <<
506 valveTopPosition_[valveI] << endl;
507 Info << "Valve Bottom Position for valve n. " << valveI + 1 << " = " <<
508 valveBottomPosition_[valveI] << endl;
511 Info << "virtualPistonPosition = " << virtualPistonPosition()
512 << ", deckHeight = " << deckHeight()
513 << ", pistonPosition = " << pistonPosition()
516 pistonPosition() += deltaZ;
518 scalarField Vold = V();
531 dimensionedScalar("zero", dimensionSet(0, 0, 0, 0, 0), 0.0),
532 zeroGradientFvPatchScalarField::typeName
535 vMesh.internalField() = V();
536 vMesh.oldTime().internalField() = V0();
539 // Coupling the interface Again
543 pointField newPointsNew = allPoints();
545 // Attach the interface
546 Info << "Coupling sliding interfaces" << endl;
549 prepareValveDetach();
551 pointField oldPointsNew = oldAllPoints();
553 // Changing topology by hand
554 autoPtr<mapPolyMesh> topoChangeMap3 = topoChanger_.changeMesh();
556 Info << "Sliding interfaces coupled: " << attached() << endl;
557 if (topoChangeMap3->morphing())
559 Info << "mesh changed 3" << endl;
561 mSolver.updateMesh(topoChangeMap3());
563 if (topoChangeMap3->hasMotionPoints())
565 movePoints(topoChangeMap3->preMotionPoints());
571 // correct the motion after attaching the sliding interface
572 Info<< "oldPointsNew.size = " << oldPointsNew.size() << nl
573 << "allPointsNew.size = " << allPoints().size() << nl
574 << "pointsNew.size = " << points().size() << endl;
576 pointField mappedOldPointsNew(allPoints().size());
578 pointField newPoints = allPoints();
579 // pointField newPoints = points();
581 mappedOldPointsNew.map
584 topoChangeMap3->pointMap()
587 movePoints(mappedOldPointsNew);
592 movePoints(mappedOldPointsNew);
593 Info<< "max mesh phi, 3 = " << max(phi()) << nl
594 << "min mesh phi, 3 = " << min(phi()) << nl
595 << "mappedOldPointsNew.size() = "
596 << mappedOldPointsNew.size() << nl
597 << "newPoints.size() = " << newPoints.size() << nl
598 << "topoChangeMap3->pointMap().size() = "
599 << topoChangeMap3->pointMap().size() << endl;
601 movePoints(newPoints);