From 60a18983994ebe925ebb86a8516ad7f926192959 Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 3 Mar 2010 14:59:02 +0000 Subject: [PATCH 01/21] STYLE: Fixed creation date --- .../sampledTriSurfaceMesh/sampledTriSurfaceMesh.C | 4 ++-- .../sampledTriSurfaceMesh/sampledTriSurfaceMesh.H | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C index 58b200832b..7e9274616e 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -146,7 +146,7 @@ bool Foam::sampledTriSurfaceMesh::update() // Find the cells the triangles of the surface are in. // Does approximation by looking at the face centres only - const pointField fc = surface_.faceCentres(); + const pointField& fc = surface_.faceCentres(); cellLabels_.setSize(fc.size()); diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H index 1c1aabebcf..eef8a16224 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License From af32ffeaad6455525484c1f1b60cdcee50bb9cd0 Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 3 Mar 2010 14:59:39 +0000 Subject: [PATCH 02/21] ENH: Implement gradient coupled temperature bc as fixedGradient instead of fixedValue. --- ...allHeatFluxTemperatureFvPatchScalarField.C | 29 ++++++++++--------- ...allHeatFluxTemperatureFvPatchScalarField.H | 4 +-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C index b1f8c3bed2..5013a4e6a2 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C @@ -38,7 +38,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const DimensionedField& iF ) : - fixedValueFvPatchScalarField(p, iF), + fixedGradientFvPatchScalarField(p, iF), q_(p.size(), 0.0), KName_("undefined-K") {} @@ -53,7 +53,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const fvPatchFieldMapper& mapper ) : - fixedValueFvPatchScalarField(ptf, p, iF, mapper), + fixedGradientFvPatchScalarField(ptf, p, iF, mapper), q_(ptf.q_, mapper), KName_(ptf.KName_) {} @@ -67,7 +67,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const dictionary& dict ) : - fixedValueFvPatchScalarField(p, iF, dict), + fixedGradientFvPatchScalarField(p, iF, dict), q_("q", dict, p.size()), KName_(dict.lookup("K")) {} @@ -79,7 +79,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const solidWallHeatFluxTemperatureFvPatchScalarField& tppsf ) : - fixedValueFvPatchScalarField(tppsf), + fixedGradientFvPatchScalarField(tppsf), q_(tppsf.q_), KName_(tppsf.KName_) {} @@ -92,7 +92,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const DimensionedField& iF ) : - fixedValueFvPatchScalarField(tppsf, iF), + fixedGradientFvPatchScalarField(tppsf, iF), q_(tppsf.q_), KName_(tppsf.KName_) {} @@ -105,7 +105,7 @@ void Foam::solidWallHeatFluxTemperatureFvPatchScalarField::autoMap const fvPatchFieldMapper& m ) { - fixedValueFvPatchScalarField::autoMap(m); + fixedGradientFvPatchScalarField::autoMap(m); q_.autoMap(m); } @@ -116,7 +116,7 @@ void Foam::solidWallHeatFluxTemperatureFvPatchScalarField::rmap const labelList& addr ) { - fixedValueFvPatchScalarField::rmap(ptf, addr); + fixedGradientFvPatchScalarField::rmap(ptf, addr); const solidWallHeatFluxTemperatureFvPatchScalarField& hfptf = refCast(ptf); @@ -132,14 +132,14 @@ void Foam::solidWallHeatFluxTemperatureFvPatchScalarField::updateCoeffs() return; } - const scalarField& Kw = - patch().lookupPatchField(KName_); + const scalarField& Kw = patch().lookupPatchField + ( + KName_ + ); - const fvPatchScalarField& Tw = *this; + gradient() = q_/Kw; - operator==(q_/(patch().deltaCoeffs()*Kw) + Tw.patchInternalField()); - - fixedValueFvPatchScalarField::updateCoeffs(); + fixedGradientFvPatchScalarField::updateCoeffs(); } @@ -148,9 +148,10 @@ void Foam::solidWallHeatFluxTemperatureFvPatchScalarField::write Ostream& os ) const { - fixedValueFvPatchScalarField::write(os); + fixedGradientFvPatchScalarField::write(os); q_.writeEntry("q", os); os.writeKeyword("K") << KName_ << token::END_STATEMENT << nl; + this->writeEntry("value", os); } diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.H index 85a1ef1cf1..d621e4d15a 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.H @@ -46,7 +46,7 @@ SourceFiles #ifndef solidWallHeatFluxTemperatureFvPatchScalarField_H #define solidWallHeatFluxTemperatureFvPatchScalarField_H -#include "fixedValueFvPatchFields.H" +#include "fixedGradientFvPatchFields.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -59,7 +59,7 @@ namespace Foam class solidWallHeatFluxTemperatureFvPatchScalarField : - public fixedValueFvPatchScalarField + public fixedGradientFvPatchScalarField { // Private data From 1a87cd16fbdd2f12b68130e357dd309f101449ce Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 4 Mar 2010 13:45:44 +0000 Subject: [PATCH 03/21] ENH: Add averaging to all iso-surface based sampledSurfaces. The optional 'average' switch causes use of the average-of-pointvalues instead of the original volField. --- .../distanceSurface/distanceSurface.C | 1 + .../distanceSurface/distanceSurface.H | 3 + .../distanceSurfaceTemplates.C | 10 +- .../isoSurface/sampledIsoSurface.C | 100 +----------------- .../isoSurface/sampledIsoSurface.H | 12 --- .../isoSurface/sampledIsoSurfaceTemplates.C | 20 +++- .../sampledCuttingPlane/sampledCuttingPlane.C | 1 + .../sampledCuttingPlane/sampledCuttingPlane.H | 3 + .../sampledCuttingPlaneTemplates.C | 20 +++- .../sampledSurface/sampledSurface.H | 7 ++ .../sampledSurface/sampledSurfaceTemplates.C | 55 ++++++++++ 11 files changed, 120 insertions(+), 112 deletions(-) diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C index 888b51b9c6..92e8694874 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C @@ -284,6 +284,7 @@ Foam::distanceSurface::distanceSurface distance_(readScalar(dict.lookup("distance"))), signed_(readBool(dict.lookup("signed"))), regularise_(dict.lookupOrDefault("regularise", true)), + average_(dict.lookupOrDefault("average", false)), zoneName_(word::null), needsUpdate_(true), isoSurfPtr_(NULL), diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H index b46546abbf..9fd2ffd9f0 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H @@ -68,6 +68,9 @@ class distanceSurface //- Whether to coarsen const Switch regularise_; + //- Whether to recalculate cell values as average of point values + const Switch average_; + //- zone name (if restricted to zones) word zoneName_; diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C b/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C index 1a66028f95..ea54214fb6 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C @@ -62,7 +62,15 @@ Foam::distanceSurface::interpolateField ); // Sample. - return surface().interpolate(volFld, pointFld()); + return surface().interpolate + ( + ( + average_ + ? pointAverage(pointFld())() + : volFld + ), + pointFld() + ); } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C index 235af8607a..11a0d74cae 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C @@ -164,7 +164,10 @@ void Foam::sampledIsoSurface::getIsoFields() const // point field. if (average_) { - storedVolFieldPtr_.reset(average(fvm, *pointFieldPtr_).ptr()); + storedVolFieldPtr_.reset + ( + pointAverage(*pointFieldPtr_).ptr() + ); volFieldPtr_ = storedVolFieldPtr_.operator->(); } @@ -265,7 +268,7 @@ void Foam::sampledIsoSurface::getIsoFields() const { storedVolSubFieldPtr_.reset ( - average(subFvm, *pointSubFieldPtr_).ptr() + pointAverage(*pointSubFieldPtr_).ptr() ); volSubFieldPtr_ = storedVolSubFieldPtr_.operator->(); } @@ -286,99 +289,6 @@ void Foam::sampledIsoSurface::getIsoFields() const } -Foam::tmp Foam::sampledIsoSurface::average -( - const fvMesh& mesh, - const pointScalarField& pfld -) const -{ - tmp tcellAvg - ( - new volScalarField - ( - IOobject - ( - "cellAvg", - mesh.time().timeName(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - mesh, - dimensionedScalar("zero", dimless, scalar(0.0)) - ) - ); - volScalarField& cellAvg = tcellAvg(); - - labelField nPointCells(mesh.nCells(), 0); - { - for (label pointI = 0; pointI < mesh.nPoints(); pointI++) - { - const labelList& pCells = mesh.pointCells(pointI); - - forAll(pCells, i) - { - label cellI = pCells[i]; - - cellAvg[cellI] += pfld[pointI]; - nPointCells[cellI]++; - } - } - } - forAll(cellAvg, cellI) - { - cellAvg[cellI] /= nPointCells[cellI]; - } - // Give value to calculatedFvPatchFields - cellAvg.correctBoundaryConditions(); - - return tcellAvg; -} - - -Foam::tmp Foam::sampledIsoSurface::average -( - const pointMesh& pMesh, - const volScalarField& fld -) const -{ - tmp tpointAvg - ( - new pointScalarField - ( - IOobject - ( - "pointAvg", - fld.time().timeName(), - fld.db(), - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - pMesh, - dimensionedScalar("zero", dimless, scalar(0.0)) - ) - ); - pointScalarField& pointAvg = tpointAvg(); - - for (label pointI = 0; pointI < fld.mesh().nPoints(); pointI++) - { - const labelList& pCells = fld.mesh().pointCells(pointI); - - forAll(pCells, i) - { - pointAvg[pointI] += fld[pCells[i]]; - } - pointAvg[pointI] /= pCells.size(); - } - // Give value to calculatedFvPatchFields - pointAvg.correctBoundaryConditions(); - - return tpointAvg; -} - - bool Foam::sampledIsoSurface::updateGeometry() const { const fvMesh& fvm = static_cast(mesh()); diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H index ccaa4d8750..990ee4c476 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H @@ -118,18 +118,6 @@ class sampledIsoSurface //- Get fields needed to recreate iso surface. void getIsoFields() const; - tmp average - ( - const fvMesh&, - const pointScalarField& - ) const; - - tmp average - ( - const pointMesh&, - const volScalarField& fld - ) const; - //- Create iso surface (if time has changed) // Do nothing (and return false) if no update was needed bool updateGeometry() const; diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C index a8dfa78506..40f05bd206 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C @@ -71,7 +71,15 @@ Foam::sampledIsoSurface::interpolateField volPointInterpolation::New(volSubFld.mesh()).interpolate(volSubFld); // Sample. - return surface().interpolate(volSubFld, tpointSubFld()); + return surface().interpolate + ( + ( + average_ + ? pointAverage(tpointSubFld())() + : volSubFld + ), + tpointSubFld() + ); } else { @@ -79,7 +87,15 @@ Foam::sampledIsoSurface::interpolateField volPointInterpolation::New(volFld.mesh()).interpolate(volFld); // Sample. - return surface().interpolate(volFld, tpointFld()); + return surface().interpolate + ( + ( + average_ + ? pointAverage(tpointFld())() + : volFld + ), + tpointFld() + ); } } diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C index 2bcf3784b6..5e369ed533 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C @@ -254,6 +254,7 @@ Foam::sampledCuttingPlane::sampledCuttingPlane plane_(dict), mergeTol_(dict.lookupOrDefault("mergeTol", 1E-6)), regularise_(dict.lookupOrDefault("regularise", true)), + average_(dict.lookupOrDefault("average", false)), zoneID_(dict.lookupOrDefault("zone", word::null), mesh.cellZones()), exposedPatchName_(word::null), needsUpdate_(true), diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H index fcf14db8bd..54e0f6627c 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H @@ -66,6 +66,9 @@ class sampledCuttingPlane //- Whether to coarsen const Switch regularise_; + //- Whether to recalculate cell values as average of point values + const Switch average_; + //- zone name/index (if restricted to zones) mutable cellZoneID zoneID_; diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C index ad1d97ffe9..ea0ed6bf47 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C @@ -67,7 +67,15 @@ Foam::sampledCuttingPlane::interpolateField volPointInterpolation::New(volSubFld.mesh()).interpolate(volSubFld); // Sample. - return surface().interpolate(volSubFld, tpointSubFld()); + return surface().interpolate + ( + ( + average_ + ? pointAverage(tpointSubFld())() + : volSubFld + ), + tpointSubFld() + ); } else { @@ -77,7 +85,15 @@ Foam::sampledCuttingPlane::interpolateField ); // Sample. - return surface().interpolate(volFld, tpointFld()); + return surface().interpolate + ( + ( + average_ + ? pointAverage(tpointFld())() + : volFld + ), + tpointFld() + ); } } diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H index 265b5c3db7..837e8aa159 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H @@ -312,6 +312,13 @@ public: //- Project field onto surface tmp > project(const Field&) const; + //- Interpolate from points to cell centre + template + tmp > pointAverage + ( + const GeometricField& pfld + ) const; + //- Sample field on surface virtual tmp sample ( diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C b/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C index 3aff356cef..d943792bd2 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C @@ -155,4 +155,59 @@ Foam::sampledSurface::project } +template +Foam::tmp > +Foam::sampledSurface::pointAverage +( + const GeometricField& pfld +) const +{ + const fvMesh& mesh = dynamic_cast(pfld.mesh()()); + + tmp > tcellAvg + ( + new GeometricField + ( + IOobject + ( + "cellAvg", + mesh.time().timeName(), + pfld.db(), + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + mesh, + dimensioned("zero", dimless, pTraits::zero) + ) + ); + GeometricField& cellAvg = tcellAvg(); + + labelField nPointCells(mesh.nCells(), 0); + { + for (label pointI = 0; pointI < mesh.nPoints(); pointI++) + { + const labelList& pCells = mesh.pointCells(pointI); + + forAll(pCells, i) + { + label cellI = pCells[i]; + + cellAvg[cellI] += pfld[pointI]; + nPointCells[cellI]++; + } + } + } + forAll(cellAvg, cellI) + { + cellAvg[cellI] /= nPointCells[cellI]; + } + // Give value to calculatedFvPatchFields + cellAvg.correctBoundaryConditions(); + + return tcellAvg; +} + + + // ************************************************************************* // From edeb20c856d963bb0873c9558760a3f9f03f7277 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 4 Mar 2010 13:47:09 +0000 Subject: [PATCH 04/21] ENH: Added faceZones support. Reverted back to using scheduled comms (less memory) --- .../foamToEnsight/ensightField.C | 388 +++-- .../foamToEnsight/ensightMesh.C | 1332 ++++++++++------- .../foamToEnsight/ensightMesh.H | 77 +- .../foamToEnsight/foamToEnsight.C | 9 + 4 files changed, 1157 insertions(+), 649 deletions(-) diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C index 1204ac5976..e446dcac89 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C @@ -110,40 +110,30 @@ void writeAllData { if (nPrims) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(vf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << key << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData(map(vf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, prims, cmpt); + } + } } } @@ -160,40 +150,30 @@ void writeAllDataBinary { if (nPrims) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(vf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary(key,ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary(map(vf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, prims, cmpt); + } + } } } @@ -210,40 +190,31 @@ void writeAllFaceData { if (nPrims) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(pf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << key << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData(map(pf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(pf, prims, cmpt); + } + } } } @@ -260,40 +231,31 @@ void writeAllFaceDataBinary { if (nPrims) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(pf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary(key,ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary(map(pf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(pf, prims, cmpt); + } + } } } @@ -539,6 +501,10 @@ void ensightFieldAscii const wordHashSet& patchNames = eMesh.patchNames(); const HashTable& nPatchPrims = eMesh.nPatchPrims(); + const List& faceZoneFaceSets = eMesh.faceZoneFaceSets(); + const wordHashSet& faceZoneNames = eMesh.faceZoneNames(); + const HashTable& + nFaceZonePrims = eMesh.nFaceZonePrims(); const labelList& tets = meshCellSets.tets; const labelList& pyrs = meshCellSets.pyrs; @@ -557,7 +523,7 @@ void ensightFieldAscii postProcPath/ensightFileName, runTime.writeFormat(), runTime.writeVersion(), - runTime.writeCompression() + IOstream::UNCOMPRESSED ); } @@ -567,6 +533,8 @@ void ensightFieldAscii if (patchNames.empty()) { + eMesh.barrier(); + if (Pstream::master()) { if (timeIndex == 0) @@ -592,29 +560,10 @@ void ensightFieldAscii if (meshCellSets.nHexesWedges) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(vf, hexes, wedges, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << "hexa8" << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData @@ -625,17 +574,57 @@ void ensightFieldAscii for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, hexes, wedges, cmpt); + } + } } - writeAllData("penta6", vf, prisms, meshCellSets.nPrisms, ensightFile); - writeAllData("pyramid5", vf, pyrs, meshCellSets.nPyrs, ensightFile); - writeAllData("tetra4", vf, tets, meshCellSets.nTets, ensightFile); - writeAllData("nfaced", vf, polys, meshCellSets.nPolys, ensightFile); + writeAllData + ( + "penta6", + vf, + prisms, + meshCellSets.nPrisms, + ensightFile + ); + + writeAllData + ( + "pyramid5", + vf, + pyrs, + meshCellSets.nPyrs, + ensightFile + ); + + writeAllData + ( + "tetra4", + vf, + tets, + meshCellSets.nTets, + ensightFile + ); + + writeAllData + ( + "nfaced", + vf, + polys, + meshCellSets.nPolys, + ensightFile + ); } label ensightPatchI = eMesh.patchPartOffset(); @@ -644,6 +633,8 @@ void ensightFieldAscii { const word& patchName = allPatchNames[patchi]; + eMesh.barrier(); + if (patchNames.empty() || patchNames.found(patchName)) { if @@ -664,6 +655,80 @@ void ensightFieldAscii } } + // write faceZones, if requested + if (faceZoneNames.size()) + { + // Interpolates cell values to faces - needed only when exporting + // faceZones... + GeometricField sf + ( + linearInterpolate(vf) + ); + + forAllConstIter(wordHashSet, faceZoneNames, iter) + { + const word& faceZoneName = iter.key(); + + eMesh.barrier(); + + label zoneID = mesh.faceZones().findZoneID(faceZoneName); + + const faceZone& fz = mesh.faceZones()[zoneID]; + + // Prepare data to write + label nIncluded = 0; + forAll(fz, i) + { + if (eMesh.faceToBeIncluded(fz[i])) + { + ++nIncluded; + } + } + + Field values(nIncluded); + + // Loop on the faceZone and store the needed field values + label j = 0; + forAll(fz, i) + { + label faceI = fz[i]; + if (mesh.isInternalFace(faceI)) + { + values[j] = sf[faceI]; + ++j; + } + else + { + if (eMesh.faceToBeIncluded(faceI)) + { + label patchI = mesh.boundaryMesh().whichPatch(faceI); + const polyPatch& pp = mesh.boundaryMesh()[patchI]; + label patchFaceI = pp.whichFace(faceI); + Type value = sf.boundaryField()[patchI][patchFaceI]; + values[j] = value; + ++j; + } + } + } + + if + ( + writePatchField + ( + values, + zoneID, + ensightPatchI, + faceZoneFaceSets[zoneID], + nFaceZonePrims.find(faceZoneName)(), + ensightFile + ) + ) + { + ensightPatchI++; + } + } + } + if (Pstream::master()) { delete ensightFilePtr; @@ -695,6 +760,10 @@ void ensightFieldBinary const wordHashSet& patchNames = eMesh.patchNames(); const HashTable& nPatchPrims = eMesh.nPatchPrims(); + const List& faceZoneFaceSets = eMesh.faceZoneFaceSets(); + const wordHashSet& faceZoneNames = eMesh.faceZoneNames(); + const HashTable& + nFaceZonePrims = eMesh.nFaceZonePrims(); const labelList& tets = meshCellSets.tets; const labelList& pyrs = meshCellSets.pyrs; @@ -722,6 +791,8 @@ void ensightFieldBinary if (patchNames.empty()) { + eMesh.barrier(); + if (Pstream::master()) { if (timeIndex == 0) @@ -743,29 +814,10 @@ void ensightFieldBinary if (meshCellSets.nHexesWedges) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(vf, hexes, wedges, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary("hexa8",ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary @@ -776,11 +828,20 @@ void ensightFieldBinary for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, hexes, wedges, cmpt); + } + } } writeAllDataBinary @@ -826,6 +887,8 @@ void ensightFieldBinary { const word& patchName = allPatchNames[patchi]; + eMesh.barrier(); + if (patchNames.empty() || patchNames.found(patchName)) { if @@ -844,6 +907,81 @@ void ensightFieldBinary ensightPatchI++; } } + + } + + // write faceZones, if requested + if (faceZoneNames.size()) + { + // Interpolates cell values to faces - needed only when exporting + // faceZones... + GeometricField sf + ( + linearInterpolate(vf) + ); + + forAllConstIter(wordHashSet, faceZoneNames, iter) + { + const word& faceZoneName = iter.key(); + + eMesh.barrier(); + + label zoneID = mesh.faceZones().findZoneID(faceZoneName); + + const faceZone& fz = mesh.faceZones()[zoneID]; + + // Prepare data to write + label nIncluded = 0; + forAll(fz, i) + { + if (eMesh.faceToBeIncluded(fz[i])) + { + ++nIncluded; + } + } + + Field values(nIncluded); + + // Loop on the faceZone and store the needed field values + label j = 0; + forAll(fz, i) + { + label faceI = fz[i]; + if (mesh.isInternalFace(faceI)) + { + values[j] = sf[faceI]; + ++j; + } + else + { + if (eMesh.faceToBeIncluded(faceI)) + { + label patchI = mesh.boundaryMesh().whichPatch(faceI); + const polyPatch& pp = mesh.boundaryMesh()[patchI]; + label patchFaceI = pp.whichFace(faceI); + Type value = sf.boundaryField()[patchI][patchFaceI]; + values[j] = value; + ++j; + } + } + } + + if + ( + writePatchFieldBinary + ( + values, + zoneID, + ensightPatchI, + faceZoneFaceSets[zoneID], + nFaceZonePrims.find(faceZoneName)(), + ensightFile + ) + ) + { + ensightPatchI++; + } + } } if (Pstream::master()) diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C index 5f848736be..daece0473b 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C @@ -30,11 +30,14 @@ License #include "fvMesh.H" #include "globalMeshData.H" #include "PstreamCombineReduceOps.H" +#include "processorPolyPatch.H" #include "cellModeller.H" #include "IOmanip.H" #include "itoa.H" #include "ensightWriteBinary.H" +#include "globalIndex.H" #include "mapDistribute.H" +#include "stringListOps.H" #include @@ -56,7 +59,11 @@ Foam::ensightMesh::ensightMesh boundaryFaceSets_(mesh_.boundary().size()), allPatchNames_(0), patchNames_(0), - nPatchPrims_(0) + nPatchPrims_(0), + faceZoneFaceSets_(mesh_.faceZones().size()), + faceZoneNames_(0), + nFaceZonePrims_(0), + boundaryFaceToBeIncluded_(0) { const cellShapeList& cellShapes = mesh.cellShapes(); @@ -80,10 +87,7 @@ Foam::ensightMesh::ensightMesh if (args.optionFound("patches")) { - wordList patchNameList - ( - args.optionLookup("patches")() - ); + wordList patchNameList(args.optionLookup("patches")()); if (patchNameList.empty()) { @@ -218,7 +222,6 @@ Foam::ensightMesh::ensightMesh } } - forAll(allPatchNames_, patchi) { const word& patchName = allPatchNames_[patchi]; @@ -240,6 +243,133 @@ Foam::ensightMesh::ensightMesh nPatchPrims_.insert(patchName, nfp); } + + // faceZones + if (args.optionFound("faceZones")) + { + wordList patchNameList(args.optionLookup("faceZones")()); + + const wordList faceZoneNamesAll = mesh_.faceZones().names(); + + // Find out faceZone names that match with what requested at command + // line + forAll(patchNameList, i) + { + labelList matches = findStrings(patchNameList[i], faceZoneNamesAll); + + forAll(matches, matchI) + { + faceZoneNames_.insert(faceZoneNamesAll[matches[matchI]]); + } + } + + // Build list of boundary faces to be exported + boundaryFaceToBeIncluded_.setSize + ( + mesh_.nFaces() + - mesh_.nInternalFaces(), + 1 + ); + + forAll(mesh_.boundaryMesh(), patchI) + { + const polyPatch& pp = mesh_.boundaryMesh()[patchI]; + if + ( + isA(pp) + && !refCast(pp).owner() + ) + { + label bFaceI = pp.start()-mesh_.nInternalFaces(); + forAll(pp, i) + { + boundaryFaceToBeIncluded_[bFaceI++] = 0; + } + } + } + + // Count face types in each faceZone + forAll(faceZoneNamesAll, zoneI) + { + //const word& zoneName = faceZoneNamesAll[zoneI]; + + const faceZone& fz = mesh.faceZones()[zoneI]; + + if (fz.size()) + { + labelList& tris = faceZoneFaceSets_[zoneI].tris; + labelList& quads = faceZoneFaceSets_[zoneI].quads; + labelList& polys = faceZoneFaceSets_[zoneI].polys; + + tris.setSize(fz.size()); + quads.setSize(fz.size()); + polys.setSize(fz.size()); + + label nTris = 0; + label nQuads = 0; + label nPolys = 0; + + label faceCounter = 0; + + forAll(fz, i) + { + label faceI = fz[i]; + + // Avoid counting faces on processor boundaries twice + if (faceToBeIncluded(faceI)) + { + const face& f = mesh_.faces()[faceI]; + + if (f.size() == 3) + { + tris[nTris++] = faceCounter; + } + else if (f.size() == 4) + { + quads[nQuads++] = faceCounter; + } + else + { + polys[nPolys++] = faceCounter; + } + + ++faceCounter; + } + } + + tris.setSize(nTris); + quads.setSize(nQuads); + polys.setSize(nPolys); + } + } + + forAll(faceZoneNamesAll, zoneI) + { + const word& zoneName = faceZoneNamesAll[zoneI]; + nFacePrimitives nfp; + + if (faceZoneNames_.found(zoneName)) + { + if + ( + faceZoneFaceSets_[zoneI].tris.size() + || faceZoneFaceSets_[zoneI].quads.size() || + faceZoneFaceSets_[zoneI].polys.size() + ) + { + nfp.nTris = faceZoneFaceSets_[zoneI].tris.size(); + nfp.nQuads = faceZoneFaceSets_[zoneI].quads.size(); + nfp.nPolys = faceZoneFaceSets_[zoneI].polys.size(); + } + } + + reduce(nfp.nTris, sumOp