ENH: redistributePar: split off mesh creation/loading

This commit is contained in:
mattijs
2012-04-02 10:51:32 +01:00
parent 5beb857d8e
commit f3bb0c7b29
2 changed files with 305 additions and 292 deletions

View File

@ -1,3 +1,4 @@
loadOrCreateMesh.C
redistributePar.C redistributePar.C
EXE = $(FOAM_APPBIN)/redistributePar EXE = $(FOAM_APPBIN)/redistributePar

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -54,6 +54,7 @@ Description
#include "mapDistributePolyMesh.H" #include "mapDistributePolyMesh.H"
#include "IOobjectList.H" #include "IOobjectList.H"
#include "globalIndex.H" #include "globalIndex.H"
#include "loadOrCreateMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -62,292 +63,292 @@ Description
static const scalar defaultMergeTol = 1E-6; static const scalar defaultMergeTol = 1E-6;
// Read mesh if available. Otherwise create empty mesh with same non-proc //// Read mesh if available. Otherwise create empty mesh with same non-proc
// patches as proc0 mesh. Requires all processors to have all patches //// patches as proc0 mesh. Requires all processors to have all patches
// (and in same order). //// (and in same order).
autoPtr<fvMesh> createMesh //autoPtr<fvMesh> createMesh
( //(
const Time& runTime, // const Time& runTime,
const word& regionName, // const word& regionName,
const fileName& instDir, // const fileName& instDir,
const bool haveMesh // const bool haveMesh
) //)
{ //{
//Pout<< "Create mesh for time = " // //Pout<< "Create mesh for time = "
// << runTime.timeName() << nl << endl; // // << runTime.timeName() << nl << endl;
//
IOobject io // IOobject io
( // (
regionName, // regionName,
instDir, // instDir,
runTime, // runTime,
IOobject::MUST_READ // IOobject::MUST_READ
); // );
//
if (!haveMesh) // if (!haveMesh)
{ // {
// Create dummy mesh. Only used on procs that don't have mesh. // // Create dummy mesh. Only used on procs that don't have mesh.
IOobject noReadIO(io); // IOobject noReadIO(io);
noReadIO.readOpt() = IOobject::NO_READ; // noReadIO.readOpt() = IOobject::NO_READ;
fvMesh dummyMesh // fvMesh dummyMesh
( // (
noReadIO, // noReadIO,
xferCopy(pointField()), // xferCopy(pointField()),
xferCopy(faceList()), // xferCopy(faceList()),
xferCopy(labelList()), // xferCopy(labelList()),
xferCopy(labelList()), // xferCopy(labelList()),
false // false
); // );
// Add some dummy zones so upon reading it does not read them // // Add some dummy zones so upon reading it does not read them
// from the undecomposed case. Should be done as extra argument to // // from the undecomposed case. Should be done as extra argument to
// regIOobject::readStream? // // regIOobject::readStream?
List<pointZone*> pz // List<pointZone*> pz
( // (
1, // 1,
new pointZone // new pointZone
( // (
"dummyPointZone", // "dummyPointZone",
labelList(0), // labelList(0),
0, // 0,
dummyMesh.pointZones() // dummyMesh.pointZones()
) // )
); // );
List<faceZone*> fz // List<faceZone*> fz
( // (
1, // 1,
new faceZone // new faceZone
( // (
"dummyFaceZone", // "dummyFaceZone",
labelList(0), // labelList(0),
boolList(0), // boolList(0),
0, // 0,
dummyMesh.faceZones() // dummyMesh.faceZones()
) // )
); // );
List<cellZone*> cz // List<cellZone*> cz
( // (
1, // 1,
new cellZone // new cellZone
( // (
"dummyCellZone", // "dummyCellZone",
labelList(0), // labelList(0),
0, // 0,
dummyMesh.cellZones() // dummyMesh.cellZones()
) // )
); // );
dummyMesh.addZones(pz, fz, cz); // dummyMesh.addZones(pz, fz, cz);
//Pout<< "Writing dummy mesh to " << dummyMesh.polyMesh::objectPath() // //Pout<< "Writing dummy mesh to " << dummyMesh.polyMesh::objectPath()
// << endl; // // << endl;
dummyMesh.write(); // dummyMesh.write();
} // }
//
//Pout<< "Reading mesh from " << io.objectPath() << endl; // //Pout<< "Reading mesh from " << io.objectPath() << endl;
autoPtr<fvMesh> meshPtr(new fvMesh(io)); // autoPtr<fvMesh> meshPtr(new fvMesh(io));
fvMesh& mesh = meshPtr(); // fvMesh& mesh = meshPtr();
//
//
// Sync patches // // Sync patches
// ~~~~~~~~~~~~ // // ~~~~~~~~~~~~
//
if (Pstream::master()) // if (Pstream::master())
{ // {
// Send patches // // Send patches
for // for
( // (
int slave=Pstream::firstSlave(); // int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave(); // slave<=Pstream::lastSlave();
slave++ // slave++
) // )
{ // {
OPstream toSlave(Pstream::scheduled, slave); // OPstream toSlave(Pstream::scheduled, slave);
toSlave << mesh.boundaryMesh(); // toSlave << mesh.boundaryMesh();
} // }
} // }
else // else
{ // {
// Receive patches // // Receive patches
IPstream fromMaster(Pstream::scheduled, Pstream::masterNo()); // IPstream fromMaster(Pstream::scheduled, Pstream::masterNo());
PtrList<entry> patchEntries(fromMaster); // PtrList<entry> patchEntries(fromMaster);
//
if (haveMesh) // if (haveMesh)
{ // {
// Check master names against mine // // Check master names against mine
//
const polyBoundaryMesh& patches = mesh.boundaryMesh(); // const polyBoundaryMesh& patches = mesh.boundaryMesh();
//
forAll(patchEntries, patchI) // forAll(patchEntries, patchI)
{ // {
const entry& e = patchEntries[patchI]; // const entry& e = patchEntries[patchI];
const word type(e.dict().lookup("type")); // const word type(e.dict().lookup("type"));
const word& name = e.keyword(); // const word& name = e.keyword();
//
if (type == processorPolyPatch::typeName) // if (type == processorPolyPatch::typeName)
{ // {
break; // break;
} // }
//
if (patchI >= patches.size()) // if (patchI >= patches.size())
{ // {
FatalErrorIn // FatalErrorIn
( // (
"createMesh(const Time&, const fileName&, const bool)" // "createMesh(const Time&, const fileName&, const bool)"
) << "Non-processor patches not synchronised." // ) << "Non-processor patches not synchronised."
<< endl // << endl
<< "Processor " << Pstream::myProcNo() // << "Processor " << Pstream::myProcNo()
<< " has only " << patches.size() // << " has only " << patches.size()
<< " patches, master has " // << " patches, master has "
<< patchI // << patchI
<< exit(FatalError); // << exit(FatalError);
} // }
//
if // if
( // (
type != patches[patchI].type() // type != patches[patchI].type()
|| name != patches[patchI].name() // || name != patches[patchI].name()
) // )
{ // {
FatalErrorIn // FatalErrorIn
( // (
"createMesh(const Time&, const fileName&, const bool)" // "createMesh(const Time&, const fileName&, const bool)"
) << "Non-processor patches not synchronised." // ) << "Non-processor patches not synchronised."
<< endl // << endl
<< "Master patch " << patchI // << "Master patch " << patchI
<< " name:" << type // << " name:" << type
<< " type:" << type << endl // << " type:" << type << endl
<< "Processor " << Pstream::myProcNo() // << "Processor " << Pstream::myProcNo()
<< " patch " << patchI // << " patch " << patchI
<< " has name:" << patches[patchI].name() // << " has name:" << patches[patchI].name()
<< " type:" << patches[patchI].type() // << " type:" << patches[patchI].type()
<< exit(FatalError); // << exit(FatalError);
} // }
} // }
} // }
else // else
{ // {
// Add patch // // Add patch
List<polyPatch*> patches(patchEntries.size()); // List<polyPatch*> patches(patchEntries.size());
label nPatches = 0; // label nPatches = 0;
//
forAll(patchEntries, patchI) // forAll(patchEntries, patchI)
{ // {
const entry& e = patchEntries[patchI]; // const entry& e = patchEntries[patchI];
const word type(e.dict().lookup("type")); // const word type(e.dict().lookup("type"));
const word& name = e.keyword(); // const word& name = e.keyword();
//
if (type == processorPolyPatch::typeName) // if (type == processorPolyPatch::typeName)
{ // {
break; // break;
} // }
//
//Pout<< "Adding patch:" << nPatches // //Pout<< "Adding patch:" << nPatches
// << " name:" << name << " type:" << type << endl; // // << " name:" << name << " type:" << type << endl;
//
dictionary patchDict(e.dict()); // dictionary patchDict(e.dict());
patchDict.remove("nFaces"); // patchDict.remove("nFaces");
patchDict.add("nFaces", 0); // patchDict.add("nFaces", 0);
patchDict.remove("startFace"); // patchDict.remove("startFace");
patchDict.add("startFace", 0); // patchDict.add("startFace", 0);
//
patches[patchI] = polyPatch::New // patches[patchI] = polyPatch::New
( // (
name, // name,
patchDict, // patchDict,
nPatches++, // nPatches++,
mesh.boundaryMesh() // mesh.boundaryMesh()
).ptr(); // ).ptr();
} // }
patches.setSize(nPatches); // patches.setSize(nPatches);
mesh.addFvPatches(patches, false); // no parallel comms // mesh.addFvPatches(patches, false); // no parallel comms
//
//// Write empty mesh now we have correct patches // //// Write empty mesh now we have correct patches
//meshPtr().write(); // //meshPtr().write();
} // }
} // }
//
//
// Determine zones // // Determine zones
// ~~~~~~~~~~~~~~~ // // ~~~~~~~~~~~~~~~
//
wordList pointZoneNames(mesh.pointZones().names()); // wordList pointZoneNames(mesh.pointZones().names());
Pstream::scatter(pointZoneNames); // Pstream::scatter(pointZoneNames);
wordList faceZoneNames(mesh.faceZones().names()); // wordList faceZoneNames(mesh.faceZones().names());
Pstream::scatter(faceZoneNames); // Pstream::scatter(faceZoneNames);
wordList cellZoneNames(mesh.cellZones().names()); // wordList cellZoneNames(mesh.cellZones().names());
Pstream::scatter(cellZoneNames); // Pstream::scatter(cellZoneNames);
//
if (!haveMesh) // if (!haveMesh)
{ // {
// Add the zones. Make sure to remove the old dummy ones first // // Add the zones. Make sure to remove the old dummy ones first
mesh.pointZones().clear(); // mesh.pointZones().clear();
mesh.faceZones().clear(); // mesh.faceZones().clear();
mesh.cellZones().clear(); // mesh.cellZones().clear();
//
List<pointZone*> pz(pointZoneNames.size()); // List<pointZone*> pz(pointZoneNames.size());
forAll(pointZoneNames, i) // forAll(pointZoneNames, i)
{ // {
pz[i] = new pointZone // pz[i] = new pointZone
( // (
pointZoneNames[i], // pointZoneNames[i],
labelList(0), // labelList(0),
i, // i,
mesh.pointZones() // mesh.pointZones()
); // );
} // }
List<faceZone*> fz(faceZoneNames.size()); // List<faceZone*> fz(faceZoneNames.size());
forAll(faceZoneNames, i) // forAll(faceZoneNames, i)
{ // {
fz[i] = new faceZone // fz[i] = new faceZone
( // (
faceZoneNames[i], // faceZoneNames[i],
labelList(0), // labelList(0),
boolList(0), // boolList(0),
i, // i,
mesh.faceZones() // mesh.faceZones()
); // );
} // }
List<cellZone*> cz(cellZoneNames.size()); // List<cellZone*> cz(cellZoneNames.size());
forAll(cellZoneNames, i) // forAll(cellZoneNames, i)
{ // {
cz[i] = new cellZone // cz[i] = new cellZone
( // (
cellZoneNames[i], // cellZoneNames[i],
labelList(0), // labelList(0),
i, // i,
mesh.cellZones() // mesh.cellZones()
); // );
} // }
mesh.addZones(pz, fz, cz); // mesh.addZones(pz, fz, cz);
} // }
//
//
if (!haveMesh) // if (!haveMesh)
{ // {
// We created a dummy mesh file above. Delete it. // // We created a dummy mesh file above. Delete it.
//Pout<< "Removing dummy mesh " << io.objectPath() << endl; // //Pout<< "Removing dummy mesh " << io.objectPath() << endl;
rmDir(io.objectPath()); // rmDir(io.objectPath());
} // }
//
// Force recreation of globalMeshData. // // Force recreation of globalMeshData.
mesh.clearOut(); // mesh.clearOut();
mesh.globalData(); // mesh.globalData();
//
//
// Do some checks. // // Do some checks.
//
// Check if the boundary definition is unique // // Check if the boundary definition is unique
mesh.boundaryMesh().checkDefinition(true); // mesh.boundaryMesh().checkDefinition(true);
// Check if the boundary processor patches are correct // // Check if the boundary processor patches are correct
mesh.boundaryMesh().checkParallelSync(true); // mesh.boundaryMesh().checkParallelSync(true);
// Check names of zones are equal // // Check names of zones are equal
mesh.cellZones().checkDefinition(true); // mesh.cellZones().checkDefinition(true);
mesh.cellZones().checkParallelSync(true); // mesh.cellZones().checkParallelSync(true);
mesh.faceZones().checkDefinition(true); // mesh.faceZones().checkDefinition(true);
mesh.faceZones().checkParallelSync(true); // mesh.faceZones().checkParallelSync(true);
mesh.pointZones().checkDefinition(true); // mesh.pointZones().checkDefinition(true);
mesh.pointZones().checkParallelSync(true); // mesh.pointZones().checkParallelSync(true);
//
return meshPtr; // return meshPtr;
} //}
// Get merging distance when matching face centres // Get merging distance when matching face centres
@ -786,13 +787,24 @@ int main(int argc, char *argv[])
const bool allHaveMesh = (findIndex(haveMesh, false) == -1); const bool allHaveMesh = (findIndex(haveMesh, false) == -1);
// Create mesh // Create mesh
autoPtr<fvMesh> meshPtr = createMesh //autoPtr<fvMesh> meshPtr = createMesh
//(
// runTime,
// regionName,
// masterInstDir,
// haveMesh[Pstream::myProcNo()]
//);
autoPtr<fvMesh> meshPtr = loadOrCreateMesh
( (
runTime, IOobject
regionName, (
masterInstDir, regionName,
haveMesh[Pstream::myProcNo()] masterInstDir,
runTime,
Foam::IOobject::MUST_READ
)
); );
fvMesh& mesh = meshPtr(); fvMesh& mesh = meshPtr();
// Print some statistics // Print some statistics