/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2019-2021 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 . \*---------------------------------------------------------------------------*/ #include "surfaceWriter.H" #include "proxySurfaceWriter.H" #include "MeshedSurfaceProxy.H" #include "Time.H" #include "globalIndex.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(surfaceWriter, 0); defineRunTimeSelectionTable(surfaceWriter, word); defineRunTimeSelectionTable(surfaceWriter, wordDict); } Foam::scalar Foam::surfaceWriter::defaultMergeDim = 1e-8; const Foam::meshedSurf::emptySurface Foam::surfaceWriter::emptySurface_; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // bool Foam::surfaceWriter::supportedType(const word& writeType) { return ( wordConstructorTablePtr_->found(writeType) || wordDictConstructorTablePtr_->found(writeType) || MeshedSurfaceProxy::canWriteType(writeType) ); } Foam::autoPtr Foam::surfaceWriter::New(const word& writeType) { // Constructors without dictionary options auto cstrIter = wordConstructorTablePtr_->cfind(writeType); if (!cstrIter.found()) { if (MeshedSurfaceProxy::canWriteType(writeType)) { // Generally unknown, but handle via 'proxy' handler return autoPtr ( new surfaceWriters::proxyWriter(writeType) ); } FatalErrorInFunction << "Unknown write type \"" << writeType << "\"\n\n" << "Valid write types : " << flatOutput(wordConstructorTablePtr_->sortedToc()) << nl << "Valid proxy types : " << MeshedSurfaceProxy::writeTypes() << endl << exit(FatalError); } return autoPtr(cstrIter()()); } Foam::autoPtr Foam::surfaceWriter::New ( const word& writeType, const dictionary& writeOpts ) { // Constructors with dictionary options auto cstrIter2 = wordDictConstructorTablePtr_->cfind(writeType); if (cstrIter2.found()) { return autoPtr(cstrIter2()(writeOpts)); } // Constructors without dictionary options auto cstrIter = wordConstructorTablePtr_->cfind(writeType); if (!cstrIter.found()) { if (MeshedSurfaceProxy::canWriteType(writeType)) { // Generally unknown, but handle via 'proxy' handler return autoPtr ( new surfaceWriters::proxyWriter(writeType, writeOpts) ); } FatalErrorInFunction << "Unknown write type \"" << writeType << "\"\n\n" << "Valid write types : " << wordConstructorTablePtr_->sortedToc() << nl << "Valid proxy types : " << MeshedSurfaceProxy::writeTypes() << endl << exit(FatalError); } return autoPtr(cstrIter()()); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::surfaceWriter::surfaceWriter() : surf_(std::cref(emptySurface_)), surfComp_(), useComponents_(false), upToDate_(false), wroteGeom_(false), parallel_(true), useTimeDir_(false), isPointData_(false), verbose_(false), nFields_(0), mergeDim_(defaultMergeDim), merged_(), currTime_(), outputPath_() { surfaceWriter::close(); } Foam::surfaceWriter::surfaceWriter(const dictionary& options) : surfaceWriter() { options.readIfPresent("verbose", verbose_); } Foam::surfaceWriter::surfaceWriter ( const meshedSurf& surf, bool parallel, const dictionary& options ) : surfaceWriter(options) { setSurface(surf, parallel); } Foam::surfaceWriter::surfaceWriter ( const pointField& points, const faceList& faces, bool parallel, const dictionary& options ) : surfaceWriter(options) { setSurface(points, faces, parallel); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::surfaceWriter::~surfaceWriter() { close(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::surfaceWriter::setTime(const instant& inst) { currTime_ = inst; } void Foam::surfaceWriter::setTime(scalar timeValue) { currTime_ = instant(timeValue); } void Foam::surfaceWriter::setTime(scalar timeValue, const word& timeName) { currTime_.value() = timeValue; currTime_.name() = timeName; } void Foam::surfaceWriter::unsetTime() { currTime_.value() = 0; currTime_.name().clear(); } void Foam::surfaceWriter::beginTime(const Time& t) { setTime(t.value(), t.timeName()); } void Foam::surfaceWriter::beginTime(const instant& inst) { setTime(inst); } void Foam::surfaceWriter::endTime() { unsetTime(); } void Foam::surfaceWriter::open(const fileName& outputPath) { outputPath_ = outputPath; wroteGeom_ = false; } void Foam::surfaceWriter::open ( const meshedSurf& surf, const fileName& outputPath, bool parallel ) { close(); setSurface(surf, parallel); open(outputPath); } void Foam::surfaceWriter::open ( const pointField& points, const faceList& faces, const fileName& outputPath, bool parallel ) { close(); setSurface(points, faces, parallel); open(outputPath); } void Foam::surfaceWriter::open ( const meshedSurf& surf, const fileName& outputPath ) { close(); setSurface(surf, parallel_); open(outputPath); } void Foam::surfaceWriter::open ( const pointField& points, const faceList& faces, const fileName& outputPath ) { close(); setSurface(points, faces, parallel_); open(outputPath); } void Foam::surfaceWriter::close() { outputPath_.clear(); wroteGeom_ = false; } void Foam::surfaceWriter::clear() { close(); expire(); useComponents_ = false; surf_ = std::cref(emptySurface_); surfComp_.clear(); } void Foam::surfaceWriter::setSurface ( const meshedSurf& surf, bool parallel ) { expire(); useComponents_ = false; surf_ = std::cref(surf); surfComp_.clear(); parallel_ = (parallel && Pstream::parRun()); } void Foam::surfaceWriter::setSurface ( const pointField& points, const faceList& faces, bool parallel ) { expire(); useComponents_ = true; surf_ = std::cref(emptySurface_); surfComp_.reset(points, faces); parallel_ = (parallel && Pstream::parRun()); } void Foam::surfaceWriter::setSurface ( const meshedSurf& surf ) { setSurface(surf, parallel_); } void Foam::surfaceWriter::setSurface ( const pointField& points, const faceList& faces ) { setSurface(points, faces, parallel_); } bool Foam::surfaceWriter::needsUpdate() const { return !upToDate_; } bool Foam::surfaceWriter::wroteData() const { return wroteGeom_; } bool Foam::surfaceWriter::expire() { const bool changed = upToDate_; upToDate_ = false; wroteGeom_ = false; merged_.clear(); // Field count (nFields_) is a different type of accounting // and is unaffected by geometry changes return changed; } bool Foam::surfaceWriter::hasSurface() const { return (useComponents_ || (&emptySurface_ != &(surf_.get()))); } bool Foam::surfaceWriter::empty() const { const bool value = ( useComponents_ ? surfComp_.faces().empty() : surf_.get().faces().empty() ); return (parallel_ ? returnReduce(value, andOp()) : value); } Foam::label Foam::surfaceWriter::size() const { const label value = ( useComponents_ ? surfComp_.faces().size() : surf_.get().faces().size() ); return (parallel_ ? returnReduce(value, sumOp