Skip to content
Snippets Groups Projects
Commit c0feb565 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: optional face area normals output for VTK surface format

- similar to additional flag for the raw surface writer (#2003)

  Example,
  ```
  formatOptions
  {
      vtk
      {
          normal      yes;
      }
  }
parent 7c46daea
Branches
Tags
No related merge requests found
......@@ -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;
......
......@@ -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_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment