37#include <boost/geometry.hpp>
41namespace bg = boost::geometry;
42namespace bgi = boost::geometry::index;
62 ASSERTL0(ptsInField->GetDim() <=
m_dim,
"too many dimensions in inField");
63 ASSERTL0(ptsOutField->GetDim() <=
m_dim,
"too many dimensions in outField");
100 for (
size_t i = 0; i < nOutPts; ++i)
111 int progress = int(100 * i / nOutPts);
130 for (
size_t i = 0; i < nOutPts; ++i)
148 int progress = int(100 * i / nOutPts);
162 numPts = 1 << numPts;
163 numPts = min(numPts,
int(
m_ptsInField->GetNpoints() / 2));
168 for (
size_t i = 0; i < nOutPts; ++i)
179 int progress = int(100 * i / nOutPts);
193 "No filter width set");
202 for (
size_t i = 0; i < nOutPts; ++i)
213 int progress = int(100 * i / nOutPts);
243 ASSERTL0(ptsInField->GetNFields() == ptsOutField->GetNFields(),
244 "number of fields does not match");
245 ASSERTL0(ptsInField->GetDim() <=
m_dim,
"too many dimesions in inField");
246 ASSERTL0(ptsOutField->GetDim() <=
m_dim,
"too many dimesions in outField");
257 "weights dimension mismatch");
264 for (
size_t i = 0; i < nFields; ++i)
266 for (
size_t j = 0; j < nOutPts; ++j)
277 for (
size_t k = 0; k < nPts; ++k)
332 cout <<
"Number of points: " <<
m_neighInds.GetRows() << endl;
335 cout <<
"mean Number of Neighbours per point: "
354 vector<PtsPoint> neighbourPts;
356 size_t numPts = neighbourPts.size();
371 NekDouble sigmaNew = 0.25 * neighbourPts.back().dist;
373 for (
size_t i = 0; i < numPts; i++)
379 NekDouble ts2 = 2.0 * sigmaNew * sigmaNew;
380 for (
size_t i = 0; i < numPts; ++i)
383 exp(-1.0 * neighbourPts[i].dist * neighbourPts[i].dist / ts2);
387 for (
size_t i = 0; i < numPts; ++i)
409 for (i = 0; i < npts - 1; ++i)
430 ASSERTL0(i != npts - 1,
"Failed to find coordinate " +
431 boost::lexical_cast<string>(coord) +
432 " within provided input points");
446 vector<PtsPoint> neighbourPts;
473 vector<PtsPoint> neighbourPts;
476 for (
int i = 0; i < neighbourPts.size(); i++)
482 for (
int i = 0; i < neighbourPts.size(); ++i)
492 for (
int i = 0; i < neighbourPts.size(); ++i)
494 m_weights[searchPt.
idx][i] = 1 / pow(
double(neighbourPts[i].dist),
499 for (
int i = 0; i < neighbourPts.size(); ++i)
523 for (i = 0; i < npts - 1; ++i)
542 (pdiff * (pdiff + pdiff2));
548 ((pdiff + pdiff2) * pdiff2);
565 (pdiff * (pdiff + pdiff2));
568 ((pdiff + pdiff2) * pdiff);
582 ASSERTL0(i != npts - 1,
"Failed to find coordinate " +
583 boost::lexical_cast<string>(coord) +
584 " within provided input points");
589 std::vector<PtsPointPair> inPoints;
601 m_rtree->insert(inPoints.begin(), inPoints.end());
604 for (
auto &it : inPoints)
606 std::vector<PtsPointPair> result;
611 m_rtree->query(bgi::nearest(it.first, 2), std::back_inserter(result));
616 for (
auto &it2 : result)
618 if (it.second != it2.second &&
638 vector<PtsPoint> &neighbourPts,
639 const unsigned int numPts)
641 std::vector<PtsPointPair> result;
644 m_rtree->query(bgi::nearest(searchBPoint, numPts),
645 std::back_inserter(result));
648 for (
int i = 0; i < result.size(); ++i)
650 int idx = result[i].second;
656 NekDouble d = bg::distance(searchBPoint, result[i].first);
657 neighbourPts.push_back(
PtsPoint(idx, coords,
d));
660 sort(neighbourPts.begin(), neighbourPts.end());
672 vector<PtsPoint> &neighbourPts,
674 const unsigned int maxPts)
679 searchPt.
coords[2] - dist);
681 searchPt.
coords[2] + dist);
682 bg::model::box<BPoint> bbox(bbMin, bbMax);
685 std::vector<PtsPointPair> result;
688 m_rtree->query(bgi::within(bbox) && bgi::nearest(searchBPoint, maxPts),
689 std::back_inserter(result));
693 m_rtree->query(bgi::within(bbox), std::back_inserter(result));
697 for (
int i = 0; i < result.size(); ++i)
699 int idx = result[i].second;
705 NekDouble d = bg::distance(searchBPoint, result[i].first);
710 neighbourPts.push_back(
PtsPoint(idx, coords,
d));
714 sort(neighbourPts.begin(), neighbourPts.end());
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Array< OneD, NekDouble > coords
void Interpolate(const LibUtilities::PtsFieldSharedPtr ptsInField, LibUtilities::PtsFieldSharedPtr &ptsOutField)
Interpolate from a pts field to a pts field.
Array< TwoD, NekDouble > m_weights
Interpolation weights for each neighbour. Structure: m_weights[physPtIdx][neighbourIdx].
int GetCoordId() const
Returns the coordinate id along which the interpolation should be performed.
void PrintStatistics()
Returns if the weights have already been computed.
LibUtilities::PtsFieldSharedPtr GetInField() const
Returns the input field.
int m_maxPts
Max number of interpolation points.
Array< TwoD, unsigned int > m_neighInds
Indices of the relevant neighbours for each physical point. Structure: m_neighInds[ptIdx][neighbourId...
LibUtilities::PtsFieldSharedPtr GetOutField() const
Returns the output field.
static const int m_dim
dimension of this interpolator. Hardcoded to 3
InterpMethod m_method
Interpolation Method.
int GetDim() const
returns the dimension of the Interpolator. Should be higher than the dimensions of the interpolated f...
std::shared_ptr< PtsRtree > m_rtree
A tree structure to speed up the neighbour search. Note that we fill it with an iterator,...
std::pair< BPoint, unsigned int > PtsPointPair
NekDouble m_filtWidth
Filter width used for some interpolation algorithms.
void CalcW_Linear(const PtsPoint &searchPt, int coordId)
Computes interpolation weights using linear interpolation.
boost::geometry::model::point< NekDouble, m_dim, boost::geometry::cs::cartesian > BPoint
void CalcW_NNeighbour(const PtsPoint &searchPt)
Computes interpolation weights using nearest neighbour interpolation.
LibUtilities::PtsFieldSharedPtr m_ptsInField
input field
void CalcW_Shepard(const PtsPoint &searchPt, int numPts)
Computes interpolation weights using linear interpolation.
NekDouble GetFiltWidth() const
Returns the filter width.
InterpMethod GetInterpMethod() const
Returns the interpolation method used by this interpolator.
void CalcW_Gauss(const PtsPoint &searchPt, const NekDouble sigma, const int maxPts=250)
Computes interpolation weights using gaussian interpolation.
std::function< void(const int position, const int goal)> m_progressCallback
void FindNNeighbours(const PtsPoint &searchPt, std::vector< PtsPoint > &neighbourPts, const unsigned int numPts=1)
Finds the nearest neighbours of a point.
void CalcW_Quadratic(const PtsPoint &searchPt, int coordId)
Computes interpolation weights using quadratic interpolation.
void CalcWeights(const LibUtilities::PtsFieldSharedPtr ptsInField, LibUtilities::PtsFieldSharedPtr &ptsOutField, bool reuseTree=false)
Compute interpolation weights without doing any interpolation.
void FindNeighbours(const PtsPoint &searchPt, std::vector< PtsPoint > &neighbourPts, const NekDouble dist, const unsigned int maxPts=1)
Finds the nearest neighbours of a point.
short int m_coordId
coordinate id along which the interpolation should be performed
LibUtilities::PtsFieldSharedPtr m_ptsOutField
output field
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< PtsField > PtsFieldSharedPtr
static const NekDouble kNekZeroTol
std::vector< double > d(NPUPPER *NPUPPER)