1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | 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 "simpleEngineTopoFvMesh.H"
27 #include "slidingInterface.H"
28 #include "layerAdditionRemoval.H"
29 #include "attachDetach.H"
30 #include "surfaceFields.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 void Foam::simpleEngineTopoFvMesh::addZonesAndModifiers()
36 // Add the zones and mesh modifiers to operate piston and valve motion
40 pointZones().size() > 0
41 || faceZones().size() > 0
42 || cellZones().size() > 0
45 Info<< "void Foam::simpleEngineTopoFvMesh::addZonesAndModifiers() : "
46 << "Zones and modifiers already present. Skipping."
49 if (topoChanger_.size() == 0)
53 "void simpleEngineTopoFvMesh::addZonesAndModifiers()"
54 ) << "Mesh modifiers not read properly"
61 Info<< "Time = " << engineTime_.theta() << endl
62 << "Adding zones to the engine mesh" << endl;
64 List<pointZone*> pz(nValves());
65 List<faceZone*> fz(6*nValves() + 1);
66 List<cellZone*> cz(0);
68 label nPointZones = 0;
71 for (label valveI = 0; valveI < nValves(); valveI++)
73 // If both sides of the interface exist, add sliding interface
77 valves_[valveI].curtainInCylinderPatchID().active()
78 && valves_[valveI].curtainInPortPatchID().active()
81 Info<< "Adding sliding interface zones for curtain of valve "
82 << valveI + 1 << endl;
87 "cutPointsV" + Foam::name(valveI + 1),
94 const polyPatch& cylCurtain =
96 [valves_[valveI].curtainInCylinderPatchID().index()];
98 labelList cylCurtainLabels(cylCurtain.size(), cylCurtain.start());
100 forAll (cylCurtainLabels, i)
102 cylCurtainLabels[i] += i;
108 "curtainCylZoneV" + Foam::name(valveI + 1),
110 boolList(cylCurtainLabels.size(), false),
116 const polyPatch& portCurtain =
118 [valves_[valveI].curtainInPortPatchID().index()];
120 labelList portCurtainLabels
126 forAll (portCurtainLabels, i)
128 portCurtainLabels[i] += i;
134 "curtainPortZoneV" + Foam::name(valveI + 1),
136 boolList(portCurtainLabels.size(), false),
142 // Add empty zone for cut faces
146 "cutFaceZoneV" + Foam::name(valveI + 1),
154 // Create a detach zone
157 valves_[valveI].detachInCylinderPatchID().active()
158 && valves_[valveI].detachInPortPatchID().active()
159 && valves_[valveI].detachFaces().size() > 0
162 Info<< "Adding detach boundary for valve "
163 << valveI + 1 << endl;
165 const vectorField& areas = Sf().internalField();
167 const labelList& df = valves_[valveI].detachFaces();
169 boolList flip(df.size(), false);
171 const vector& pistonAxis = piston().cs().axis();
175 if (isInternalFace(df[dfI]))
177 if ((areas[df[dfI]] & pistonAxis) > 0)
186 "void simpleEngineTopoFvMesh::"
187 "addZonesAndModifiers()"
188 ) << "found boundary face in valve detach definition"
189 << " for valve " << valveI + 1
190 << ". This is not allowed. Detach faces: "
191 << df << " nInternalFaces: " << nInternalFaces()
192 << abort(FatalError);
196 // Add detach face zone
200 "detachFaceZoneV" + Foam::name(valveI + 1),
211 Info << "No valve curtain for valve " << valveI + 1 << endl;
214 // Make a zone for layer addition at the top of the valve
215 if (valves_[valveI].poppetPatchID().active())
217 Info<< "Adding poppet layer addition zone for valve "
218 << valveI + 1 << endl;
220 const polyPatch& poppetPatch =
222 [valves_[valveI].poppetPatchID().index()];
224 labelList poppetPatchLabels
230 forAll (poppetPatchLabels, i)
232 poppetPatchLabels[i] += i;
238 "poppetZoneV" + Foam::name(valveI + 1),
240 boolList(poppetPatchLabels.size(), true),
248 Info << "No poppet layer addition zone for valve "
249 << valveI + 1 << endl;
252 if (valves_[valveI].bottomPatchID().active())
254 Info<< "Adding bottom layer addition zone for valve "
255 << valveI + 1 << endl;
257 const polyPatch& bottomPatch =
259 [valves_[valveI].bottomPatchID().index()];
261 labelList bottomPatchLabels
267 forAll (bottomPatchLabels, i)
269 bottomPatchLabels[i] += i;
275 "bottomZoneV" + Foam::name(valveI + 1),
277 boolList(bottomPatchLabels.size(), true),
285 Info << "No bottom layer addition zone for valve "
286 << valveI + 1 << endl;
290 // Add the piston zone
291 if (piston().patchID().active())
293 Info << "Adding layer addition zone for piston" << endl;
295 const polyPatch& pistonPatch =
296 boundaryMesh()[piston().patchID().index()];
298 labelList pistonPatchLabels(pistonPatch.size(), pistonPatch.start());
300 forAll (pistonPatchLabels, i)
302 pistonPatchLabels[i] += i;
310 boolList(pistonPatchLabels.size(), true),
317 Info<< "Adding " << nPointZones << " point and "
318 << nFaceZones << " face zones" << endl;
320 pz.setSize(nPointZones);
321 fz.setSize(nFaceZones);
322 addZones(pz, fz, cz);
324 topoChanger_.setSize(4*nValves() + 1);
327 for (label valveI = 0; valveI < nValves(); valveI++)
329 // Add valve curtain sliding interface
332 valves_[valveI].curtainInCylinderPatchID().active()
333 && valves_[valveI].curtainInPortPatchID().active()
341 "valveSlider" + Foam::name(valveI + 1),
344 "curtainPortZoneV" + Foam::name(valveI + 1),
345 "curtainCylZoneV" + Foam::name(valveI + 1),
346 "cutPointsV" + Foam::name(valveI + 1),
347 "cutFaceZoneV" + Foam::name(valveI + 1),
348 valves_[valveI].curtainInPortPatchID().name(),
349 valves_[valveI].curtainInCylinderPatchID().name(),
350 slidingInterface::INTEGRAL, // always integral
351 true, // attach-detach action
352 intersection::VISIBLE
358 // Add attach-detach for valve
361 valves_[valveI].detachInCylinderPatchID().active()
362 && valves_[valveI].detachInPortPatchID().active()
363 && valves_[valveI].detachFaces().size() > 0
371 "valveAttachDetach" + Foam::name(valveI + 1),
374 "detachFaceZoneV" + Foam::name(valveI + 1),
375 valves_[valveI].detachInCylinderPatchID().name(),
376 valves_[valveI].detachInPortPatchID().name(),
378 true // Manual triggering
383 // Add valve poppet layer addition
384 if (valves_[valveI].poppetPatchID().active())
389 new layerAdditionRemoval
391 "valvePoppetLayer" + Foam::name(valveI + 1),
394 "poppetZoneV" + Foam::name(valveI + 1),
395 valves_[valveI].minTopLayer(),
396 valves_[valveI].maxTopLayer()
402 // Add valve bottom layer addition
403 if (valves_[valveI].bottomPatchID().active())
408 new layerAdditionRemoval
410 "valveBottomLayer" + Foam::name(valveI + 1),
413 "bottomZoneV" + Foam::name(valveI + 1),
414 valves_[valveI].minBottomLayer(),
415 valves_[valveI].maxBottomLayer()
422 // Add piston layer addition
423 if (piston().patchID().active())
428 new layerAdditionRemoval
441 Info << "Adding " << nMods << " topology modifiers" << endl;
442 topoChanger_.setSize(nMods);
444 // Write mesh and modifiers
445 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
446 topoChanger_.write();
451 // ************************************************************************* //