Merge commit 'OpenCFD/master' into olesenm

This commit is contained in:
Mark Olesen
2009-09-23 09:14:28 +02:00
16 changed files with 543 additions and 189 deletions

View File

@ -37,6 +37,7 @@ License
#include "mapDistributePolyMesh.H"
#include "featureEdgeMesh.H"
#include "Cloud.H"
#include "globalIndex.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -1244,40 +1245,122 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::refine
}
// Do refinement of consistent set of cells followed by truncation and
// load balancing.
//// Do refinement of consistent set of cells followed by truncation and
//// load balancing.
//Foam::autoPtr<Foam::mapDistributePolyMesh>
//Foam::meshRefinement::refineAndBalance
//(
// const string& msg,
// decompositionMethod& decomposer,
// fvMeshDistribute& distributor,
// const labelList& cellsToRefine
//)
//{
// // Do all refinement
// refine(cellsToRefine);
//
// if (debug)
// {
// Pout<< "Writing refined but unbalanced " << msg
// << " mesh to time " << timeName() << endl;
// write
// (
// debug,
// mesh_.time().path()
// /timeName()
// );
// Pout<< "Dumped debug data in = "
// << mesh_.time().cpuTimeIncrement() << " s" << endl;
//
// // test all is still synced across proc patches
// checkData();
// }
//
// Info<< "Refined mesh in = "
// << mesh_.time().cpuTimeIncrement() << " s" << endl;
// printMeshInfo(debug, "After refinement " + msg);
//
//
// // Load balancing
// // ~~~~~~~~~~~~~~
//
// autoPtr<mapDistributePolyMesh> distMap;
//
// if (Pstream::nProcs() > 1)
// {
// scalarField cellWeights(mesh_.nCells(), 1);
//
// distMap = balance
// (
// false, //keepZoneFaces
// false, //keepBaffles
// cellWeights,
// decomposer,
// distributor
// );
//
// Info<< "Balanced mesh in = "
// << mesh_.time().cpuTimeIncrement() << " s" << endl;
//
// printMeshInfo(debug, "After balancing " + msg);
//
//
// if (debug)
// {
// Pout<< "Writing balanced " << msg
// << " mesh to time " << timeName() << endl;
// write
// (
// debug,
// mesh_.time().path()/timeName()
// );
// Pout<< "Dumped debug data in = "
// << mesh_.time().cpuTimeIncrement() << " s" << endl;
//
// // test all is still synced across proc patches
// checkData();
// }
// }
//
// return distMap;
//}
// Do load balancing followed by refinement of consistent set of cells.
Foam::autoPtr<Foam::mapDistributePolyMesh>
Foam::meshRefinement::refineAndBalance
(
const string& msg,
decompositionMethod& decomposer,
fvMeshDistribute& distributor,
const labelList& cellsToRefine
const labelList& initCellsToRefine,
const scalar maxLoadUnbalance
)
{
// Do all refinement
refine(cellsToRefine);
labelList cellsToRefine(initCellsToRefine);
if (debug)
{
Pout<< "Writing refined but unbalanced " << msg
<< " mesh to time " << timeName() << endl;
write
(
debug,
mesh_.time().path()
/timeName()
);
Pout<< "Dumped debug data in = "
<< mesh_.time().cpuTimeIncrement() << " s" << endl;
// test all is still synced across proc patches
checkData();
}
Info<< "Refined mesh in = "
<< mesh_.time().cpuTimeIncrement() << " s" << endl;
printMeshInfo(debug, "After refinement " + msg);
//{
// globalIndex globalCells(mesh_.nCells());
//
// Info<< "** Distribution before balancing/refining:" << endl;
// for (label procI = 0; procI < Pstream::nProcs(); procI++)
// {
// Info<< " " << procI << '\t'
// << globalCells.localSize(procI) << endl;
// }
// Info<< endl;
//}
//{
// globalIndex globalCells(cellsToRefine.size());
//
// Info<< "** Cells to be refined:" << endl;
// for (label procI = 0; procI < Pstream::nProcs(); procI++)
// {
// Info<< " " << procI << '\t'
// << globalCells.localSize(procI) << endl;
// }
// Info<< endl;
//}
// Load balancing
@ -1287,20 +1370,62 @@ Foam::meshRefinement::refineAndBalance
if (Pstream::nProcs() > 1)
{
distMap = balance
// First check if we need to balance at all. Precalculate number of
// cells after refinement and see what maximum difference is.
scalar nNewCells = scalar(mesh_.nCells() + 7*cellsToRefine.size());
scalar nIdealNewCells =
returnReduce(nNewCells, sumOp<scalar>())
/ Pstream::nProcs();
scalar unbalance = returnReduce
(
false, //keepZoneFaces
false, //keepBaffles
decomposer,
distributor
mag(1.0-nNewCells/nIdealNewCells),
maxOp<scalar>()
);
Info<< "Balanced mesh in = "
<< mesh_.time().cpuTimeIncrement() << " s" << endl;
if (unbalance <= maxLoadUnbalance)
{
Info<< "Skipping balancing since max unbalance " << unbalance
<< " in = "
<< mesh_.time().cpuTimeIncrement() << " s" << endl;
}
else
{
scalarField cellWeights(mesh_.nCells(), 1);
forAll(cellsToRefine, i)
{
cellWeights[cellsToRefine[i]] += 7;
}
distMap = balance
(
false, //keepZoneFaces
false, //keepBaffles
cellWeights,
decomposer,
distributor
);
// Update cells to refine
distMap().distributeCellIndices(cellsToRefine);
Info<< "Balanced mesh in = "
<< mesh_.time().cpuTimeIncrement() << " s" << endl;
}
//{
// globalIndex globalCells(mesh_.nCells());
//
// Info<< "** Distribution after balancing:" << endl;
// for (label procI = 0; procI < Pstream::nProcs(); procI++)
// {
// Info<< " " << procI << '\t'
// << globalCells.localSize(procI) << endl;
// }
// Info<< endl;
//}
printMeshInfo(debug, "After balancing " + msg);
if (debug)
{
Pout<< "Writing balanced " << msg
@ -1318,6 +1443,46 @@ Foam::meshRefinement::refineAndBalance
}
}
// Refinement
// ~~~~~~~~~~
refine(cellsToRefine);
if (debug)
{
Pout<< "Writing refined " << msg
<< " mesh to time " << timeName() << endl;
write
(
debug,
mesh_.time().path()
/timeName()
);
Pout<< "Dumped debug data in = "
<< mesh_.time().cpuTimeIncrement() << " s" << endl;
// test all is still synced across proc patches
checkData();
}
Info<< "Refined mesh in = "
<< mesh_.time().cpuTimeIncrement() << " s" << endl;
//{
// globalIndex globalCells(mesh_.nCells());
//
// Info<< "** After refinement distribution:" << endl;
// for (label procI = 0; procI < Pstream::nProcs(); procI++)
// {
// Info<< " " << procI << '\t'
// << globalCells.localSize(procI) << endl;
// }
// Info<< endl;
//}
printMeshInfo(debug, "After refinement " + msg);
return distMap;
}