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 "verticalValves.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::verticalValves::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::verticalValves::makeSlidersLive()
93 // Enable sliding interface
94 forAll (topoChanger_, modI)
96 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
98 topoChanger_[modI].disable();
100 else if (isA<slidingInterface>(topoChanger_[modI]))
102 topoChanger_[modI].enable();
104 else if (isA<attachDetach>(topoChanger_[modI]))
106 topoChanger_[modI].enable();
110 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
111 << "Don't know what to do with mesh modifier "
112 << modI << " of type " << topoChanger_[modI].type()
113 << abort(FatalError);
119 bool Foam::verticalValves::attached() const
121 const polyTopoChanger& morphs = topoChanger_;
125 forAll (morphs, modI)
127 if (typeid(morphs[modI]) == typeid(slidingInterface))
131 || refCast<const slidingInterface>(morphs[modI]).attached();
135 // Check thal all sliders are in sync (debug only)
136 forAll (morphs, modI)
138 if (typeid(morphs[modI]) == typeid(slidingInterface))
143 != refCast<const slidingInterface>(morphs[modI]).attached()
146 FatalErrorIn("bool movingSquaresTM::attached() const")
147 << "Slider " << modI << " named " << morphs[modI].name()
148 << " out of sync: Should be" << result
149 << abort(FatalError);
157 void Foam::verticalValves::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()
208 void Foam::verticalValves::valveAttach()
210 // Enable sliding interface
211 forAll (topoChanger_, modI)
213 if (isA<attachDetach>(topoChanger_[modI]))
215 const attachDetach& ad =
216 refCast<const attachDetach>(topoChanger_[modI]);
218 const word masterName = ad.masterPatchID().name();
220 // Find the valve with that name
221 label valveIndex = -1;
223 forAll (valves_, valveI)
227 valves_[valveI].detachInCylinderPatchID().name()
240 "void Foam::engineTopoFvMesh::prepareValveDetach()"
241 ) << "Cannot match patch for attach/detach " << modI
242 << abort(FatalError);
247 Info<< " valveI: " << valveIndex << " attached: "
249 << " valve open: " << valves_[valveIndex].isOpen()
259 void Foam::verticalValves::prepareValveDetach()
261 // Enable sliding interface
262 forAll (topoChanger_, modI)
264 if (isA<attachDetach>(topoChanger_[modI]))
266 const attachDetach& ad =
267 refCast<const attachDetach>(topoChanger_[modI]);
269 const word masterName = ad.masterPatchID().name();
271 // Find the valve with that name
272 label valveIndex = -1;
274 forAll (valves_, valveI)
278 valves_[valveI].detachInCylinderPatchID().name()
291 "void Foam::engineTopoFvMesh::prepareValveDetach()"
292 ) << "Cannot match patch for attach/detach " << modI
293 << abort(FatalError);
298 Info<< " valveI: " << valveIndex << " attached: "
300 << " valve open: " << valves_[valveIndex].isOpen()
304 if (valves_[valveIndex].isOpen())
317 bool Foam::verticalValves::update()
320 tetDecompositionMotionSolver& mSolver =
321 refCast<tetDecompositionMotionSolver>(msPtr_());
323 // Detaching the interface
326 Info << "Decoupling sliding interfaces" << endl;
329 autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
331 Info << "sliding interfaces successfully decoupled!!!" << endl;
332 if (topoChangeMap1->morphing())
334 mSolver.updateMesh(topoChangeMap1());
339 Info << "Sliding interfaces decoupled" << endl;
343 Info << "Executing layer action" << endl;
348 scalar deltaZ = engTime().pistonDisplacement().value();
350 // Find piston mesh modifier
351 const label pistonLayerID =
352 topoChanger_.findModifierID("pistonLayer");
354 if (realDeformation())
356 Info << "Mesh deformation mode" << endl;
357 topoChanger_[pistonLayerID].disable();
358 forAll(valves_, valveI)
360 // Find piston mesh modifier
361 const label valveLayerID1 =
362 topoChanger_.findModifierID
365 + Foam::name(valveI + 1)
368 topoChanger_[valveLayerID1].disable();
370 if(valves_[valveI].bottomPatchID().active())
372 // Find piston mesh modifier
373 const label valveLayerID2 =
374 topoChanger_.findModifierID
377 + Foam::name(valveI + 1)
380 topoChanger_[valveLayerID2].disable();
386 // Activate piston layer
387 Info << "Piston layering mode" << endl;
388 topoChanger_[pistonLayerID].enable();
389 forAll(valves_, valveI)
391 // Find piston mesh modifier
392 const label valveLayerID1 =
393 topoChanger_.findModifierID
396 + Foam::name(valveI + 1)
398 topoChanger_[valveLayerID1].enable();
400 if(valves_[valveI].bottomPatchID().active())
402 // Find piston mesh modifier
403 const label valveLayerID2 =
404 topoChanger_.findModifierID
407 + Foam::name(valveI + 1)
410 topoChanger_[valveLayerID2].enable();
415 scalar minLayerThickness = piston().minLayer();
416 virtualPistonPosition() += deltaZ;
418 forAll(valves_,valveI)
420 if(!realDeformation())
422 scalar valveDisplacement =
423 valves_[valveI].curVelocity()*
424 valves_[valveI].cs().axis().z()*engTime().deltaT().value();
426 valveTopPosition_[valveI] += valveDisplacement;
427 valveBottomPosition_[valveI] += valveDisplacement;
428 valvePistonPosition_[valveI] += deltaZ;
432 forAll(valves_,valveI)
434 if(valves_[valveI].poppetPatchID().active())
437 // Find valve layer mesh modifier
438 const label valveLayerID =
439 topoChanger_.findModifierID
442 + Foam::name(valveI + 1)
445 if (valveLayerID < 0)
447 FatalErrorIn("void engineFvMesh::moveAndMorph()")
448 << "valve modifier not found."
449 << abort(FatalError);
452 if (valves_[valveI].curLift() < valveTopTol_)
454 topoChanger_[valveLayerID].disable();
458 topoChanger_[valveLayerID].enable();
462 if(valves_[valveI].isOpen())
464 isReallyClosed_[valveI] = false;
469 // Changing topology by hand
470 autoPtr<mapPolyMesh> topoChangeMap2 = topoChanger_.changeMesh();
472 if (pistonLayerID < 0)
474 FatalErrorIn("void engineFvMesh::moveAndMorph()")
475 << "Piston modifier not found."
476 << abort(FatalError);
479 // Work array for new points position.
480 pointField newPoints = points();
482 // Changing topology by hand
483 if (topoChangeMap2->morphing())
485 mSolver.updateMesh(topoChangeMap2());
487 if (topoChangeMap2->hasMotionPoints())
489 movePoints(topoChangeMap2->preMotionPoints());
490 newPoints = topoChangeMap2->preMotionPoints();
500 // Reset the position of layered interfaces
504 1) Move all the piston points
507 bool poppetDeformation = false;
509 if(!realDeformation())
511 Info << "verticalValves::update()::Layering mode" << endl;
513 # include "movePistonPoints.H"
514 # include "moveValvePoints.H"
515 movePoints(newPoints);
516 # include "poppetDeformation.H"
517 newPoints = points();
518 setVirtualPositions();
522 Info << "verticalValves::update()::Deformation mode" << endl;
524 # include "moveAllTogether.H"
525 movePoints(mSolver.curPoints());
526 setVirtualPositions();
527 newPoints = points();
528 # include "moveTopOfTheValves.H"
529 movePoints(newPoints);
530 # include "poppetDeformation.H"
531 newPoints = points();
532 setVirtualPositions();
535 forAll(valves(), valveI)
537 Info << "Valve Top Position for valve n. " << valveI + 1 << " = " <<
538 valveTopPosition_[valveI] << endl;
539 Info << "Valve Bottom Position for valve n. " << valveI + 1 << " = " <<
540 valveBottomPosition_[valveI] << endl;
541 Info << "Valve Piston Position for valve n. " << valveI + 1 << " = " <<
542 valvePistonPosition_[valveI] << endl;
545 Info << "virtualPistonPosition = " << virtualPistonPosition()
546 << ", deckHeight = " << deckHeight()
547 << ", pistonPosition = " << pistonPosition()
550 pistonPosition() += deltaZ;
552 scalarField Vold = V();
565 dimensionedScalar("zero", dimensionSet(0, 0, 0, 0, 0), 0.0),
566 zeroGradientFvPatchScalarField::typeName
569 vMesh.internalField() = V();
570 vMesh.oldTime().internalField() = V0();
573 // Coupling the interface Again
576 pointField oldPointsNew = oldPoints();
578 // Attach the interface
579 Info << "Coupling sliding interfaces" << endl;
582 prepareValveDetach();
586 // Changing topology by hand
587 autoPtr<mapPolyMesh> topoChangeMap3 = topoChanger_.changeMesh();
589 Info << "Sliding interfaces coupled: " << attached() << endl;
590 if (topoChangeMap3->morphing())
592 mSolver.updateMesh(topoChangeMap3());
594 if (topoChangeMap3->hasMotionPoints())
596 // movePoints(topoChangeMap3->preMotionPoints());
601 if(correctPointsMotion_)
603 // correct the motion after attaching the sliding interface
604 pointField mappedOldPointsNew(allPoints().size());
606 mappedOldPointsNew.map
609 topoChangeMap3->pointMap()
611 pointField newPoints = allPoints();
613 movePoints(mappedOldPointsNew);
617 movePoints(newPoints);