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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "layerSmooth.H"
27 #include "slidingInterface.H"
28 #include "layerAdditionRemoval.H"
29 #include "attachDetach.H"
30 #include "surfaceFields.H"
31 #include "regionSplit.H"
32 #include "componentMixedTetPolyPatchVectorField.H"
33 #include "mapPolyMesh.H"
35 #include "tetPolyMesh.H"
36 #include "tetPointFields.H"
37 #include "elementFields.H"
38 #include "fixedValueTetPolyPatchFields.H"
39 #include "slipTetPolyPatchFields.H"
43 #include "symmetryFvPatch.H"
44 #include "wedgeFvPatch.H"
45 #include "emptyFvPatch.H"
46 #include "zeroGradientTetPolyPatchFields.H"
47 #include "tetMotionSolver.H"
49 #include "fixedValueTetPolyPatchFields.H"
50 #include "mixedTetPolyPatchFields.H"
51 #include "slipTetPolyPatchFields.H"
52 #include "zeroGradientTetPolyPatchFields.H"
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56 void Foam::layerSmooth::makeLayersLive()
59 forAll (topoChanger_, modI)
61 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
63 topoChanger_[modI].enable();
65 else if (isA<attachDetach>(topoChanger_[modI]))
67 topoChanger_[modI].enable();
71 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
72 << "Don't know what to do with mesh modifier "
73 << modI << " of type " << topoChanger_[modI].type()
80 void Foam::layerSmooth::valveDetach()
82 // Enable sliding interface
83 forAll (topoChanger_, modI)
85 if (isA<attachDetach>(topoChanger_[modI]))
87 const attachDetach& ad =
88 refCast<const attachDetach>(topoChanger_[modI]);
90 const word masterName = ad.masterPatchID().name();
92 // Find the valve with that name
93 label valveIndex = -1;
95 forAll (valves_, valveI)
99 valves_[valveI].detachInCylinderPatchID().name()
112 "void Foam::engineTopoFvMesh::prepareValveDetach()"
113 ) << "Cannot match patch for attach/detach " << modI
114 << abort(FatalError);
119 Info<< " valveI: " << valveIndex << " attached: "
121 << " valve open: " << valves_[valveIndex].isOpen()
131 void Foam::layerSmooth::valveAttach()
133 // Enable sliding interface
134 forAll (topoChanger_, modI)
136 if (isA<attachDetach>(topoChanger_[modI]))
138 const attachDetach& ad =
139 refCast<const attachDetach>(topoChanger_[modI]);
141 const word masterName = ad.masterPatchID().name();
143 // Find the valve with that name
144 label valveIndex = -1;
146 forAll (valves_, valveI)
150 valves_[valveI].detachInCylinderPatchID().name()
163 "void Foam::engineTopoFvMesh::prepareValveDetach()"
164 ) << "Cannot match patch for attach/detach " << modI
165 << abort(FatalError);
170 Info<< " valveI: " << valveIndex << " attached: "
172 << " valve open: " << valves_[valveIndex].isOpen()
182 void Foam::layerSmooth::prepareValveDetach()
184 // Enable sliding interface
185 forAll (topoChanger_, modI)
187 if (isA<attachDetach>(topoChanger_[modI]))
189 const attachDetach& ad =
190 refCast<const attachDetach>(topoChanger_[modI]);
192 const word masterName = ad.masterPatchID().name();
194 // Find the valve with that name
195 label valveIndex = -1;
197 forAll (valves_, valveI)
201 valves_[valveI].detachInCylinderPatchID().name()
214 "void Foam::engineTopoFvMesh::prepareValveDetach()"
215 ) << "Cannot match patch for attach/detach " << modI
216 << abort(FatalError);
221 Info<< " valveI: " << valveIndex << " attached: "
223 << " valve open: " << valves_[valveIndex].isOpen()
227 if (valves_[valveIndex].isOpen())
240 bool Foam::layerSmooth::update()
243 Info << "bool Foam::layerSmooth::update()" << endl;
245 tetMotionSolver& mSolver =
246 refCast<tetMotionSolver>(msPtr_());
248 tetPointVectorField& motionU = mSolver.motionU();
250 // motionU.internalField() = (vector::zero);
252 // Info << motionU << endl;
255 // Find piston mesh modifier
256 const label pistonLayerID = topoChanger_.findModifierID("pistonLayer");
261 Info << "valveDetach()" << endl;
263 topoChanger_[pistonLayerID].disable();
265 Info << "disable()" << endl;
267 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
269 Info << "changeMesh()" << endl;
271 if (topoChangeMap->morphing())
273 mSolver.updateMesh(topoChangeMap());
274 Info << "mSolver.updateMesh(topoChangeMap())" << endl;
279 scalar deltaZ = engTime().pistonDisplacement().value();
280 Info<< "deltaZ = " << deltaZ << " Piston at:" << pistonPosition()
282 virtualPistonPosition() += deltaZ;
284 Info << "pistonLayerID: " << pistonLayerID << endl;
286 const layerAdditionRemoval& pistonLayers =
287 dynamicCast<const layerAdditionRemoval>
289 topoChanger_[pistonLayerID]
292 bool realDeformation = deformation();
296 virtualPistonPosition() + deltaZ
297 > deckHeight() - engTime().clearance().value() - SMALL
300 realDeformation = true;
305 // Disable layer addition
306 Info << "**Mesh deformation mode" << endl;
307 topoChanger_[pistonLayerID].disable();
311 // Enable layer addition
312 Info << "**Piston layering mode" << endl;
313 topoChanger_[pistonLayerID].enable();
316 scalar minLayerThickness = pistonLayers.minLayerThickness();
318 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
320 pointField newPoints = points();
322 if (topoChangeMap->morphing())
324 mSolver.updateMesh(topoChangeMap());
326 if (topoChangeMap().hasMotionPoints())
328 movePoints(topoChangeMap().preMotionPoints());
329 newPoints = topoChangeMap().preMotionPoints();
337 # include "movePistonPointsLayeringLayerSmooth.H"
338 Info << "movePoints" << endl;
339 movePoints(newPoints);
340 Info << "setBoundaryMotion" << endl;
342 //# include "setBoundaryMotion.H"
344 # include "setValveMotionBoundaryCondition.H"
346 // Set piston velocity
347 if (piston().patchID().active())
350 componentMixedTetPolyPatchVectorField& pp =
351 refCast<componentMixedTetPolyPatchVectorField>
353 motionU.boundaryField()[piston().patchID().index()]
356 pp.refValue() = vector::zero;
359 motionU.correctBoundaryConditions();
362 //# include "setPistonMotionBoundaryCondition.H"
363 Info << "mSolver" << endl;
365 Info << "newPoints" << endl;
366 newPoints = mSolver.curPoints();
367 Info << "movePoints 2" << endl;
368 movePoints(newPoints);
372 # include "setValveMotionBoundaryCondition.H"
373 # include "setPistonMotionBoundaryConditionLayerSmooth.H"
375 newPoints = mSolver.curPoints();
376 movePoints(newPoints);
380 pointField oldPointsNew = oldPoints();
381 pointField newPointsNew = points();
383 prepareValveDetach();
384 topoChanger_[pistonLayerID].disable();
385 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
387 Info << "changeMesh" << endl;
390 if (topoChangeMap->morphing())
392 Info << "meshChanged" << endl;
394 mSolver.updateMesh(topoChangeMap());
395 Info << "updateMesh" << endl;
398 // correct the motion after attaching the sliding interface
400 pointField mappedOldPointsNew(allPoints().size());
402 mappedOldPointsNew.map(oldPointsNew, topoChangeMap->pointMap());
403 pointField newPoints = allPoints();
405 movePoints(mappedOldPointsNew);
408 movePoints(newPoints);
413 Info << "CHANGED LAST" << endl;
415 // Info << motionU << endl;
422 if(moving() && meshChanged)
424 Info << "MOOOOOOOOOOVING!!!!!!!" << endl;
425 Info << "min V0() post motion = " << min(V0()) << endl;
428 Info << "min V() post-motion = " << min(V()) << endl;
429 Info << "max phi() post-motion = " << max(phi()) << endl;
430 Info << "min phi() post-motion = " << min(phi()) << endl;
433 Info << "Total cylinder volume at CA " << engTime().timeName() << " = " <<
442 pointField oldPointsNew = oldPoints();
443 pointField newPointsNew = points();
445 // Attach the interface
446 Info << "Coupling sliding interfaces" << endl;
449 prepareValveDetach();
453 // Changing topology by hand
454 autoPtr<mapPolyMesh> topoChangeMap3 = topoChanger_.changeMesh();
455 Info << "Sliding interfaces coupled: " << attached() << endl;
457 if (topoChangeMap3->morphing())
459 mSolver.updateMesh(topoChangeMap3());
461 if (topoChangeMap3->hasMotionPoints())
463 // movePoints(topoChangeMap3->preMotionPoints());
467 if(correctPointsMotion_)
469 // correct the motion after attaching the sliding interface
470 pointField mappedOldPointsNew(allPoints().size());
472 mappedOldPointsNew.map(oldPointsNew, topoChangeMap3->pointMap());
473 pointField newPoints = allPoints();
475 movePoints(mappedOldPointsNew);
478 movePoints(newPoints);