Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / simpleEngineTopoFvMesh / addSimpleEngineTopoFvMeshModifiers.C
blob07885450f3155cff61253d2de6bb2d2c18d08d46
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
38     if
39     (
40         pointZones().size() > 0
41      || faceZones().size() > 0
42      || cellZones().size() > 0
43     )
44     {
45         Info<< "void Foam::simpleEngineTopoFvMesh::addZonesAndModifiers() : "
46             << "Zones and modifiers already present.  Skipping."
47             << endl;
49         if (topoChanger_.size() == 0)
50         {
51             FatalErrorIn
52             (
53                 "void simpleEngineTopoFvMesh::addZonesAndModifiers()"
54             )   << "Mesh modifiers not read properly"
55                 << abort(FatalError);
56         }
58         return;
59     }
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;
69     label nFaceZones = 0;
71     for (label valveI = 0; valveI < nValves(); valveI++)
72     {
73         // If both sides of the interface exist, add sliding interface
74         // for a valve
75         if
76         (
77             valves_[valveI].curtainInCylinderPatchID().active()
78          && valves_[valveI].curtainInPortPatchID().active()
79         )
80         {
81             Info<< "Adding sliding interface zones for curtain of valve "
82                 << valveI + 1 << endl;
84             pz[nPointZones] =
85                 new pointZone
86                 (
87                     "cutPointsV" + Foam::name(valveI + 1),
88                     labelList(0),
89                     nPointZones,
90                     pointZones()
91                 );
92             nPointZones++;
94             const polyPatch& cylCurtain =
95                 boundaryMesh()
96                     [valves_[valveI].curtainInCylinderPatchID().index()];
98             labelList cylCurtainLabels(cylCurtain.size(), cylCurtain.start());
100             forAll (cylCurtainLabels, i)
101             {
102                 cylCurtainLabels[i] += i;
103             }
105             fz[nFaceZones] =
106                 new faceZone
107                 (
108                     "curtainCylZoneV" + Foam::name(valveI + 1),
109                     cylCurtainLabels,
110                     boolList(cylCurtainLabels.size(), false),
111                     nFaceZones,
112                     faceZones()
113                 );
114             nFaceZones++;
116             const polyPatch& portCurtain =
117                 boundaryMesh()
118                     [valves_[valveI].curtainInPortPatchID().index()];
120             labelList portCurtainLabels
121             (
122                 portCurtain.size(),
123                 portCurtain.start()
124             );
126             forAll (portCurtainLabels, i)
127             {
128                 portCurtainLabels[i] += i;
129             }
131             fz[nFaceZones] =
132                 new faceZone
133                 (
134                     "curtainPortZoneV" + Foam::name(valveI + 1),
135                     portCurtainLabels,
136                     boolList(portCurtainLabels.size(), false),
137                     nFaceZones,
138                     faceZones()
139                 );
140             nFaceZones++;
142             // Add empty zone for cut faces
143             fz[nFaceZones] =
144                 new faceZone
145                 (
146                     "cutFaceZoneV" + Foam::name(valveI + 1),
147                     labelList(0),
148                     boolList(0, false),
149                     nFaceZones,
150                     faceZones()
151                 );
152             nFaceZones++;
154             // Create a detach zone
155             if
156             (
157                 valves_[valveI].detachInCylinderPatchID().active()
158              && valves_[valveI].detachInPortPatchID().active()
159              && valves_[valveI].detachFaces().size() > 0
160             )
161             {
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();
173                 forAll (df, dfI)
174                 {
175                     if (isInternalFace(df[dfI]))
176                     {
177                         if ((areas[df[dfI]] & pistonAxis) > 0)
178                         {
179                             flip[dfI] = true;
180                         }
181                     }
182                     else
183                     {
184                         FatalErrorIn
185                         (
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);
193                     }
194                 }
196                 // Add detach face zone
197                 fz[nFaceZones] =
198                     new faceZone
199                     (
200                         "detachFaceZoneV" + Foam::name(valveI + 1),
201                         df,
202                         flip,
203                         nFaceZones,
204                         faceZones()
205                     );
206                 nFaceZones++;
207             }
208         }
209         else
210         {
211             Info << "No valve curtain for valve " << valveI + 1 << endl;
212         }
214         // Make a zone for layer addition at the top of the valve
215         if (valves_[valveI].poppetPatchID().active())
216         {
217             Info<< "Adding poppet layer addition zone for valve "
218                 << valveI + 1 << endl;
220             const polyPatch& poppetPatch =
221                 boundaryMesh()
222                     [valves_[valveI].poppetPatchID().index()];
224             labelList poppetPatchLabels
225             (
226                 poppetPatch.size(),
227                 poppetPatch.start()
228             );
230             forAll (poppetPatchLabels, i)
231             {
232                 poppetPatchLabels[i] += i;
233             }
235             fz[nFaceZones] =
236                 new faceZone
237                 (
238                     "poppetZoneV" + Foam::name(valveI + 1),
239                     poppetPatchLabels,
240                     boolList(poppetPatchLabels.size(), true),
241                     nFaceZones,
242                     faceZones()
243                 );
244             nFaceZones++;
245         }
246         else
247         {
248             Info << "No poppet layer addition zone for valve "
249                 << valveI + 1 << endl;
250         }
252         if (valves_[valveI].bottomPatchID().active())
253         {
254             Info<< "Adding bottom layer addition zone for valve "
255                 << valveI + 1 << endl;
257             const polyPatch& bottomPatch =
258                 boundaryMesh()
259                     [valves_[valveI].bottomPatchID().index()];
261             labelList bottomPatchLabels
262             (
263                 bottomPatch.size(),
264                 bottomPatch.start()
265             );
267             forAll (bottomPatchLabels, i)
268             {
269                 bottomPatchLabels[i] += i;
270             }
272             fz[nFaceZones] =
273                 new faceZone
274                 (
275                     "bottomZoneV" + Foam::name(valveI + 1),
276                     bottomPatchLabels,
277                     boolList(bottomPatchLabels.size(), true),
278                     nFaceZones,
279                     faceZones()
280                 );
281             nFaceZones++;
282         }
283         else
284         {
285             Info << "No bottom layer addition zone for valve "
286                 << valveI + 1 << endl;
287         }
288     }
290     // Add the piston zone
291     if (piston().patchID().active())
292     {
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)
301         {
302             pistonPatchLabels[i] += i;
303         }
305         fz[nFaceZones] =
306             new faceZone
307             (
308                 "pistonZone",
309                 pistonPatchLabels,
310                 boolList(pistonPatchLabels.size(), true),
311                 nFaceZones,
312                 faceZones()
313             );
314         nFaceZones++;
315     }
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);
325     label nMods = 0;
327     for (label valveI = 0; valveI < nValves(); valveI++)
328     {
329         // Add valve curtain sliding interface
330         if
331         (
332             valves_[valveI].curtainInCylinderPatchID().active()
333          && valves_[valveI].curtainInPortPatchID().active()
334         )
335         {
336             topoChanger_.set
337             (
338                 nMods,
339                 new slidingInterface
340                 (
341                     "valveSlider" + Foam::name(valveI + 1),
342                     nMods,
343                     topoChanger_,
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
353                 )
354             );
355             nMods++;
356         }
358         // Add attach-detach for valve
359         if
360         (
361             valves_[valveI].detachInCylinderPatchID().active()
362          && valves_[valveI].detachInPortPatchID().active()
363          && valves_[valveI].detachFaces().size() > 0
364         )
365         {
366             topoChanger_.set
367             (
368                 nMods,
369                 new attachDetach
370                 (
371                     "valveAttachDetach" + Foam::name(valveI + 1),
372                     nMods,
373                     topoChanger_,
374                     "detachFaceZoneV" + Foam::name(valveI + 1),
375                     valves_[valveI].detachInCylinderPatchID().name(),
376                     valves_[valveI].detachInPortPatchID().name(),
377                     scalarField(0),
378                     true                // Manual triggering
379                 )
380             );
381             nMods++;
382         }
383         // Add valve poppet layer addition
384         if (valves_[valveI].poppetPatchID().active())
385         {
386             topoChanger_.set
387             (
388                 nMods,
389                 new layerAdditionRemoval
390                 (
391                     "valvePoppetLayer" + Foam::name(valveI + 1),
392                     nMods,
393                     topoChanger_,
394                     "poppetZoneV" + Foam::name(valveI + 1),
395                     valves_[valveI].minTopLayer(),
396                     valves_[valveI].maxTopLayer()
397                 )
398             );
399             nMods++;
400         }
402         // Add valve bottom layer addition
403         if (valves_[valveI].bottomPatchID().active())
404         {
405             topoChanger_.set
406             (
407                 nMods,
408                 new layerAdditionRemoval
409                 (
410                     "valveBottomLayer" + Foam::name(valveI + 1),
411                     nMods,
412                     topoChanger_,
413                     "bottomZoneV" + Foam::name(valveI + 1),
414                     valves_[valveI].minBottomLayer(),
415                     valves_[valveI].maxBottomLayer()
416                 )
417             );
418             nMods++;
419         }
420     }
422     // Add piston layer addition
423     if (piston().patchID().active())
424     {
425         topoChanger_.set
426         (
427             nMods,
428             new layerAdditionRemoval
429             (
430                 "pistonLayer",
431                 nMods,
432                 topoChanger_,
433                 "pistonZone",
434                 piston().minLayer(),
435                 piston().maxLayer()
436             )
437         );
438         nMods++;
439     }
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();
447     write();
451 // ************************************************************************* //