36 #include <boost/geometry.hpp> 41 namespace bg = boost::geometry;
42 namespace bgi = boost::geometry::index;
63 void Interpolator::Interpolate(
64 const vector<MultiRegions::ExpListSharedPtr> expInField,
65 vector<MultiRegions::ExpListSharedPtr> &expOutField,
68 ASSERTL0(expInField.size() == expOutField.size(),
69 "number of fields does not match");
70 ASSERTL0(expInField[0]->GetCoordim(0) <= GetDim(),
71 "too many dimesions in inField");
72 ASSERTL0(expOutField[0]->GetCoordim(0) <= GetDim(),
73 "too many dimesions in outField");
75 "only direct evaluation supported for this interpolation");
77 m_expInField = expInField;
78 m_expOutField = expOutField;
80 int nInDim = expInField[0]->GetCoordim(0);
81 int nOutPts = m_expOutField[0]->GetTotPoints();
82 int nOutDim = m_expOutField[0]->GetCoordim(0);
88 for (
int i = 0; i < nOutDim; ++i)
94 m_expOutField[0]->GetCoords(coords[0]);
96 else if (nOutDim == 2)
98 m_expOutField[0]->GetCoords(coords[0], coords[1]);
100 else if (nOutDim == 3)
102 m_expOutField[0]->GetCoords(coords[0], coords[1], coords[2]);
105 for (
int i = 0; i < nOutPts; ++i)
107 for (
int j = 0; j < nOutDim; ++j)
109 Scoords[j] = coords[j][i];
113 int elmtid = m_expInField[0]->GetExpIndex(Scoords, Lcoords,
120 for(
int j = 0; j < nInDim; ++j)
122 Lcoords[j] = std::max(Lcoords[j], -1.0);
123 Lcoords[j] = std::min(Lcoords[j], 1.0);
128 int offset = m_expInField[0]->GetPhys_Offset(elmtid);
130 for (
int f = 0; f < m_expInField.size(); ++f)
133 m_expInField[f]->GetExp(elmtid)->StdPhysEvaluate(
134 Lcoords, m_expInField[f]->GetPhys() + offset);
136 if ((boost::math::isnan)(value))
138 ASSERTL0(
false,
"new value is not a number");
142 m_expOutField[f]->UpdatePhys()[i] = value;
148 for (
int f = 0; f < m_expInField.size(); ++f)
150 m_expOutField[f]->UpdatePhys()[i] = def_value;
154 int progress = int(100 * i / nOutPts);
155 if (m_progressCallback && progress > lastProg)
157 m_progressCallback(i, nOutPts);
174 void Interpolator::Interpolate(
175 const vector<MultiRegions::ExpListSharedPtr> expInField,
179 ASSERTL0(expInField.size() == ptsOutField->GetNFields(),
180 "number of fields does not match");
181 ASSERTL0(expInField[0]->GetCoordim(0) <= GetDim(),
182 "too many dimesions in inField");
183 ASSERTL0(ptsOutField->GetDim() <= GetDim(),
184 "too many dimesions in outField");
185 ASSERTL0(ptsOutField->GetDim() >= expInField[0]->GetCoordim(0),
186 "too few dimesions in outField");
188 "only direct evaluation supported for this interpolation");
190 m_expInField = expInField;
191 m_ptsOutField = ptsOutField;
193 int nInDim = expInField[0]->GetCoordim(0);
194 int nOutPts = m_ptsOutField->GetNpoints();
197 for (
int i = 0; i < nOutPts; ++i)
201 for (
int j = 0; j < m_ptsOutField->GetDim(); ++j)
203 coords[j] = m_ptsOutField->GetPointVal(j, i);
207 int elmtid = m_expInField[0]->GetExpIndex(coords, Lcoords,
213 for(
int j = 0; j < nInDim; ++j)
215 Lcoords[j] = std::max(Lcoords[j], -1.0);
216 Lcoords[j] = std::min(Lcoords[j], 1.0);
221 int offset = m_expInField[0]->GetPhys_Offset(elmtid);
223 for (
int f = 0; f < m_expInField.size(); ++f)
226 m_expInField[f]->GetExp(elmtid)->StdPhysEvaluate(
227 Lcoords, m_expInField[f]->GetPhys() + offset);
229 if ((boost::math::isnan)(value))
231 ASSERTL0(
false,
"new value is not a number");
235 m_ptsOutField->SetPointVal(m_ptsOutField->GetDim() + f, i,
242 for (
int f = 0; f < m_expInField.size(); ++f)
244 m_ptsOutField->SetPointVal(m_ptsOutField->GetDim() + f, i,
249 int progress = int(100 * i / nOutPts);
250 if (m_progressCallback && progress > lastProg)
252 m_progressCallback(i, nOutPts);
266 void Interpolator::Interpolate(
268 vector<MultiRegions::ExpListSharedPtr> &expOutField)
270 ASSERTL0(expOutField.size() == ptsInField->GetNFields(),
271 "number of fields does not match");
272 ASSERTL0(ptsInField->GetDim() <= GetDim(),
"too many dimesions in inField");
273 ASSERTL0(expOutField[0]->GetCoordim(0) <= GetDim(),
274 "too many dimesions in outField");
276 m_ptsInField = ptsInField;
277 m_expOutField = expOutField;
279 int nFields = max((
int)ptsInField->GetNFields(), (int)m_expOutField.size());
280 int nOutPts = m_expOutField[0]->GetTotPoints();
281 int outDim = m_expOutField[0]->GetCoordim(0);
285 for (
int i = 0; i < outDim; ++i)
291 m_expOutField[0]->GetCoords(pts[0]);
293 else if (outDim == 2)
295 m_expOutField[0]->GetCoords(pts[0], pts[1]);
297 else if (outDim == 3)
299 m_expOutField[0]->GetCoords(pts[0], pts[1], pts[2]);
304 for (
int f = 0; f < expOutField.size(); ++f)
306 tmpPts->AddField(m_expOutField[f]->GetCoeffs(),
307 m_ptsInField->GetFieldName(f));
311 LibUtilities::Interpolator::Interpolate(m_ptsInField, tmpPts);
314 for (
int i = 0; i < nFields; i++)
316 for (
int j = 0; j < nOutPts; ++j)
318 m_expOutField[i]->UpdatePhys()[j] = tmpPts->GetPointVal(i, j);
323 void Interpolator::Interpolate(
327 LibUtilities::Interpolator::Interpolate(ptsInField, ptsOutField);
#define ASSERTL0(condition, msg)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< PtsField > PtsFieldSharedPtr
static const NekDouble kGeomFactorsTol