From 2857e9512fafd50b4a917de4aad823500cd0257a Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 20 Oct 2016 08:58:27 +0200 Subject: [PATCH] ENH: propagate face area to sampling (issue #266) - make top-level Sf(), magSf(), Cf() pure virtual since the sub-classes will always be providing the face/point storage, with either triSurface or MeshedSurface in the background --- .../distanceSurface/distanceSurface.H | 19 ++++ .../isoSurface/sampledIsoSurface.H | 34 +++++- .../isoSurface/sampledIsoSurfaceCell.H | 23 +++- .../sampledCuttingPlane/sampledCuttingPlane.H | 33 +++++- .../sampledPatch/sampledPatch.H | 21 +++- .../sampledPlane/sampledPlane.H | 21 +++- .../sampledSurface/sampledSurface.C | 105 ------------------ .../sampledSurface/sampledSurface.H | 36 ++---- .../sampledTriSurfaceMesh.H | 20 +++- .../sampledThresholdCellFaces.H | 21 +++- 10 files changed, 187 insertions(+), 146 deletions(-) diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H index 755eb818e4..407e8914db 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H @@ -193,6 +193,25 @@ public: return facesPtr_; } + //- Face area vectors + virtual const vectorField& Sf() const + { + return surface().Sf(); + } + + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return surface().magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return surface().Cf(); + } + + const triSurface& surface() const { if (cell_) diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H index a0ea506337..19efe340b7 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H @@ -158,6 +158,11 @@ public: // Member Functions + const isoSurface& surface() const + { + return surfPtr_(); + } + //- Does the surface need an update? virtual bool needsUpdate() const; @@ -194,16 +199,32 @@ public: return facesPtr_; } - - const isoSurface& surface() const + //- Face area magnitudes + virtual const vectorField& Sf() const { - return surfPtr_(); + return surface().Sf(); } - //- Lookup or read isoField. Sets volFieldPtr_ and pointFieldPtr_. + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return surface().magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return surface().Cf(); + } + + + //- Lookup or read isoField. + // Sets volFieldPtr_ and pointFieldPtr_. void getIsoField(); + // Sample + //- Sample field on surface virtual tmp sample ( @@ -235,6 +256,8 @@ public: ) const; + // Interpolate + //- Interpolate field on surface virtual tmp interpolate ( @@ -265,6 +288,9 @@ public: const interpolation& ) const; + + // Output + //- Write virtual void print(Ostream&) const; }; diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H index b404976ee0..f7a267aa9d 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H @@ -54,6 +54,9 @@ class sampledIsoSurfaceCell public sampledSurface, public triSurface { + //- Private typedef for convenience + typedef triSurface MeshStorage; + // Private data //- Field to get isoSurface of @@ -145,7 +148,7 @@ public: //- Points of surface virtual const pointField& points() const { - return triSurface::points(); + return MeshStorage::points(); } //- Faces of surface @@ -165,6 +168,24 @@ public: return facesPtr_; } + //- Face area magnitudes + virtual const vectorField& Sf() const + { + return MeshStorage::Sf(); + } + + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return MeshStorage::magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return MeshStorage::Cf(); + } + //- Sample field on surface virtual tmp sample diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H index eb50106b59..c4fb497767 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H @@ -141,6 +141,12 @@ public: // Member Functions + //const isoSurfaceCell& surface() const + const isoSurface& surface() const + { + return isoSurfPtr_(); + } + //- Does the surface need an update? virtual bool needsUpdate() const; @@ -176,13 +182,27 @@ public: return facesPtr_; } - - //const isoSurfaceCell& surface() const - const isoSurface& surface() const + //- Face area magnitudes + virtual const vectorField& Sf() const { - return isoSurfPtr_(); + return surface().Sf(); } + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return surface().magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return surface().Cf(); + } + + + // Sample + //- Sample field on surface virtual tmp sample ( @@ -214,6 +234,8 @@ public: ) const; + // Interpolate + //- Interpolate field on surface virtual tmp interpolate ( @@ -244,6 +266,9 @@ public: const interpolation& ) const; + + // Output + //- Write virtual void print(Ostream&) const; }; diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H index b16ddef634..e47d7494ba 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -180,8 +180,27 @@ public: return MeshStorage::faces(); } + //- Face area vectors + virtual const vectorField& Sf() const + { + return MeshStorage::Sf(); + } + + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return MeshStorage::magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return MeshStorage::Cf(); + } + // Sample + //- Sample field on surface virtual tmp sample ( diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.H b/src/sampling/sampledSurface/sampledPlane/sampledPlane.H index 6746361c1e..6269d39d9a 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.H +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -140,6 +140,25 @@ public: return cuttingPlane::faces(); } + //- Face area magnitudes + virtual const vectorField& Sf() const + { + return cuttingPlane::Sf(); + } + + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return cuttingPlane::magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return cuttingPlane::Cf(); + } + + //- For every face original cell in mesh const labelList& meshCells() const { diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C index d1281cfb45..ddaea516a0 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C @@ -41,76 +41,10 @@ namespace Foam void Foam::sampledSurface::clearGeom() const { - deleteDemandDrivenData(SfPtr_); - deleteDemandDrivenData(magSfPtr_); - deleteDemandDrivenData(CfPtr_); area_ = -1; } -void Foam::sampledSurface::makeSf() const -{ - // It is an error to recalculate if the pointer is already set - if (SfPtr_) - { - FatalErrorInFunction - << "face area vectors already exist" - << abort(FatalError); - } - - const faceList& theFaces = faces(); - SfPtr_ = new vectorField(theFaces.size()); - - vectorField& values = *SfPtr_; - forAll(theFaces, facei) - { - values[facei] = theFaces[facei].normal(points()); - } -} - - -void Foam::sampledSurface::makeMagSf() const -{ - // It is an error to recalculate if the pointer is already set - if (magSfPtr_) - { - FatalErrorInFunction - << "mag face areas already exist" - << abort(FatalError); - } - - const faceList& theFaces = faces(); - magSfPtr_ = new scalarField(theFaces.size()); - - scalarField& values = *magSfPtr_; - forAll(theFaces, facei) - { - values[facei] = theFaces[facei].mag(points()); - } -} - - -void Foam::sampledSurface::makeCf() const -{ - // It is an error to recalculate if the pointer is already set - if (CfPtr_) - { - FatalErrorInFunction - << "face centres already exist" - << abort(FatalError); - } - - const faceList& theFaces = faces(); - CfPtr_ = new vectorField(theFaces.size()); - - vectorField& values = *CfPtr_; - forAll(theFaces, facei) - { - values[facei] = theFaces[facei].centre(points()); - } -} - - // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * // Foam::autoPtr Foam::sampledSurface::New @@ -156,9 +90,6 @@ Foam::sampledSurface::sampledSurface name_(name), mesh_(mesh), interpolate_(interpolate), - SfPtr_(nullptr), - magSfPtr_(nullptr), - CfPtr_(nullptr), area_(-1) {} @@ -173,9 +104,6 @@ Foam::sampledSurface::sampledSurface name_(name), mesh_(mesh), interpolate_(dict.lookupOrDefault("interpolate", false)), - SfPtr_(nullptr), - magSfPtr_(nullptr), - CfPtr_(nullptr), area_(-1) { dict.readIfPresent("name", name_); @@ -192,39 +120,6 @@ Foam::sampledSurface::~sampledSurface() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -const Foam::vectorField& Foam::sampledSurface::Sf() const -{ - if (!SfPtr_) - { - makeSf(); - } - - return *SfPtr_; -} - - -const Foam::scalarField& Foam::sampledSurface::magSf() const -{ - if (!magSfPtr_) - { - makeMagSf(); - } - - return *magSfPtr_; -} - - -const Foam::vectorField& Foam::sampledSurface::Cf() const -{ - if (!CfPtr_) - { - makeCf(); - } - - return *CfPtr_; -} - - Foam::scalar Foam::sampledSurface::area() const { if (area_ < 0) diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H index b0a19707a9..3ddf4c2980 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -98,31 +98,10 @@ class sampledSurface // Demand-driven data - //- Face area vectors - mutable vectorField* SfPtr_; - - //- Mag face area vectors - mutable scalarField* magSfPtr_; - - //- Face centres - mutable vectorField* CfPtr_; - //- Total surface area mutable scalar area_; - // Make geometric data - - //- Make Sf - void makeSf() const; - - //- Make magSf - void makeMagSf() const; - - //- Make Cf - void makeCf() const; - - // Service methods //- Check field size matches surface size @@ -284,18 +263,19 @@ public: //- Faces of surface virtual const faceList& faces() const = 0; - //- Return face area vectors - virtual const vectorField& Sf() const; + //- Face area vectors + virtual const vectorField& Sf() const = 0; - //- Return face area magnitudes - virtual const scalarField& magSf() const; + //- Face area magnitudes + virtual const scalarField& magSf() const = 0; - //- Return face centres as vectorField - virtual const vectorField& Cf() const; + //- Face centres + virtual const vectorField& Cf() const = 0; //- The total surface area scalar area() const; + //- Integration of a field across the surface template Type integrate(const Field&) const; diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H index 6a41255075..1d62d0a02a 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -216,6 +216,24 @@ public: return MeshStorage::faces(); } + //- Face area vectors + virtual const vectorField& Sf() const + { + return MeshStorage::Sf(); + } + + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return MeshStorage::magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return MeshStorage::Cf(); + } + //- Sample field on surface virtual tmp sample diff --git a/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H index 840a9920ad..2fa91d2345 100644 --- a/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H +++ b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -148,6 +148,25 @@ public: return MeshStorage::faces(); } + //- Face area vectors (normals) + virtual const vectorField& Sf() const + { + return MeshStorage::Sf(); + } + + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return MeshStorage::magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return MeshStorage::Cf(); + } + + //- Sample field on surface virtual tmp sample(const volScalarField&) const;