Nektar++
Classes | Public Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Nektar::LibUtilities::Interpolator Class Reference

A class that contains algorithms for interpolation between pts fields, expansions and different meshes. More...

#include <Interpolator.h>

Inheritance diagram for Nektar::LibUtilities::Interpolator:
[legend]

Classes

class  PtsPoint
 

Public Member Functions

 Interpolator (InterpMethod method=eNoMethod, short int coordId=-1, NekDouble filtWidth=0.0, int maxPts=1000)
 Constructor of the Interpolator class. More...
 
void CalcWeights (const LibUtilities::PtsFieldSharedPtr ptsInField, LibUtilities::PtsFieldSharedPtr &ptsOutField, bool reuseTree=false)
 Compute interpolation weights without doing any interpolation. More...
 
void Interpolate (const LibUtilities::PtsFieldSharedPtr ptsInField, LibUtilities::PtsFieldSharedPtr &ptsOutField)
 Interpolate from a pts field to a pts field. More...
 
int GetDim () const
 returns the dimension of the Interpolator. Should be higher than the dimensions of the interpolated fields More...
 
NekDouble GetFiltWidth () const
 Returns the filter width. More...
 
int GetCoordId () const
 Returns the coordinate id along which the interpolation should be performed. More...
 
InterpMethod GetInterpMethod () const
 Returns the interpolation method used by this interpolator. More...
 
LibUtilities::PtsFieldSharedPtr GetInField () const
 Returns the input field. More...
 
LibUtilities::PtsFieldSharedPtr GetOutField () const
 Returns the output field. More...
 
void PrintStatistics ()
 Returns if the weights have already been computed. More...
 
template<typename FuncPointerT , typename ObjectPointerT >
void SetProgressCallback (FuncPointerT func, ObjectPointerT obj)
 sets a callback funtion which gets called every time the interpolation progresses More...
 

Protected Attributes

LibUtilities::PtsFieldSharedPtr m_ptsInField
 input field More...
 
LibUtilities::PtsFieldSharedPtr m_ptsOutField
 output field More...
 
std::function< void(const int position, const int goal)> m_progressCallback
 

Private Types

typedef boost::geometry::model::point< NekDouble, m_dim, boost::geometry::cs::cartesian > BPoint
 
typedef std::pair< BPoint, unsigned int > PtsPointPair
 
typedef boost::geometry::index::rtree< PtsPointPair, boost::geometry::index::rstar< 16 > > PtsRtree
 

Private Member Functions

void CalcW_Gauss (const PtsPoint &searchPt, const NekDouble sigma, const int maxPts=250)
 Computes interpolation weights using gaussian interpolation. More...
 
void CalcW_Linear (const PtsPoint &searchPt, int coordId)
 Computes interpolation weights using linear interpolation. More...
 
void CalcW_NNeighbour (const PtsPoint &searchPt)
 Computes interpolation weights using nearest neighbour interpolation. More...
 
void CalcW_Shepard (const PtsPoint &searchPt, int numPts)
 Computes interpolation weights using linear interpolation. More...
 
void CalcW_Quadratic (const PtsPoint &searchPt, int coordId)
 Computes interpolation weights using quadratic interpolation. More...
 
void SetupTree ()
 
void FindNeighbours (const PtsPoint &searchPt, std::vector< PtsPoint > &neighbourPts, const NekDouble dist, const unsigned int maxPts=1)
 Finds the nearest neighbours of a point. More...
 
void FindNNeighbours (const PtsPoint &searchPt, std::vector< PtsPoint > &neighbourPts, const unsigned int numPts=1)
 Finds the nearest neighbours of a point. More...
 

Private Attributes

InterpMethod m_method
 Interpolation Method. More...
 
std::shared_ptr< PtsRtreem_rtree
 A tree structure to speed up the neighbour search. Note that we fill it with an iterator, so instead of rstar, the packing algorithm is used. More...
 
Array< TwoD, NekDoublem_weights
 Interpolation weights for each neighbour. Structure: m_weights[physPtIdx][neighbourIdx]. More...
 
Array< TwoD, unsigned int > m_neighInds
 Indices of the relevant neighbours for each physical point. Structure: m_neighInds[ptIdx][neighbourIdx]. More...
 
NekDouble m_filtWidth
 Filter width used for some interpolation algorithms. More...
 
int m_maxPts
 Max number of interpolation points. More...
 
short int m_coordId
 coordinate id along which the interpolation should be performed More...
 

Static Private Attributes

static const int m_dim = 3
 dimension of this interpolator. Hardcoded to 3 More...
 

Detailed Description

A class that contains algorithms for interpolation between pts fields, expansions and different meshes.

Definition at line 71 of file LibUtilities/BasicUtils/Interpolator.h.

Member Typedef Documentation

◆ BPoint

typedef boost::geometry::model::point<NekDouble, m_dim, boost::geometry::cs::cartesian> Nektar::LibUtilities::Interpolator::BPoint
private

Definition at line 172 of file LibUtilities/BasicUtils/Interpolator.h.

◆ PtsPointPair

typedef std::pair<BPoint, unsigned int> Nektar::LibUtilities::Interpolator::PtsPointPair
private

Definition at line 173 of file LibUtilities/BasicUtils/Interpolator.h.

◆ PtsRtree

typedef boost::geometry::index::rtree<PtsPointPair, boost::geometry::index::rstar<16> > Nektar::LibUtilities::Interpolator::PtsRtree
private

Definition at line 176 of file LibUtilities/BasicUtils/Interpolator.h.

Constructor & Destructor Documentation

◆ Interpolator()

Nektar::LibUtilities::Interpolator::Interpolator ( InterpMethod  method = eNoMethod,
short int  coordId = -1,
NekDouble  filtWidth = 0.0,
int  maxPts = 1000 
)
inline

Constructor of the Interpolator class.

Parameters
methodinterpolation method, defaults to a sensible value if not set
coordIdcoordinate id along which the interpolation should be performed
filtWidthfilter width, required by some algorithms such as eGauss
maxPtslimit number of considered points

if method is not specified, the best algorithm is chosen automatically.

If coordId is not specified, a full 1D/2D/3D interpolation is performed without collapsing any coordinate.

filtWidth must be specified for the eGauss algorithm only.

Definition at line 92 of file LibUtilities/BasicUtils/Interpolator.h.

94 : m_method(method), m_filtWidth(filtWidth), m_maxPts(maxPts),
95 m_coordId(coordId)
96 {
97 }
int m_maxPts
Max number of interpolation points.
NekDouble m_filtWidth
Filter width used for some interpolation algorithms.
short int m_coordId
coordinate id along which the interpolation should be performed

Member Function Documentation

◆ CalcW_Gauss()

void Nektar::LibUtilities::Interpolator::CalcW_Gauss ( const PtsPoint searchPt,
const NekDouble  sigma,
const int  maxPts = 250 
)
private

Computes interpolation weights using gaussian interpolation.

Parameters
searchPtpoint for which the weights are computed
sigmastandard deviation of the gauss function

Performs an interpolation using gauss weighting. Ideal for filtering fields. The filter width should be half the FWHM (= 1.1774 sigma) and must be set in the constructor of the Interpolator class.

Definition at line 350 of file LibUtilities/BasicUtils/Interpolator.cpp.

