1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2005-2010 Tommaso Lucchini
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
28 \*---------------------------------------------------------------------------*/
30 #include "engineValveSliding.H"
31 #include "slidingInterface.H"
32 #include "layerAdditionRemoval.H"
33 #include "attachDetach.H"
34 #include "surfaceFields.H"
35 #include "regionSplit.H"
36 #include "componentMixedTetPolyPatchVectorField.H"
37 #include "mapPolyMesh.H"
39 #include "tetPolyMesh.H"
40 #include "tetPointFields.H"
41 #include "elementFields.H"
42 #include "fixedValueTetPolyPatchFields.H"
43 #include "slipTetPolyPatchFields.H"
47 #include "symmetryFvPatch.H"
48 #include "wedgeFvPatch.H"
49 #include "emptyFvPatch.H"
50 #include "zeroGradientTetPolyPatchFields.H"
51 #include "tetDecompositionMotionSolver.H"
53 #include "fixedValueTetPolyPatchFields.H"
54 #include "mixedTetPolyPatchFields.H"
55 #include "slipTetPolyPatchFields.H"
56 #include "zeroGradientTetPolyPatchFields.H"
58 #include "zeroGradientFvPatchFields.H"
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 void Foam::engineValveSliding::makeLayersLive()
66 forAll (topoChanger_, modI)
68 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
70 topoChanger_[modI].enable();
72 else if (isA<slidingInterface>(topoChanger_[modI]))
74 topoChanger_[modI].disable();
76 else if (isA<attachDetach>(topoChanger_[modI]))
78 topoChanger_[modI].enable();
82 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
83 << "Don't know what to do with mesh modifier "
84 << modI << " of type " << topoChanger_[modI].type()
90 void Foam::engineValveSliding::makeSlidersLive()
92 // Enable sliding interface
93 forAll (topoChanger_, modI)
95 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
97 topoChanger_[modI].disable();
99 else if (isA<slidingInterface>(topoChanger_[modI]))
101 topoChanger_[modI].enable();
103 else if (isA<attachDetach>(topoChanger_[modI]))
105 topoChanger_[modI].enable();
109 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
110 << "Don't know what to do with mesh modifier "
111 << modI << " of type " << topoChanger_[modI].type()
112 << abort(FatalError);
118 bool Foam::engineValveSliding::attached() const
120 const polyTopoChanger& morphs = topoChanger_;
124 forAll (morphs, modI)
126 if (typeid(morphs[modI]) == typeid(slidingInterface))
130 || refCast<const slidingInterface>(morphs[modI]).attached();
134 // Check thal all sliders are in sync (debug only)
135 forAll (morphs, modI)
137 if (typeid(morphs[modI]) == typeid(slidingInterface))
142 != refCast<const slidingInterface>(morphs[modI]).attached()
145 FatalErrorIn("bool movingSquaresTM::attached() const")
146 << "Slider " << modI << " named " << morphs[modI].name()
147 << " out of sync: Should be" << result
148 << abort(FatalError);
157 void Foam::engineValveSliding::valveDetach()
159 // Enable sliding interface
160 forAll (topoChanger_, modI)
162 if (isA<attachDetach>(topoChanger_[modI]))
164 const attachDetach& ad =
165 refCast<const attachDetach>(topoChanger_[modI]);
167 const word masterName = ad.masterPatchID().name();
169 // Find the valve with that name
170 label valveIndex = -1;
172 forAll (valves_, valveI)
176 valves_[valveI].detachInCylinderPatchID().name()
189 "void Foam::engineTopoFvMesh::prepareValveDetach()"
190 ) << "Cannot match patch for attach/detach " << modI
191 << abort(FatalError);
196 Info<< " valveI: " << valveIndex << " attached: "
198 << " valve open: " << valves_[valveIndex].isOpen()
207 void Foam::engineValveSliding::valveAttach()
209 // Enable sliding interface
210 forAll (topoChanger_, modI)
212 if (isA<attachDetach>(topoChanger_[modI]))
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)
226 valves_[valveI].detachInCylinderPatchID().name()
239 "void Foam::engineTopoFvMesh::prepareValveDetach()"
240 ) << "Cannot match patch for attach/detach " << modI
241 << abort(FatalError);
246 Info<< " valveI: " << valveIndex << " attached: "
248 << " valve open: " << valves_[valveIndex].isOpen()
258 void Foam::engineValveSliding::prepareValveDetach()
260 // Enable sliding interface
261 forAll (topoChanger_, modI)
263 if (isA<attachDetach>(topoChanger_[modI]))
265 const attachDetach& ad =
266 refCast<const attachDetach>(topoChanger_[modI]);
268 const word masterName = ad.masterPatchID().name();
270 // Find the valve with that name
271 label valveIndex = -1;
273 forAll (valves_, valveI)
277 valves_[valveI].detachInCylinderPatchID().name()
290 "void Foam::engineTopoFvMesh::prepareValveDetach()"
291 ) << "Cannot match patch for attach/detach " << modI
292 << abort(FatalError);
297 Info<< " valveI: " << valveIndex << " attached: "
299 << " valve open: " << valves_[valveIndex].isOpen()
303 if (valves_[valveIndex].isOpen())
316 bool Foam::engineValveSliding::update()
319 tetDecompositionMotionSolver& mSolver =
320 refCast<tetDecompositionMotionSolver>(msPtr_());
322 // Detaching the interfacethobois2DSlidingDeform
325 Info << "Decoupling sliding interfaces" << endl;
328 autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
330 Info << "sliding interfaces successfully decoupled!!!" << endl;
331 if (topoChangeMap1->morphing())
333 mSolver.updateMesh(topoChangeMap1());
338 Info << "Sliding interfaces decoupled" << endl;
342 Info << "Executing layer action" << endl;
344 scalar deltaZ = engTime().pistonDisplacement().value();
350 forAll(valves_, valveI)
352 scalar valveDisplacement = valves_[valveI].curVelocity()*
353 valves_[valveI].cs().axis().z()*engTime().deltaT().value();
355 Info << "valveDisplacement = " << valveDisplacement << nl
356 << "valve velocity =" << valves_[valveI].curVelocity() << nl
357 << "valve lift =" << valves_[valveI].curLift() << nl
358 << "valve deformation lift ="
359 << valves_[valveI].deformationLift() << endl;
364 forAll(valves_,valveI)
366 if(valves_[valveI].curLift() >= valves_[valveI].deformationLift())
368 if(valves_[valveI].poppetPatchID().active())
370 // Find valve layer mesh modifier
371 const label valveLayerID =
372 topoChanger_.findModifierID
375 + Foam::name(valveI + 1)
378 if (valveLayerID < 0)
380 FatalErrorIn("void engineFvMesh::moveAndMorph()")
381 << "valve modifier not found."
382 << abort(FatalError);
385 topoChanger_[valveLayerID].enable();
390 if(valves_[valveI].poppetPatchID().active())
392 // Find valve layer mesh modifier
393 const label valveLayerID =
394 topoChanger_.findModifierID
397 + Foam::name(valveI + 1)
400 if (valveLayerID < 0)
402 FatalErrorIn("void engineFvMesh::moveAndMorph()")
403 << "valve modifier not found."
404 << abort(FatalError);
407 topoChanger_[valveLayerID].disable();
412 pointField newPoints = points();
414 autoPtr<mapPolyMesh> topoChangeMap2 = topoChanger_.changeMesh();
416 // Changing topology by hand
417 if (topoChangeMap2->morphing())
419 mSolver.updateMesh(topoChangeMap2());
421 if (topoChangeMap2->hasMotionPoints())
423 movePoints(topoChangeMap2->preMotionPoints());
424 newPoints = topoChangeMap2->preMotionPoints();
430 // Work array for new points position.
434 // Reset the position of layered interfaces
439 # include "setMotionBoundaryConditionEngineValveSliding.H"
441 DynamicList<label> constrainedPoints(mSolver.curPoints()().size()/100);
442 DynamicList<vector> constrainedVelocity
444 mSolver.curPoints()().size()/100
447 # include "setEngineValveSlidingConstraint.H"
449 forAll (constrainedPoints, i)
451 mSolver.setConstraint
453 constrainedPoints[i],
454 constrainedVelocity[i]
458 // Info << mSolver.motionU() << endl;
460 Info << "pre solve" << endl;
464 newPoints = mSolver.curPoints();
465 movePoints(newPoints);
467 Info << "max mesh phi, 1 = " << max(phi()) << endl;
468 Info << "min mesh phi, 1 = " << min(phi()) << endl;
470 setVirtualPositions();
471 mSolver.clearConstraints();
477 # include "moveValvePointsEngineValveSliding.H"
478 movePoints(newPoints);
479 // newPoints = points();
480 newPoints = allPoints();
481 setVirtualPositions();
483 Info << "max mesh phi, 2 = " << max(phi()) << endl;
484 Info << "min mesh phi, 2 = " << min(phi()) << endl;
488 Info << ", deckHeight = " << deckHeight()
489 << ", pistonPosition = " << pistonPosition() << endl;
491 pistonPosition() += deltaZ;
493 Info << "max V()-V0() before = " << max(mag(V() - V0())) << endl;
494 Info << "max V() before = " << max(mag(V())) << endl;
496 Info<< "BEFORE mag(points - oldPoints)/deltaT = "
497 << max(mag(points() - oldPoints()))/engTime().deltaT().value() << endl;
502 Info<< "OLD " << "point " << pp << " " << points()[pp]
503 << " old point = " << oldPoints()[pp] << mag(points()[pp] -
504 oldPoints()[pp])/engTime().deltaT().value() << endl;
509 //*/ //Tommaso, 23/5/2008
512 // Grab old points to correct the motion
513 pointField oldPointsNew = oldAllPoints();
514 // pointField oldPointsNew = oldPoints();
516 // Attach the interface
517 Info << "Coupling sliding interfaces" << endl;
520 // Changing topology by hand
521 autoPtr<mapPolyMesh> topoChangeMap4 = topoChanger_.changeMesh();
523 // Changing topology by hand
524 if(topoChangeMap4->morphing())
526 mSolver.updateMesh(topoChangeMap4());
528 if (topoChangeMap4->hasMotionPoints())
530 // Info<< "Topology change; executing pre-motion "
531 // << "after sliding attach" << endl;
533 // Info<< "topoChangeMap4->preMotionPoints().size() = "
534 // << topoChangeMap4->preMotionPoints().size() << endl;
535 // Info << "allPoints.size() = " << allPoints().size() << endl;
536 // Info << "points.size() = " << points().size() << endl;
538 movePoints(topoChangeMap4->preMotionPoints());
539 // newPoints = topoChangeMap4->preMotionPoints();
540 // newPoints = allPoints();
541 newPoints = allPoints();
545 surfaceScalarField correctedMeshPhi = phi();
548 Info << "max V()-V0() after = " << max(mag(V() - V0())) << endl;
549 Info << "max V() before = " << max(mag(V())) << endl;
552 Info << "AFTER mag(points - oldPoints)/deltaT = "
553 << max(mag(points() - oldPoints()))/engTime().deltaT().value()
555 Info << "max V()-V0() after movePoints?!? = "
556 << max(mag(V() - V0())) << endl;
558 pointField mappedOldPointsNew(allPoints().size());
560 mappedOldPointsNew.map(oldPointsNew, topoChangeMap4->pointMap());
562 forAll(valves(), valveI)
564 const labelList& cutPointsAddressing =
567 pointZones().findZoneID
570 + Foam::name(valveI + 1)
574 forAll(cutPointsAddressing, i)
576 mappedOldPointsNew[cutPointsAddressing[i]] =
577 newPoints[cutPointsAddressing[i]];
581 pointField newPoints = allPoints();
583 movePoints(mappedOldPointsNew);
587 movePoints(newPoints);
589 Info<< "max mesh phi, sliding mesh attached = "
590 << max(mag(phi().internalField())) << endl;
591 Info<< "max mesh phi, sliding mesh attached = "
592 << min(mag(phi().internalField())) << endl;
594 Info<< "AFTER 2 mag(points - oldPoints)/deltaT = "
595 << max(mag(points() - oldPoints()))/engTime().deltaT().value()
597 Info << "AFTER 2 max V()-V0() after = "
598 << max(mag(V() - V0())) << endl;