diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C index 20b57d80b38a5ab7cb491961ba7dc6e05d64c2cd..5ae942673ad0ca3335f813c253b5908f1c53367b 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C @@ -46,13 +46,14 @@ namespace Foam ); template<> - const char* NamedEnum<sampledTriSurfaceMesh::samplingSource, 2>::names[] = + const char* NamedEnum<sampledTriSurfaceMesh::samplingSource, 3>::names[] = { "cells", + "insideCells", "boundaryFaces" }; - const NamedEnum<sampledTriSurfaceMesh::samplingSource, 2> + const NamedEnum<sampledTriSurfaceMesh::samplingSource, 3> sampledTriSurfaceMesh::samplingSourceNames_; @@ -147,7 +148,7 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher) // elements globalIndex globalCells ( - sampleSource_ == cells + (sampleSource_ == cells || sampleSource_ == insideCells) ? mesh().nCells() : mesh().nFaces() ); @@ -178,6 +179,25 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher) } } } + else if (sampleSource_ == insideCells) + { + // Search for cell containing point + + const indexedOctree<treeDataCell>& cellTree = meshSearcher.cellTree(); + + forAll(fc, triI) + { + if (cellTree.bb().contains(fc[triI])) + { + label index = cellTree.findInside(fc[triI]); + if (index != -1) + { + nearest[triI].first() = 0.0; + nearest[triI].second() = globalCells.toGlobal(index); + } + } + } + } else { // Search for nearest boundaryFace @@ -364,6 +384,19 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher) } } } + else if (sampleSource_ == insideCells) + { + // samplePoints_ : per surface point a location inside the cell + // sampleElements_ : per surface point the cell + + forAll(points(), pointI) + { + const point& pt = points()[pointI]; + label cellI = cellOrFaceLabels[pointToFace[pointI]]; + sampleElements_[pointI] = cellI; + samplePoints_[pointI] = pt; + } + } else { // samplePoints_ : per surface point a location on the boundary @@ -388,6 +421,9 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher) // if sampleSource_ == cells: // samplePoints_ : n/a // sampleElements_ : per surface triangle the cell + // if sampleSource_ == insideCells: + // samplePoints_ : n/a + // sampleElements_ : -1 or per surface triangle the cell // else: // samplePoints_ : n/a // sampleElements_ : per surface triangle the boundary face @@ -406,7 +442,7 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher) if (sampledSurface::interpolate()) { - if (sampleSource_ == cells) + if (sampleSource_ == cells || sampleSource_ == insideCells) { forAll(samplePoints_, pointI) { @@ -443,7 +479,7 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher) } else { - if (sampleSource_ == cells) + if (sampleSource_ == cells || sampleSource_ == insideCells) { forAll(sampleElements_, triI) { diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H index 7ef68570c43b0a67ac48c7b13005de6ca249bc0a..1e7cd4e6ed36a82bae54774d07c1dbfcf328c71b 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H @@ -30,7 +30,7 @@ Description - it either samples cells or (non-coupled) boundary faces - - 4 different modes: + - 6 different modes: - source=cells, interpolate=false: finds per triangle centre the nearest cell centre and uses its value - source=cells, interpolate=true @@ -40,6 +40,12 @@ Description the boundary of the cell (to make sure interpolateCellPoint gets a valid location) + - source=insideCells, interpolate=false: + finds per triangle centre the cell containing it and uses its value. + Trims triangles outside mesh. + - source=insideCells, interpolate=true + Per surface point interpolate cell containing it. + - source=boundaryFaces, interpolate=false: finds per triangle centre the nearest point on the boundary (uncoupled faces only) and uses the value (or 0 if the nearest @@ -88,7 +94,8 @@ public: enum samplingSource { cells, - boundaryFaces + insideCells, + boundaryFaces, }; private: @@ -99,7 +106,7 @@ private: // Private data - static const NamedEnum<samplingSource, 2> samplingSourceNames_; + static const NamedEnum<samplingSource, 3> samplingSourceNames_; //- Surface to sample on const triSurfaceMesh surface_; diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMeshTemplates.C b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMeshTemplates.C index ca6931ef8745d5c23516627bf8d8504507299bda..d251431a550ea89caf5e5c7fd67c4bf2a56919e3 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMeshTemplates.C +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMeshTemplates.C @@ -38,7 +38,7 @@ Foam::sampledTriSurfaceMesh::sampleField tmp<Field<Type> > tvalues(new Field<Type>(sampleElements_.size())); Field<Type>& values = tvalues(); - if (sampleSource_ == cells) + if (sampleSource_ == cells || sampleSource_ == insideCells) { // Sample cells @@ -94,7 +94,7 @@ Foam::sampledTriSurfaceMesh::interpolateField tmp<Field<Type> > tvalues(new Field<Type>(sampleElements_.size())); Field<Type>& values = tvalues(); - if (sampleSource_ == cells) + if (sampleSource_ == cells || sampleSource_ == insideCells) { // Sample cells.