352{
353 // find nearest neighbours
354 vector<PtsPoint> neighbourPts;
355 FindNeighbours(searchPt, neighbourPts, 4 * sigma, maxPts);
356 size_t numPts = neighbourPts.size();
357
358 // handle the cases that there was no or just one point within 4 * sigma
359 if (numPts == 0)
360 {
361 return;
362 }
363 if (numPts == 1)
364 {
365 m_neighInds[searchPt.idx][0] = neighbourPts.front().idx;
366 m_weights[searchPt.idx][0] = 1.0;
367
368 return;
369 }
370
371 NekDouble sigmaNew = 0.25 * neighbourPts.back().dist;
372
373 for (size_t i = 0; i < numPts; i++)
374 {
375 m_neighInds[searchPt.idx][i] = neighbourPts.at(i).idx;
376 }
377
378 NekDouble wSum = 0.0;
379 NekDouble ts2 = 2.0 * sigmaNew * sigmaNew;
380 for (size_t i = 0; i < numPts; ++i)
381 {
382 m_weights[searchPt.idx][i] =
383 exp(-1.0 * neighbourPts[i].dist * neighbourPts[i].dist / ts2);
384 wSum += m_weights[searchPt.idx][i];
385 }
386
387 for (size_t i = 0; i < numPts; ++i)
388 {
389 m_weights[searchPt.idx][i] = m_weights[searchPt.idx][i] / wSum;
390 }
391}
Array< TwoD, NekDouble > m_weights
Interpolation weights for each neighbour. Structure: m_weights[physPtIdx][neighbourIdx].
Array< TwoD, unsigned int > m_neighInds
Indices of the relevant neighbours for each physical point. Structure: m_neighInds[ptIdx][neighbourId...
void FindNeighbours(const PtsPoint &searchPt, std::vector< PtsPoint > &neighbourPts, const NekDouble dist, const unsigned int maxPts=1)
Finds the nearest neighbours of a point.
double NekDouble

References FindNeighbours(), Nektar::LibUtilities::Interpolator::PtsPoint::idx, m_neighInds, and m_weights.

Referenced by CalcWeights().

◆ CalcW_Linear()

void Nektar::LibUtilities::Interpolator::CalcW_Linear ( const PtsPoint searchPt,
int  m_coordId 
)
private

Computes interpolation weights using linear interpolation.

Parameters
searchPtpoint for which the weights are computed
m_coordIdcoordinate id along which the interpolation should be performed

Currently, only implemented for 1D

Definition at line 402 of file LibUtilities/BasicUtils/Interpolator.cpp.

403{
404 int npts = m_ptsInField->GetNpoints();
405 int i;
406
407 NekDouble coord = searchPt.coords[m_coordId];
408
409 for (i = 0; i < npts - 1; ++i)
410 {
411 if ((m_ptsInField->GetPointVal(0, i) <=
412 (coord + NekConstants::kNekZeroTol)) &&
413 (coord <=
414 (m_ptsInField->GetPointVal(0, i + 1) + NekConstants::kNekZeroTol)))
415 {
416 NekDouble pdiff = m_ptsInField->GetPointVal(0, i + 1) -
417 m_ptsInField->GetPointVal(0, i);
418
419 m_neighInds[searchPt.idx][0] = i;
420 m_neighInds[searchPt.idx][1] = i + 1;
421
422 m_weights[searchPt.idx][0] =
423 (m_ptsInField->GetPointVal(0, i + 1) - coord) / pdiff;
424 m_weights[searchPt.idx][1] =
425 (coord - m_ptsInField->GetPointVal(0, i)) / pdiff;
426
427 break;
428 }
429 }
430 ASSERTL0(i != npts - 1, "Failed to find coordinate " +
431 boost::lexical_cast<string>(coord) +
432 " within provided input points");
433}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
LibUtilities::PtsFieldSharedPtr m_ptsInField
input field
static const NekDouble kNekZeroTol

References ASSERTL0, Nektar::LibUtilities::Interpolator::PtsPoint::coords, Nektar::LibUtilities::Interpolator::PtsPoint::idx, Nektar::NekConstants::kNekZeroTol, m_coordId, m_neighInds, m_ptsInField, and m_weights.

Referenced by CalcWeights().

◆ CalcW_NNeighbour()

void Nektar::LibUtilities::Interpolator::CalcW_NNeighbour ( const PtsPoint searchPt)
private

Computes interpolation weights using nearest neighbour interpolation.

Parameters
searchPtpoint for which the weights are computed
m_coordIdcoordinate id along which the interpolation should be performed

Definition at line 443 of file LibUtilities/BasicUtils/Interpolator.cpp.

444{
445 // find nearest neighbours
446 vector<PtsPoint> neighbourPts;
447 // TODO: we currently dont handle the case when there are more than one
448 // most distant points (of same distance)
449 FindNNeighbours(searchPt, neighbourPts, 1);
450
451 m_neighInds[searchPt.idx][0] = neighbourPts[0].idx;
452 m_weights[searchPt.idx][0] = 1.0;
453}
void FindNNeighbours(const PtsPoint &searchPt, std::vector< PtsPoint > &neighbourPts, const unsigned int numPts=1)
Finds the nearest neighbours of a point.

References FindNNeighbours(), Nektar::LibUtilities::Interpolator::PtsPoint::idx, m_neighInds, and m_weights.

Referenced by CalcWeights().

◆ CalcW_Quadratic()

void Nektar::LibUtilities::Interpolator::CalcW_Quadratic ( const PtsPoint searchPt,
int  m_coordId 
)
private

Computes interpolation weights using quadratic interpolation.

Parameters
searchPtpoint for which the weights are computed
m_coordIdcoordinate id along which the interpolation should be performed

Currently, only implemented for 1D. Falls back to linear interpolation if only 2 values are available.

Definition at line 516 of file LibUtilities/BasicUtils/Interpolator.cpp.

517{
518 int npts = m_ptsInField->GetNpoints();
519 int i;
520
521 NekDouble coord = searchPt.coords[m_coordId];
522
523 for (i = 0; i < npts - 1; ++i)
524 {
525 if ((m_ptsInField->GetPointVal(0, i) <=
526 (coord + NekConstants::kNekZeroTol)) &&
527 (coord <=
528 (m_ptsInField->GetPointVal(0, i + 1) + NekConstants::kNekZeroTol)))
529 {
530 NekDouble pdiff = m_ptsInField->GetPointVal(0, i + 1) -
531 m_ptsInField->GetPointVal(0, i);
532 NekDouble h1, h2, h3;
533
534 if (i < npts - 2)
535 {
536 // forwards stencil
537 NekDouble pdiff2 = m_ptsInField->GetPointVal(0, i + 2) -
538 m_ptsInField->GetPointVal(0, i + 1);
539
540 h1 = (m_ptsInField->GetPointVal(0, i + 1) - coord) *
541 (m_ptsInField->GetPointVal(0, i + 2) - coord) /
542 (pdiff * (pdiff + pdiff2));
543 h2 = (coord - m_ptsInField->GetPointVal(0, i)) *
544 (m_ptsInField->GetPointVal(0, i + 2) - coord) /
545 (pdiff * pdiff2);
546 h3 = (coord - m_ptsInField->GetPointVal(0, i)) *
547 (coord - m_ptsInField->GetPointVal(0, i + 1)) /
548 ((pdiff + pdiff2) * pdiff2);
549
550 m_neighInds[searchPt.idx][0] = i;
551 m_neighInds[searchPt.idx][1] = i + 1;
552 m_neighInds[searchPt.idx][2] = i + 2;
553 }
554 else
555 {
556 // backwards stencil
557 NekDouble pdiff2 = m_ptsInField->GetPointVal(0, i) -
558 m_ptsInField->GetPointVal(0, i - 1);
559
560 h1 = (m_ptsInField->GetPointVal(0, i + 1) - coord) *
561 (coord - m_ptsInField->GetPointVal(0, i - 1)) /
562 (pdiff * pdiff2);
563 h2 = (coord - m_ptsInField->GetPointVal(0, i)) *
564 (coord - m_ptsInField->GetPointVal(0, i - 1)) /
565 (pdiff * (pdiff + pdiff2));
566 h3 = (m_ptsInField->GetPointVal(0, i) - coord) *
567 (m_ptsInField->GetPointVal(0, i + 1) - coord) /
568 ((pdiff + pdiff2) * pdiff);
569
570 m_neighInds[searchPt.idx][0] = i;
571 m_neighInds[searchPt.idx][1] = i + 1;
572 m_neighInds[searchPt.idx][2] = i - 1;
573 }
574
575 m_weights[searchPt.idx][0] = h1;
576 m_weights[searchPt.idx][1] = h2;
577 m_weights[searchPt.idx][2] = h3;
578
579 break;
580 }
581 }
582 ASSERTL0(i != npts - 1, "Failed to find coordinate " +
583 boost::lexical_cast<string>(coord) +
584 " within provided input points");
585}

References ASSERTL0, Nektar::LibUtilities::Interpolator::PtsPoint::coords, Nektar::LibUtilities::Interpolator::PtsPoint::idx, Nektar::NekConstants::kNekZeroTol, m_coordId, m_neighInds, m_ptsInField, and m_weights.

Referenced by CalcWeights().

◆ CalcW_Shepard()

void Nektar::LibUtilities::Interpolator::CalcW_Shepard ( const PtsPoint searchPt,
int  numPts 
)
private

Computes interpolation weights using linear interpolation.

Parameters
searchPtpoint for which the weights are computed
m_coordIdcoordinate id along which the interpolation should be performed

The algorithm is based on Shepard, D. (1968). A two-dimensional interpolation function for irregularly-spaced data. Proceedings of the 1968 23rd ACM National Conference. pp. 517–524.

In order to save memory, for n dimesnions, only 2^n points are considered. Contrary to Shepard, we use a fixed number of points with fixed weighting factors 1/d^n.

Definition at line 470 of file LibUtilities/BasicUtils/Interpolator.cpp.

471{
472 // find nearest neighbours
473 vector<PtsPoint> neighbourPts;
474 FindNNeighbours(searchPt, neighbourPts, numPts);
475
476 for (int i = 0; i < neighbourPts.size(); i++)
477 {
478 m_neighInds[searchPt.idx][i] = neighbourPts[i].idx;
479 }
480
481 // In case d < kNekZeroTol, use the exact point and return
482 for (int i = 0; i < neighbourPts.size(); ++i)
483 {
484 if (neighbourPts[i].dist <= NekConstants::kNekZeroTol)
485 {
486 m_weights[searchPt.idx][i] = 1.0;
487 return;
488 }
489 }
490
491 NekDouble wSum = 0.0;
492 for (int i = 0; i < neighbourPts.size(); ++i)
493 {
494 m_weights[searchPt.idx][i] = 1 / pow(double(neighbourPts[i].dist),
495 double(m_ptsInField->GetDim()));
496 wSum += m_weights[searchPt.idx][i];
497 }
498
499 for (int i = 0; i < neighbourPts.size(); ++i)
500 {
501 m_weights[searchPt.idx][i] = m_weights[searchPt.idx][i] / wSum;
502 }
503}

References FindNNeighbours(), Nektar::LibUtilities::Interpolator::PtsPoint::idx, Nektar::NekConstants::kNekZeroTol, m_neighInds, m_ptsInField, and m_weights.

Referenced by CalcWeights().

◆ CalcWeights()

void Nektar::LibUtilities::Interpolator::CalcWeights ( const LibUtilities::PtsFieldSharedPtr  ptsInField,
LibUtilities::PtsFieldSharedPtr ptsOutField,
bool  reuseTree = false 
)

Compute interpolation weights without doing any interpolation.

Parameters
ptsInFieldinput field
ptsOutFieldoutput field
reuseTreeif an r-tree has been constructed already, reuse it (e.g. for repeated calls over the same input points).

In and output fields must have the same dimension. The most suitable algorithm is chosen automatically if it wasnt set explicitly.

Definition at line 58 of file LibUtilities/BasicUtils/Interpolator.cpp.

61{
62 ASSERTL0(ptsInField->GetDim() <= m_dim, "too many dimensions in inField");
63 ASSERTL0(ptsOutField->GetDim() <= m_dim, "too many dimensions in outField");
64
65 m_ptsInField = ptsInField;
66 m_ptsOutField = ptsOutField;
67
68 size_t nOutPts = m_ptsOutField->GetNpoints();
69 int lastProg = 0;
70
71 // set a default method
72 if (m_method == eNoMethod)
73 {
74 if (m_ptsInField->GetDim() == 3)
75 {
77 }
78 else if (m_ptsInField->GetDim() == 1 || m_coordId >= 0)
79 {
81 }
82 else
83 {
85 }
86 }
87
88 if ((!m_rtree || !reuseTree) && m_method != eQuadratic)
89 {
90 SetupTree();
91 }
92
93 switch (m_method)
94 {
96 {
97 m_weights = Array<TwoD, NekDouble>(nOutPts, 1, 0.0);
98 m_neighInds = Array<TwoD, unsigned int>(nOutPts, 1, 0u);
99
100 for (size_t i = 0; i < nOutPts; ++i)
101 {
102 Array<OneD, NekDouble> tmp(m_dim, 0.0);
103 for (size_t j = 0; j < m_ptsOutField->GetDim(); ++j)
104 {
105 tmp[j] = m_ptsOutField->GetPointVal(j, i);
106 }
107 PtsPoint searchPt(i, tmp, 1E30);
108
109 CalcW_NNeighbour(searchPt);
110
111 int progress = int(100 * i / nOutPts);
112 if (m_progressCallback && progress > lastProg)
113 {
114 m_progressCallback(i, nOutPts);
115 lastProg = progress;
116 }
117 }
118
119 break;
120 }
121
122 case eQuadratic:
123 {
124 ASSERTL0(m_ptsInField->GetDim() == 1 || m_coordId >= 0,
125 "not implemented");
126
127 m_weights = Array<TwoD, NekDouble>(nOutPts, 3, 0.0);
128 m_neighInds = Array<TwoD, unsigned int>(nOutPts, 3, 0u);
129
130 for (size_t i = 0; i < nOutPts; ++i)
131 {
132 Array<OneD, NekDouble> tmp(m_dim, 0.0);
133 for (size_t j = 0; j < m_ptsOutField->GetDim(); ++j)
134 {
135 tmp[j] = m_ptsOutField->GetPointVal(j, i);
136 }
137 PtsPoint searchPt(i, tmp, 1E30);
138
139 if (m_ptsInField->GetNpoints() <= 2)
140 {
141 CalcW_Linear(searchPt, m_coordId);
142 }
143 else
144 {
145 CalcW_Quadratic(searchPt, m_coordId);
146 }
147
148 int progress = int(100 * i / nOutPts);
149 if (m_progressCallback && progress > lastProg)
150 {
151 m_progressCallback(i, nOutPts);
152 lastProg = progress;
153 }
154 }
155
156 break;
157 }
158
159 case eShepard:
160 {
161 int numPts = m_ptsInField->GetDim();
162 numPts = 1 << numPts; // 2 ^ numPts
163 numPts = min(numPts, int(m_ptsInField->GetNpoints() / 2));
164
165 m_weights = Array<TwoD, NekDouble>(nOutPts, numPts, 0.0);
166 m_neighInds = Array<TwoD, unsigned int>(nOutPts, numPts, 0u);
167
168 for (size_t i = 0; i < nOutPts; ++i)
169 {
170 Array<OneD, NekDouble> tmp(m_dim, 0.0);
171 for (size_t j = 0; j < m_ptsOutField->GetDim(); ++j)
172 {
173 tmp[j] = m_ptsOutField->GetPointVal(j, i);
174 }
175 PtsPoint searchPt(i, tmp, 1E30);
176
177 CalcW_Shepard(searchPt, numPts);
178
179 int progress = int(100 * i / nOutPts);
180 if (m_progressCallback && progress > lastProg)
181 {
182 m_progressCallback(i, nOutPts);
183 lastProg = progress;
184 }
185 }
186
187 break;
188 }
189
190 case eGauss:
191 {
193 "No filter width set");
194 // use m_filtWidth as FWHM
195 NekDouble sigma = m_filtWidth * 0.4246609001;
196
197 m_maxPts = min(m_maxPts, int(m_ptsInField->GetNpoints() / 2));
198
199 m_weights = Array<TwoD, NekDouble>(nOutPts, m_maxPts, 0.0);
200 m_neighInds = Array<TwoD, unsigned int>(nOutPts, m_maxPts, 0u);
201
202 for (size_t i = 0; i < nOutPts; ++i)
203 {
204 Array<OneD, NekDouble> tmp(m_dim, 0.0);
205 for (size_t j = 0; j < m_ptsOutField->GetDim(); ++j)
206 {
207 tmp[j] = m_ptsOutField->GetPointVal(j, i);
208 }
209 PtsPoint searchPt(i, tmp, 1E30);
210
211 CalcW_Gauss(searchPt, sigma, m_maxPts);
212
213 int progress = int(100 * i / nOutPts);
214 if (m_progressCallback && progress > lastProg)
215 {
216 m_progressCallback(i, nOutPts);
217 lastProg = progress;
218 }
219 }
220
221 break;
222 }
223
224 default:
225 NEKERROR(ErrorUtil::efatal, "Invalid interpolation m_method");
226 break;
227 }
228}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
static const int m_dim
dimension of this interpolator. Hardcoded to 3
std::shared_ptr< PtsRtree > m_rtree
A tree structure to speed up the neighbour search. Note that we fill it with an iterator,...
void CalcW_Linear(const PtsPoint &searchPt, int coordId)
Computes interpolation weights using linear interpolation.
void CalcW_NNeighbour(const PtsPoint &searchPt)
Computes interpolation weights using nearest neighbour interpolation.
void CalcW_Shepard(const PtsPoint &searchPt, int numPts)
Computes interpolation weights using linear interpolation.
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 CalcW_Quadratic(const PtsPoint &searchPt, int coordId)
Computes interpolation weights using quadratic interpolation.
LibUtilities::PtsFieldSharedPtr m_ptsOutField
output field

