Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / twoStrokeEngine / addTwoStrokeEngineModifiers.C
blob57ebaf66de0a980ec31bec22451adcad6d1749d6
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 "twoStrokeEngine.H"
27 #include "slidingInterface.H"
28 #include "layerAdditionRemoval.H"
29 #include "surfaceFields.H"
30 #include "regionSplit.H"
31 #include "pointSet.H"
32 #include "faceSet.H"
33 #include "cellSet.H"
34 #include "SortableList.H"
37 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
39 void Foam::twoStrokeEngine::addZonesAndModifiers()
41     // Add the zones and mesh modifiers to operate piston motion
42     if (faceZones().size() > 0)
43     {
44         Info<< "Time = " << engTime().theta() << endl;
45         Info<< "void twoStrokeEngine::addZonesAndModifiers() : "
46             << "Zones and modifiers already present.  Skipping."
47             << endl;
49         if (topoChanger_.size() == 0)
50         {
51             FatalErrorIn
52             (
53                 "void twoStrokeEngine::addZonesAndModifiers()"
54             )   << "Mesh modifiers not read properly"
55                 << abort(FatalError);
56         }
58         setVirtualPistonPosition();
59         checkAndCalculate();
61         return;
62     }
64     checkAndCalculate();
66     Info<< "Time = " << engTime().theta() << endl
67         << "Adding zones to the engine mesh" << endl;
69     // Zones to add
70     // fz = 4: virtual piston, outSidePort, insidePort, cutFaceZone
71     // pz = 2: piston points, cutPointZone
72     // cz = 1: moving mask
74     label nPorts = scavInCylPatches_.size();
77     List<pointZone*> pz(nPorts + 2);
78     List<faceZone*> fz(3*nPorts + 1);
80     // Added piston cells and head cells
81     List<cellZone*> cz(3);
83     label nPointZones = 0;
84     label nFaceZones = 0;
85     label nCellZones = 0;
87     Info << "Adding piston layer faces" << endl;
89 #   include "addPistonLayer.H"
91     // Add head points that do not move
93     {
94         cellSet headCellSet(*this, headCellsSetName_);
96         cz[nCellZones] =
97             new cellZone
98             (
99                 "headCells",
100                 headCellSet.toc(),
101                 nCellZones,
102                 cellZones()
103             );
105         nCellZones++;
106     }
108     //  Sliding interface for scavenging ports
110     if (nPorts > 0)
111     {
112         forAll(scavInCylPatches_, patchi)
113         {
114             // Inner slider
115             const polyPatch& innerScav =
116                 boundaryMesh()
117                 [
118                     boundaryMesh().findPatchID(scavInCylPatches_[patchi])
119                 ];
121             // Outer slider
122             const polyPatch& outerScav =
123                 boundaryMesh()
124                 [
125                     boundaryMesh().findPatchID(scavInPortPatches_[patchi])
126                 ];
128             // Add zone if both patches has got faces
129             if (!innerScav.empty() && !outerScav.empty())
130             {
131                 // Inner
132                 labelList isf(innerScav.size());
134                 forAll (isf, i)
135                 {
136                     isf[i] = innerScav.start() + i;
137                 }
139                 fz[nFaceZones] = new faceZone
140                 (
141                     scavInCylPatches_[patchi] + "Zone"
142                   + Foam::name(patchi + 1),
143                     isf,
144                     boolList(innerScav.size(), false),
145                     nFaceZones,
146                     faceZones()
147                 );
149                 nFaceZones++;
151                 // Outer
152                 labelList osf(outerScav.size());
154                 forAll (osf, i)
155                 {
156                     osf[i] = outerScav.start() + i;
157                 }
159                 fz[nFaceZones] = new faceZone
160                 (
161                     scavInPortPatches_[patchi] + "Zone"
162                   + Foam::name(patchi + 1),
163                     osf,
164                     boolList(outerScav.size(), false),
165                     nFaceZones,
166                     faceZones()
167                 );
169                 nFaceZones++;
171                 // Cut faces
172                 fz[nFaceZones] = new faceZone
173                 (
174                     "cutFaceZone" + Foam::name(patchi + 1),
175                     labelList(0),
176                     boolList(0, false),
177                     nFaceZones,
178                     faceZones()
179                 );
181                 nFaceZones++;
183                 // Cut points
184                 pz[nPointZones] = new pointZone
185                 (
186                     "cutPointZone" + Foam::name(patchi + 1),
187                     labelList(0),
188                     nPointZones,
189                     pointZones()
190                 );
192                 nPointZones++;
193             }
194         }
195     }
197     Info << "Adding moving cells zone" << endl;
199     {
200         cellSet movingCells(*this, movingCellSetName_);
202         cz[nCellZones] = new cellZone
203         (
204             "movingCells",
205             movingCells.toc(),
206             nCellZones,
207             cellZones()
208         );
210         nCellZones++;
211     }
213     Pout<< "Adding " << nPointZones << " point, "
214         << nFaceZones << " face zones and " << nCellZones
215         << " cell zones" << endl;
217     pz.setSize(nPointZones);
218     fz.setSize(nFaceZones);
219     cz.setSize(nCellZones);
220     addZones(pz, fz, cz);
222     List<polyMeshModifier*> tm(nPorts + 1);
223     label nMods = 0;
225     // Add piston layer addition
227 #   include "addPistonLayerAdditionRemovalMeshModifier.H"
229     if (nPorts > 0)
230     {
231         forAll (scavInPortPatches_, i)
232         {
233             // Check if patches are present on local processor
234             const label sipID =
235                 boundaryMesh().findPatchID(scavInPortPatches_[i]);
237             const label sicID =
238                 boundaryMesh().findPatchID(scavInCylPatches_[i]);
240             if (sipID > -1 && sicID > -1)
241             {
242                 if
243                 (
244                     boundaryMesh()[sipID].size() > 0
245                  && boundaryMesh()[sicID].size() > 0
246                 )
247                 {
248                     Pout<< "Adding slider for pair " << scavInPortPatches_[i]
249                         << " and " << scavInCylPatches_[i]
250                         << " with sizes "
251                         << boundaryMesh()[sipID].size() << " "
252                         << boundaryMesh()[sicID].size() << endl;
254                     // Patches present.  Add modifier
255                     topoChanger_.setSize(topoChanger_.size() + 1);
257                     topoChanger_.set
258                     (
259                         nMods,
260                         new slidingInterface
261                         (
262                             "portCylinderInterface" + Foam::name(i + 1),
263                             nMods,
264                             topoChanger_,
265                             scavInPortPatches_[i] + "Zone" + Foam::name(i + 1),
266                             scavInCylPatches_[i] + "Zone" + Foam::name(i + 1),
267                             "cutPointZone" + Foam::name(i + 1),
268                             "cutFaceZone" + Foam::name(i + 1),
269                             scavInPortPatches_[i],
270                             scavInCylPatches_[i],
271                             slidingInterface::INTEGRAL,
272                             true,                   // Attach-detach action
273                             intersection::VISIBLE   // Projection algorithm
274                         )
275                     );
277                     nMods++;
278                 }
279             }
280         }
281     }
283     Info << "Adding " << nMods << " topology modifiers" << endl;
285     // Calculating the virtual piston position
287     setVirtualPistonPosition();
290     topoChanger_.setSize(nMods);
292     // Write mesh modifiers
293     topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
294     topoChanger_.write();
295     write();
297     Info << "virtualPistonPosition = " << virtualPistonPosition() << endl;
298     Info << "piston position = " << pistonPosition() << endl;
302 // ************************************************************************* //