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 "layerSmooth.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"
44 #include "symmetryFvPatch.H"
45 #include "wedgeFvPatch.H"
46 #include "emptyFvPatch.H"
47 #include "zeroGradientTetPolyPatchFields.H"
48 #include "tetDecompositionMotionSolver.H"
50 #include "fixedValueTetPolyPatchFields.H"
51 #include "mixedTetPolyPatchFields.H"
52 #include "slipTetPolyPatchFields.H"
53 #include "zeroGradientTetPolyPatchFields.H"
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 void Foam::layerSmooth::makeLayersLive()
60 forAll (topoChanger_, modI)
62 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
64 topoChanger_[modI].enable();
66 else if (isA<attachDetach>(topoChanger_[modI]))
68 topoChanger_[modI].enable();
72 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
73 << "Don't know what to do with mesh modifier "
74 << modI << " of type " << topoChanger_[modI].type()
81 void Foam::layerSmooth::valveDetach()
83 // Enable sliding interface
84 forAll (topoChanger_, modI)
86 if (isA<attachDetach>(topoChanger_[modI]))
88 const attachDetach& ad =
89 refCast<const attachDetach>(topoChanger_[modI]);
91 const word masterName = ad.masterPatchID().name();
93 // Find the valve with that name
94 label valveIndex = -1;
96 forAll (valves_, valveI)
100 valves_[valveI].detachInCylinderPatchID().name()
113 "void Foam::engineTopoFvMesh::prepareValveDetach()"
114 ) << "Cannot match patch for attach/detach " << modI
115 << abort(FatalError);
120 Info<< " valveI: " << valveIndex << " attached: "
122 << " valve open: " << valves_[valveIndex].isOpen()
132 void Foam::layerSmooth::valveAttach()
134 // Enable sliding interface
135 forAll (topoChanger_, modI)
137 if (isA<attachDetach>(topoChanger_[modI]))
139 const attachDetach& ad =
140 refCast<const attachDetach>(topoChanger_[modI]);
142 const word masterName = ad.masterPatchID().name();
144 // Find the valve with that name
145 label valveIndex = -1;
147 forAll (valves_, valveI)
151 valves_[valveI].detachInCylinderPatchID().name()
164 "void Foam::engineTopoFvMesh::prepareValveDetach()"
165 ) << "Cannot match patch for attach/detach " << modI
166 << abort(FatalError);
171 Info<< " valveI: " << valveIndex << " attached: "
173 << " valve open: " << valves_[valveIndex].isOpen()
183 void Foam::layerSmooth::prepareValveDetach()
185 // Enable sliding interface
186 forAll (topoChanger_, modI)
188 if (isA<attachDetach>(topoChanger_[modI]))
190 const attachDetach& ad =
191 refCast<const attachDetach>(topoChanger_[modI]);
193 const word masterName = ad.masterPatchID().name();
195 // Find the valve with that name
196 label valveIndex = -1;
198 forAll (valves_, valveI)
202 valves_[valveI].detachInCylinderPatchID().name()
215 "void Foam::engineTopoFvMesh::prepareValveDetach()"
216 ) << "Cannot match patch for attach/detach " << modI
217 << abort(FatalError);
222 Info<< " valveI: " << valveIndex << " attached: "
224 << " valve open: " << valves_[valveIndex].isOpen()
228 if (valves_[valveIndex].isOpen())
241 bool Foam::layerSmooth::update()
244 Info << "bool Foam::layerSmooth::update()" << endl;
246 tetDecompositionMotionSolver& mSolver =
247 refCast<tetDecompositionMotionSolver>(msPtr_());
249 tetPointVectorField& motionU = mSolver.motionU();
251 // motionU.internalField() = (vector::zero);
253 // Info << motionU << endl;
256 // Find piston mesh modifier
257 const label pistonLayerID = topoChanger_.findModifierID("pistonLayer");
262 Info << "valveDetach()" << endl;
264 topoChanger_[pistonLayerID].disable();
266 Info << "disable()" << endl;
268 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
270 Info << "changeMesh()" << endl;
272 if (topoChangeMap->morphing())
274 mSolver.updateMesh(topoChangeMap());
275 Info << "mSolver.updateMesh(topoChangeMap())" << endl;
280 scalar deltaZ = engTime().pistonDisplacement().value();
281 Info<< "deltaZ = " << deltaZ << " Piston at:" << pistonPosition()
283 virtualPistonPosition() += deltaZ;
285 Info << "pistonLayerID: " << pistonLayerID << endl;
287 const layerAdditionRemoval& pistonLayers =
288 dynamicCast<const layerAdditionRemoval>
290 topoChanger_[pistonLayerID]
293 bool realDeformation = deformation();
297 virtualPistonPosition() + deltaZ
298 > deckHeight() - engTime().clearance().value() - SMALL
301 realDeformation = true;
306 // Disable layer addition
307 Info << "**Mesh deformation mode" << endl;
308 topoChanger_[pistonLayerID].disable();
312 // Enable layer addition
313 Info << "**Piston layering mode" << endl;
314 topoChanger_[pistonLayerID].enable();
317 scalar minLayerThickness = pistonLayers.minLayerThickness();
319 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
321 pointField newPoints = points();
323 if (topoChangeMap->morphing())
325 mSolver.updateMesh(topoChangeMap());
327 if (topoChangeMap().hasMotionPoints())
329 movePoints(topoChangeMap().preMotionPoints());
330 newPoints = topoChangeMap().preMotionPoints();
338 # include "movePistonPointsLayeringLayerSmooth.H"
339 Info << "movePoints" << endl;
340 movePoints(newPoints);
341 Info << "setBoundaryMotion" << endl;
343 //# include "setBoundaryMotion.H"
345 # include "setValveMotionBoundaryCondition.H"
347 // Set piston velocity
348 if (piston().patchID().active())
351 componentMixedTetPolyPatchVectorField& pp =
352 refCast<componentMixedTetPolyPatchVectorField>
354 motionU.boundaryField()[piston().patchID().index()]
357 pp.refValue() = vector::zero;
360 motionU.correctBoundaryConditions();
363 //# include "setPistonMotionBoundaryCondition.H"
364 Info << "mSolver" << endl;
366 Info << "newPoints" << endl;
367 newPoints = mSolver.curPoints();
368 Info << "movePoints 2" << endl;
369 movePoints(newPoints);
373 # include "setValveMotionBoundaryCondition.H"
374 # include "setPistonMotionBoundaryConditionLayerSmooth.H"
376 newPoints = mSolver.curPoints();
377 movePoints(newPoints);
381 pointField oldPointsNew = oldPoints();
382 pointField newPointsNew = points();
384 prepareValveDetach();
385 topoChanger_[pistonLayerID].disable();
386 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
388 Info << "changeMesh" << endl;
391 if (topoChangeMap->morphing())
393 Info << "meshChanged" << endl;
395 mSolver.updateMesh(topoChangeMap());
396 Info << "updateMesh" << endl;
399 // correct the motion after attaching the sliding interface
401 pointField mappedOldPointsNew(allPoints().size());
403 mappedOldPointsNew.map(oldPointsNew, topoChangeMap->pointMap());
404 pointField newPoints = allPoints();
406 movePoints(mappedOldPointsNew);
409 movePoints(newPoints);
414 Info << "CHANGED LAST" << endl;
416 // Info << motionU << endl;
423 if(moving() && meshChanged)
425 Info << "MOOOOOOOOOOVING!!!!!!!" << endl;
426 Info << "min V0() post motion = " << min(V0()) << endl;
429 Info << "min V() post-motion = " << min(V()) << endl;
430 Info << "max phi() post-motion = " << max(phi()) << endl;
431 Info << "min phi() post-motion = " << min(phi()) << endl;
434 Info << "Total cylinder volume at CA " << engTime().timeName() << " = " <<
443 pointField oldPointsNew = oldPoints();
444 pointField newPointsNew = points();
446 // Attach the interface
447 Info << "Coupling sliding interfaces" << endl;
450 prepareValveDetach();
454 // Changing topology by hand
455 autoPtr<mapPolyMesh> topoChangeMap3 = topoChanger_.changeMesh();
456 Info << "Sliding interfaces coupled: " << attached() << endl;
458 if (topoChangeMap3->morphing())
460 mSolver.updateMesh(topoChangeMap3());
462 if (topoChangeMap3->hasMotionPoints())
464 // movePoints(topoChangeMap3->preMotionPoints());
468 if(correctPointsMotion_)
470 // correct the motion after attaching the sliding interface
471 pointField mappedOldPointsNew(allPoints().size());
473 mappedOldPointsNew.map(oldPointsNew, topoChangeMap3->pointMap());
474 pointField newPoints = allPoints();
476 movePoints(mappedOldPointsNew);
479 movePoints(newPoints);