References ASSERTL0, CalcW_Gauss(), CalcW_Linear(), CalcW_NNeighbour(), CalcW_Quadratic(), CalcW_Shepard(), Nektar::ErrorUtil::efatal, Nektar::LibUtilities::eGauss, Nektar::LibUtilities::eNearestNeighbour, Nektar::LibUtilities::eNoMethod, Nektar::LibUtilities::eQuadratic, Nektar::LibUtilities::eShepard, Nektar::NekConstants::kNekZeroTol, m_coordId, m_dim, m_filtWidth, m_maxPts, m_method, m_neighInds, m_progressCallback, m_ptsInField, m_ptsOutField, m_rtree, m_weights, NEKERROR, and SetupTree().

Referenced by Nektar::SolverUtils::SessionFunction::EvaluatePts(), and Interpolate().

◆ FindNeighbours()

void Nektar::LibUtilities::Interpolator::FindNeighbours ( const PtsPoint searchPt,
std::vector< PtsPoint > &  neighbourPts,
const NekDouble  dist,
const unsigned int  maxPts = 1 
)
private

Finds the nearest neighbours of a point.

Parameters
searchPtpoint for which the neighbours are searched
neighbourPtspossible neighbour points
distlimits the distance of the neighbours

Definition at line 671 of file LibUtilities/BasicUtils/Interpolator.cpp.

