From e5e89deabd3630f7120a11f0723a6ab7bb8bac65 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 16 May 2008 17:00:34 +0200 Subject: [PATCH] sampledSurfaces : avoid crash with empty surfaces --- .../sampledSurfaces/IOsampledSurfaces.C.save | 86 ------------- .../sampledSurfaces/IOsampledSurfaces.H.save | 115 ------------------ .../sampledSurfacesTemplates.C | 48 +++++--- 3 files changed, 28 insertions(+), 221 deletions(-) delete mode 100644 src/sampling/sampledSurface/sampledSurfaces/IOsampledSurfaces.C.save delete mode 100644 src/sampling/sampledSurface/sampledSurfaces/IOsampledSurfaces.H.save diff --git a/src/sampling/sampledSurface/sampledSurfaces/IOsampledSurfaces.C.save b/src/sampling/sampledSurface/sampledSurfaces/IOsampledSurfaces.C.save deleted file mode 100644 index 417791963c..0000000000 --- a/src/sampling/sampledSurface/sampledSurfaces/IOsampledSurfaces.C.save +++ /dev/null @@ -1,86 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -\*---------------------------------------------------------------------------*/ - -#include "IOsampledSurfaces.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::IOsampledSurfaces::IOsampledSurfaces -( - const objectRegistry& obr, - const fileName& dictName, - const bool loadFromFiles -) -: - IOdictionary - ( - IOobject - ( - dictName, - obr.time().system(), - obr, - IOobject::MUST_READ, - IOobject::NO_WRITE - ) - ), - sampledSurfaces(obr, *this, loadFromFiles) -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::IOsampledSurfaces::~IOsampledSurfaces() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::IOsampledSurfaces::read() -{ - if (regIOobject::read()) - { - sampledSurfaces::read(*this); - return true; - } - else - { - return false; - } -} - - -void Foam::IOsampledSurfaces::write() -{ - sampledSurfaces::write(); -} - - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledSurfaces/IOsampledSurfaces.H.save b/src/sampling/sampledSurface/sampledSurfaces/IOsampledSurfaces.H.save deleted file mode 100644 index 0a243cb98f..0000000000 --- a/src/sampling/sampledSurface/sampledSurfaces/IOsampledSurfaces.H.save +++ /dev/null @@ -1,115 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -Class - IOsampledSurfaces - -Description - Set of surfaces to sample. - Call surfaces.write() to sample and write files. - -SourceFiles - surfaces.C - -\*---------------------------------------------------------------------------*/ - -#ifndef IOsampledSurfaces_H -#define IOsampledSurfaces_H - -#include "sampledSurfaces.H" -#include "IOdictionary.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class IOsampledSurfaces Declaration -\*---------------------------------------------------------------------------*/ - -class IOsampledSurfaces -: - public IOdictionary, - public sampledSurfaces -{ - // Private Member Functions - - //- Disallow default bitwise copy construct and assignment - IOsampledSurfaces(const IOsampledSurfaces&); - void operator=(const IOsampledSurfaces&); - -public: - - // Constructors - - //- Construct for given objectRegistry and dictionary - // allow the possibility to read from files - IOsampledSurfaces - ( - const objectRegistry& obr, - const fileName& dictName = "sampleSurfaceDict", - const bool loadFromFiles = false - ); - - - // Destructor - - virtual ~IOsampledSurfaces(); - - - // Member Functions - - //- Read the surfaces - virtual bool read(); - - //- Write the surfaces - virtual void write(); - - - //- Update for changes of mesh - void updateMesh(const mapPolyMesh&) - { - read(); - sampledSurfaces::correct(true); - } - - //- Update for changes of mesh - void movePoints(const pointField&) - { - read(); - sampledSurfaces::correct(true); - } -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index 214c9bc93a..abb811f752 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -143,31 +143,39 @@ void Foam::sampledSurfaces::sampleAndWrite } // Write to time directory under outputPath_ - formatter.write - ( - outputPath_, - timeDir, - s.name(), - mergeList_[surfI].points, - mergeList_[surfI].faces, - fieldName, - allValues - ); + // skip surface without faces (eg, a failed cut-plane) + if (mergeList_[surfI].faces.size()) + { + formatter.write + ( + outputPath_, + timeDir, + s.name(), + mergeList_[surfI].points, + mergeList_[surfI].faces, + fieldName, + allValues + ); + } } } else { // Write to time directory under outputPath_ - formatter.write - ( - outputPath_, - timeDir, - s.name(), - s.points(), - s.faces(), - fieldName, - values - ); + // skip surface without faces (eg, a failed cut-plane) + if (s.faces().size()) + { + formatter.write + ( + outputPath_, + timeDir, + s.name(), + s.points(), + s.faces(), + fieldName, + values + ); + } } } }