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 "engineValveSliding.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::engineValveSliding::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::engineValveSliding::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::engineValveSliding::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::engineValveSliding::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::engineValveSliding::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::engineValveSliding::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::engineValveSliding::update()
318 tetMotionSolver& mSolver =
319 refCast<tetMotionSolver>(msPtr_());
321 // Detaching the interfacethobois2DSlidingDeform
324 Info << "Decoupling sliding interfaces" << endl;
327 autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
329 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();
349 forAll(valves_, valveI)
351 scalar valveDisplacement = valves_[valveI].curVelocity()*
352 valves_[valveI].cs().axis().z()*engTime().deltaT().value();
354 Info << "valveDisplacement = " << valveDisplacement << nl
355 << "valve velocity =" << valves_[valveI].curVelocity() << nl
356 << "valve lift =" << valves_[valveI].curLift() << nl
357 << "valve deformation lift ="
358 << valves_[valveI].deformationLift() << endl;
363 forAll(valves_,valveI)
365 if(valves_[valveI].curLift() >= valves_[valveI].deformationLift())
367 if(valves_[valveI].poppetPatchID().active())
369 // Find valve layer mesh modifier
370 const label valveLayerID =
371 topoChanger_.findModifierID
374 + Foam::name(valveI + 1)
377 if (valveLayerID < 0)
379 FatalErrorIn("void engineFvMesh::moveAndMorph()")
380 << "valve modifier not found."
381 << abort(FatalError);
384 topoChanger_[valveLayerID].enable();
389 if(valves_[valveI].poppetPatchID().active())
391 // Find valve layer mesh modifier
392 const label valveLayerID =
393 topoChanger_.findModifierID
396 + Foam::name(valveI + 1)
399 if (valveLayerID < 0)
401 FatalErrorIn("void engineFvMesh::moveAndMorph()")
402 << "valve modifier not found."
403 << abort(FatalError);
406 topoChanger_[valveLayerID].disable();
411 pointField newPoints = points();
413 autoPtr<mapPolyMesh> topoChangeMap2 = topoChanger_.changeMesh();
415 // Changing topology by hand
416 if (topoChangeMap2->morphing())
418 mSolver.updateMesh(topoChangeMap2());
420 if (topoChangeMap2->hasMotionPoints())
422 movePoints(topoChangeMap2->preMotionPoints());
423 newPoints = topoChangeMap2->preMotionPoints();
429 // Work array for new points position.
433 // Reset the position of layered interfaces
438 # include "setMotionBoundaryConditionEngineValveSliding.H"
440 DynamicList<label> constrainedPoints(mSolver.curPoints()().size()/100);
441 DynamicList<vector> constrainedVelocity
443 mSolver.curPoints()().size()/100
446 # include "setEngineValveSlidingConstraint.H"
448 forAll (constrainedPoints, i)
450 mSolver.setConstraint
452 constrainedPoints[i],
453 constrainedVelocity[i]
457 // Info << mSolver.motionU() << endl;
459 Info << "pre solve" << endl;
463 newPoints = mSolver.curPoints();
464 movePoints(newPoints);
466 Info << "max mesh phi, 1 = " << max(phi()) << endl;
467 Info << "min mesh phi, 1 = " << min(phi()) << endl;
469 setVirtualPositions();
470 mSolver.clearConstraints();
476 # include "moveValvePointsEngineValveSliding.H"
477 movePoints(newPoints);
478 // newPoints = points();
479 newPoints = allPoints();
480 setVirtualPositions();
482 Info << "max mesh phi, 2 = " << max(phi()) << endl;
483 Info << "min mesh phi, 2 = " << min(phi()) << endl;
487 Info << ", deckHeight = " << deckHeight()
488 << ", pistonPosition = " << pistonPosition() << endl;
490 pistonPosition() += deltaZ;
492 Info << "max V()-V0() before = " << max(mag(V() - V0())) << endl;
493 Info << "max V() before = " << max(mag(V())) << endl;
495 Info<< "BEFORE mag(points - oldPoints)/deltaT = "
496 << max(mag(points() - oldPoints()))/engTime().deltaT().value() << endl;
501 Info<< "OLD " << "point " << pp << " " << points()[pp]
502 << " old point = " << oldPoints()[pp] << mag(points()[pp] -
503 oldPoints()[pp])/engTime().deltaT().value() << endl;
508 //*/ //Tommaso, 23/5/2008
511 // Grab old points to correct the motion
512 pointField oldPointsNew = oldAllPoints();
513 // pointField oldPointsNew = oldPoints();
515 // Attach the interface
516 Info << "Coupling sliding interfaces" << endl;
519 // Changing topology by hand
520 autoPtr<mapPolyMesh> topoChangeMap4 = topoChanger_.changeMesh();
522 // Changing topology by hand
523 if(topoChangeMap4->morphing())
525 mSolver.updateMesh(topoChangeMap4());
527 if (topoChangeMap4->hasMotionPoints())
529 // Info<< "Topology change; executing pre-motion "
530 // << "after sliding attach" << endl;
532 // Info<< "topoChangeMap4->preMotionPoints().size() = "
533 // << topoChangeMap4->preMotionPoints().size() << endl;
534 // Info << "allPoints.size() = " << allPoints().size() << endl;
535 // Info << "points.size() = " << points().size() << endl;
537 movePoints(topoChangeMap4->preMotionPoints());
538 // newPoints = topoChangeMap4->preMotionPoints();
539 // newPoints = allPoints();
540 newPoints = allPoints();
544 surfaceScalarField correctedMeshPhi = phi();
547 Info << "max V()-V0() after = " << max(mag(V() - V0())) << endl;
548 Info << "max V() before = " << max(mag(V())) << endl;
551 Info << "AFTER mag(points - oldPoints)/deltaT = "
552 << max(mag(points() - oldPoints()))/engTime().deltaT().value()
554 Info << "max V()-V0() after movePoints?!? = "
555 << max(mag(V() - V0())) << endl;
557 pointField mappedOldPointsNew(allPoints().size());
559 mappedOldPointsNew.map(oldPointsNew, topoChangeMap4->pointMap());
561 forAll(valves(), valveI)
563 const labelList& cutPointsAddressing =
566 pointZones().findZoneID
569 + Foam::name(valveI + 1)
573 forAll(cutPointsAddressing, i)
575 mappedOldPointsNew[cutPointsAddressing[i]] =
576 newPoints[cutPointsAddressing[i]];
580 pointField newPoints = allPoints();
582 movePoints(mappedOldPointsNew);
586 movePoints(newPoints);
588 Info<< "max mesh phi, sliding mesh attached = "
589 << max(mag(phi().internalField())) << endl;
590 Info<< "max mesh phi, sliding mesh attached = "
591 << min(mag(phi().internalField())) << endl;
593 Info<< "AFTER 2 mag(points - oldPoints)/deltaT = "
594 << max(mag(points() - oldPoints()))/engTime().deltaT().value()
596 Info << "AFTER 2 max V()-V0() after = "
597 << max(mag(V() - V0())) << endl;