675{
676 BPoint searchBPoint(searchPt.coords[0], searchPt.coords[1],
677 searchPt.coords[2]);
678 BPoint bbMin(searchPt.coords[0] - dist, searchPt.coords[1] - dist,
679 searchPt.coords[2] - dist);
680 BPoint bbMax(searchPt.coords[0] + dist, searchPt.coords[1] + dist,
681 searchPt.coords[2] + dist);
682 bg::model::box<BPoint> bbox(bbMin, bbMax);
683
684 // find points within the distance box
685 std::vector<PtsPointPair> result;
686 if (maxPts >= 1)
687 {
688 m_rtree->query(bgi::within(bbox) && bgi::nearest(searchBPoint, maxPts),
689 std::back_inserter(result));
690 }
691 else
692 {
693 m_rtree->query(bgi::within(bbox), std::back_inserter(result));
694 }
695
696 // massage into or own format
697 for (int i = 0; i < result.size(); ++i)
698 {
699 int idx = result[i].second;
700 Array<OneD, NekDouble> coords(m_dim, 0.0);
701 for (int j = 0; j < m_ptsInField->GetDim(); ++j)
702 {
703 coords[j] = m_ptsInField->GetPointVal(j, idx);
704 }
705 NekDouble d = bg::distance(searchBPoint, result[i].first);
706
707 // discard points beyonf dist
708 if (d <= dist)
709 {
710 neighbourPts.push_back(PtsPoint(idx, coords, d));
711 }
712 }
713
714 sort(neighbourPts.begin(), neighbourPts.end());
715}
boost::geometry::model::point< NekDouble, m_dim, boost::geometry::cs::cartesian > BPoint
std::vector< double > d(NPUPPER *NPUPPER)

