openfoam/applications/utilities/postProcessing/dataConversion/foamToVTK/convertAreaFields.H
Mark Olesen 9af3f85cf9 STYLE: simplify short-circuit involving autoPtr (#1775)
- with '&&' conditions, often better to check for non-null autoPtr
  first (it is cheap)

- check as bool instead of valid() method for cleaner code, especially
  when the wrapped item itself has a valid/empty or good.
  Also when handling multiple checks.

  Now
      if (ptr && ptr->valid())
      if (ptr1 || ptr2)

  instead
      if (ptr.valid() && ptr->valid())
      if (ptr1.valid() || ptr2.valid())
2020-07-16 10:17:25 +02:00

119 lines
3.3 KiB
C++

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Description
Code chunk for converting finite-area - included by foamToVTK.
\*---------------------------------------------------------------------------*/
//
// Finite-area mesh and fields - need not exist
//
// No subsetting!
if (doFiniteArea)
{
using reportFields = foamToVtkReportFields;
autoPtr<faMesh> faMeshPtr;
const label nAreaFields =
objects.count(stringListOps::foundOp<word>(fieldTypes::area));
if (nAreaFields)
{
const bool throwing = FatalError.throwExceptions();
try
{
faMeshPtr.reset(new faMesh(meshProxy.baseMesh()));
}
catch (const Foam::error& err)
{
faMeshPtr.clear();
}
FatalError.throwExceptions(throwing);
}
if (faMeshPtr && nAreaFields)
{
reportFields::area(Info, objects);
const auto& pp = faMeshPtr->patch();
vtk::surfaceMeshWriter writer
(
pp,
writeOpts,
(
outputDir/regionPrefix/"finite-area"
/ "finiteArea" + timeDesc
),
Pstream::parRun()
);
writer.beginFile(faMeshPtr->name());
writer.writeTimeValue(timeValue);
writer.writeGeometry();
writer.beginCellData(nAreaFields);
writeAllAreaFields
(
writer,
*faMeshPtr,
objects,
true // syncPar
);
fileName outputName(writer.output());
writer.close();
if (Pstream::master())
{
// Add to file-series and emit as JSON
fileName seriesName(vtk::seriesWriter::base(outputName));
vtk::seriesWriter& series = vtkSeries(seriesName);
// First time?
// Load from file, verify against filesystem,
// prune time >= currentTime
if (series.empty())
{
series.load(seriesName, true, timeValue);
}
series.append(timeValue, outputName);
series.write(seriesName);
}
}
}
// ************************************************************************* //