diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/meshSubsetHelper.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/meshSubsetHelper.C new file mode 100644 index 0000000000..05bdc9420b --- /dev/null +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/meshSubsetHelper.C @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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 "meshSubsetHelper.H" + +#include "cellSet.H" +#include "cellZone.H" +#include "Time.H" +#include "IOstreams.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::meshSubsetHelper::meshSubsetHelper +( + fvMesh& baseMesh, + const word& name, + const bool isCellSet +) +: + baseMesh_(baseMesh), + subsetter_(baseMesh), + name_(name), + type_(name_.empty() ? 0 : isCellSet ? 1 : 2) +{ + correct(); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::meshSubsetHelper::correct(bool verbose) +{ + if (type_ == 1) + { + if (verbose) + { + Info<< "Subsetting mesh based on cellSet " << name_ << endl; + } + + cellSet subset(baseMesh_, name_); + subsetter_.setLargeCellSubset(subset); + } + else if (type_ == 2) + { + if (verbose) + { + Info<< "Subsetting mesh based on cellZone " << name_ << endl; + } + + labelHashSet subset(baseMesh_.cellZones()[name_]); + subsetter_.setLargeCellSubset(subset, 0); + } +} + + +Foam::polyMesh::readUpdateState Foam::meshSubsetHelper::readUpdate() +{ + polyMesh::readUpdateState meshState = baseMesh_.readUpdate(); + + if (meshState != polyMesh::UNCHANGED) + { + correct(true); + } + + return meshState; +} + + +// ************************************************************************* // diff --git a/src/fileFormats/ensight/part/ensightCells.C b/src/fileFormats/ensight/part/ensightCells.C index 5e17013314..8db55a927a 100644 --- a/src/fileFormats/ensight/part/ensightCells.C +++ b/src/fileFormats/ensight/part/ensightCells.C @@ -43,7 +43,7 @@ namespace Foam >::names[] = { "tetra4", "pyramid5", "penta6", "hexa8", "nfaced" }; } -const Foam::NamedEnum +const Foam::NamedEnum Foam::ensightCells::elemEnum; @@ -73,7 +73,7 @@ void Foam::ensightCells::resize() { n += sizes_[typeI]; } - address_.setSize(n, 0); + address_.setSize(n, Zero); // assign corresponding sub-lists n = 0; @@ -94,7 +94,7 @@ Foam::ensightCells::ensightCells(const label partIndex) : index_(partIndex), address_(), - sizes_(0), + sizes_(Zero), lists_() { // Ensure sub-lists are properly initialized to nullptr @@ -111,7 +111,7 @@ Foam::ensightCells::ensightCells(const ensightCells& obj) : index_(obj.index_), address_(obj.address_), - sizes_(0), + sizes_(), lists_() { // Ensure sub-lists are properly initialized to nullptr @@ -137,7 +137,6 @@ Foam::ensightCells::ensightCells(const ensightCells& obj) Foam::ensightCells::~ensightCells() { - sizes_ = 0; forAll(lists_, typeI) { deleteDemandDrivenData(lists_[typeI]); @@ -153,7 +152,7 @@ Foam::FixedList Foam::ensightCells::sizes() const FixedList count; forAll(lists_, typeI) { - count[typeI] = lists_[typeI] ? lists_[typeI]->size() : 0; + count[typeI] = lists_[typeI]->size(); } return count; @@ -173,7 +172,7 @@ Foam::label Foam::ensightCells::total() const void Foam::ensightCells::clear() { - sizes_ = 0; + sizes_ = Zero; // reset sizes resize(); } @@ -220,7 +219,7 @@ void Foam::ensightCells::classify // Count the shapes // Can avoid double looping, but only at the expense of allocation - sizes_ = 0; // reset sizes + sizes_ = Zero; // reset sizes for (label listI = 0; listI < sz; ++listI) { const label id = indirect ? addressing[listI] : listI; @@ -247,8 +246,8 @@ void Foam::ensightCells::classify sizes_[what]++; } - resize(); // adjust allocation - sizes_ = 0; // reset sizes + resize(); // adjust allocation + sizes_ = Zero; // reset sizes // Assign cell-id per shape type for (label listI = 0; listI < sz; ++listI) diff --git a/src/fileFormats/ensight/part/ensightFaces.C b/src/fileFormats/ensight/part/ensightFaces.C index d20e585ae4..e1e67153fd 100644 --- a/src/fileFormats/ensight/part/ensightFaces.C +++ b/src/fileFormats/ensight/part/ensightFaces.C @@ -43,7 +43,7 @@ namespace Foam >::names[] = { "tria3", "quad4", "nsided" }; } -const Foam::NamedEnum +const Foam::NamedEnum Foam::ensightFaces::elemEnum; @@ -109,7 +109,7 @@ void Foam::ensightFaces::resize() { n += sizes_[typeI]; } - address_.setSize(n, 0); + address_.setSize(n, Zero); // assign corresponding sub-lists n = 0; @@ -134,7 +134,7 @@ Foam::ensightFaces::ensightFaces(label partIndex) index_(partIndex), address_(), flipMap_(), - sizes_(0), + sizes_(Zero), lists_() { // Ensure sub-lists are properly initialized to nullptr @@ -152,7 +152,7 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj) index_(obj.index_), address_(obj.address_), flipMap_(obj.flipMap_), - sizes_(0), + sizes_(), lists_() { // Ensure sub-lists are properly initialized to nullptr @@ -178,7 +178,6 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj) Foam::ensightFaces::~ensightFaces() { - sizes_ = 0; forAll(lists_, typeI) { deleteDemandDrivenData(lists_[typeI]); @@ -215,7 +214,7 @@ Foam::label Foam::ensightFaces::total() const void Foam::ensightFaces::clear() { - sizes_ = 0; + sizes_ = Zero; // reset sizes resize(); } @@ -285,15 +284,15 @@ void Foam::ensightFaces::classify(const faceList& faces) // Count the shapes // Can avoid double looping, but only at the expense of allocation - sizes_ = 0; // reset sizes + sizes_ = Zero; // reset sizes for (label listI = 0; listI < sz; ++listI) { const enum elemType what = whatType(faces[listI]); sizes_[what]++; } - resize(); // adjust allocation - sizes_ = 0; // reset sizes + resize(); // adjust allocation + sizes_ = Zero; // reset sizes // Assign face-id per shape type for (label listI = 0; listI < sz; ++listI) @@ -320,7 +319,7 @@ void Foam::ensightFaces::classify // Count the shapes // Can avoid double looping, but only at the expense of allocation - sizes_ = 0; // reset sizes + sizes_ = Zero; // reset sizes for (label listI = 0; listI < sz; ++listI) { const label faceId = addressing[listI]; @@ -332,8 +331,8 @@ void Foam::ensightFaces::classify } } - resize(); // adjust allocation - sizes_ = 0; // reset sizes + resize(); // adjust allocation + sizes_ = Zero; // reset sizes if (useFlip) { diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/controlDict b/tutorials/incompressible/simpleFoam/motorBike/system/controlDict index 5678be2ee3..d728f0be9c 100644 --- a/tutorials/incompressible/simpleFoam/motorBike/system/controlDict +++ b/tutorials/incompressible/simpleFoam/motorBike/system/controlDict @@ -50,6 +50,7 @@ functions #include "wallBoundedStreamLines" #include "cuttingPlane" #include "forceCoeffs" + #include "ensightWrite" } diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/ensightWrite b/tutorials/incompressible/simpleFoam/motorBike/system/ensightWrite new file mode 100644 index 0000000000..34e7b14d71 --- /dev/null +++ b/tutorials/incompressible/simpleFoam/motorBike/system/ensightWrite @@ -0,0 +1,17 @@ +// -*- C++ -*- +// Minimal example of using the ensight write function object. +// Many more options possible +ensightWrite +{ + type ensightWrite; + libs ("libutilityFunctionObjects.so"); + log true; + + // Fields to output (words or regex) + fields (U p "(k|epsilon|omega)"); + + writeControl writeTime; + writeIterval 1; +} + +// ************************************************************************* //