References Nektar::LibUtilities::Interpolator::PtsPoint::coords, Nektar::UnitTests::d(), m_dim, m_ptsInField, and m_rtree.

Referenced by CalcW_Gauss().

◆ FindNNeighbours()

void Nektar::LibUtilities::Interpolator::FindNNeighbours ( const PtsPoint searchPt,
std::vector< PtsPoint > &  neighbourPts,
const unsigned int  numPts = 1 
)
private

Finds the nearest neighbours of a point.

Parameters
searchPtpoint for which the neighbours are searched
neighbourPtspossible neighbour points
numPtslimits the number of neighbours found to the numPts nearest ones

Definition at line 637 of file LibUtilities/BasicUtils/Interpolator.cpp.

640{
641 std::vector<PtsPointPair> result;
642 BPoint searchBPoint(searchPt.coords[0], searchPt.coords[1],
643 searchPt.coords[2]);
644 m_rtree->query(bgi::nearest(searchBPoint, numPts),
645 std::back_inserter(result));
646
647 // massage into or own format
648 for (int i = 0; i < result.size(); ++i)
649 {
650 int idx = result[i].second;
651 Array<OneD, NekDouble> coords(m_dim, 0.0);
652 for (int j = 0; j < m_ptsInField->GetDim(); ++j)
653 {
654 coords[j] = m_ptsInField->GetPointVal(j, idx);
655 }
656 NekDouble d = bg::distance(searchBPoint, result[i].first);
657 neighbourPts.push_back(PtsPoint(idx, coords, d));
658 }
659
660 sort(neighbourPts.begin(), neighbourPts.end());
661}

References Nektar::LibUtilities::Interpolator::PtsPoint::coords, Nektar::UnitTests::d(), m_dim, m_ptsInField, and m_rtree.

Referenced by CalcW_NNeighbour(), and CalcW_Shepard().

◆ GetCoordId()

int Nektar::LibUtilities::Interpolator::GetCoordId ( ) const

Returns the coordinate id along which the interpolation should be performed.

Definition at line 293 of file LibUtilities/BasicUtils/Interpolator.cpp.

294{
295 return m_coordId;
296}

References m_coordId.

◆ GetDim()

int Nektar::LibUtilities::Interpolator::GetDim ( ) const

returns the dimension of the Interpolator. Should be higher than the dimensions of the interpolated fields

Definition at line 288 of file LibUtilities/BasicUtils/Interpolator.cpp.

289{
290 return m_dim;
291}

References m_dim.

◆ GetFiltWidth()

NekDouble Nektar::LibUtilities::Interpolator::GetFiltWidth ( ) const

Returns the filter width.

Definition at line 298 of file LibUtilities/BasicUtils/Interpolator.cpp.

299{
300 return m_filtWidth;
301}

References m_filtWidth.

◆ GetInField()

LibUtilities::PtsFieldSharedPtr Nektar::LibUtilities::Interpolator::GetInField ( ) const

Returns the input field.

Definition at line 308 of file LibUtilities/BasicUtils/Interpolator.cpp.

309{
310 return m_ptsInField;
311}

References m_ptsInField.

◆ GetInterpMethod()

InterpMethod Nektar::LibUtilities::Interpolator::GetInterpMethod ( ) const

Returns the interpolation method used by this interpolator.

Definition at line 303 of file LibUtilities/BasicUtils/Interpolator.cpp.

304{
305 return m_method;
306}

References m_method.

◆ GetOutField()

LibUtilities::PtsFieldSharedPtr Nektar::LibUtilities::Interpolator::GetOutField ( ) const

Returns the output field.

Definition at line 313 of file LibUtilities/BasicUtils/Interpolator.cpp.

314{
315 return m_ptsOutField;
316}

References m_ptsOutField.

◆ Interpolate()

void Nektar::LibUtilities::Interpolator::Interpolate ( const LibUtilities::PtsFieldSharedPtr  ptsInField,
LibUtilities::PtsFieldSharedPtr ptsOutField 
)

Interpolate from a pts field to a pts field.

Parameters
ptsInFieldinput field
ptsOutFieldoutput field

In and output fields must have the same dimension and number of fields. The most suitable algorithm is chosen automatically if it wasnt set explicitly.

Definition at line 240 of file LibUtilities/BasicUtils/Interpolator.cpp.

242{
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");
247
248 m_ptsInField = ptsInField;
249 m_ptsOutField = ptsOutField;
250
251 if (m_weights.GetRows() == 0)
252 {
254 }
255
256 ASSERTL0(m_weights.GetRows() == m_ptsOutField->GetNpoints(),
257 "weights dimension mismatch");
258
259 size_t nFields = m_ptsOutField->GetNFields();
260 size_t nOutPts = m_ptsOutField->GetNpoints();
261 size_t inDim = m_ptsInField->GetDim();
262
263 // interpolate points and transform
264 for (size_t i = 0; i < nFields; ++i)
265 {
266 for (size_t j = 0; j < nOutPts; ++j)
267 {
268 size_t nPts = m_weights.GetColumns();
269
270 // skip if there were no neighbours found for this point
271 if (nPts == 0)
272 {
273 continue;
274 }
275
276 NekDouble val = 0.0;
277 for (size_t k = 0; k < nPts; ++k)
278 {
279 size_t nIdx = m_neighInds[j][k];
280 val += m_weights[j][k] *
281 m_ptsInField->GetPointVal(inDim + i, nIdx);
282 }
283 m_ptsOutField->SetPointVal(m_ptsOutField->GetDim() + i, j, val);
284 }
285 }
286}
void CalcWeights(const LibUtilities::PtsFieldSharedPtr ptsInField, LibUtilities::PtsFieldSharedPtr &ptsOutField, bool reuseTree=false)
Compute interpolation weights without doing any interpolation.

References ASSERTL0, CalcWeights(), m_dim, m_neighInds, m_ptsInField, m_ptsOutField, and m_weights.

Referenced by Nektar::FieldUtils::Interpolator< T >::Interpolate().

◆ PrintStatistics()

void Nektar::LibUtilities::Interpolator::PrintStatistics ( )

Returns if the weights have already been computed.

Definition at line 318 of file LibUtilities/BasicUtils/Interpolator.cpp.

319{
320 int meanN = 0;
321 for (int i = 0; i < m_neighInds.GetRows(); ++i)
322 {
323 for (int j = 0; j < m_neighInds.GetColumns(); ++j)
324 {
325 if (m_neighInds[i][j] > 0)
326 {
327 meanN += 1;
328 }
329 }
330 }
331
332 cout << "Number of points: " << m_neighInds.GetRows() << endl;
333 if (m_neighInds.GetRows() > 0)
334 {
335 cout << "mean Number of Neighbours per point: "
336 << meanN / m_neighInds.GetRows() << endl;
337 }
338}

References m_neighInds.

Referenced by Nektar::SolverUtils::SessionFunction::EvaluatePts().

◆ SetProgressCallback()

template<typename FuncPointerT , typename ObjectPointerT >
void Nektar::LibUtilities::Interpolator::SetProgressCallback ( FuncPointerT  func,
ObjectPointerT  obj 
)
inline

sets a callback funtion which gets called every time the interpolation progresses

