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 "accordionEngineMesh.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"
41 #include "symmetryTetPolyPatch.H"
45 #include "symmetryFvPatch.H"
46 #include "wedgeFvPatch.H"
47 #include "emptyFvPatch.H"
48 #include "zeroGradientTetPolyPatchFields.H"
49 #include "tetDecompositionMotionSolver.H"
51 #include "fixedValueTetPolyPatchFields.H"
52 #include "mixedTetPolyPatchFields.H"
53 #include "slipTetPolyPatchFields.H"
54 #include "zeroGradientTetPolyPatchFields.H"
58 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59 void Foam::accordionEngineMesh::makeLayersLive()
62 forAll (topoChanger_, modI)
64 if (isA<layerAdditionRemoval>(topoChanger_[modI]))
66 topoChanger_[modI].enable();
68 else if (isA<slidingInterface>(topoChanger_[modI]))
70 topoChanger_[modI].disable();
72 else if (isA<attachDetach>(topoChanger_[modI]))
74 topoChanger_[modI].enable();
78 FatalErrorIn("void Foam::engineTopoFvMesh::makeLayersLive()")
79 << "Don't know what to do with mesh modifier "
80 << modI << " of type " << topoChanger_[modI].type()
86 void Foam::accordionEngineMesh::makeDetachLive()
88 // Enable sliding interface
89 forAll (topoChanger_, modI)
91 if (isA<attachDetach>(topoChanger_[modI]))
93 topoChanger_[modI].enable();
97 FatalErrorIn("void Foam::accordionEngineMesh::makeDetachLive()")
98 << "Don't know what to do with mesh modifier "
99 << modI << " of type " << topoChanger_[modI].type()
100 << abort(FatalError);
106 void Foam::accordionEngineMesh::valveDetach()
108 // Enable sliding interface
109 forAll (topoChanger_, modI)
111 if (isA<attachDetach>(topoChanger_[modI]))
113 const attachDetach& ad =
114 refCast<const attachDetach>(topoChanger_[modI]);
116 const word masterName = ad.masterPatchID().name();
118 // Find the valve with that name
119 label valveIndex = -1;
121 forAll (valves_, valveI)
125 valves_[valveI].detachInCylinderPatchID().name()
138 "void Foam::engineTopoFvMesh::prepareValveDetach()"
139 ) << "Cannot match patch for attach/detach " << modI
140 << abort(FatalError);
145 Info<< " valveI: " << valveIndex << " attached: "
147 << " valve open: " << valves_[valveIndex].isOpen()
156 void Foam::accordionEngineMesh::valveAttach()
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()
207 void Foam::accordionEngineMesh::prepareValveDetach()
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()
252 if (valves_[valveIndex].isOpen())
265 bool Foam::accordionEngineMesh::update()
267 tetDecompositionMotionSolver& mSolver =
268 refCast<tetDecompositionMotionSolver>(msPtr_());
270 tetPointVectorField& motionU = mSolver.motionU();
272 Info << "motioU.size() = " << motionU.internalField().size() << endl;
274 scalar deltaZ = engTime().pistonDisplacement().value();
276 // deltaZ set to zero, FIXED PISTON POSITION
279 virtualPistonPosition() += deltaZ;
285 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
287 if (topoChangeMap->morphing())
289 mSolver.updateMesh(topoChangeMap());
290 Info << "mSolver.updateMesh(topoChangeMap())" << endl;
292 if (topoChangeMap->hasMotionPoints())
294 movePoints(topoChangeMap->preMotionPoints());
300 pointField newPoints = points();
303 # include "setValveMotionBoundaryConditionAccordionEngineMesh.H"
304 # include "setPistonMotionBoundaryConditionAccordionEngineMesh.H"
307 DynamicList<label> constrainedPoints(mSolver.curPoints()().size()/100);
308 DynamicList<vector> constrainedVelocity
310 mSolver.curPoints()().size()/100
313 # include "setAccordionEngineMeshConstraints.H"
316 labelList constrainedPointsList(constrainedPoints.shrink());
317 vectorField constrainedVelocityField(constrainedVelocity.shrink());
319 forAll (constrainedPointsList, i)
321 mSolver.setConstraint
323 constrainedPointsList[i],
324 constrainedVelocityField[i]
330 //set to zero the motion U along the x and y directions
332 newPoints = mSolver.curPoints();
333 movePoints(newPoints);
334 setVirtualPositions();
335 mSolver.clearConstraints();
338 // pointField oldPointsNew = oldPoints();
339 pointField oldPointsNew = oldAllPoints();
340 newPoints = points();
342 Info << "max mesh phi before = " << max((phi())) << endl;
343 Info << "min mesh phi before = " << min((phi())) << endl;
346 prepareValveDetach();
348 autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
350 if (topoChangeMap1->morphing())
352 mSolver.updateMesh(topoChangeMap1());
354 if (topoChangeMap1->hasMotionPoints())
356 // movePoints(topoChangeMap1->preMotionPoints());
360 // correct the motion after attaching the sliding interface
361 pointField mappedOldPointsNew(allPoints().size());
363 mappedOldPointsNew.map(oldPointsNew, topoChangeMap1->pointMap());
364 pointField newPoints = allPoints();
366 movePoints(mappedOldPointsNew);
369 movePoints(newPoints);
374 Info << "max mesh phi after = " << max((phi())) << endl;
375 Info << "min mesh phi after = " << min((phi())) << endl;
377 /* if(correctPointsMotion_)
379 // correct the motion after attaching the sliding interface
380 pointField mappedOldPointsNew(allPoints().size());
382 mappedOldPointsNew.map(oldPointsNew, topoChangeMap3->pointMap());
383 pointField newPoints = allPoints();
385 movePoints(mappedOldPointsNew);
388 movePoints(newPoints);
391 // Info << motionU << endl;
395 Info << "meshChanged1" << endl;
397 mSolver.updateMesh(topoChangeMap1());
400 pointField mappedOldPointsNew(allPoints().size());
402 mappedOldPointsNew.map(oldPointsNew, topoChangeMap1->pointMap());
403 pointField newPoints = allPoints();
405 movePoints(mappedOldPointsNew);
408 movePoints(newPoints);
412 Info<< "Total cylinder volume at CA " << engTime().timeName() << " = "