diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index 9a77a66417..8684d76932 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -20,6 +20,7 @@ FoamFile // gnuplot // raw // vtk +// ensight // csv setFormat raw; diff --git a/src/finiteVolume/fvMesh/fvMesh.C b/src/finiteVolume/fvMesh/fvMesh.C index 51ded1992f..e90919877d 100644 --- a/src/finiteVolume/fvMesh/fvMesh.C +++ b/src/finiteVolume/fvMesh/fvMesh.C @@ -59,6 +59,8 @@ License #include "upwindFECCellToFaceStencilObject.H" #include "centredCFCFaceToCellStencilObject.H" +#include "meshSearchMeshObject.H" +#include "meshSearchFACECENTRETETSMeshObject.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -99,6 +101,11 @@ void Foam::fvMesh::clearGeom() CentredFitData::Delete(*this); skewCorrectionVectors::Delete(*this); //quadraticFitSnGradData::Delete(*this); + + // Note: should be in polyMesh::clearGeom but meshSearch not in OpenFOAM + // library + meshSearchMeshObject::Delete(*this); + meshSearchFACECENTRETETSMeshObject::Delete(*this); } @@ -128,6 +135,11 @@ void Foam::fvMesh::clearAddressing() upwindFECCellToFaceStencilObject::Delete(*this); centredCFCFaceToCellStencilObject::Delete(*this); + + // Note: should be in polyMesh::clearGeom but meshSearch not in OpenFOAM + // library + meshSearchMeshObject::Delete(*this); + meshSearchFACECENTRETETSMeshObject::Delete(*this); } diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index 9950b9b061..ec3d7c7471 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -87,67 +87,22 @@ Foam::tmp Foam::mappedPatchBase::facePoints ) const { const polyMesh& mesh = pp.boundaryMesh().mesh(); - const labelList& tetBasePts = mesh.tetBasePtIs(); - const pointField& p = pp.points(); - const pointField& cellCentres = mesh.cellCentres(); - const labelList& faceCells = pp.faceCells(); + + // Force construction of min-tet decomp + (void)mesh.tetBasePtIs(); // Initialise to face-centre - tmp tfacePoints(new pointField(patch_.faceCentres())); + tmp tfacePoints(new pointField(patch_.size())); pointField& facePoints = tfacePoints(); forAll(pp, faceI) { - const face& f = pp[faceI]; - - if (f.size() <= 3) - { - // Point already on tets of cell. - } - else - { - // Find intersection of (face-centre-decomposition) centre to - // cell-centre with face-diagonal-decomposition triangles. - const point& cc = cellCentres[faceCells[faceI]]; - vector d = facePoints[faceI]-cc; - - const label fp0 = tetBasePts[faceI]; - const point& basePoint = p[f[fp0]]; - - //bool foundPoint = false; - - label fp = f.fcIndex(fp0); - for (label i = 2; i < f.size(); i++) - { - const point& thisPoint = p[f[fp]]; - label nextFp = f.fcIndex(fp); - const point& nextPoint = p[f[nextFp]]; - - const triPointRef tri(basePoint, thisPoint, nextPoint); - pointHit hitInfo = tri.intersection - ( - cc, - d, - intersection::HALF_RAY - ); - - if (hitInfo.hit() && hitInfo.distance() > 0) - { - facePoints[faceI] = hitInfo.hitPoint(); - //foundPoint = true; - break; - } - - fp = nextFp; - } - - //if (!foundPoint) - //{ - // Pout<< "cell:" << faceCells[faceI] << " at:" << cc - // << " face-centre:" << patch_.faceCentres()[faceI] - // << " did not find any intersection." << endl; - //} - } + facePoints[faceI] = facePoint + ( + mesh, + pp.start()+faceI, + polyMesh::FACEDIAGTETS + ).rawPoint(); } return tfacePoints; @@ -572,11 +527,13 @@ void Foam::mappedPatchBase::calcMapping() const ) << "Did not find " << nNotFound << " out of " << sampleProcs.size() << " total samples." << " Sampling these on owner cell centre instead." << endl - << "patch_:" << patch_.name() << endl - << "sampleRegion_:" << sampleRegion_ << endl - << "mode_:" << sampleModeNames_[mode_] << endl - << "samplePatch_:" << samplePatch_ << endl - << "offsetMode_:" << offsetModeNames_[offsetMode_] << endl; + << "On patch " << patch_.name() + << " on region " << sampleRegion_ + << " in mode " << sampleModeNames_[mode_] << endl + << "whilst sampling patch " << samplePatch_ << endl + << " with offset mode " << offsetModeNames_[offsetMode_] + << endl + << "Suppressing further warnings from " << type() << endl; hasWarned = true; } @@ -1137,6 +1094,87 @@ Foam::tmp Foam::mappedPatchBase::samplePoints() const } +Foam::pointIndexHit Foam::mappedPatchBase::facePoint +( + const polyMesh& mesh, + const label faceI, + const polyMesh::cellRepresentation decompMode +) +{ + const point& fc = mesh.faceCentres()[faceI]; + + switch (decompMode) + { + case polyMesh::FACEPLANES: + case polyMesh::FACECENTRETETS: + { + // For both decompositions the face centre is guaranteed to be + // on the face + return pointIndexHit(true, fc, faceI); + } + break; + + case polyMesh::FACEDIAGTETS: + { + // Find the intersection of a ray from face centre to cell + // centre + // Find intersection of (face-centre-decomposition) centre to + // cell-centre with face-diagonal-decomposition triangles. + + const pointField& p = mesh.points(); + const face& f = mesh.faces()[faceI]; + + if (f.size() <= 3) + { + // Return centre of triangle. + return pointIndexHit(true, fc, 0); + } + + label cellI = mesh.faceOwner()[faceI]; + const point& cc = mesh.cellCentres()[cellI]; + vector d = fc-cc; + + const label fp0 = mesh.tetBasePtIs()[faceI]; + const point& basePoint = p[f[fp0]]; + + label fp = f.fcIndex(fp0); + for (label i = 2; i < f.size(); i++) + { + const point& thisPoint = p[f[fp]]; + label nextFp = f.fcIndex(fp); + const point& nextPoint = p[f[nextFp]]; + + const triPointRef tri(basePoint, thisPoint, nextPoint); + pointHit hitInfo = tri.intersection + ( + cc, + d, + intersection::HALF_RAY + ); + + if (hitInfo.hit() && hitInfo.distance() > 0) + { + return pointIndexHit(true, hitInfo.hitPoint(), i-2); + } + + fp = nextFp; + } + + // Fall-back + return pointIndexHit(false, fc, -1); + } + break; + + default: + { + FatalErrorIn("mappedPatchBase::facePoint()") + << "problem" << abort(FatalError); + return pointIndexHit(); + } + } +} + + void Foam::mappedPatchBase::write(Ostream& os) const { os.writeKeyword("sampleMode") << sampleModeNames_[mode_] diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H index 142bd86fb4..d5f6743edb 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H @@ -339,9 +339,24 @@ public: //- Get the patch on the region const polyPatch& samplePolyPatch() const; + // Helpers + //- Get the sample points tmp samplePoints() const; + //- Get a point on the face given a face decomposition method: + // face-centre-tet : face centre. Returns index of face. + // face-planes : face centre. Returns index of face. + // face-diagonal : intersection of ray from cellcentre to + // facecentre with any of the triangles. + // Returns index (0..size-2) of triangle. + static pointIndexHit facePoint + ( + const polyMesh&, + const label faceI, + const polyMesh::cellRepresentation + ); + // Distribute diff --git a/src/sampling/Make/files b/src/sampling/Make/files index f7c4775e88..0c89693a8e 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -11,6 +11,7 @@ sampledSet/polyLine/polyLineSet.C sampledSet/face/faceOnlySet.C sampledSet/midPoint/midPointSet.C sampledSet/midPointAndFace/midPointAndFaceSet.C +/* sampledSet/patchSeed/patchSeedSet.C */ sampledSet/sampledSet/sampledSet.C sampledSet/sampledSets/sampledSets.C sampledSet/sampledSets/sampledSetsGrouping.C @@ -21,6 +22,7 @@ sampledSet/uniform/uniformSet.C setWriters = sampledSet/writers $(setWriters)/writers.C +$(setWriters)/ensight/ensightSetWriterRunTime.C $(setWriters)/gnuplot/gnuplotSetWriterRunTime.C $(setWriters)/jplot/jplotSetWriterRunTime.C $(setWriters)/raw/rawSetWriterRunTime.C diff --git a/src/sampling/sampledSet/writers/ensight/ensightSetWriter.C b/src/sampling/sampledSet/writers/ensight/ensightSetWriter.C new file mode 100644 index 0000000000..23d8e7843d --- /dev/null +++ b/src/sampling/sampledSet/writers/ensight/ensightSetWriter.C @@ -0,0 +1,315 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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 "ensightSetWriter.H" +#include "coordSet.H" +#include "OFstream.H" +#include "addToRunTimeSelectionTable.H" +#include "IOmanip.H" +#include "foamVersion.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::ensightSetWriter::ensightSetWriter() +: + writer() +{} + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::ensightSetWriter::~ensightSetWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::fileName Foam::ensightSetWriter::getFileName +( + const coordSet& points, + const wordList& valueSetNames +) const +{ + return + this->getBaseName(points, valueSetNames) + //+ '_' + //+ pTraits::typeName + + ".case"; +} + + +template +void Foam::ensightSetWriter::write +( + const coordSet& points, + const wordList& valueSetNames, + const List*>& valueSets, + Ostream& os +) const +{ + const fileName base(os.name().lessExt()); + const fileName meshFile(base + ".mesh"); + + // Write .case file + os << "FORMAT" << nl + << "type: ensight gold" << nl + << nl + << "GEOMETRY" << nl + << "model: 1 " << meshFile.name().c_str() << nl + << nl + << "VARIABLE" + << nl; + forAll(valueSetNames, setI) + { + fileName dataFile(base + ".***." + valueSetNames[setI]); + + os.setf(ios_base::left); + os << pTraits::typeName + << " per node: 1 " + << setw(15) << valueSetNames[setI] + << " " << dataFile.name().c_str() + << nl; + } + os << nl + << "TIME" << nl + << "time set: 1" << nl + << "number of steps: 1" << nl + << "filename start number: 0" << nl + << "filename increment: 1" << nl + << "time values:" << nl + << "0.00000e+00" << nl; + + // Write .mesh file + { + string desc = string("written by OpenFOAM-") + Foam::FOAMversion; + OFstream os(meshFile); + os.setf(ios_base::scientific, ios_base::floatfield); + os.precision(5); + + os << "EnSight Geometry File" << nl + << desc.c_str() << nl + << "node id assign" << nl + << "element id assign" << nl + << "part" << nl + << setw(10) << 1 << nl + << "internalMesh" << nl + << "coordinates" << nl + << setw(10) << points.size() << nl; + + for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++) + { + forAll(points, pointI) + { + const scalar comp = points[pointI][cmpt]; + if (mag(comp) >= scalar(floatScalarVSMALL)) + { + os << setw(12) << comp << nl; + } + else + { + os << setw(12) << scalar(0) << nl; + } + } + } + os << "point" << nl + << setw(10) << points.size() << nl; + forAll(points, pointI) + { + os << setw(10) << pointI+1 << nl; + } + } + + // Write data files + forAll(valueSetNames, setI) + { + fileName dataFile(base + ".000." + valueSetNames[setI]); + OFstream os(dataFile); + os.setf(ios_base::scientific, ios_base::floatfield); + os.precision(5); + { + os << pTraits::typeName << nl + << "part" << nl + << setw(10) << 1 << nl + << "coordinates" << nl; + for (direction cmpt = 0; cmpt < pTraits::nComponents; cmpt++) + { + const scalarField fld = valueSets[setI]->component(cmpt); + forAll(fld, i) + { + if (mag(fld[i]) >= scalar(floatScalarVSMALL)) + { + os << setw(12) << fld[i] << nl; + } + else + { + os << setw(12) << scalar(0) << nl; + } + } + } + } + } +} + + +template +void Foam::ensightSetWriter::write +( + const bool writeTracks, + const PtrList& tracks, + const wordList& valueSetNames, + const List > >& valueSets, + Ostream& os +) const +{ + const fileName base(os.name().lessExt()); + const fileName meshFile(base + ".mesh"); + + // Write .case file + os << "FORMAT" << nl + << "type: ensight gold" << nl + << nl + << "GEOMETRY" << nl + << "model: 1 " << meshFile.name().c_str() << nl + << nl + << "VARIABLE" + << nl; + forAll(valueSetNames, setI) + { + fileName dataFile(base + ".***." + valueSetNames[setI]); + + os.setf(ios_base::left); + os << pTraits::typeName + << " per node: 1 " + << setw(15) << valueSetNames[setI] + << " " << dataFile.name().c_str() + << nl; + } + os << nl + << "TIME" << nl + << "time set: 1" << nl + << "number of steps: 1" << nl + << "filename start number: 0" << nl + << "filename increment: 1" << nl + << "time values:" << nl + << "0.00000e+00" << nl; + + // Write .mesh file + { + string desc = string("written by OpenFOAM-") + Foam::FOAMversion; + OFstream os(meshFile); + os.setf(ios_base::scientific, ios_base::floatfield); + os.precision(5); + os << "EnSight Geometry File" << nl + << desc.c_str() << nl + << "node id assign" << nl + << "element id assign" << nl; + + forAll(tracks, trackI) + { + const coordSet& points = tracks[trackI]; + + os << "part" << nl + << setw(10) << trackI+1 << nl + << "internalMesh" << nl + << "coordinates" << nl + << setw(10) << points.size() << nl; + + for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++) + { + forAll(points, pointI) + { + const scalar comp = points[pointI][cmpt]; + if (mag(comp) >= scalar(floatScalarVSMALL)) + { + os << setw(12) << comp << nl; + } + else + { + os << setw(12) << scalar(0) << nl; + } + } + } + + if (writeTracks) + { + os << "bar2" << nl + << setw(10) << points.size()-1 << nl; + for (label i = 0; i < points.size()-1; i++) + { + os << setw(10) << i+1 + << setw(10) << i+2 + << nl; + } + } + } + } + + + // Write data files + forAll(valueSetNames, setI) + { + fileName dataFile(base + ".000." + valueSetNames[setI]); + OFstream os(dataFile); + os.setf(ios_base::scientific, ios_base::floatfield); + os.precision(5); + { + os << pTraits::typeName << nl; + + const List >& fieldVals = valueSets[setI]; + forAll(fieldVals, trackI) + { + os << "part" << nl + << setw(10) << trackI+1 << nl + << "coordinates" << nl; + + for + ( + direction cmpt = 0; + cmpt < pTraits::nComponents; + cmpt++ + ) + { + const scalarField fld = fieldVals[trackI].component(cmpt); + forAll(fld, i) + { + if (mag(fld[i]) >= scalar(floatScalarVSMALL)) + { + os << setw(12) << fld[i] << nl; + } + else + { + os << setw(12) << scalar(0) << nl; + } + } + } + } + } + } +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/ensight/ensightSetWriter.H b/src/sampling/sampledSet/writers/ensight/ensightSetWriter.H new file mode 100644 index 0000000000..5118c85faa --- /dev/null +++ b/src/sampling/sampledSet/writers/ensight/ensightSetWriter.H @@ -0,0 +1,111 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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 . + +Class + Foam::ensightSetWriter + +Description + +SourceFiles + ensightSetWriter.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightSetWriter_H +#define ensightSetWriter_H + +#include "writer.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class ensightSetWriter Declaration +\*---------------------------------------------------------------------------*/ + +template +class ensightSetWriter +: + public writer +{ + +public: + + //- Runtime type information + TypeName("ensight"); + + + // Constructors + + //- Construct null + ensightSetWriter(); + + + //- Destructor + virtual ~ensightSetWriter(); + + + // Member Functions + + virtual fileName getFileName + ( + const coordSet&, + const wordList& + ) const; + + virtual void write + ( + const coordSet&, + const wordList&, + const List*>&, + Ostream& + ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList&, + const wordList& valueSetNames, + const List > >&, + Ostream& + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "ensightSetWriter.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/ensight/ensightSetWriterRunTime.C b/src/sampling/sampledSet/writers/ensight/ensightSetWriterRunTime.C new file mode 100644 index 0000000000..b987035b33 --- /dev/null +++ b/src/sampling/sampledSet/writers/ensight/ensightSetWriterRunTime.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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 "ensightSetWriter.H" +#include "writers.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeSetWriters(ensightSetWriter); +} + +// ************************************************************************* // diff --git a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/streamLines b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/streamLines index a8a0c377cc..aa0b6a1d7b 100644 --- a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/streamLines +++ b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/streamLines @@ -14,7 +14,7 @@ streamLines outputControl outputTime; // outputInterval 10; - setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; + setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; //csv; //ensight; // Velocity field to use for tracking. U U; diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/streamLines b/tutorials/incompressible/simpleFoam/motorBike/system/streamLines index 82c3f1d68c..8b82eccbb1 100644 --- a/tutorials/incompressible/simpleFoam/motorBike/system/streamLines +++ b/tutorials/incompressible/simpleFoam/motorBike/system/streamLines @@ -14,7 +14,7 @@ streamLines outputControl outputTime; // outputInterval 10; - setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; + setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; //csv; //ensight; // Velocity field to use for tracking. UName U; diff --git a/tutorials/incompressible/simpleFoam/pitzDaily/system/controlDict b/tutorials/incompressible/simpleFoam/pitzDaily/system/controlDict index aaedd23dab..688796fe63 100644 --- a/tutorials/incompressible/simpleFoam/pitzDaily/system/controlDict +++ b/tutorials/incompressible/simpleFoam/pitzDaily/system/controlDict @@ -58,7 +58,7 @@ functions outputControl outputTime; // outputInterval 10; - setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; + setFormat vtk; //gnuplot;//xmgr;//raw;//jplot;//csv;//ensight; // Velocity field to use for tracking. UName U; diff --git a/tutorials/incompressible/simpleFoam/pitzDailyExptInlet/system/controlDict b/tutorials/incompressible/simpleFoam/pitzDailyExptInlet/system/controlDict index c2b5d2e493..18e4c651fb 100644 --- a/tutorials/incompressible/simpleFoam/pitzDailyExptInlet/system/controlDict +++ b/tutorials/incompressible/simpleFoam/pitzDailyExptInlet/system/controlDict @@ -58,7 +58,7 @@ functions outputControl outputTime; // outputInterval 10; - setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; + setFormat vtk; //gnuplot;//xmgr;//raw;//jplot;//csv;//ensight; // Velocity field to use for tracking. UName U;