ENH: Better writing of cell size fields. Writes to constant for the correct mesh.

This commit is contained in:
graham
2010-09-23 18:22:25 +01:00
parent 30eab62ecf
commit fef610ae9f
3 changed files with 89 additions and 27 deletions

View File

@ -938,7 +938,8 @@ void Foam::conformalVoronoiMesh::setVertexSizeAndAlignment()
// for // for
// ( // (
// Triangulation::Finite_vertices_iterator vit = finite_vertices_begin(); // Triangulation::Finite_vertices_iterator vit =
// finite_vertices_begin();
// vit != finite_vertices_end(); // vit != finite_vertices_end();
// vit++ // vit++
// ) // )
@ -1488,8 +1489,6 @@ void Foam::conformalVoronoiMesh::move()
if (runTime_.outputTime()) if (runTime_.outputTime())
{ {
writeMesh(runTime_.timeName(), false); writeMesh(runTime_.timeName(), false);
writeTargetCellSize();
} }
// Remove the entire tessellation // Remove the entire tessellation

View File

@ -746,9 +746,10 @@ public:
const fileName& fName const fileName& fName
) const; ) const;
//- Read mesh from file as an fvMesh then calculate and write a //- Calculate and write a field of the target cell size,
// field of the target cell size // target cell volume, actual cell volume and equivalent
void writeTargetCellSize() const; // actual cell size (cbrt(actual cell volume)).
void writeCellSizes(const fvMesh& mesh) const;
}; };

View File

@ -201,6 +201,7 @@ void Foam::conformalVoronoiMesh::writeMesh
} }
} }
void Foam::conformalVoronoiMesh::writeMesh void Foam::conformalVoronoiMesh::writeMesh
( (
const word& meshName, const word& meshName,
@ -228,7 +229,7 @@ void Foam::conformalVoronoiMesh::writeMesh
IOobject::AUTO_WRITE IOobject::AUTO_WRITE
); );
polyMesh pMesh fvMesh mesh
( (
io, io,
xferMove(points), xferMove(points),
@ -247,18 +248,20 @@ void Foam::conformalVoronoiMesh::writeMesh
patchSizes[p], patchSizes[p],
patchStarts[p], patchStarts[p],
p, p,
pMesh.boundaryMesh() mesh.boundaryMesh()
); );
} }
pMesh.addPatches(patches); mesh.addFvPatches(patches);
if (!pMesh.write()) if (!mesh.write())
{ {
FatalErrorIn("Foam::conformalVoronoiMesh::writeMesh") FatalErrorIn("Foam::conformalVoronoiMesh::writeMesh")
<< "Failed writing polyMesh." << "Failed writing polyMesh."
<< exit(FatalError); << exit(FatalError);
} }
writeCellSizes(mesh);
} }
@ -294,22 +297,12 @@ void Foam::conformalVoronoiMesh::writeObjMesh
} }
void Foam::conformalVoronoiMesh::writeTargetCellSize() const void Foam::conformalVoronoiMesh::writeCellSizes
(
const fvMesh& mesh
) const
{ {
{ {
Info<< nl << "Create fvMesh" << endl;
fvMesh fMesh
(
IOobject
(
Foam::polyMesh::defaultRegion,
runTime_.constant(),
runTime_,
IOobject::MUST_READ
)
);
timeCheck(); timeCheck();
Info<< nl << "Create targetCellSize volScalarField" << endl; Info<< nl << "Create targetCellSize volScalarField" << endl;
@ -319,26 +312,95 @@ void Foam::conformalVoronoiMesh::writeTargetCellSize() const
IOobject IOobject
( (
"targetCellSize", "targetCellSize",
runTime_.timeName(), mesh.polyMesh::instance(),
runTime_, runTime_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE
), ),
fMesh, mesh,
dimensionedScalar("cellSize", dimLength, 0), dimensionedScalar("cellSize", dimLength, 0),
zeroGradientPointPatchField<scalar>::typeName zeroGradientPointPatchField<scalar>::typeName
); );
scalarField& cellSize = targetCellSize.internalField(); scalarField& cellSize = targetCellSize.internalField();
const vectorField& C = fMesh.cellCentres(); const vectorField& C = mesh.cellCentres();
forAll(cellSize, i) forAll(cellSize, i)
{ {
cellSize[i] = cellSizeControl().cellSize(C[i]); cellSize[i] = cellSizeControl().cellSize(C[i]);
} }
Info<< nl << "Create targetCellVolume volScalarField" << endl;
volScalarField targetCellVolume
(
IOobject
(
"targetCellVolume",
mesh.polyMesh::instance(),
runTime_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("cellVolume", dimLength, 0),
zeroGradientPointPatchField<scalar>::typeName
);
targetCellVolume.internalField() = pow3(cellSize);
Info<< nl << "Create actualCellVolume volScalarField" << endl;
volScalarField actualCellVolume
(
IOobject
(
"actualCellVolume",
mesh.polyMesh::instance(),
runTime_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("cellVolume", dimVolume, 0),
zeroGradientPointPatchField<scalar>::typeName
);
actualCellVolume.internalField() = mesh.cellVolumes();
Info<< nl << "Create equivalentCellSize volScalarField" << endl;
volScalarField equivalentCellSize
(
IOobject
(
"equivalentCellSize",
mesh.polyMesh::instance(),
runTime_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("cellSize", dimLength, 0),
zeroGradientPointPatchField<scalar>::typeName
);
equivalentCellSize.internalField() = pow
(
actualCellVolume.internalField(),
1.0/3.0
);
targetCellSize.correctBoundaryConditions();
targetCellVolume.correctBoundaryConditions();
actualCellVolume.correctBoundaryConditions();
equivalentCellSize.correctBoundaryConditions();
targetCellSize.write(); targetCellSize.write();
targetCellVolume.write();
actualCellVolume.write();
equivalentCellSize.write();
} }
// { // {