Commit 9da52157 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add sampledSurface::sampleOnPoints

- loop for interpolating volume elements to face points,
  which removes duplicate code in several other places
parent 2f608271
......@@ -61,36 +61,13 @@ Foam::sampledIsoSurfaceCell::sampleOnPoints
{
updateGeometry(); // Recreate geometry if time has changed
const labelList& elements = meshCells_;
// One value per point
auto tvalues = tmp<Field<Type>>::New(points().size());
auto& values = tvalues.ref();
const faceList& fcs = faces();
const pointField& pts = points();
bitSet pointDone(points().size());
forAll(faces(), cutFacei)
{
const face& f = fcs[cutFacei];
const label celli = elements[cutFacei];
for (const label pointi : f)
{
if (pointDone.set(pointi))
{
values[pointi] = interpolator.interpolate
(
pts[pointi],
celli
);
}
}
}
return tvalues;
return sampledSurface::sampleOnPoints
(
interpolator,
meshCells_,
faces(),
points()
);
}
......
......@@ -61,36 +61,13 @@ Foam::sampledIsoSurfaceTopo::sampleOnPoints
{
updateGeometry(); // Recreate geometry if time has changed
const labelList& elements = meshCells_;
// One value per point
auto tvalues = tmp<Field<Type>>::New(points().size());
auto& values = tvalues.ref();
const faceList& fcs = faces();
const pointField& pts = points();
bitSet pointDone(points().size());
forAll(faces(), cutFacei)
{
const face& f = fcs[cutFacei];
const label celli = elements[cutFacei];
for (const label pointi : f)
{
if (pointDone.set(pointi))
{
values[pointi] = interpolator.interpolate
(
pts[pointi],
celli
);
}
}
}
return tvalues;
return sampledSurface::sampleOnPoints
(
interpolator,
meshCells_,
faces(),
points()
);
}
......
......@@ -53,38 +53,13 @@ Foam::sampledCuttingSurface::sampleOnPoints
const interpolation<Type>& interpolator
) const
{
// elements to sample
const labelList& elements = meshCells();
// One value per point.
// Initialize with Zero to handle missed/degenerate faces
auto tvalues = tmp<Field<Type>>::New(points().size(), Zero);
auto& values = tvalues.ref();
bitSet pointDone(points().size());
const faceList& fcs = faces();
forAll(fcs, facei)
{
const face& f = fcs[facei];
const label celli = elements[facei];
for (const label pointi : f)
{
if (pointDone.set(pointi))
{
values[pointi] = interpolator.interpolate
(
points()[pointi],
celli
);
}
}
}
return tvalues;
return sampledSurface::sampleOnPoints
(
interpolator,
meshCells(),
faces(),
points()
);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -54,38 +54,13 @@ Foam::sampledPlane::sampleOnPoints
const interpolation<Type>& interpolator
) const
{
// elements to sample
const labelList& elements = meshCells();
// One value per point.
// Initialize with Zero to handle missed/degenerate faces
auto tvalues = tmp<Field<Type>>::New(points().size(), Zero);
auto& values = tvalues.ref();
bitSet pointDone(points().size());
const faceList& fcs = faces();
forAll(fcs, facei)
{
const face& f = fcs[facei];
const label celli = elements[facei];
for (const label pointi : f)
{
if (pointDone.set(pointi))
{
values[pointi] = interpolator.interpolate
(
points()[pointi],
celli
);
}
}
}
return tvalues;
return sampledSurface::sampleOnPoints
(
interpolator,
meshCells(),
faces(),
points()
);
}
......
......@@ -132,7 +132,7 @@ protected:
// Protected Member Functions
//- General loop for sampling elements to faces.
//- Loop for sampling volume elements to faces.
// The defaultValue is used for invalid (negative) elements
template<class Type>
static tmp<Field<Type>> sampleOnFaces
......@@ -145,6 +145,17 @@ protected:
);
//- Loop for interpolating volume elements to face points.
template<class Type>
static tmp<Field<Type>> sampleOnPoints
(
const interpolation<Type>& interpolator,
const labelUList& elements,
const faceList& fcs,
const pointField& pts
);
//- Create cell values by averaging the point values
template<class Type>
static tmp<GeometricField<Type, fvPatchField, volMesh>> pointAverage
......
......@@ -74,6 +74,56 @@ Foam::sampledSurface::sampleOnFaces
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::sampledSurface::sampleOnPoints
(
const interpolation<Type>& interpolator,
const labelUList& elements,
const faceList& fcs,
const pointField& pts
)
{
const label len = elements.size();
if (len != fcs.size())
{
FatalErrorInFunction
<< "size mismatch: "
<< "sampled elements (" << len
<< ") != faces (" << fcs.size() << ')'
<< exit(FatalError);
}
// One value per point
// Initialize with Zero to handle missed/degenerate faces
auto tvalues = tmp<Field<Type>>::New(pts.size(), Zero);
auto& values = tvalues.ref();
bitSet pointDone(pts.size());
forAll(fcs, facei)
{
const face& f = fcs[facei];
const label celli = elements[facei];
for (const label pointi : f)
{
if (pointDone.set(pointi))
{
values[pointi] = interpolator.interpolate
(
pts[pointi],
celli
);
}
}
}
return tvalues;
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::sampledSurface::pointAverage
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -42,27 +42,15 @@ Foam::sampledThresholdCellFaces::sampleOnFaces
const interpolation<Type>& sampler
) const
{
updateGeometry(); // Recreate geometry if time has changed
const labelList& elements = meshCells_;
const label len = faces().size();
auto tvalues = tmp<Field<Type>>::New(len);
auto& values = tvalues.ref();
const faceList& fcs = faces();
const pointField& pts = points();
for (label i=0; i < len; ++i)
{
const label celli = elements[i];
const point pt = fcs[i].centre(pts);
values[i] = sampler.interpolate(pt, celli);
}
return tvalues;
updateGeometry(); // Recreate geometry if time has changed
return sampledSurface::sampleOnFaces
(
sampler,
meshCells_,
faces(),
points()
);
}
......@@ -73,38 +61,15 @@ Foam::sampledThresholdCellFaces::sampleOnPoints
const interpolation<Type>& interpolator
) const
{
updateGeometry(); // Recreate geometry if time has changed
const labelList& elements = meshCells_;
// One value per point
auto tvalues = tmp<Field<Type>>::New(points().size(), Zero);
auto& values = tvalues.ref();
bitSet pointDone(points().size());
const faceList& fcs = faces();
const pointField& pts = points();
forAll(fcs, i)
{
const face& f = fcs[i];
const label celli = elements[i];
for (const label pointi : f)
{
if (pointDone.set(pointi))
{
values[pointi] = interpolator.interpolate
(
pts[pointi],
celli
);
}
}
}
return tvalues;
updateGeometry(); // Recreate geometry if time has changed
return sampledSurface::sampleOnPoints
(
interpolator,
meshCells_,
faces(),
points()
);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment