Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / mesh / generation / blockMesh / mergePatchPairsOld.H
blob675835e843d76b4f40fe20afcbfcb30aa605aff8
2     // Read in a list of dictionaries for the merge patch pairs
3     if (meshDict.found("mergePatchPairs"))
4     {
5         List<Pair<word> > mergePatchPairs
6         (
7             meshDict.lookup("mergePatchPairs")
8         );
10         if (mergePatchPairs.size() > 0)
11         {
12             // Create and add point and face zones and mesh modifiers
13             List<pointZone*> pz(mergePatchPairs.size());
14             List<faceZone*> fz(3*mergePatchPairs.size());
15             List<cellZone*> cz(0);
17             forAll (mergePatchPairs, pairI)
18             {
19                 const word mergeName
20                 (
21                     mergePatchPairs[pairI].first()
22                   + mergePatchPairs[pairI].second()
23                   + name(pairI)
24                 );
26                 pz[pairI] = new pointZone
27                 (
28                     mergeName + "CutPointZone",
29                     labelList(0),
30                     0,
31                     mesh.pointZones()
32                 );
34                 // Master patch
35                 const word masterPatchName(mergePatchPairs[pairI].first());
36                 const polyPatch& masterPatch =
37                     mesh.boundaryMesh()
38                     [
39                         mesh.boundaryMesh().findPatchID(masterPatchName)
40                     ];
42                 labelList isf(masterPatch.size());
44                 forAll (isf, i)
45                 {
46                     isf[i] = masterPatch.start() + i;
47                 }
49                 fz[3*pairI] = new faceZone
50                 (
51                     mergeName + "MasterZone",
52                     isf,
53                     boolList(masterPatch.size(), false),
54                     0,
55                     mesh.faceZones()
56                 );
58                 // Slave patch
59                 const word slavePatchName(mergePatchPairs[pairI].second());
60                 const polyPatch& slavePatch =
61                     mesh.boundaryMesh()
62                     [
63                         mesh.boundaryMesh().findPatchID(slavePatchName)
64                     ];
66                 labelList osf(slavePatch.size());
68                 forAll (osf, i)
69                 {
70                     osf[i] = slavePatch.start() + i;
71                 }
73                 fz[3*pairI + 1] = new faceZone
74                 (
75                     mergeName + "SlaveZone",
76                     osf,
77                     boolList(slavePatch.size(), false),
78                     1,
79                     mesh.faceZones()
80                 );
82                 // Add empty zone for cut faces
83                 fz[3*pairI + 2] = new faceZone
84                 (
85                     mergeName + "CutFaceZone",
86                     labelList(0),
87                     boolList(0, false),
88                     2,
89                     mesh.faceZones()
90                 );
91             }  // end of all merge pairs
93             Info << "Adding point and face zones" << endl;
94             mesh.addZones(pz, fz, cz);
97             Info << "Creating topo change" << endl;
98             polyTopoChanger attacher(mesh);
99             attacher.setSize(mergePatchPairs.size());
101             forAll (mergePatchPairs, pairI)
102             {
103                 const word mergeName
104                 (
105                     mergePatchPairs[pairI].first()
106                   + mergePatchPairs[pairI].second()
107                   + name(pairI)
108                 );
110                 // Add the sliding interface mesh modifier
111                 attacher.set
112                 (
113                     pairI,
114                     new slidingInterface
115                     (
116                         "couple" + name(pairI),
117                         pairI,
118                         attacher,
119                         mergeName + "MasterZone",
120                         mergeName + "SlaveZone",
121                         mergeName + "CutPointZone",
122                         mergeName + "CutFaceZone",
123                         mergePatchPairs[pairI].first(),
124                         mergePatchPairs[pairI].second(),
125                         slidingInterface::INTEGRAL, // always integral
126                         intersection::VISIBLE
127                     )
128                 );
129             }
131             attacher.changeMesh();
133             // Clean the mesh after attach
134             labelList patchSizes(mesh.boundaryMesh().size());
135             labelList patchStarts(mesh.boundaryMesh().size());
137             forAll (mesh.boundaryMesh(), patchI)
138             {
139                 patchSizes[patchI] = mesh.boundaryMesh()[patchI].size();
140                 patchStarts[patchI] = mesh.boundaryMesh()[patchI].start();
141             }
143             mesh.resetPrimitives
144             (
145                 xferCopy<pointField>(mesh.points()),
146                 xferCopy<faceList>(mesh.faces()),
147                 xferCopy<labelList>(mesh.faceOwner()),
148                 xferCopy<labelList>(mesh.faceNeighbour()),
149                 patchSizes,
150                 patchStarts
151             );
153             mesh.setInstance(runTime.constant());
154             mesh.removeZones();
155         }
156     }
157     else
158     {
159         Info<< nl << "There are no merge patch pairs" << endl;
160     }
163     // Set any cellZones (note: cell labelling unaffected by above
164     // mergePatchPairs)
166     label nZones = blocks.numZonedBlocks();
168     if (nZones > 0)
169     {
170         Info<< nl << "Adding cell zones" << endl;
172         // Map from zoneName to cellZone index
173         HashTable<label> zoneMap(nZones);
175         // Cells per zone.
176         List<DynamicList<label> > zoneCells(nZones);
178         // Running cell counter
179         label cellI = 0;
181         // Largest zone so far
182         label freeZoneI = 0;
184         forAll(blocks, blockI)
185         {
186             const block& b = blocks[blockI];
187             const labelListList& blockCells = b.cells();
188             const word& zoneName = b.blockDef().zoneName();
190             if (zoneName.size())
191             {
192                 HashTable<label>::const_iterator iter = zoneMap.find(zoneName);
194                 label zoneI;
196                 if (iter == zoneMap.end())
197                 {
198                     zoneI = freeZoneI++;
200                     Info<< "    " << zoneI << '\t' << zoneName << endl;
202                     zoneMap.insert(zoneName, zoneI);
203                 }
204                 else
205                 {
206                     zoneI = iter();
207                 }
209                 forAll(blockCells, i)
210                 {
211                     zoneCells[zoneI].append(cellI++);
212                 }
213             }
214             else
215             {
216                 cellI += b.cells().size();
217             }
218         }
221         List<cellZone*> cz(zoneMap.size());
223         Info<< nl << "Writing cell zones as cellSets" << endl;
225         forAllConstIter(HashTable<label>, zoneMap, iter)
226         {
227             label zoneI = iter();
229             cz[zoneI]= new cellZone
230             (
231                 iter.key(),
232                 zoneCells[zoneI].shrink(),
233                 zoneI,
234                 mesh.cellZones()
235             );
237             // Write as cellSet for ease of processing
238             cellSet cset
239             (
240                 mesh,
241                 iter.key(),
242                 labelHashSet(zoneCells[zoneI].shrink())
243             );
244             cset.write();
245         }
247         mesh.pointZones().setSize(0);
248         mesh.faceZones().setSize(0);
249         mesh.cellZones().setSize(0);
250         mesh.addZones(List<pointZone*>(0), List<faceZone*>(0), cz);
251     }
253     // Set the precision of the points data to 10
254     IOstream::defaultPrecision(10);
256     Info << nl << "Writing polyMesh" << endl;
257     mesh.removeFiles();
258     if (!mesh.write())
259     {
260         FatalErrorIn(args.executable())
261             << "Failed writing polyMesh."
262             << exit(FatalError);
263     }
265     Info<< nl << "End" << endl;
267     return 0;
271 // ************************************************************************* //