Definition at line 135 of file LibUtilities/BasicUtils/Interpolator.h.

136 {
138 std::bind(func, obj, std::placeholders::_1, std::placeholders::_2);
139 }

References m_progressCallback.

Referenced by Nektar::SolverUtils::SessionFunction::EvaluatePts(), Nektar::FieldUtils::ProcessInterpPoints::InterpolateFieldToPts(), Nektar::FieldUtils::ProcessInterpPtsToPts::InterpolatePtsToPts(), Nektar::FieldUtils::ProcessInterpField::v_Process(), and Nektar::FieldUtils::ProcessInterpPointDataToFld::v_Process().

◆ SetupTree()

void Nektar::LibUtilities::Interpolator::SetupTree ( )
private

Definition at line 587 of file LibUtilities/BasicUtils/Interpolator.cpp.

588{
589 std::vector<PtsPointPair> inPoints;
590 for (int i = 0; i < m_ptsInField->GetNpoints(); ++i)
591 {
592 Array<OneD, NekDouble> coords(3, 0.0);
593 for (int j = 0; j < m_ptsInField->GetDim(); ++j)
594 {
595 coords[j] = m_ptsInField->GetPointVal(j, i);
596 }
597 inPoints.push_back(
598 PtsPointPair(BPoint(coords[0], coords[1], coords[2]), i));
599 }
601 m_rtree->insert(inPoints.begin(), inPoints.end());
602
603 // remove duplicates from tree
604 for (auto &it : inPoints)
605 {
606 std::vector<PtsPointPair> result;
607
608 // find nearest 2 points (2 because one of these might be the one we
609 // are
610 // checking)
611 m_rtree->query(bgi::nearest(it.first, 2), std::back_inserter(result));
612
613 // in case any of these 2 points is too close, remove the current
614 // point
615 // from the tree
616 for (auto &it2 : result)
617 {
618 if (it.second != it2.second &&
619 bg::distance(it.first, it2.first) <= NekConstants::kNekZeroTol)
620 {
621 m_rtree->remove(it);
622 break;
623 }
624 }
625 }
626}
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::NekConstants::kNekZeroTol, m_ptsInField, and m_rtree.

Referenced by CalcWeights().

Member Data Documentation

◆ m_coordId

short int Nektar::LibUtilities::Interpolator::m_coordId
private

coordinate id along which the interpolation should be performed

Definition at line 195 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcW_Linear(), CalcW_Quadratic(), CalcWeights(), and GetCoordId().

◆ m_dim

const int Nektar::LibUtilities::Interpolator::m_dim = 3
staticprivate

dimension of this interpolator. Hardcoded to 3

Definition at line 169 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcWeights(), FindNeighbours(), FindNNeighbours(), GetDim(), and Interpolate().

◆ m_filtWidth

NekDouble Nektar::LibUtilities::Interpolator::m_filtWidth
private

Filter width used for some interpolation algorithms.

Definition at line 191 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcWeights(), and GetFiltWidth().

◆ m_maxPts

int Nektar::LibUtilities::Interpolator::m_maxPts
private

Max number of interpolation points.

Definition at line 193 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcWeights().

◆ m_method

InterpMethod Nektar::LibUtilities::Interpolator::m_method
private

Interpolation Method.

Definition at line 179 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcWeights(), and GetInterpMethod().

◆ m_neighInds

Array<TwoD, unsigned int> Nektar::LibUtilities::Interpolator::m_neighInds
private

Indices of the relevant neighbours for each physical point. Structure: m_neighInds[ptIdx][neighbourIdx].

Definition at line 189 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcW_Gauss(), CalcW_Linear(), CalcW_NNeighbour(), CalcW_Quadratic(), CalcW_Shepard(), CalcWeights(), Interpolate(), and PrintStatistics().

◆ m_progressCallback

std::function<void(const int position, const int goal)> Nektar::LibUtilities::Interpolator::m_progressCallback
protected

Definition at line 147 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcWeights(), and SetProgressCallback().

◆ m_ptsInField

LibUtilities::PtsFieldSharedPtr Nektar::LibUtilities::Interpolator::m_ptsInField
protected

◆ m_ptsOutField

LibUtilities::PtsFieldSharedPtr Nektar::LibUtilities::Interpolator::m_ptsOutField
protected

output field

Definition at line 145 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcWeights(), GetOutField(), and Interpolate().

◆ m_rtree

std::shared_ptr<PtsRtree> Nektar::LibUtilities::Interpolator::m_rtree
private

A tree structure to speed up the neighbour search. Note that we fill it with an iterator, so instead of rstar, the packing algorithm is used.

Definition at line 183 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcWeights(), FindNeighbours(), FindNNeighbours(), and SetupTree().

◆ m_weights

Array<TwoD, NekDouble> Nektar::LibUtilities::Interpolator::m_weights
private

Interpolation weights for each neighbour. Structure: m_weights[physPtIdx][neighbourIdx].

Definition at line 186 of file LibUtilities/BasicUtils/Interpolator.h.

Referenced by CalcW_Gauss(), CalcW_Linear(), CalcW_NNeighbour(), CalcW_Quadratic(), CalcW_Shepard(), CalcWeights(), and Interpolate().