BUG: boundaryData output incorrect when no fields are sampled (fixes #2163)

- add "point data" or "face data" note to the boundaryData output
  for easier diagnositics in the future.
This commit is contained in:
Mark Olesen
2021-07-20 12:38:05 +02:00
parent 40ff2acdd6
commit 7f2cbd6cd4
2 changed files with 78 additions and 77 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -108,6 +108,57 @@ Foam::surfaceWriters::boundaryDataWriter::boundaryDataWriter
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::surfaceWriters::boundaryDataWriter::serialWriteGeometry
(
const regIOobject& iopts,
const meshedSurf& surf
)
{
const pointField& points = surf.points();
const faceList& faces = surf.faces();
if (verbose_)
{
if (this->isPointData())
{
Info<< "Writing points: " << iopts.objectPath() << endl;
}
else
{
Info<< "Writing face centres: " << iopts.objectPath() << endl;
}
}
// Like regIOobject::writeObject without instance() adaptation
// since this would write to e.g. 0/ instead of postProcessing/
OFstream osGeom(iopts.objectPath(), streamOpt_);
if (header_)
{
iopts.writeHeader(osGeom);
}
if (this->isPointData())
{
// Just like writeData, but without copying beforehand
osGeom << points;
}
else
{
primitivePatch pp(SubList<face>(faces), points);
// Just like writeData, but without copying beforehand
osGeom << pp.faceCentres();
}
if (header_)
{
iopts.writeEndDivider(osGeom);
}
}
Foam::fileName Foam::surfaceWriters::boundaryDataWriter::write() Foam::fileName Foam::surfaceWriters::boundaryDataWriter::write()
{ {
checkOpen(); checkOpen();
@ -129,6 +180,7 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::write()
mkDir(surfaceDir); mkDir(surfaceDir);
} }
// Write sample locations
pointIOField iopts pointIOField iopts
( (
IOobject IOobject
@ -140,30 +192,9 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::write()
false false
) )
); );
iopts.note() = (this->isPointData() ? "point data" : "face data");
if (verbose_) serialWriteGeometry(iopts, surf);
{
Info<< "Writing points: " << iopts.objectPath() << endl;
}
// Like regIOobject::writeObject without instance() adaptation
// since this would write to e.g. 0/ instead of postProcessing/
OFstream osGeom(iopts.objectPath(), streamOpt_);
if (header_)
{
iopts.writeHeader(osGeom);
}
// Just like writeData, but without copying beforehand
osGeom << surf.points();
if (header_)
{
iopts.writeEndDivider(osGeom);
}
} }
wroteGeom_ = true; wroteGeom_ = true;
@ -212,14 +243,13 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
const pointField& points = surf.points();
const faceList& faces = surf.faces();
if (!isDir(outputFile.path())) if (!isDir(outputFile.path()))
{ {
mkDir(outputFile.path()); mkDir(outputFile.path());
} }
// Write sample locations
{
pointIOField iopts pointIOField iopts
( (
IOobject IOobject
@ -231,47 +261,10 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
false false
) )
); );
iopts.note() = (this->isPointData() ? "point data" : "face data");
if (verbose_) serialWriteGeometry(iopts, surf);
{
if (this->isPointData())
{
Info<< "Writing points: " << iopts.objectPath() << endl;
} }
else
{
Info<< "Writing face centres: " << iopts.objectPath() << endl;
}
}
// Like regIOobject::writeObject without instance() adaptation
// since this would write to e.g. 0/ instead of postProcessing/
OFstream osGeom(iopts.objectPath(), streamOpt_);
if (header_)
{
iopts.writeHeader(osGeom);
}
if (this->isPointData())
{
// Just like writeData, but without copying beforehand
osGeom << points;
}
else
{
primitivePatch pp(SubList<face>(faces), points);
// Just like writeData, but without copying beforehand
osGeom << pp.faceCentres();
}
if (header_)
{
iopts.writeEndDivider(osGeom);
}
// Write field // Write field
{ {
@ -286,6 +279,7 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
false false
) )
); );
iofld.note() = (this->isPointData() ? "point data" : "face data");
OFstream osField(iofld.objectPath(), streamOpt_); OFstream osField(iofld.objectPath(), streamOpt_);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -134,6 +134,10 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward Declarations
class regIOobject;
namespace surfaceWriters namespace surfaceWriters
{ {
@ -159,6 +163,9 @@ class boundaryDataWriter
// Private Member Functions // Private Member Functions
//- Write serial surface geometry to "points" file.
void serialWriteGeometry(const regIOobject&, const meshedSurf& surf);
//- Templated write field operation //- Templated write field operation
template<class Type> template<class Type>
fileName writeTemplate fileName writeTemplate