diff --git a/applications/test/PatchEdgeFaceWave/Test-PatchEdgeFaceWave.C b/applications/test/PatchEdgeFaceWave/Test-PatchEdgeFaceWave.C index 2dfb19118b2e86503119a8a72872980d6af13942..cfc402e14a943938aa50499e7efdde7f9f470b97 100644 --- a/applications/test/PatchEdgeFaceWave/Test-PatchEdgeFaceWave.C +++ b/applications/test/PatchEdgeFaceWave/Test-PatchEdgeFaceWave.C @@ -32,6 +32,7 @@ Description #include "volFields.H" #include "PatchEdgeFaceWave.H" #include "patchEdgeFaceInfo.H" +#include "patchDist.H" using namespace Foam; @@ -49,80 +50,115 @@ int main(int argc, char *argv[]) // Get name of patch const word patchName = args[1]; - const polyPatch& patch = patches[patchName]; - // Data on all edges and faces - List<patchEdgeFaceInfo> allEdgeInfo(patch.nEdges()); - List<patchEdgeFaceInfo> allFaceInfo(patch.size()); + // 1. Walk from a single edge + { + // Data on all edges and faces + List<patchEdgeFaceInfo> allEdgeInfo(patch.nEdges()); + List<patchEdgeFaceInfo> allFaceInfo(patch.size()); - // Initial seed - DynamicList<label> initialEdges; - DynamicList<patchEdgeFaceInfo> initialEdgesInfo; + // Initial seed + DynamicList<label> initialEdges; + DynamicList<patchEdgeFaceInfo> initialEdgesInfo; - // Just set an edge on the master - if (Pstream::master()) - { - label edgeI = 0; - Info<< "Starting walk on edge " << edgeI << endl; + // Just set an edge on the master + if (Pstream::master()) + { + label edgeI = 0; + Info<< "Starting walk on edge " << edgeI << endl; - initialEdges.append(edgeI); - const edge& e = patch.edges()[edgeI]; - initialEdgesInfo.append - ( - patchEdgeFaceInfo + initialEdges.append(edgeI); + const edge& e = patch.edges()[edgeI]; + initialEdgesInfo.append ( - e.centre(patch.localPoints()), - 0.0 - ) + patchEdgeFaceInfo + ( + e.centre(patch.localPoints()), + 0.0 + ) + ); + } + + + // Walk + PatchEdgeFaceWave + < + primitivePatch, + patchEdgeFaceInfo + > calc + ( + mesh, + patch, + initialEdges, + initialEdgesInfo, + allEdgeInfo, + allFaceInfo, + returnReduce(patch.nEdges(), sumOp<label>()) ); - } - // Walk - PatchEdgeFaceWave - < - primitivePatch, - patchEdgeFaceInfo - > calc - ( - mesh, - patch, - initialEdges, - initialEdgesInfo, - allEdgeInfo, - allFaceInfo, - returnReduce(patch.nEdges(), sumOp<label>()) - ); - - - // Extract as patchField - volScalarField vsf - ( - IOobject + // Extract as patchField + volScalarField vsf ( - "patchDist", - runTime.timeName(), + IOobject + ( + "patchDist", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), mesh, - IOobject::NO_READ, - IOobject::AUTO_WRITE - ), - mesh, - dimensionedScalar("patchDist", dimLength, 0.0) - ); - scalarField pf(vsf.boundaryField()[patch.index()].size()); - forAll(pf, faceI) - { - pf[faceI] = Foam::sqrt(allFaceInfo[faceI].distSqr()); + dimensionedScalar("patchDist", dimLength, 0.0) + ); + scalarField pf(vsf.boundaryField()[patch.index()].size()); + forAll(pf, faceI) + { + pf[faceI] = Foam::sqrt(allFaceInfo[faceI].distSqr()); + } + vsf.boundaryField()[patch.index()] = pf; + + Info<< "Writing patchDist volScalarField to " << runTime.value() + << endl; + + vsf.write(); } - vsf.boundaryField()[patch.index()] = pf; - Info<< "Writing patchDist volScalarField to " << runTime.value() - << endl; - vsf.write(); + // 2. Use a wrapper to walk from all boundary edges on selected patches + { + labelHashSet otherPatchIDs(identity(mesh.boundaryMesh().size())); + otherPatchIDs.erase(patch.index()); + + Info<< "Walking on patch " << patch.index() + << " from edges shared with patches " << otherPatchIDs + << endl; + + patchDist pwd(patch, otherPatchIDs); + + // Extract as patchField + volScalarField vsf + ( + IOobject + ( + "otherPatchDist", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedScalar("otherPatchDist", dimLength, 0.0) + ); + vsf.boundaryField()[patch.index()] = pwd; + + Info<< "Writing otherPatchDist volScalarField to " << runTime.value() + << endl; + vsf.write(); + } Info<< "\nEnd\n" << endl; return 0; diff --git a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C index 791f68cf98b971857449ff053c754adb0e8e2350..a8c18c0712b9dbfac1480f6400d25229e0503e1e 100644 --- a/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C +++ b/applications/utilities/mesh/manipulation/renumberMesh/renumberMesh.C @@ -459,6 +459,11 @@ autoPtr<mapPolyMesh> reorderMesh int main(int argc, char *argv[]) { + argList::addNote + ( + "Renumber mesh to minimise bandwidth" + ); + argList::addOption ( "blockSize", @@ -479,6 +484,11 @@ int main(int argc, char *argv[]) # include "addRegionOption.H" # include "addOverwriteOption.H" # include "addTimeOptions.H" + argList::addBoolOption + ( + "dict", + "renumber according to system/renumberMeshDict" + ); # include "setRootCase.H" # include "createTime.H" @@ -495,6 +505,9 @@ int main(int argc, char *argv[]) # include "createNamedMesh.H" const word oldInstance = mesh.pointsInstance(); + const bool readDict = args.optionFound("dict"); + + label blockSize = 0; args.optionReadIfPresent("blockSize", blockSize, 0); @@ -539,28 +552,29 @@ int main(int argc, char *argv[]) // Construct renumberMethod - IOobject io - ( - "renumberMeshDict", - runTime.system(), - mesh, - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ); - autoPtr<renumberMethod> renumberPtr; - if (io.headerOk()) + if (readDict) { - Info<< "Detected local " << runTime.system()/io.name() << "." << nl - << "Using this to select renumberMethod." << nl << endl; - renumberPtr = renumberMethod::New(IOdictionary(io)); + Info<< "Renumber according to renumberMeshDict." << nl << endl; + + IOdictionary renumberDict + ( + IOobject + ( + "renumberMeshDict", + runTime.system(), + mesh, + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE + ) + ); + + renumberPtr = renumberMethod::New(renumberDict); } else { - Info<< "No local " << runTime.system()/io.name() - << " dictionary found. Using default renumberMethod." << nl - << endl; + Info<< "Using default renumberMethod." << nl << endl; dictionary renumberDict; renumberPtr.reset(new CuthillMcKeeRenumber(renumberDict)); } diff --git a/applications/utilities/mesh/manipulation/topoSet/topoSetDict b/applications/utilities/mesh/manipulation/topoSet/topoSetDict index 9c910aa7ec9c26643114cc28a8b3449a2d4963b1..5b8a4b73bbe85c562c9e50527fd1b113a8796c3b 100644 --- a/applications/utilities/mesh/manipulation/topoSet/topoSetDict +++ b/applications/utilities/mesh/manipulation/topoSet/topoSetDict @@ -211,7 +211,8 @@ FoamFile // source patchToFace; // sourceInfo // { -// name ".*Wall"; // Name of patch, regular expressions allowed +// name ".*Wall"; // Name of patch or patch group, +// // (regular expressions allowed) // } // // // All faces of faceZone diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index 9a77a6641738e71c7cb209a4b9548ffbc9ed5018..8684d769326caccad8e9d16984e8129ec4fe54f4 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 51ded1992f336227d735535fdc977e25f79c955e..e90919877d74510879cc58993e31c2e3fa3097a8 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<quadraticLinearFitPolynomial>::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/Make/files b/src/meshTools/Make/files index d8687b042b89308c367984eea3f3486d7604594e..5912ea12e423618bc998e964cc4061d4be829be4 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -27,6 +27,8 @@ polyMeshZipUpCells/polyMeshZipUpCells.C primitiveMeshGeometry/primitiveMeshGeometry.C meshSearch/meshSearch.C +meshSearch/meshSearchFACECENTRETETSMeshObject.C +meshSearch/meshSearchMeshObject.C meshTools/meshTools.C @@ -39,6 +41,7 @@ $(pWave)/pointEdgePoint.C patchWave = $(algorithms)/PatchEdgeFaceWave $(patchWave)/PatchEdgeFaceWaveName.C $(patchWave)/patchEdgeFaceInfo.C +$(patchWave)/patchDist.C meshWave = $(algorithms)/MeshWave $(meshWave)/MeshWaveName.C diff --git a/src/meshTools/algorithms/PatchEdgeFaceWave/patchDist.C b/src/meshTools/algorithms/PatchEdgeFaceWave/patchDist.C new file mode 100644 index 0000000000000000000000000000000000000000..22ea9a35f1dcd704884ac13c1154eab13a3f40d2 --- /dev/null +++ b/src/meshTools/algorithms/PatchEdgeFaceWave/patchDist.C @@ -0,0 +1,173 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "patchDist.H" +#include "PatchEdgeFaceWave.H" +#include "syncTools.H" +#include "polyMesh.H" +#include "patchEdgeFaceInfo.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::patchDist::patchDist +( + const polyPatch& patch, + const labelHashSet& nbrPatchIDs +) +: + patch_(patch), + nbrPatchIDs_(nbrPatchIDs), + nUnset_(0) +{ + patchDist::correct(); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::patchDist::~patchDist() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::patchDist::correct() +{ + // Mark all edge connected to a nbrPatch. + label nBnd = 0; + forAllConstIter(labelHashSet, nbrPatchIDs_, iter) + { + label nbrPatchI = iter.key(); + const polyPatch& nbrPatch = patch_.boundaryMesh()[nbrPatchI]; + nBnd += nbrPatch.nEdges()-nbrPatch.nInternalEdges(); + } + + // Mark all edges. Note: should use HashSet but have no syncTools + // functionality for these. + EdgeMap<label> nbrEdges(2*nBnd); + + forAllConstIter(labelHashSet, nbrPatchIDs_, iter) + { + label nbrPatchI = iter.key(); + const polyPatch& nbrPatch = patch_.boundaryMesh()[nbrPatchI]; + const labelList& nbrMp = nbrPatch.meshPoints(); + + for + ( + label edgeI = nbrPatch.nInternalEdges(); + edgeI < nbrPatch.nEdges(); + edgeI++ + ) + { + const edge& e = nbrPatch.edges()[edgeI]; + const edge meshE = edge(nbrMp[e[0]], nbrMp[e[1]]); + nbrEdges.insert(meshE, nbrPatchI); + } + } + + + // Make sure these boundary edges are marked everywhere. + syncTools::syncEdgeMap + ( + patch_.boundaryMesh().mesh(), + nbrEdges, + maxEqOp<label>() + ); + + + // Data on all edges and faces + List<patchEdgeFaceInfo> allEdgeInfo(patch_.nEdges()); + List<patchEdgeFaceInfo> allFaceInfo(patch_.size()); + + // Initial seed + label nBndEdges = patch_.nEdges() - patch_.nInternalEdges(); + DynamicList<label> initialEdges(2*nBndEdges); + DynamicList<patchEdgeFaceInfo> initialEdgesInfo(2*nBndEdges); + + + // Seed all my edges that are also nbrEdges + + const labelList& mp = patch_.meshPoints(); + + for + ( + label edgeI = patch_.nInternalEdges(); + edgeI < patch_.nEdges(); + edgeI++ + ) + { + const edge& e = patch_.edges()[edgeI]; + const edge meshE = edge(mp[e[0]], mp[e[1]]); + EdgeMap<label>::const_iterator edgeFnd = nbrEdges.find(meshE); + if (edgeFnd != nbrEdges.end()) + { + initialEdges.append(edgeI); + initialEdgesInfo.append + ( + patchEdgeFaceInfo + ( + e.centre(patch_.localPoints()), + 0.0 + ) + ); + } + } + + + // Walk + PatchEdgeFaceWave + < + primitivePatch, + patchEdgeFaceInfo + > calc + ( + patch_.boundaryMesh().mesh(), + patch_, + initialEdges, + initialEdgesInfo, + allEdgeInfo, + allFaceInfo, + returnReduce(patch_.nEdges(), sumOp<label>()) + ); + + + // Extract into *this + setSize(patch_.size()); + nUnset_ = 0; + forAll(allFaceInfo, faceI) + { + if (allFaceInfo[faceI].valid(calc.data())) + { + operator[](faceI) = Foam::sqrt(allFaceInfo[faceI].distSqr()); + } + else + { + nUnset_++; + } + } +} + + +// ************************************************************************* // diff --git a/src/meshTools/algorithms/PatchEdgeFaceWave/patchDist.H b/src/meshTools/algorithms/PatchEdgeFaceWave/patchDist.H new file mode 100644 index 0000000000000000000000000000000000000000..11cf2f48250162435da54f481195fbb7d40dfa45 --- /dev/null +++ b/src/meshTools/algorithms/PatchEdgeFaceWave/patchDist.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 <http://www.gnu.org/licenses/>. + +Class + Foam::patchDist + +Description + Like wallDist but calculates on patch distance to nearest neighbouring + patches. Uses PatchEdgeFaceWave to do actual calculation. + +SourceFiles + patchDist.C + +\*---------------------------------------------------------------------------*/ + +#ifndef patchDist_H +#define patchDist_H + +#include "scalarField.H" +#include "HashSet.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +//class polyMesh; +class polyPatch; + +/*---------------------------------------------------------------------------*\ + Class patchDist Declaration +\*---------------------------------------------------------------------------*/ + +class patchDist +: + public scalarField +{ + + +private: + + // Private Member Data + + //- Patch to operate on + const polyPatch& patch_; + + //- Patches to determine the distance to + const labelHashSet nbrPatchIDs_; + + //- Number of unset faces. + label nUnset_; + +public: + + // Constructors + + //- Construct from patch and neighbour patches. + patchDist + ( + const polyPatch& pp, + const labelHashSet& nbrPatchIDs + ); + + + //- Destructor + virtual ~patchDist(); + + + // Member Functions + + const scalarField& y() const + { + return *this; + } + + label nUnset() const + { + return nUnset_; + } + + //- Correct for mesh geom/topo changes + virtual void correct(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index 2b62b29e34a3a1acc188519cca8491a28981d13f..ec3d7c7471c843c9fbc96ec18d95a35e01859817 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -26,7 +26,7 @@ License #include "mappedPatchBase.H" #include "addToRunTimeSelectionTable.H" #include "ListListOps.H" -#include "meshSearch.H" +#include "meshSearchMeshObject.H" #include "meshTools.H" #include "OFstream.H" #include "Random.H" @@ -37,6 +37,7 @@ License #include "Time.H" #include "mapDistribute.H" #include "SubField.H" +#include "triPointRef.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -80,64 +81,99 @@ const Foam::NamedEnum<Foam::mappedPatchBase::offsetMode, 3> // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +Foam::tmp<Foam::pointField> Foam::mappedPatchBase::facePoints +( + const polyPatch& pp +) const +{ + const polyMesh& mesh = pp.boundaryMesh().mesh(); + + // Force construction of min-tet decomp + (void)mesh.tetBasePtIs(); + + // Initialise to face-centre + tmp<pointField> tfacePoints(new pointField(patch_.size())); + pointField& facePoints = tfacePoints(); + + forAll(pp, faceI) + { + facePoints[faceI] = facePoint + ( + mesh, + pp.start()+faceI, + polyMesh::FACEDIAGTETS + ).rawPoint(); + } + + return tfacePoints; +} + + void Foam::mappedPatchBase::collectSamples ( + const pointField& facePoints, pointField& samples, labelList& patchFaceProcs, labelList& patchFaces, pointField& patchFc ) const { - // Collect all sample points and the faces they come from. - List<pointField> globalFc(Pstream::nProcs()); - List<pointField> globalSamples(Pstream::nProcs()); - labelListList globalFaces(Pstream::nProcs()); - - globalFc[Pstream::myProcNo()] = patch_.faceCentres(); - globalSamples[Pstream::myProcNo()] = samplePoints(); - globalFaces[Pstream::myProcNo()] = identity(patch_.size()); - - // Distribute to all processors - Pstream::gatherList(globalSamples); - Pstream::scatterList(globalSamples); - Pstream::gatherList(globalFaces); - Pstream::scatterList(globalFaces); - Pstream::gatherList(globalFc); - Pstream::scatterList(globalFc); - - // Rework into straight list - samples = ListListOps::combine<pointField> - ( - globalSamples, - accessOp<pointField>() - ); - patchFaces = ListListOps::combine<labelList> - ( - globalFaces, - accessOp<labelList>() - ); - patchFc = ListListOps::combine<pointField> - ( - globalFc, - accessOp<pointField>() - ); + { + List<pointField> globalFc(Pstream::nProcs()); + globalFc[Pstream::myProcNo()] = facePoints; + Pstream::gatherList(globalFc); + Pstream::scatterList(globalFc); + // Rework into straight list + patchFc = ListListOps::combine<pointField> + ( + globalFc, + accessOp<pointField>() + ); + } - patchFaceProcs.setSize(patchFaces.size()); - labelList nPerProc - ( - ListListOps::subSizes + { + List<pointField> globalSamples(Pstream::nProcs()); + globalSamples[Pstream::myProcNo()] = samplePoints(facePoints); + Pstream::gatherList(globalSamples); + Pstream::scatterList(globalSamples); + // Rework into straight list + samples = ListListOps::combine<pointField> + ( + globalSamples, + accessOp<pointField>() + ); + } + + { + labelListList globalFaces(Pstream::nProcs()); + globalFaces[Pstream::myProcNo()] = identity(patch_.size()); + // Distribute to all processors + Pstream::gatherList(globalFaces); + Pstream::scatterList(globalFaces); + + patchFaces = ListListOps::combine<labelList> ( globalFaces, accessOp<labelList>() - ) - ); - label sampleI = 0; - forAll(nPerProc, procI) + ); + } + { - for (label i = 0; i < nPerProc[procI]; i++) + labelList nPerProc(Pstream::nProcs()); + nPerProc[Pstream::myProcNo()] = patch_.size(); + Pstream::gatherList(nPerProc); + Pstream::scatterList(nPerProc); + + patchFaceProcs.setSize(patchFaces.size()); + + label sampleI = 0; + forAll(nPerProc, procI) { - patchFaceProcs[sampleI++] = procI; + for (label i = 0; i < nPerProc[procI]; i++) + { + patchFaceProcs[sampleI++] = procI; + } } } } @@ -173,8 +209,9 @@ void Foam::mappedPatchBase::findSamples << sampleModeNames_[mode_] << " mode." << exit(FatalError); } - // Octree based search engine - meshSearch meshSearchEngine(mesh); + //- Note: face-diagonal decomposition + const meshSearchMeshObject& meshSearchEngine = + meshSearchMeshObject::New(mesh); forAll(samples, sampleI) { @@ -290,8 +327,9 @@ void Foam::mappedPatchBase::findSamples << sampleModeNames_[mode_] << " mode." << exit(FatalError); } - // Octree based search engine - meshSearch meshSearchEngine(mesh); + //- Note: face-diagonal decomposition + const meshSearchMeshObject& meshSearchEngine = + meshSearchMeshObject::New(mesh); forAll(samples, sampleI) { @@ -355,23 +393,6 @@ void Foam::mappedPatchBase::findSamples } } - // Check for samples not being found - forAll(nearest, sampleI) - { - if (!nearest[sampleI].first().hit()) - { - FatalErrorIn - ( - "mappedPatchBase::findSamples" - "(const pointField&, labelList&" - ", labelList&, pointField&)" - ) << "Did not find sample " << samples[sampleI] - << " on any processor of region " << sampleRegion_ - << exit(FatalError); - } - } - - // Convert back into proc+local index sampleProcs.setSize(samples.size()); sampleIndices.setSize(samples.size()); @@ -379,21 +400,40 @@ void Foam::mappedPatchBase::findSamples forAll(nearest, sampleI) { - sampleProcs[sampleI] = nearest[sampleI].second().second(); - sampleIndices[sampleI] = nearest[sampleI].first().index(); - sampleLocations[sampleI] = nearest[sampleI].first().hitPoint(); + if (!nearest[sampleI].first().hit()) + { + sampleProcs[sampleI] = -1; + sampleIndices[sampleI] = -1; + sampleLocations[sampleI] = vector::max; + } + else + { + sampleProcs[sampleI] = nearest[sampleI].second().second(); + sampleIndices[sampleI] = nearest[sampleI].first().index(); + sampleLocations[sampleI] = nearest[sampleI].first().hitPoint(); + } } } void Foam::mappedPatchBase::calcMapping() const { + static bool hasWarned = false; + if (mapPtr_.valid()) { FatalErrorIn("mappedPatchBase::calcMapping() const") << "Mapping already calculated" << exit(FatalError); } + // Get points on face (since cannot use face-centres - might be off + // face-diagonal decomposed tets. + tmp<pointField> patchPoints(facePoints(patch_)); + + // Get offsetted points + const pointField offsettedPoints = samplePoints(patchPoints()); + + // Do a sanity check // Am I sampling my own patch? This only makes sense for a non-zero // offset. @@ -405,8 +445,10 @@ void Foam::mappedPatchBase::calcMapping() const ); // Check offset - vectorField d(samplePoints()-patch_.faceCentres()); - if (sampleMyself && gAverage(mag(d)) <= ROOTVSMALL) + vectorField d(offsettedPoints-patchPoints()); + bool coincident = (gAverage(mag(d)) <= ROOTVSMALL); + + if (sampleMyself && coincident) { WarningIn ( @@ -438,7 +480,15 @@ void Foam::mappedPatchBase::calcMapping() const labelList patchFaceProcs; labelList patchFaces; pointField patchFc; - collectSamples(samples, patchFaceProcs, patchFaces, patchFc); + collectSamples + ( + patchPoints, + samples, + patchFaceProcs, + patchFaces, + patchFc + ); + // Find processor and cell/face samples are in and actual location. labelList sampleProcs; @@ -446,6 +496,77 @@ void Foam::mappedPatchBase::calcMapping() const pointField sampleLocations; findSamples(samples, sampleProcs, sampleIndices, sampleLocations); + // Check for samples that were not found. This will only happen for + // NEARESTCELL since finds cell containing a location + if (mode_ == NEARESTCELL) + { + label nNotFound = 0; + forAll(sampleProcs, sampleI) + { + if (sampleProcs[sampleI] == -1) + { + nNotFound++; + } + } + reduce(nNotFound, sumOp<label>()); + + if (nNotFound > 0) + { + if (!hasWarned) + { + WarningIn + ( + "mappedPatchBase::mappedPatchBase\n" + "(\n" + " const polyPatch& pp,\n" + " const word& sampleRegion,\n" + " const sampleMode mode,\n" + " const word& samplePatch,\n" + " const vector& offset\n" + ")\n" + ) << "Did not find " << nNotFound + << " out of " << sampleProcs.size() << " total samples." + << " Sampling these on owner cell centre instead." << 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; + } + + // Reset the samples that cannot be found to the cell centres. + pointField patchCc; + { + List<pointField> globalCc(Pstream::nProcs()); + globalCc[Pstream::myProcNo()] = patch_.faceCellCentres(); + Pstream::gatherList(globalCc); + Pstream::scatterList(globalCc); + patchCc = ListListOps::combine<pointField> + ( + globalCc, + accessOp<pointField>() + ); + } + + forAll(sampleProcs, sampleI) + { + if (sampleProcs[sampleI] == -1) + { + // Reset to cell centres + samples[sampleI] = patchCc[sampleI]; + } + } + + // And re-search. Note: could be optimised to only search missing + // points. + findSamples(samples, sampleProcs, sampleIndices, sampleLocations); + } + } + // Now we have all the data we need: // - where sample originates from (so destination when mapping): @@ -613,7 +734,7 @@ void Foam::mappedPatchBase::calcAMI() const /* const polyPatch& nbr = samplePolyPatch(); -// pointField nbrPoints(samplePoints()); +// pointField nbrPoints(offsettedPoints()); pointField nbrPoints(nbr.localPoints()); if (debug) @@ -932,9 +1053,12 @@ const Foam::polyPatch& Foam::mappedPatchBase::samplePolyPatch() const } -Foam::tmp<Foam::pointField> Foam::mappedPatchBase::samplePoints() const +Foam::tmp<Foam::pointField> Foam::mappedPatchBase::samplePoints +( + const pointField& fc +) const { - tmp<pointField> tfld(new pointField(patch_.faceCentres())); + tmp<pointField> tfld(new pointField(fc)); pointField& fld = tfld(); switch (offsetMode_) @@ -964,6 +1088,93 @@ Foam::tmp<Foam::pointField> Foam::mappedPatchBase::samplePoints() const } +Foam::tmp<Foam::pointField> Foam::mappedPatchBase::samplePoints() const +{ + return samplePoints(facePoints(patch_)); +} + + +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 43c19a671c508401dc7b3a2c0151256914133c1d..d5f6743edbdeb06b93d7a527e5b88a41423c31bf 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H @@ -33,7 +33,7 @@ Description sampleRegion region0; // What to sample: - // - nearestCell : sample nearest cell + // - nearestCell : sample cell containing point // - nearestPatchFace : nearest face on selected patch // - nearestPatchFaceAMI : nearest face on selected patch - patches need not conform @@ -204,9 +204,14 @@ protected: // Protected Member Functions + //- Get the points from face-centre-decomposition face centres + // and project them onto the face-diagonal-decomposition triangles. + tmp<pointField> facePoints(const polyPatch&) const; + //- Collect single list of samples and originating processor+face. void collectSamples ( + const pointField& facePoints, pointField&, labelList& patchFaceProcs, labelList& patchFaces, @@ -222,6 +227,9 @@ protected: pointField& sampleLocations // actual representative location ) const; + //- Get the sample points given the face points + tmp<pointField> samplePoints(const pointField&) const; + //- Calculate mapping void calcMapping() const; @@ -331,9 +339,24 @@ public: //- Get the patch on the region const polyPatch& samplePolyPatch() const; + // Helpers + //- Get the sample points tmp<pointField> 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/meshTools/meshSearch/meshSearchFACECENTRETETSMeshObject.C b/src/meshTools/meshSearch/meshSearchFACECENTRETETSMeshObject.C new file mode 100644 index 0000000000000000000000000000000000000000..ab023bfdc293dd1842d162cb77c0324cf21968db --- /dev/null +++ b/src/meshTools/meshSearch/meshSearchFACECENTRETETSMeshObject.C @@ -0,0 +1,48 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "meshSearchFACECENTRETETSMeshObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(meshSearchFACECENTRETETSMeshObject, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::meshSearchFACECENTRETETSMeshObject::meshSearchFACECENTRETETSMeshObject +( + const polyMesh& mesh +) +: + MeshObject<polyMesh, meshSearchFACECENTRETETSMeshObject>(mesh), + meshSearch(mesh, polyMesh::FACECENTRETETS) +{} + + +// ************************************************************************* // diff --git a/src/meshTools/meshSearch/meshSearchFACECENTRETETSMeshObject.H b/src/meshTools/meshSearch/meshSearchFACECENTRETETSMeshObject.H new file mode 100644 index 0000000000000000000000000000000000000000..2ddaf9d4fa3edfce313217a7b9264f8140fd5dcf --- /dev/null +++ b/src/meshTools/meshSearch/meshSearchFACECENTRETETSMeshObject.H @@ -0,0 +1,92 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 <http://www.gnu.org/licenses/>. + +Class + Foam::meshSearchFACECENTRETETSMeshObject + +Description + MeshObject wrapper around meshSearch(mesh, polyMesh::FACECENTRETETS). + +SourceFiles + +\*---------------------------------------------------------------------------*/ + +#ifndef meshSearchFACECENTRETETSMeshObject_H +#define meshSearchFACECENTRETETSMeshObject_H + +#include "MeshObject.H" +#include "meshSearch.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class meshSearchFACECENTRETETSMeshObject Declaration +\*---------------------------------------------------------------------------*/ + +class meshSearchFACECENTRETETSMeshObject +: + public MeshObject<polyMesh, meshSearchFACECENTRETETSMeshObject>, + public meshSearch +{ + +public: + + // Declare name of the class and its debug switch + TypeName("meshSearchFACECENTRETETSMeshObject"); + + + // Constructors + + //- Constructor given polyMesh + explicit meshSearchFACECENTRETETSMeshObject(const polyMesh& mesh); + + //- Destructor + virtual ~meshSearchFACECENTRETETSMeshObject() + {} + +// +// // Member functions +// +// // Edit +// +// //- Update mesh topology using the morph engine +// void updateMesh(); +// +// //- Correct weighting factors for moving mesh. +// bool movePoints(); +// +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/meshTools/meshSearch/meshSearchMeshObject.C b/src/meshTools/meshSearch/meshSearchMeshObject.C new file mode 100644 index 0000000000000000000000000000000000000000..12211345a17b5c3706d207c5f03c855999bc5040 --- /dev/null +++ b/src/meshTools/meshSearch/meshSearchMeshObject.C @@ -0,0 +1,45 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "meshSearchMeshObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(meshSearchMeshObject, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::meshSearchMeshObject::meshSearchMeshObject(const polyMesh& mesh) +: + MeshObject<polyMesh, meshSearchMeshObject>(mesh), + meshSearch(mesh) +{} + + +// ************************************************************************* // diff --git a/src/meshTools/meshSearch/meshSearchMeshObject.H b/src/meshTools/meshSearch/meshSearchMeshObject.H new file mode 100644 index 0000000000000000000000000000000000000000..838aa80c70540eb8ac88e5686d486428733678b7 --- /dev/null +++ b/src/meshTools/meshSearch/meshSearchMeshObject.H @@ -0,0 +1,92 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 <http://www.gnu.org/licenses/>. + +Class + Foam::meshSearchMeshObject + +Description + MeshObject wrapper around meshSearch(mesh). + +SourceFiles + +\*---------------------------------------------------------------------------*/ + +#ifndef meshSearchMeshObject_H +#define meshSearchMeshObject_H + +#include "MeshObject.H" +#include "meshSearch.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class meshSearchMeshObject Declaration +\*---------------------------------------------------------------------------*/ + +class meshSearchMeshObject +: + public MeshObject<polyMesh, meshSearchMeshObject>, + public meshSearch +{ + +public: + + // Declare name of the class and its debug switch + TypeName("meshSearchMeshObject"); + + + // Constructors + + //- Constructor given polyMesh + explicit meshSearchMeshObject(const polyMesh& mesh); + + //- Destructor + virtual ~meshSearchMeshObject() + {} + +// +// // Member functions +// +// // Edit +// +// //- Update mesh topology using the morph engine +// void updateMesh(); +// +// //- Correct weighting factors for moving mesh. +// bool movePoints(); +// +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/meshTools/searchableSurface/searchableSurfaceCollection.C b/src/meshTools/searchableSurface/searchableSurfaceCollection.C index 794cee20902a761ea97d50f6ead7ee5ba0f68c20..91115688b23c78d644c6d4bff98d9b37e54f8502 100644 --- a/src/meshTools/searchableSurface/searchableSurfaceCollection.C +++ b/src/meshTools/searchableSurface/searchableSurfaceCollection.C @@ -247,6 +247,35 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection transform_.setSize(surfI); subGeom_.setSize(surfI); indexOffset_.setSize(surfI+1); + + // Bounds is the overall bounds + bounds() = boundBox(point::max, point::min); + + forAll(subGeom_, surfI) + { + const boundBox& surfBb = subGeom_[surfI].bounds(); + + // Transform back to global coordinate sys. + const point surfBbMin = transform_[surfI].globalPosition + ( + cmptMultiply + ( + surfBb.min(), + scale_[surfI] + ) + ); + const point surfBbMax = transform_[surfI].globalPosition + ( + cmptMultiply + ( + surfBb.max(), + scale_[surfI] + ) + ); + + bounds().min() = min(bounds().min(), surfBbMin); + bounds().max() = max(bounds().max(), surfBbMax); + } } @@ -579,6 +608,9 @@ void Foam::searchableSurfaceCollection::getNormal vectorField surfNormal; subGeom_[surfI].getNormal(surfInfo[surfI], surfNormal); + // Transform back to global coordinate sys. + surfNormal = transform_[surfI].globalVector(surfNormal); + const labelList& map = infoMap[surfI]; forAll(map, i) { diff --git a/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C b/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C index 6e40feb9efe31ec4ff4014cd0416c50ae41c6eb3..dd74c17135079b95e806541231d5e9ffec3bcebc 100644 --- a/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C +++ b/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C @@ -187,6 +187,8 @@ Foam::searchableSurfaceWithGaps::searchableSurfaceWithGaps io.db().lookupObject<searchableSurface>(subGeomName); subGeom_.set(0, &const_cast<searchableSurface&>(s)); + + bounds() = subGeom_[0].bounds(); } diff --git a/src/meshTools/sets/faceSources/patchToFace/patchToFace.C b/src/meshTools/sets/faceSources/patchToFace/patchToFace.C index 4ee6ead86395b4036934dec5127389ac70a92ca2..4dec42630384f7def2cbd900a7e2d8219be702c0 100644 --- a/src/meshTools/sets/faceSources/patchToFace/patchToFace.C +++ b/src/meshTools/sets/faceSources/patchToFace/patchToFace.C @@ -54,33 +54,34 @@ Foam::topoSetSource::addToUsageTable Foam::patchToFace::usage_ void Foam::patchToFace::combine(topoSet& set, const bool add) const { - bool hasMatched = false; - - forAll(mesh_.boundaryMesh(), patchI) + labelHashSet patchIDs = mesh_.boundaryMesh().patchSet + ( + List<wordRe>(1, patchName_), + true, // warn if not found + true // use patch groups if available + ); + + forAllConstIter(labelHashSet, patchIDs, iter) { - const polyPatch& pp = mesh_.boundaryMesh()[patchI]; - - if (patchName_.match(pp.name())) - { - Info<< " Found matching patch " << pp.name() - << " with " << pp.size() << " faces." << endl; + label patchI = iter.key(); - hasMatched = true; + const polyPatch& pp = mesh_.boundaryMesh()[patchI]; + Info<< " Found matching patch " << pp.name() + << " with " << pp.size() << " faces." << endl; - for - ( - label faceI = pp.start(); - faceI < pp.start() + pp.size(); - faceI++ - ) - { - addOrDelete(set, faceI, add); - } + for + ( + label faceI = pp.start(); + faceI < pp.start() + pp.size(); + faceI++ + ) + { + addOrDelete(set, faceI, add); } } - if (!hasMatched) + if (patchIDs.empty()) { WarningIn("patchToFace::combine(topoSet&, const bool)") << "Cannot find any patch named " << patchName_ << endl diff --git a/src/postProcessing/functionObjects/field/nearWallFields/nearWallFields.C b/src/postProcessing/functionObjects/field/nearWallFields/nearWallFields.C index 2be79c30ccf0afa67337221717cd5b9cb560060b..d586dfba0ca815fd4a2c25fb5ebdda54711a10b4 100644 --- a/src/postProcessing/functionObjects/field/nearWallFields/nearWallFields.C +++ b/src/postProcessing/functionObjects/field/nearWallFields/nearWallFields.C @@ -70,13 +70,23 @@ Foam::nearWallFields::nearWallFields // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::nearWallFields::~nearWallFields() -{} +{ + if (debug) + { + Info<< "nearWallFields::~nearWallFields()" << endl; + } +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::nearWallFields::read(const dictionary& dict) { + if (debug) + { + Info<< "nearWallFields::read(const dictionary&)" << endl; + } + if (active_) { const fvMesh& mesh = refCast<const fvMesh>(obr_); @@ -122,6 +132,11 @@ void Foam::nearWallFields::read(const dictionary& dict) void Foam::nearWallFields::execute() { + if (debug) + { + Info<< "nearWallFields:execute()" << endl; + } + if (active_) { sampleFields(vsf_); @@ -135,12 +150,22 @@ void Foam::nearWallFields::execute() void Foam::nearWallFields::end() { - // Do nothing + if (debug) + { + Info<< "nearWallFields:end()" << endl; + } + // Update fields + execute(); } void Foam::nearWallFields::write() { + if (debug) + { + Info<< "nearWallFields:write()" << endl; + } + // Do nothing if (active_) { diff --git a/src/sampling/Make/files b/src/sampling/Make/files index f7c4775e8863e3e9127a7907b502d2bf7da7bc79..0c89693a8ea5326887f74c5d6c15c3c75878ab26 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 0000000000000000000000000000000000000000..23d8e7843d085810b58c33e31ec97e461d6d6a9a --- /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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "ensightSetWriter.H" +#include "coordSet.H" +#include "OFstream.H" +#include "addToRunTimeSelectionTable.H" +#include "IOmanip.H" +#include "foamVersion.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Type> +Foam::ensightSetWriter<Type>::ensightSetWriter() +: + writer<Type>() +{} + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template<class Type> +Foam::ensightSetWriter<Type>::~ensightSetWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +Foam::fileName Foam::ensightSetWriter<Type>::getFileName +( + const coordSet& points, + const wordList& valueSetNames +) const +{ + return + this->getBaseName(points, valueSetNames) + //+ '_' + //+ pTraits<Type>::typeName + + ".case"; +} + + +template<class Type> +void Foam::ensightSetWriter<Type>::write +( + const coordSet& points, + const wordList& valueSetNames, + const List<const Field<Type>*>& 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<Type>::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<Type>::typeName << nl + << "part" << nl + << setw(10) << 1 << nl + << "coordinates" << nl; + for (direction cmpt = 0; cmpt < pTraits<Type>::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<class Type> +void Foam::ensightSetWriter<Type>::write +( + const bool writeTracks, + const PtrList<coordSet>& tracks, + const wordList& valueSetNames, + const List<List<Field<Type> > >& 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<Type>::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<Type>::typeName << nl; + + const List<Field<Type> >& fieldVals = valueSets[setI]; + forAll(fieldVals, trackI) + { + os << "part" << nl + << setw(10) << trackI+1 << nl + << "coordinates" << nl; + + for + ( + direction cmpt = 0; + cmpt < pTraits<Type>::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 0000000000000000000000000000000000000000..5118c85faa79fbc268592aa0b37efb7c614d5608 --- /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 <http://www.gnu.org/licenses/>. + +Class + Foam::ensightSetWriter + +Description + +SourceFiles + ensightSetWriter.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightSetWriter_H +#define ensightSetWriter_H + +#include "writer.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class ensightSetWriter Declaration +\*---------------------------------------------------------------------------*/ + +template<class Type> +class ensightSetWriter +: + public writer<Type> +{ + +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<const Field<Type>*>&, + Ostream& + ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList<coordSet>&, + const wordList& valueSetNames, + const List<List<Field<Type> > >&, + 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 0000000000000000000000000000000000000000..b987035b332e4c01e1cb1d33f391956ff6ccb392 --- /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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#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 a8a0c377ccb47536f9ec3b687382794dbb1318dd..aa0b6a1d7bab2101cc5a69c2740d7df5c71e667b 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 82c3f1d68c2c92f7c1c55f84dbf15627305ffc88..8b82eccbb16348876d59add2e411a07bc9a416ac 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 aaedd23dab9b1b592cc799596df2f301c0917407..688796fe63772f17a3360838b27e238bd1675fbb 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 c2b5d2e493f326b7c385fc98ee0957a1d3ea4427..18e4c651fbf9051a7d2feaa321f710d1fe22c18a 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;