From 003e62fadced1e2083eaded46109de5f29f664ab Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 29 Feb 2012 11:51:42 +0000 Subject: [PATCH] ENH: distanceSurface: use either cell (default) or cross-cell isosurface --- .../distanceSurface/distanceSurface.C | 95 +++++++++++++++---- .../distanceSurface/distanceSurface.H | 41 ++++++-- .../distanceSurfaceTemplates.C | 48 ++++++++-- 3 files changed, 149 insertions(+), 35 deletions(-) diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C index 6b557df918..7d9c4eace4 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -49,6 +49,8 @@ void Foam::distanceSurface::createGeometry() // Clear any stored topologies facesPtr_.clear(); + isoSurfCellPtr_.clear(); + isoSurfPtr_.clear(); // Clear derived data clearGeom(); @@ -265,24 +267,33 @@ void Foam::distanceSurface::createGeometry() //- Direct from cell field and point field. - isoSurfPtr_.reset - ( - new isoSurface + if (cell_) + { + isoSurfCellPtr_.reset ( - cellDistance, - pointDistance_, - distance_, - regularise_ - ) - //new isoSurfaceCell - //( - // fvm, - // cellDistance, - // pointDistance_, - // distance_, - // regularise_ - //) - ); + new isoSurfaceCell + ( + fvm, + cellDistance, + pointDistance_, + distance_, + regularise_ + ) + ); + } + else + { + isoSurfPtr_.reset + ( + new isoSurface + ( + cellDistance, + pointDistance_, + distance_, + regularise_ + ) + ); + } if (debug) { @@ -321,10 +332,12 @@ Foam::distanceSurface::distanceSurface ), distance_(readScalar(dict.lookup("distance"))), signed_(readBool(dict.lookup("signed"))), + cell_(dict.lookupOrDefault("cell", true)), regularise_(dict.lookupOrDefault("regularise", true)), average_(dict.lookupOrDefault("average", false)), zoneKey_(keyType::null), needsUpdate_(true), + isoSurfCellPtr_(NULL), isoSurfPtr_(NULL), facesPtr_(NULL) { @@ -338,6 +351,52 @@ Foam::distanceSurface::distanceSurface } + +Foam::distanceSurface::distanceSurface +( + const word& name, + const polyMesh& mesh, + const bool interpolate, + const word& surfaceType, + const word& surfaceName, + const scalar distance, + const bool signedDistance, + const bool cell, + const Switch regularise, + const Switch average +) +: + sampledSurface(name, mesh, interpolate), + surfPtr_ + ( + searchableSurface::New + ( + surfaceType, + IOobject + ( + surfaceName, // name + mesh.time().constant(), // directory + "triSurface", // instance + mesh.time(), // registry + IOobject::MUST_READ, + IOobject::NO_WRITE + ), + dictionary() + ) + ), + distance_(distance), + signed_(signedDistance), + cell_(cell), + regularise_(regularise), + average_(average), + zoneKey_(keyType::null), + needsUpdate_(true), + isoSurfCellPtr_(NULL), + isoSurfPtr_(NULL), + facesPtr_(NULL) +{} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::distanceSurface::~distanceSurface() diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H index a7040ba7f8..2b97197087 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,6 +27,8 @@ Class Description A sampledSurface defined by a distance to a surface. + Uses either isoSurfaceCell or isoSurface. + SourceFiles distanceSurface.C @@ -37,7 +39,7 @@ SourceFiles #include "sampledSurface.H" #include "searchableSurface.H" -//#include "isoSurfaceCell.H" +#include "isoSurfaceCell.H" #include "isoSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -64,6 +66,9 @@ class distanceSurface //- signed distance const bool signed_; + //- Whether to use isoSurfaceCell or isoSurface + const bool cell_; + //- Whether to coarsen const Switch regularise_; @@ -84,7 +89,9 @@ class distanceSurface scalarField pointDistance_; //- Constructed iso surface - //autoPtr isoSurfPtr_; + autoPtr isoSurfCellPtr_; + + //- Constructed iso surface autoPtr isoSurfPtr_; //- triangles converted to faceList @@ -125,6 +132,21 @@ public: const dictionary& dict ); + //- Construct from components + distanceSurface + ( + const word& name, + const polyMesh& mesh, + const bool interpolate, + const word& surfaceType, + const word& surfaceName, + const scalar distance, + const bool signedDistance, + const bool cell, + const Switch regularise, + const Switch average + ); + //- Destructor virtual ~distanceSurface(); @@ -167,11 +189,16 @@ public: return facesPtr_; } - - //const isoSurfaceCell& surface() const - const isoSurface& surface() const + const triSurface& surface() const { - return isoSurfPtr_(); + if (cell_) + { + return isoSurfCellPtr_(); + } + else + { + return isoSurfPtr_(); + } } //- sample field on surface diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C b/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C index 5701d09c24..d8871126ea 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -37,7 +37,20 @@ Foam::distanceSurface::sampleField const GeometricField& vField ) const { - return tmp >(new Field(vField, surface().meshCells())); + if (cell_) + { + return tmp > + ( + new Field(vField, isoSurfCellPtr_().meshCells()) + ); + } + else + { + return tmp > + ( + new Field(vField, isoSurfPtr_().meshCells()) + ); + } } @@ -60,15 +73,30 @@ Foam::distanceSurface::interpolateField ); // Sample. - return surface().interpolate - ( + if (cell_) + { + return isoSurfCellPtr_().interpolate ( - average_ - ? pointAverage(pointFld())() - : volFld - ), - pointFld() - ); + ( + average_ + ? pointAverage(pointFld())() + : volFld + ), + pointFld() + ); + } + else + { + return isoSurfPtr_().interpolate + ( + ( + average_ + ? pointAverage(pointFld())() + : volFld + ), + pointFld() + ); + } }