mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: inconsistent surfaceFieldValue writing (fixes #1999)
- setup writer outside the data loop to ensure that the number of output fields is correct (VTK format). - ignore 'interpolate' on sampled surfaces to ensure proper face sampling, never allow point sampling BUG: incorrect debug-switch for sampledIsoSurface
This commit is contained in:
@ -1034,16 +1034,6 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
|
||||
mesh_,
|
||||
dict.subDict("sampledSurfaceDict")
|
||||
);
|
||||
|
||||
if (sampledPtr_->interpolate())
|
||||
{
|
||||
// Should probably ignore interpolate entirely,
|
||||
// but the oldest isoSurface algorithm requires it!
|
||||
WarningInFunction
|
||||
<< type() << ' ' << name() << ": "
|
||||
<< "sampledSurface with interpolate = true "
|
||||
<< "is likely incorrect" << nl << nl;
|
||||
}
|
||||
}
|
||||
|
||||
Info<< type() << ' ' << name() << ':' << nl
|
||||
@ -1061,15 +1051,6 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
|
||||
|
||||
if (usesWeight())
|
||||
{
|
||||
if (stSampled == regionType_)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Cannot use weighted operation '"
|
||||
<< operationTypeNames_[operation_]
|
||||
<< "' for sampledSurface"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
// Can have "weightFields" or "weightField"
|
||||
|
||||
bool missing = true;
|
||||
@ -1140,6 +1121,9 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
|
||||
)
|
||||
);
|
||||
|
||||
// Propagate field counts (per surface)
|
||||
surfaceWriterPtr_->nFields() = fields_.size();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
surfaceWriterPtr_->verbose(true);
|
||||
|
||||
@ -96,18 +96,13 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
|
||||
|
||||
if (sampledPtr_)
|
||||
{
|
||||
if (sampledPtr_->interpolate())
|
||||
{
|
||||
const interpolationCellPoint<Type> interp(fld);
|
||||
// Could be runtime selectable
|
||||
// auto sampler = interpolation<Type>::New(sampleFaceScheme_, fld);
|
||||
|
||||
return sampledPtr_->interpolate(interp);
|
||||
}
|
||||
else
|
||||
{
|
||||
const interpolationCell<Type> interp(fld);
|
||||
// const interpolationCellPoint<Type> interp(fld);
|
||||
const interpolationCell<Type> interp(fld);
|
||||
|
||||
return sampledPtr_->sample(interp);
|
||||
}
|
||||
return sampledPtr_->sample(interp);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -324,6 +319,30 @@ Foam::label Foam::functionObjects::fieldValues::surfaceFieldValue::writeAll
|
||||
{
|
||||
label nProcessed = 0;
|
||||
|
||||
// If using the surface writer, the points/faces parameters have already
|
||||
// been merged on the master and the writeValues routine will also gather
|
||||
// all data onto the master before calling the writer.
|
||||
// Thus only call the writer on master!
|
||||
|
||||
// Begin writer time step
|
||||
if (Pstream::master() && surfaceWriterPtr_ && surfaceWriterPtr_->enabled())
|
||||
{
|
||||
auto& writer = *surfaceWriterPtr_;
|
||||
|
||||
writer.open
|
||||
(
|
||||
points,
|
||||
faces,
|
||||
(
|
||||
outputDir()
|
||||
/ regionTypeNames_[regionType_] + ("_" + regionName_)
|
||||
),
|
||||
false // serial - already merged
|
||||
);
|
||||
|
||||
writer.beginTime(time_);
|
||||
}
|
||||
|
||||
for (const word& fieldName : fields_)
|
||||
{
|
||||
if
|
||||
@ -349,6 +368,23 @@ Foam::label Foam::functionObjects::fieldValues::surfaceFieldValue::writeAll
|
||||
}
|
||||
}
|
||||
|
||||
// Finish writer time step
|
||||
if (Pstream::master() && surfaceWriterPtr_ && surfaceWriterPtr_->enabled())
|
||||
{
|
||||
auto& writer = *surfaceWriterPtr_;
|
||||
|
||||
// Write geometry if no fields were written so that we still
|
||||
// can have something to look at.
|
||||
|
||||
if (!writer.wroteData())
|
||||
{
|
||||
writer.write();
|
||||
}
|
||||
|
||||
writer.endTime();
|
||||
writer.clear();
|
||||
}
|
||||
|
||||
return nProcessed;
|
||||
}
|
||||
|
||||
@ -377,29 +413,13 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
surfaceWriterPtr_->open
|
||||
(
|
||||
points,
|
||||
faces,
|
||||
(
|
||||
outputDir()
|
||||
/ regionTypeNames_[regionType_] + ("_" + regionName_)
|
||||
),
|
||||
false // serial - already merged
|
||||
);
|
||||
fileName outputName =
|
||||
surfaceWriterPtr_->write(fieldName, allValues);
|
||||
|
||||
// Point data? Should probably disallow
|
||||
if (sampledPtr_)
|
||||
{
|
||||
surfaceWriterPtr_->isPointData() =
|
||||
sampledPtr_->interpolate();
|
||||
}
|
||||
|
||||
surfaceWriterPtr_->nFields() = 1; // Needed for VTK legacy
|
||||
|
||||
surfaceWriterPtr_->write(fieldName, allValues);
|
||||
|
||||
surfaceWriterPtr_->clear();
|
||||
// Case-local file name with "<case>" to make relocatable
|
||||
dictionary propsDict;
|
||||
propsDict.add("file", time_.relativePath(outputName, true));
|
||||
this->setProperty(fieldName, propsDict);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -215,7 +215,7 @@ protected:
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("samplediIsoSurfacePoint");
|
||||
TypeName("sampledIsoSurface");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
Reference in New Issue
Block a user