diff --git a/src/conversion/Make/files b/src/conversion/Make/files index 5d6233a1c6..eb9ac5e43c 100644 --- a/src/conversion/Make/files +++ b/src/conversion/Make/files @@ -26,6 +26,6 @@ polyDualMesh/polyDualMesh.C vtk/output/foamVtkInternalWriter.H vtk/output/foamVtkPatchWriter.H -vtk/output/foamVtkWriteSurfFields.C +vtk/output/foamVtkSurfaceFieldWriter.C LIB = $(FOAM_LIBBIN)/libconversion diff --git a/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.C b/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.C new file mode 100644 index 0000000000..7b439e8c5f --- /dev/null +++ b/src/conversion/vtk/output/foamVtkSurfaceFieldWriter.C @@ -0,0 +1,300 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "foamVtkSurfaceFieldWriter.H" +#include "emptyFvsPatchFields.H" +#include "fvsPatchFields.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::List Foam::vtk::surfaceFieldWriter::flattenBoundary +( + const surfaceVectorField& field +) const +{ + // Boundary field - flatten + + List flat(mesh_.nBoundaryFaces(), Zero); + + forAll(field.boundaryField(), patchi) + { + const polyPatch& pp = mesh_.boundaryMesh()[patchi]; + const auto& pfld = field.boundaryField()[patchi]; + + if (!isA(pfld)) + { + SubList(flat, pp.size(), pp.offset()) = pfld; + } + } + + return flat; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::vtk::surfaceFieldWriter::surfaceFieldWriter +( + const fvMesh& mesh, + const vtk::outputOptions opts +) +: + vtk::fileWriter(vtk::fileTag::POLY_DATA, opts), + mesh_(mesh), + numberOfPoints_(0) +{ + opts_.append(false); // No append mode (horrible for streaming) + opts_.legacy(false); // Disallow legacy (inconvenient) +} + + +Foam::vtk::surfaceFieldWriter::surfaceFieldWriter +( + const fvMesh& mesh, + const fileName& file, + bool parallel +) +: + surfaceFieldWriter(mesh) +{ + open(file, parallel); +} + + +Foam::vtk::surfaceFieldWriter::surfaceFieldWriter +( + const fvMesh& mesh, + const vtk::outputOptions opts, + const fileName& file, + bool parallel +) +: + surfaceFieldWriter(mesh, opts) +{ + open(file, parallel); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::vtk::surfaceFieldWriter::beginFile(std::string title) +{ + if (title.size()) + { + return vtk::fileWriter::beginFile(title); + } + + + // Provide Default title + + if (legacy()) + { + return vtk::fileWriter::beginFile("surfaceFields"); + } + + + // XML (inline) + + return vtk::fileWriter::beginFile + ( + "surfaceFields " + "case='" + mesh_.time().globalCaseName() + + "' region='" + mesh_.name() + + "' time='" + mesh_.time().timeName() + + "' index='" + Foam::name(mesh_.time().timeIndex()) + + "'" + ); +} + + +bool Foam::vtk::surfaceFieldWriter::writeGeometry() +{ + enter_Piece(); + + // Output + + const pointField& centres = mesh_.faceCentres(); + + // PointData for each face. + numberOfPoints_ = centres.size(); + + if (parallel_) + { + reduce(numberOfPoints_, sumOp