mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add sampledSurface::sampleOnPoints
- loop for interpolating volume elements to face points, which removes duplicate code in several other places
This commit is contained in:
@ -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
|
||||
return sampledSurface::sampleOnPoints
|
||||
(
|
||||
pts[pointi],
|
||||
celli
|
||||
interpolator,
|
||||
meshCells_,
|
||||
faces(),
|
||||
points()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tvalues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
return sampledSurface::sampleOnPoints
|
||||
(
|
||||
pts[pointi],
|
||||
celli
|
||||
interpolator,
|
||||
meshCells_,
|
||||
faces(),
|
||||
points()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tvalues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
return sampledSurface::sampleOnPoints
|
||||
(
|
||||
points()[pointi],
|
||||
celli
|
||||
interpolator,
|
||||
meshCells(),
|
||||
faces(),
|
||||
points()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tvalues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
return sampledSurface::sampleOnPoints
|
||||
(
|
||||
points()[pointi],
|
||||
celli
|
||||
interpolator,
|
||||
meshCells(),
|
||||
faces(),
|
||||
points()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tvalues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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.
|
||||
@ -44,25 +44,13 @@ Foam::sampledThresholdCellFaces::sampleOnFaces
|
||||
{
|
||||
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;
|
||||
return sampledSurface::sampleOnFaces
|
||||
(
|
||||
sampler,
|
||||
meshCells_,
|
||||
faces(),
|
||||
points()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -75,36 +63,13 @@ Foam::sampledThresholdCellFaces::sampleOnPoints
|
||||
{
|
||||
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
|
||||
return sampledSurface::sampleOnPoints
|
||||
(
|
||||
pts[pointi],
|
||||
celli
|
||||
interpolator,
|
||||
meshCells_,
|
||||
faces(),
|
||||
points()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tvalues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user