diff --git a/src/surfMesh/writers/vtk/vtkSurfaceWriter.C b/src/surfMesh/writers/vtk/vtkSurfaceWriter.C index 016351e62121bd28d76a65882aa29098b8f6c39a..ffbf0b4ff1421e242a2a2164303f8f568d55aeb3 100644 --- a/src/surfMesh/writers/vtk/vtkSurfaceWriter.C +++ b/src/surfMesh/writers/vtk/vtkSurfaceWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,6 +66,7 @@ Foam::surfaceWriters::vtkWriter::vtkWriter() surfaceWriter(), fmtType_(static_cast<unsigned>(vtk::formatType::INLINE_BASE64)), precision_(IOstream::defaultPrecision()), + writeNormal_(false), fieldScale_(), writer_(nullptr) {} @@ -79,6 +80,7 @@ Foam::surfaceWriters::vtkWriter::vtkWriter surfaceWriter(), fmtType_(static_cast<unsigned>(opts.fmt())), precision_(opts.precision()), + writeNormal_(false), fieldScale_(), writer_(nullptr) {} @@ -95,6 +97,7 @@ Foam::surfaceWriters::vtkWriter::vtkWriter ( options.getOrDefault("precision", IOstream::defaultPrecision()) ), + writeNormal_(options.getOrDefault("normal", false)), fieldScale_(options.subOrEmptyDict("fieldScale")), writer_(nullptr) { @@ -241,6 +244,29 @@ Foam::fileName Foam::surfaceWriters::vtkWriter::write() } writer_->writeGeometry(); + + if (writeNormal_) + { + const faceList& fcs = surf.faces(); + const pointField& pts = surf.points(); + + Field<vector> normals(fcs.size()); + forAll(fcs, facei) + { + normals[facei] = fcs[facei].areaNormal(pts); + } + + label nCellData = 1; + + if (!this->isPointData()) + { + // Ill-defined with legacy() if nFields_ not properly set... + nCellData += nFields_; + } + + writer_->beginCellData(nCellData); + writer_->write("area-normal", normals); + } } wroteGeom_ = true; diff --git a/src/surfMesh/writers/vtk/vtkSurfaceWriter.H b/src/surfMesh/writers/vtk/vtkSurfaceWriter.H index 0ae0972fd22e780f39aa358aa5fa1d763a575344..36d763c7f2796eb453a199361d4514679f457829 100644 --- a/src/surfMesh/writers/vtk/vtkSurfaceWriter.H +++ b/src/surfMesh/writers/vtk/vtkSurfaceWriter.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,7 +36,8 @@ Description format | ascii or binary format | no | binary legacy | Legacy VTK output | no | false precision | Write precision in ascii | no | same as IOstream - fieldScale | output field scaling (dictionary) | no | empty + fieldScale | Output field scaling (dictionary) | no | empty + normal | Write face area-normal in output | no | false \endtable For example, @@ -110,6 +111,9 @@ class vtkWriter //- ASCII write precision unsigned precision_; + //- Output face area normal + const bool writeNormal_; + //- Output field scaling const dictionary fieldScale_;