37#include <boost/geometry.hpp>
41namespace bg = boost::geometry;
42namespace bgi = boost::geometry::index;
64 ASSERTL0(ptsInField->GetDim() <=
m_dim,
"too many dimensions in inField");
65 ASSERTL0(ptsOutField->GetDim() <=
m_dim,
"too many dimensions in outField");
102 for (
size_t i = 0; i < nOutPts; ++i)
113 int progress = int(100 * i / nOutPts);
132 for (
size_t i = 0; i < nOutPts; ++i)
150 int progress = int(100 * i / nOutPts);
164 numPts = 1 << numPts;
165 numPts = min(numPts,
int(
m_ptsInField->GetNpoints() / 2));
170 for (
size_t i = 0; i < nOutPts; ++i)
181 int progress = int(100 * i / nOutPts);
195 "No filter width set");
204 for (
size_t i = 0; i < nOutPts; ++i)
215 int progress = int(100 * i / nOutPts);
245 ASSERTL0(ptsInField->GetNFields() == ptsOutField->GetNFields(),
246 "number of fields does not match");
247 ASSERTL0(ptsInField->GetDim() <=
m_dim,
"too many dimesions in inField");
248 ASSERTL0(ptsOutField->GetDim() <=
m_dim,
"too many dimesions in outField");
259 "weights dimension mismatch");
266 for (
size_t i = 0; i < nFields; ++i)
268 for (
size_t j = 0; j < nOutPts; ++j)
279 for (
size_t k = 0; k < nPts; ++k)
334 cout <<
"Number of points: " <<
m_neighInds.GetRows() << endl;
337 cout <<
"mean Number of Neighbours per point: "
356 vector<PtsPoint> neighbourPts;
358 size_t numPts = neighbourPts.size();
373 NekDouble sigmaNew = 0.25 * neighbourPts.back().dist;
375 for (
size_t i = 0; i < numPts; i++)
381 NekDouble ts2 = 2.0 * sigmaNew * sigmaNew;
382 for (
size_t i = 0; i < numPts; ++i)
385 exp(-1.0 * neighbourPts[i].dist * neighbourPts[i].dist / ts2);
389 for (
size_t i = 0; i < numPts; ++i)
411 for (i = 0; i < npts - 1; ++i)
432 ASSERTL0(i != npts - 1,
"Failed to find coordinate " +
433 boost::lexical_cast<string>(coord) +
434 " within provided input points");
448 vector<PtsPoint> neighbourPts;
475 vector<PtsPoint> neighbourPts;
478 for (
int i = 0; i < neighbourPts.size(); i++)
484 for (
int i = 0; i < neighbourPts.size(); ++i)
494 for (
int i = 0; i < neighbourPts.size(); ++i)
496 m_weights[searchPt.
idx][i] = 1 / pow(
double(neighbourPts[i].dist),
501 for (
int i = 0; i < neighbourPts.size(); ++i)
525 for (i = 0; i < npts - 1; ++i)
544 (pdiff * (pdiff + pdiff2));
550 ((pdiff + pdiff2) * pdiff2);
567 (pdiff * (pdiff + pdiff2));
570 ((pdiff + pdiff2) * pdiff);
584 ASSERTL0(i != npts - 1,
"Failed to find coordinate " +
585 boost::lexical_cast<string>(coord) +
586 " within provided input points");
591 std::vector<PtsPointPair> inPoints;
603 m_rtree->insert(inPoints.begin(), inPoints.end());
606 for (
auto &it : inPoints)
608 std::vector<PtsPointPair> result;
613 m_rtree->query(bgi::nearest(it.first, 2), std::back_inserter(result));
618 for (
auto &it2 : result)
620 if (it.second != it2.second &&
640 vector<PtsPoint> &neighbourPts,
641 const unsigned int numPts)
643 std::vector<PtsPointPair> result;
646 m_rtree->query(bgi::nearest(searchBPoint, numPts),
647 std::back_inserter(result));
650 for (
int i = 0; i < result.size(); ++i)
652 int idx = result[i].second;
658 NekDouble d = bg::distance(searchBPoint, result[i].first);
659 neighbourPts.push_back(
PtsPoint(idx, coords,
d));
662 sort(neighbourPts.begin(), neighbourPts.end());
674 vector<PtsPoint> &neighbourPts,
676 const unsigned int maxPts)
681 searchPt.
coords[2] - dist);
683 searchPt.
coords[2] + dist);
684 bg::model::box<BPoint> bbox(bbMin, bbMax);
687 std::vector<PtsPointPair> result;
690 m_rtree->query(bgi::within(bbox) && bgi::nearest(searchBPoint, maxPts),
691 std::back_inserter(result));
695 m_rtree->query(bgi::within(bbox), std::back_inserter(result));
699 for (
int i = 0; i < result.size(); ++i)
701 int idx = result[i].second;
707 NekDouble d = bg::distance(searchBPoint, result[i].first);
712 neighbourPts.push_back(
PtsPoint(idx, coords,
d));
716 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)
The above copyright notice and this permission notice shall be included.