When an OpenFOAM simulation runs in parallel, the data for decomposed fields and
mesh(es) has historically been stored in multiple files within separate
directories for each processor. Processor directories are named 'processorN',
where N is the processor number.
This commit introduces an alternative "collated" file format where the data for
each decomposed field (and mesh) is collated into a single file, which is
written and read on the master processor. The files are stored in a single
directory named 'processors'.
The new format produces significantly fewer files - one per field, instead of N
per field. For large parallel cases, this avoids the restriction on the number
of open files imposed by the operating system limits.
The file writing can be threaded allowing the simulation to continue running
while the data is being written to file. NFS (Network File System) is not
needed when using the the collated format and additionally, there is an option
to run without NFS with the original uncollated approach, known as
"masterUncollated".
The controls for the file handling are in the OptimisationSwitches of
etc/controlDict:
OptimisationSwitches
{
...
//- Parallel IO file handler
// uncollated (default), collated or masterUncollated
fileHandler uncollated;
//- collated: thread buffer size for queued file writes.
// If set to 0 or not sufficient for the file size threading is not used.
// Default: 2e9
maxThreadFileBufferSize 2e9;
//- masterUncollated: non-blocking buffer size.
// If the file exceeds this buffer size scheduled transfer is used.
// Default: 2e9
maxMasterFileBufferSize 2e9;
}
When using the collated file handling, memory is allocated for the data in the
thread. maxThreadFileBufferSize sets the maximum size of memory in bytes that
is allocated. If the data exceeds this size, the write does not use threading.
When using the masterUncollated file handling, non-blocking MPI communication
requires a sufficiently large memory buffer on the master node.
maxMasterFileBufferSize sets the maximum size in bytes of the buffer. If the
data exceeds this size, the system uses scheduled communication.
The installation defaults for the fileHandler choice, maxThreadFileBufferSize
and maxMasterFileBufferSize (set in etc/controlDict) can be over-ridden within
the case controlDict file, like other parameters. Additionally the fileHandler
can be set by:
- the "-fileHandler" command line argument;
- a FOAM_FILEHANDLER environment variable.
A foamFormatConvert utility allows users to convert files between the collated
and uncollated formats, e.g.
mpirun -np 2 foamFormatConvert -parallel -fileHandler uncollated
An example case demonstrating the file handling methods is provided in:
$FOAM_TUTORIALS/IO/fileHandling
The work was undertaken by Mattijs Janssens, in collaboration with Henry Weller.
371 lines
9.4 KiB
C
371 lines
9.4 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
|
\\/ M anipulation |
|
|
-------------------------------------------------------------------------------
|
|
License
|
|
This file is part of OpenFOAM.
|
|
|
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
Application
|
|
refinementLevel
|
|
|
|
Description
|
|
Tries to figure out what the refinement level is on refined cartesian
|
|
meshes. Run BEFORE snapping.
|
|
|
|
Writes
|
|
- volScalarField 'refinementLevel' with current refinement level.
|
|
- cellSet 'refCells' which are the cells that need to be refined to satisfy
|
|
2:1 refinement.
|
|
|
|
Works by dividing cells into volume bins.
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
#include "argList.H"
|
|
#include "Time.H"
|
|
#include "polyMesh.H"
|
|
#include "cellSet.H"
|
|
#include "SortableList.H"
|
|
#include "labelIOList.H"
|
|
#include "fvMesh.H"
|
|
#include "volFields.H"
|
|
|
|
using namespace Foam;
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
// Return true if any cells had to be split to keep a difference between
|
|
// neighbouring refinement levels < limitDiff. Puts cells into refCells and
|
|
// update refLevel to account for refinement.
|
|
bool limitRefinementLevel
|
|
(
|
|
const primitiveMesh& mesh,
|
|
labelList& refLevel,
|
|
cellSet& refCells
|
|
)
|
|
{
|
|
const labelListList& cellCells = mesh.cellCells();
|
|
|
|
label oldNCells = refCells.size();
|
|
|
|
forAll(cellCells, celli)
|
|
{
|
|
const labelList& cCells = cellCells[celli];
|
|
|
|
forAll(cCells, i)
|
|
{
|
|
if (refLevel[cCells[i]] > (refLevel[celli]+1))
|
|
{
|
|
// Found neighbour with >=2 difference in refLevel.
|
|
refCells.insert(celli);
|
|
refLevel[celli]++;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (refCells.size() > oldNCells)
|
|
{
|
|
Info<< "Added an additional " << refCells.size() - oldNCells
|
|
<< " cells to satisfy 1:2 refinement level"
|
|
<< endl;
|
|
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
argList::addBoolOption
|
|
(
|
|
"readLevel",
|
|
"read level from refinementLevel file"
|
|
);
|
|
|
|
#include "setRootCase.H"
|
|
#include "createTime.H"
|
|
#include "createPolyMesh.H"
|
|
|
|
Info<< "Dividing cells into bins depending on cell volume.\nThis will"
|
|
<< " correspond to refinement levels for a mesh with only 2x2x2"
|
|
<< " refinement\n"
|
|
<< "The upper range for every bin is always 1.1 times the lower range"
|
|
<< " to allow for some truncation error."
|
|
<< nl << endl;
|
|
|
|
const bool readLevel = args.optionFound("readLevel");
|
|
|
|
const scalarField& vols = mesh.cellVolumes();
|
|
|
|
SortableList<scalar> sortedVols(vols);
|
|
|
|
// All cell labels, sorted per bin.
|
|
DynamicList<DynamicList<label>> bins;
|
|
|
|
// Lower/upper limits
|
|
DynamicList<scalar> lowerLimits;
|
|
DynamicList<scalar> upperLimits;
|
|
|
|
// Create bin0. Have upperlimit as factor times lowerlimit.
|
|
bins.append(DynamicList<label>());
|
|
lowerLimits.append(sortedVols[0]);
|
|
upperLimits.append(1.1 * lowerLimits.last());
|
|
|
|
forAll(sortedVols, i)
|
|
{
|
|
if (sortedVols[i] > upperLimits.last())
|
|
{
|
|
// New value outside of current bin
|
|
|
|
// Shrink old bin.
|
|
DynamicList<label>& bin = bins.last();
|
|
|
|
bin.shrink();
|
|
|
|
Info<< "Collected " << bin.size() << " elements in bin "
|
|
<< lowerLimits.last() << " .. "
|
|
<< upperLimits.last() << endl;
|
|
|
|
// Create new bin.
|
|
bins.append(DynamicList<label>());
|
|
lowerLimits.append(sortedVols[i]);
|
|
upperLimits.append(1.1 * lowerLimits.last());
|
|
|
|
Info<< "Creating new bin " << lowerLimits.last()
|
|
<< " .. " << upperLimits.last()
|
|
<< endl;
|
|
}
|
|
|
|
// Append to current bin.
|
|
DynamicList<label>& bin = bins.last();
|
|
|
|
bin.append(sortedVols.indices()[i]);
|
|
}
|
|
Info<< endl;
|
|
|
|
bins.last().shrink();
|
|
bins.shrink();
|
|
lowerLimits.shrink();
|
|
upperLimits.shrink();
|
|
|
|
|
|
//
|
|
// Write to cellSets.
|
|
//
|
|
|
|
Info<< "Volume bins:" << nl;
|
|
forAll(bins, binI)
|
|
{
|
|
const DynamicList<label>& bin = bins[binI];
|
|
|
|
cellSet cells(mesh, "vol" + name(binI), bin.size());
|
|
|
|
forAll(bin, i)
|
|
{
|
|
cells.insert(bin[i]);
|
|
}
|
|
|
|
Info<< " " << lowerLimits[binI] << " .. " << upperLimits[binI]
|
|
<< " : writing " << bin.size() << " cells to cellSet "
|
|
<< cells.name() << endl;
|
|
|
|
cells.write();
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Convert bins into refinement level.
|
|
//
|
|
|
|
|
|
// Construct fvMesh to be able to construct volScalarField
|
|
|
|
fvMesh fMesh
|
|
(
|
|
IOobject
|
|
(
|
|
fvMesh::defaultRegion,
|
|
runTime.timeName(),
|
|
runTime
|
|
),
|
|
xferCopy(mesh.points()), // could we safely re-use the data?
|
|
xferCopy(mesh.faces()),
|
|
xferCopy(mesh.cells())
|
|
);
|
|
|
|
// Add the boundary patches
|
|
const polyBoundaryMesh& patches = mesh.boundaryMesh();
|
|
|
|
List<polyPatch*> p(patches.size());
|
|
|
|
forAll(p, patchi)
|
|
{
|
|
p[patchi] = patches[patchi].clone(fMesh.boundaryMesh()).ptr();
|
|
}
|
|
|
|
fMesh.addFvPatches(p);
|
|
|
|
|
|
// Refinement level
|
|
IOobject refHeader
|
|
(
|
|
"refinementLevel",
|
|
runTime.timeName(),
|
|
polyMesh::defaultRegion,
|
|
runTime
|
|
);
|
|
|
|
if (!readLevel && refHeader.typeHeaderOk<labelIOList>(true))
|
|
{
|
|
WarningInFunction
|
|
<< "Detected " << refHeader.name() << " file in "
|
|
<< polyMesh::defaultRegion << " directory. Please remove to"
|
|
<< " recreate it or use the -readLevel option to use it"
|
|
<< endl;
|
|
return 1;
|
|
}
|
|
|
|
|
|
labelIOList refLevel
|
|
(
|
|
IOobject
|
|
(
|
|
"refinementLevel",
|
|
runTime.timeName(),
|
|
mesh,
|
|
IOobject::NO_READ,
|
|
IOobject::AUTO_WRITE
|
|
),
|
|
labelList(mesh.nCells(), 0)
|
|
);
|
|
|
|
if (readLevel)
|
|
{
|
|
refLevel = labelIOList(refHeader);
|
|
}
|
|
|
|
// Construct volScalarField with same info for post processing
|
|
volScalarField postRefLevel
|
|
(
|
|
IOobject
|
|
(
|
|
"refinementLevel",
|
|
runTime.timeName(),
|
|
mesh,
|
|
IOobject::NO_READ,
|
|
IOobject::NO_WRITE
|
|
),
|
|
fMesh,
|
|
dimensionedScalar("zero", dimless/dimTime, 0)
|
|
);
|
|
|
|
// Set cell values
|
|
forAll(bins, binI)
|
|
{
|
|
const DynamicList<label>& bin = bins[binI];
|
|
|
|
forAll(bin, i)
|
|
{
|
|
refLevel[bin[i]] = bins.size() - binI - 1;
|
|
postRefLevel[bin[i]] = refLevel[bin[i]];
|
|
}
|
|
}
|
|
|
|
volScalarField::Boundary& postRefLevelBf =
|
|
postRefLevel.boundaryFieldRef();
|
|
|
|
// For volScalarField: set boundary values to same as cell.
|
|
// Note: could also put
|
|
// zeroGradient b.c. on postRefLevel and do evaluate.
|
|
forAll(postRefLevel.boundaryField(), patchi)
|
|
{
|
|
const polyPatch& pp = patches[patchi];
|
|
|
|
fvPatchScalarField& bField = postRefLevelBf[patchi];
|
|
|
|
Info<< "Setting field for patch "<< endl;
|
|
|
|
forAll(bField, facei)
|
|
{
|
|
label own = mesh.faceOwner()[pp.start() + facei];
|
|
|
|
bField[facei] = postRefLevel[own];
|
|
}
|
|
}
|
|
|
|
Info<< "Determined current refinement level and writing to "
|
|
<< postRefLevel.name() << " (as volScalarField; for post processing)"
|
|
<< nl
|
|
<< polyMesh::defaultRegion/refLevel.name()
|
|
<< " (as labelIOList; for meshing)" << nl
|
|
<< endl;
|
|
|
|
refLevel.write();
|
|
postRefLevel.write();
|
|
|
|
|
|
// Find out cells to refine to keep to 2:1 refinement level restriction
|
|
|
|
// Cells to refine
|
|
cellSet refCells(mesh, "refCells", 100);
|
|
|
|
while
|
|
(
|
|
limitRefinementLevel
|
|
(
|
|
mesh,
|
|
refLevel, // current refinement level
|
|
refCells // cells to refine
|
|
)
|
|
)
|
|
{}
|
|
|
|
if (refCells.size())
|
|
{
|
|
Info<< "Collected " << refCells.size() << " cells that need to be"
|
|
<< " refined to get closer to overall 2:1 refinement level limit"
|
|
<< nl
|
|
<< "Written cells to be refined to cellSet " << refCells.name()
|
|
<< nl << endl;
|
|
|
|
refCells.write();
|
|
|
|
Info<< "After refinement this tool can be run again to see if the 2:1"
|
|
<< " limit is observed all over the mesh" << nl << endl;
|
|
}
|
|
else
|
|
{
|
|
Info<< "All cells in the mesh observe the 2:1 refinement level limit"
|
|
<< nl << endl;
|
|
}
|
|
|
|
Info<< "\nEnd\n" << endl;
|
|
return 0;
|
|
}
|
|
|
|
|
|
// ************************************************************************* //
|