diff --git a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C b/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C index 49530149ca..334b481dce 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C +++ b/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C @@ -672,7 +672,7 @@ void addCouplingPatches patchDict.add("sampleRegion", sampleRegionName); label nOldPatches = newPatches.size(); - forAll(zoneNames, zoneI) + forAll(zoneNames, zonei) { const word patchNamePrefix = regionName + "_to_" + sampleRegionName + '_'; @@ -681,33 +681,33 @@ void addCouplingPatches word bottomPatchName, bottomSamplePatchName; word topPatchName, topSamplePatchName; - if (zoneIsInternal[zoneI]) + if (zoneIsInternal[zonei]) { - bottomPatchName = patchNamePrefix + zoneNames[zoneI] + "_bottom"; + bottomPatchName = patchNamePrefix + zoneNames[zonei] + "_bottom"; bottomSamplePatchName = - samplePatchNamePrefix + zoneNames[zoneI] + "_bottom"; - topPatchName = patchNamePrefix + zoneNames[zoneI] + "_top"; + samplePatchNamePrefix + zoneNames[zonei] + "_bottom"; + topPatchName = patchNamePrefix + zoneNames[zonei] + "_top"; topSamplePatchName = - samplePatchNamePrefix + zoneNames[zoneI] + "_top"; + samplePatchNamePrefix + zoneNames[zonei] + "_top"; } - else if (!zoneShadowNames.empty()) + else if (!zoneShadowNames[zonei].empty()) { - bottomPatchName = patchNamePrefix + zoneNames[zoneI]; - bottomSamplePatchName = samplePatchNamePrefix + zoneNames[zoneI]; - topPatchName = patchNamePrefix + zoneShadowNames[zoneI]; - topSamplePatchName = samplePatchNamePrefix + zoneShadowNames[zoneI]; + bottomPatchName = patchNamePrefix + zoneNames[zonei]; + bottomSamplePatchName = samplePatchNamePrefix + zoneNames[zonei]; + topPatchName = patchNamePrefix + zoneShadowNames[zonei]; + topSamplePatchName = samplePatchNamePrefix + zoneShadowNames[zonei]; } else { - bottomPatchName = patchNamePrefix + zoneNames[zoneI]; - bottomSamplePatchName = samplePatchNamePrefix + zoneNames[zoneI]; - topPatchName = zoneNames[zoneI] + "_top"; + bottomPatchName = patchNamePrefix + zoneNames[zonei]; + bottomSamplePatchName = samplePatchNamePrefix + zoneNames[zonei]; + topPatchName = zoneNames[zonei] + "_top"; } dictionary bottomPatchDict(patchDict); bottomPatchDict.add("samplePatch", bottomSamplePatchName); - zoneBottomPatch[zoneI] = + zoneBottomPatch[zonei] = addPatch ( mesh.boundaryMesh(), @@ -716,12 +716,12 @@ void addCouplingPatches newPatches ); - Pout<< zoneBottomPatch[zoneI] - << '\t' << newPatches[zoneBottomPatch[zoneI]]->name() - << '\t' << newPatches[zoneBottomPatch[zoneI]]->type() + Pout<< zoneBottomPatch[zonei] + << '\t' << newPatches[zoneBottomPatch[zonei]]->name() + << '\t' << newPatches[zoneBottomPatch[zonei]]->type() << nl; - if (zoneIsInternal[zoneI] || !zoneShadowNames.empty()) + if (zoneIsInternal[zonei] || !zoneShadowNames[zonei].empty()) { dictionary topPatchDict(patchDict); topPatchDict.add("samplePatch", topSamplePatchName); @@ -730,7 +730,7 @@ void addCouplingPatches topPatchDict.add("bottomPatch", bottomPatchName); } - zoneTopPatch[zoneI] = + zoneTopPatch[zonei] = addPatch ( mesh.boundaryMesh(), @@ -741,7 +741,7 @@ void addCouplingPatches } else { - zoneTopPatch[zoneI] = + zoneTopPatch[zonei] = addPatch ( mesh.boundaryMesh(), @@ -751,9 +751,9 @@ void addCouplingPatches ); } - Pout<< zoneTopPatch[zoneI] - << '\t' << newPatches[zoneTopPatch[zoneI]]->name() - << '\t' << newPatches[zoneTopPatch[zoneI]]->type() + Pout<< zoneTopPatch[zonei] + << '\t' << newPatches[zoneTopPatch[zonei]]->name() + << '\t' << newPatches[zoneTopPatch[zonei]]->type() << nl; } @@ -1068,38 +1068,75 @@ int main(int argc, char *argv[]) bool overwrite = args.optionFound("overwrite"); - const word oldInstance = mesh.pointsInstance(); - const dictionary dict(systemDict("extrudeToRegionMeshDict", args, mesh)); - // Point generator - autoPtr model(extrudeModel::New(dict)); - - // Region + // Region to extrude from const word shellRegionName(dict.lookup("region")); - // Faces to extrude - either faceZones or faceSets (boundary faces only) + if (shellRegionName == regionName) + { + FatalIOErrorIn(args.executable().c_str(), dict) + << "Cannot extrude into same region as mesh." << endl + << "Mesh region : " << regionName << endl + << "Shell region : " << shellRegionName + << exit(FatalIOError); + } + + // Select faces to extrude + enum class zoneSourceType { zone, set, patch }; + static const wordList zoneSourceTypeNames = + {"faceZone", "faceSet", "patch" }; + static const wordList zoneSourcesTypeNames = + {"faceZones", "faceSets", "patches" }; wordList zoneNames; wordList zoneShadowNames; - bool hasZones = dict.found("faceZones"); - if (hasZones) + List zoneSourceTypes; + auto lookupZones = [&](const zoneSourceType& type) { - dict.lookup("faceZones") >> zoneNames; - dict.readIfPresent("faceZonesShadow", zoneShadowNames); + const word& keyword = zoneSourcesTypeNames[unsigned(type)]; - if (dict.found("faceSets")) + if (dict.found(keyword)) { - FatalIOErrorIn(args.executable().c_str(), dict) - << "Please supply faces to extrude either through 'faceZones'" - << " or 'faceSets' entry. Found both." - << exit(FatalIOError); + zoneNames.append(dict.lookup(keyword)); + + zoneShadowNames.append + ( + dict.lookupOrDefault + ( + keyword + "Shadow", + wordList + ( + zoneNames.size() - zoneShadowNames.size(), + word::null + ) + ) + ); + + zoneSourceTypes.setSize(zoneNames.size(), type); + } + }; + lookupZones(zoneSourceType::zone); + lookupZones(zoneSourceType::set); + lookupZones(zoneSourceType::patch); + + Info<< nl << "Extruding:" << nl << incrIndent; + forAll(zoneNames, zonei) + { + const unsigned typei = unsigned(zoneSourceTypes[zonei]); + + if (zoneShadowNames[zonei].empty()) + { + Info<< indent << "From " << zoneSourceTypeNames[typei] << " \"" + << zoneNames[zonei] << "\"" << nl; + } + else + { + Info<< indent << "Between " << zoneSourcesTypeNames[typei] << " \"" + << zoneNames[zonei] << "\" and \"" << zoneShadowNames[zonei] + << "\"" << nl; } } - else - { - dict.lookup("faceSets") >> zoneNames; - dict.readIfPresent("faceSetsShadow", zoneShadowNames); - } + Info<< endl << decrIndent; // One-dimensional extrusion settings const Switch oneD(dict.lookupOrDefault("oneD", false)); @@ -1111,33 +1148,6 @@ int main(int argc, char *argv[]) dict.lookup("oneDPolyPatchType") >> oneDPatchType; } - // Change the primary mesh? - const Switch adaptMesh(dict.lookup("adaptMesh")); - - if (hasZones) - { - Info<< "Extruding zones " << zoneNames - << " on mesh " << regionName - << " into shell mesh " << shellRegionName - << endl; - } - else - { - Info<< "Extruding faceSets " << zoneNames - << " on mesh " << regionName - << " into shell mesh " << shellRegionName - << endl; - } - - if (shellRegionName == regionName) - { - FatalIOErrorIn(args.executable().c_str(), dict) - << "Cannot extrude into same region as mesh." << endl - << "Mesh region : " << regionName << endl - << "Shell region : " << shellRegionName - << exit(FatalIOError); - } - if (oneD) { if (oneDNonManifoldEdges) @@ -1156,7 +1166,14 @@ int main(int argc, char *argv[]) } } + // Construct the point generator + autoPtr model(extrudeModel::New(dict)); + // Change the primary mesh? + const Switch adaptMesh(dict.lookup("adaptMesh")); + + + // Determine output instance word meshInstance; if (!overwrite) { @@ -1165,222 +1182,185 @@ int main(int argc, char *argv[]) } else { - meshInstance = oldInstance; + meshInstance = mesh.pointsInstance(); } Info<< "Writing meshes to " << meshInstance << nl << endl; - const polyBoundaryMesh& patches = mesh.boundaryMesh(); + // Map from extrude zone to mesh zone, or -1 if not a mesh zone + labelList zoneMeshZoneID(zoneNames.size(), -1); + labelList shadowZoneMeshZoneID(zoneNames.size(), -1); + forAll(zoneNames, zonei) + { + if (zoneSourceTypes[zonei] != zoneSourceType::zone) continue; + + zoneMeshZoneID[zonei] = + mesh.faceZones().findZoneID(zoneNames[zonei]); + + if (zoneMeshZoneID[zonei] == -1) + { + FatalIOErrorIn(args.executable().c_str(), dict) + << "Cannot find zone " << zoneNames[zonei] + << endl << "Valid zones are " << mesh.faceZones().names() + << exit(FatalIOError); + } + + if (!zoneShadowNames[zonei].empty()) + { + shadowZoneMeshZoneID[zonei] = + mesh.faceZones().findZoneID(zoneShadowNames[zonei]); + + if (shadowZoneMeshZoneID[zonei] == -1) + { + FatalIOErrorIn(args.executable().c_str(), dict) + << "Cannot find shadow zone " << zoneShadowNames[zonei] + << endl << "Valid zones are " << mesh.faceZones().names() + << exit(FatalIOError); + } + } + } // Extract faces to extrude - // ~~~~~~~~~~~~~~~~~~~~~~~~ - - // From extrude zone to mesh zone (or -1 if extruding faceSets) - labelList zoneMeshZoneID; - labelList shadowZoneMeshZoneID; - - // Primary - labelList extrudeFaces; - labelList extrudeFaceZoneIDs; - boolList extrudeFaceFlips; - - // Shadow - labelList shadowExtrudeFaces; - labelList shadowExtrudeFaceZoneIDs; - boolList shadowExtrudeFaceFlips; - - if (hasZones) + labelList extrudeFaces, shadowExtrudeFaces; + labelList extrudeFaceZoneIDs, shadowExtrudeFaceZoneIDs; + boolList extrudeFaceFlips, shadowExtrudeFaceFlips; { - const meshFaceZones& faceZones = mesh.faceZones(); - - zoneMeshZoneID.setSize(zoneNames.size()); - forAll(zoneNames, i) + // Load any faceSets that we need + PtrList zoneSets(zoneNames.size()); + PtrList zoneShadowSets(zoneNames.size()); + forAll(zoneNames, zonei) { - zoneMeshZoneID[i] = - faceZones.findZoneID(zoneNames[i]); - if (zoneMeshZoneID[i] == -1) + if (zoneSourceTypes[zonei] == zoneSourceType::set) { - FatalIOErrorIn(args.executable().c_str(), dict) - << "Cannot find zone " << zoneNames[i] << endl - << "Valid zones are " << faceZones.names() - << exit(FatalIOError); - } - } - - label nExtrudeFaces = 0; - forAll(zoneMeshZoneID, i) - { - nExtrudeFaces += faceZones[zoneMeshZoneID[i]].size(); - } - - extrudeFaces.setSize(nExtrudeFaces); - extrudeFaceZoneIDs.setSize(nExtrudeFaces); - extrudeFaceFlips.setSize(nExtrudeFaces); - - nExtrudeFaces = 0; - forAll(zoneMeshZoneID, i) - { - const faceZone& fz = faceZones[zoneMeshZoneID[i]]; - forAll(fz, j) - { - extrudeFaces[nExtrudeFaces] = fz[j]; - extrudeFaceZoneIDs[nExtrudeFaces] = i; - extrudeFaceFlips[nExtrudeFaces] = fz.flipMap()[j]; - nExtrudeFaces++; - } - } - - // Shadow zones - if (zoneShadowNames.size()) - { - shadowZoneMeshZoneID.setSize(zoneShadowNames.size()); - forAll(zoneShadowNames, i) - { - shadowZoneMeshZoneID[i] = - faceZones.findZoneID(zoneShadowNames[i]); - if (shadowZoneMeshZoneID[i] == -1) + zoneSets.set(zonei, new faceSet(mesh, zoneNames[zonei])); + if (!zoneShadowNames.empty()) { - FatalIOErrorIn(args.executable().c_str(), dict) - << "Cannot find zone " << zoneShadowNames[i] << endl - << "Valid zones are " << faceZones.names() - << exit(FatalIOError); - } - } - - label nShadowFaces = 0; - forAll(shadowZoneMeshZoneID, i) - { - nShadowFaces += faceZones[shadowZoneMeshZoneID[i]].size(); - } - - if (nExtrudeFaces != nShadowFaces) - { - FatalIOErrorIn(args.executable().c_str(), dict) - << "Extruded faces " << nExtrudeFaces << endl - << "is different from shadow faces. " << nShadowFaces - << "This is not permitted " << endl - << exit(FatalIOError); - } - - shadowExtrudeFaces.setSize(nShadowFaces); - shadowExtrudeFaceZoneIDs.setSize(nShadowFaces); - shadowExtrudeFaceFlips.setSize(nShadowFaces); - - nShadowFaces = 0; - forAll(shadowZoneMeshZoneID, i) - { - const faceZone& fz = faceZones[shadowZoneMeshZoneID[i]]; - forAll(fz, j) - { - shadowExtrudeFaces[nShadowFaces] = fz[j]; - shadowExtrudeFaceZoneIDs[nShadowFaces] = i; - shadowExtrudeFaceFlips[nShadowFaces] = fz.flipMap()[j]; - nShadowFaces++; + zoneShadowSets.set + ( + zonei, + new faceSet(mesh, zoneShadowNames[zonei]) + ); } } } - } - else - { - zoneMeshZoneID.setSize(zoneNames.size(), -1); - // Load faceSets - PtrList zones(zoneNames.size()); - forAll(zoneNames, i) + // Create dynamic face lists + DynamicList