00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include "argList.H"
00049 #include "Time.H"
00050 #include "syncTools.H"
00051 #include "faceSet.H"
00052 #include "pointSet.H"
00053 #include "meshTools.H"
00054 #include "polyTopoChange.H"
00055 #include "polyRemoveFace.H"
00056 #include "polyModifyFace.H"
00057 #include "indirectPrimitivePatch.H"
00058 #include "processorPolyPatch.H"
00059 #include "localPointRegion.H"
00060 #include "duplicatePoints.H"
00061 #include "ReadFields.H"
00062 #include "volFields.H"
00063 #include "surfaceFields.H"
00064
00065 using namespace Foam;
00066
00067
00068
00069 void insertDuplicateMerge
00070 (
00071 const polyMesh& mesh,
00072 const labelList& duplicates,
00073 polyTopoChange& meshMod
00074 )
00075 {
00076 const faceList& faces = mesh.faces();
00077 const labelList& faceOwner = mesh.faceOwner();
00078 const faceZoneMesh& faceZones = mesh.faceZones();
00079
00080 forAll(duplicates, bFaceI)
00081 {
00082 label otherFaceI = duplicates[bFaceI];
00083
00084 if (otherFaceI != -1 && otherFaceI > bFaceI)
00085 {
00086
00087
00088 label face0 = mesh.nInternalFaces() + bFaceI;
00089 label face1 = mesh.nInternalFaces() + otherFaceI;
00090
00091 label own0 = faceOwner[face0];
00092 label own1 = faceOwner[face1];
00093
00094 if (own0 < own1)
00095 {
00096
00097 label zoneID = faceZones.whichZone(face0);
00098 bool zoneFlip = false;
00099
00100 if (zoneID >= 0)
00101 {
00102 const faceZone& fZone = faceZones[zoneID];
00103 zoneFlip = fZone.flipMap()[fZone.whichFace(face0)];
00104 }
00105
00106 meshMod.setAction(polyRemoveFace(face1));
00107 meshMod.setAction
00108 (
00109 polyModifyFace
00110 (
00111 faces[face0],
00112 face0,
00113 own0,
00114 own1,
00115 false,
00116 -1,
00117 false,
00118 zoneID,
00119 zoneFlip
00120 )
00121 );
00122 }
00123 else
00124 {
00125
00126 label zoneID = faceZones.whichZone(face1);
00127 bool zoneFlip = false;
00128
00129 if (zoneID >= 0)
00130 {
00131 const faceZone& fZone = faceZones[zoneID];
00132 zoneFlip = fZone.flipMap()[fZone.whichFace(face1)];
00133 }
00134
00135 meshMod.setAction(polyRemoveFace(face0));
00136 meshMod.setAction
00137 (
00138 polyModifyFace
00139 (
00140 faces[face1],
00141 face1,
00142 own1,
00143 own0,
00144 false,
00145 -1,
00146 false,
00147 zoneID,
00148 zoneFlip
00149 )
00150 );
00151 }
00152 }
00153 }
00154 }
00155
00156
00157 labelList findBaffles(const polyMesh& mesh, const labelList& boundaryFaces)
00158 {
00159
00160 labelList duplicates = localPointRegion::findDuplicateFaces
00161 (
00162 mesh,
00163 boundaryFaces
00164 );
00165
00166
00167
00168 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00169
00170 forAll(duplicates, bFaceI)
00171 {
00172 if (duplicates[bFaceI] != -1)
00173 {
00174 label faceI = mesh.nInternalFaces() + bFaceI;
00175 label patchI = patches.whichPatch(faceI);
00176
00177 if (isA<processorPolyPatch>(patches[patchI]))
00178 {
00179 FatalErrorIn("findBaffles(const polyMesh&, const labelList&)")
00180 << "Duplicate face " << faceI
00181 << " is on a processorPolyPatch."
00182 << "This is not allowed." << nl
00183 << "Face:" << faceI
00184 << " is on patch:" << patches[patchI].name()
00185 << abort(FatalError);
00186 }
00187 }
00188 }
00189
00190
00191
00192 {
00193 faceSet duplicateSet
00194 (
00195 mesh,
00196 "duplicateFaces",
00197 (mesh.nFaces() - mesh.nInternalFaces())/256
00198 );
00199
00200 forAll(duplicates, bFaceI)
00201 {
00202 label otherFaceI = duplicates[bFaceI];
00203
00204 if (otherFaceI != -1 && otherFaceI > bFaceI)
00205 {
00206 duplicateSet.insert(mesh.nInternalFaces() + bFaceI);
00207 duplicateSet.insert(mesh.nInternalFaces() + otherFaceI);
00208 }
00209 }
00210
00211 Pout<< "Writing " << duplicateSet.size()
00212 << " duplicate faces to faceSet " << duplicateSet.objectPath()
00213 << nl << endl;
00214 duplicateSet.write();
00215 }
00216
00217 return duplicates;
00218 }
00219
00220
00221
00222
00223 int main(int argc, char *argv[])
00224 {
00225 argList::validOptions.insert("split", "");
00226 argList::validOptions.insert("overwrite", "");
00227 argList::validOptions.insert("detectOnly", "");
00228 # include "setRootCase.H"
00229 # include "createTime.H"
00230 runTime.functionObjects().off();
00231 # include "createMesh.H"
00232 const word oldInstance = mesh.pointsInstance();
00233
00234 bool split = args.optionFound("split");
00235 bool overwrite = args.optionFound("overwrite");
00236 bool detectOnly = args.optionFound("detectOnly");
00237
00238
00239 labelList boundaryFaces(mesh.nFaces() - mesh.nInternalFaces());
00240
00241 forAll(boundaryFaces, i)
00242 {
00243 boundaryFaces[i] = i+mesh.nInternalFaces();
00244 }
00245
00246
00247 if (detectOnly)
00248 {
00249 findBaffles(mesh, boundaryFaces);
00250
00251 return 0;
00252 }
00253
00254
00255
00256
00257 IOobjectList objects(mesh, runTime.timeName());
00258
00259
00260
00261 PtrList<volScalarField> vsFlds;
00262 ReadFields(mesh, objects, vsFlds);
00263
00264 PtrList<volVectorField> vvFlds;
00265 ReadFields(mesh, objects, vvFlds);
00266
00267 PtrList<volSphericalTensorField> vstFlds;
00268 ReadFields(mesh, objects, vstFlds);
00269
00270 PtrList<volSymmTensorField> vsymtFlds;
00271 ReadFields(mesh, objects, vsymtFlds);
00272
00273 PtrList<volTensorField> vtFlds;
00274 ReadFields(mesh, objects, vtFlds);
00275
00276
00277
00278 PtrList<surfaceScalarField> ssFlds;
00279 ReadFields(mesh, objects, ssFlds);
00280
00281 PtrList<surfaceVectorField> svFlds;
00282 ReadFields(mesh, objects, svFlds);
00283
00284 PtrList<surfaceSphericalTensorField> sstFlds;
00285 ReadFields(mesh, objects, sstFlds);
00286
00287 PtrList<surfaceSymmTensorField> ssymtFlds;
00288 ReadFields(mesh, objects, ssymtFlds);
00289
00290 PtrList<surfaceTensorField> stFlds;
00291 ReadFields(mesh, objects, stFlds);
00292
00293
00294
00295 polyTopoChange meshMod(mesh);
00296
00297
00298 if (split)
00299 {
00300 Pout<< "Topologically splitting duplicate surfaces"
00301 << ", i.e. duplicating points internal to duplicate surfaces."
00302 << nl << endl;
00303
00304
00305 localPointRegion regionSide(mesh);
00306
00307
00308 duplicatePoints pointDuplicator(mesh);
00309
00310
00311 pointDuplicator.setRefinement(regionSide, meshMod);
00312 }
00313 else
00314 {
00315 Pout<< "Merging duplicate faces."
00316 << nl << endl;
00317
00318
00319 labelList duplicates(findBaffles(mesh, boundaryFaces));
00320
00321
00322 insertDuplicateMerge(mesh, duplicates, meshMod);
00323 }
00324
00325 if (!overwrite)
00326 {
00327 runTime++;
00328 }
00329
00330
00331 autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
00332
00333
00334 mesh.updateMesh(map);
00335
00336
00337 if (map().hasMotionPoints())
00338 {
00339 mesh.movePoints(map().preMotionPoints());
00340 }
00341
00342 if (overwrite)
00343 {
00344 mesh.setInstance(oldInstance);
00345 }
00346 Pout<< "Writing mesh to time " << runTime.timeName() << endl;
00347 mesh.write();
00348
00349
00350 if (split)
00351 {
00352 const labelList& pointMap = map().pointMap();
00353
00354 labelList nDupPerPoint(map().nOldPoints(), 0);
00355
00356 pointSet dupPoints(mesh, "duplicatedPoints", 100);
00357
00358 forAll(pointMap, pointI)
00359 {
00360 label oldPointI = pointMap[pointI];
00361
00362 nDupPerPoint[oldPointI]++;
00363
00364 if (nDupPerPoint[oldPointI] > 1)
00365 {
00366 dupPoints.insert(map().reversePointMap()[oldPointI]);
00367 dupPoints.insert(pointI);
00368 }
00369 }
00370
00371 Pout<< "Writing " << dupPoints.size()
00372 << " duplicated points to pointSet "
00373 << dupPoints.objectPath() << nl << endl;
00374
00375 dupPoints.write();
00376 }
00377
00378 Info<< "End\n" << endl;
00379
00380 return 0;
00381 }
00382
00383
00384