37 #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,
NekDouble def_value)
67 ASSERTL0(expInField.size() == expOutField.size(),
68 "number of fields does not match");
69 ASSERTL0(expInField[0]->GetCoordim(0) <= GetDim(),
70 "too many dimesions in inField");
71 ASSERTL0(expOutField[0]->GetCoordim(0) <= GetDim(),
72 "too many dimesions in outField");
74 "only direct evaluation supported for this interpolation");
76 m_expInField = expInField;
77 m_expOutField = expOutField;
79 int nFields = max((
int)expInField.size(), (
int)m_expOutField.size());
80 int nOutPts = m_expOutField[0]->GetTotPoints();
91 int outDim = m_expOutField[0]->GetCoordim(0) + outNumHomDir;
95 for (
int i = 0; i < outDim; ++i)
101 m_expOutField[0]->GetCoords(pts[0]);
103 else if (outDim == 2)
105 m_expOutField[0]->GetCoords(pts[0], pts[1]);
107 else if (outDim == 3)
109 m_expOutField[0]->GetCoords(pts[0], pts[1], pts[2]);
114 for (
int f = 0; f < expOutField.size(); ++f)
116 tmpPts->AddField(m_expOutField[f]->GetPhys(),
"DefaultVar");
120 Interpolate(m_expInField, tmpPts, def_value);
123 for (
int i = 0; i < nFields; i++)
125 int ptsi = outDim + i;
126 for (
int j = 0; j < nOutPts; ++j)
128 m_expOutField[i]->UpdatePhys()[j] = tmpPts->GetPointVal(ptsi, j);
144 void Interpolator::Interpolate(
145 const vector<MultiRegions::ExpListSharedPtr> expInField,
148 ASSERTL0(expInField.size() == ptsOutField->GetNFields(),
149 "number of fields does not match");
150 ASSERTL0(expInField[0]->GetCoordim(0) <= GetDim(),
151 "too many dimesions in inField");
152 ASSERTL0(ptsOutField->GetDim() <= GetDim(),
153 "too many dimesions in outField");
154 ASSERTL0(ptsOutField->GetDim() >= expInField[0]->GetCoordim(0),
155 "too few dimesions in outField");
157 "only direct evaluation supported for this interpolation");
159 "interpolation from 3DH2D expansion unsupported");
161 m_expInField = expInField;
162 m_ptsOutField = ptsOutField;
164 int nInDim = expInField[0]->GetCoordim(0);
165 int nOutPts = m_ptsOutField->GetNpoints();
169 for (
int i = 0; i < nOutPts; ++i)
173 for (
int j = 0; j < m_ptsOutField->GetDim(); ++j)
175 coords[j] = m_ptsOutField->GetPointVal(j, i);
179 elmtid = m_expInField[0]->GetExpIndex(
186 for (
int j = 0; j < nInDim; ++j)
188 Lcoords[j] = std::max(Lcoords[j], -1.0);
189 Lcoords[j] = std::min(Lcoords[j], 1.0);
194 int offset = m_expInField[0]->GetPhys_Offset(elmtid);
196 for (
int f = 0; f < m_expInField.size(); ++f)
202 ASSERTL0(m_expInField[f]->GetWaveSpace(),
203 "interpolation from 3DH1D/2DH1D requires field in "
205 NekDouble lHom = m_expInField[f]->GetHomoLen();
207 2. * M_PI * fmod(coords[nInDim], lHom) / lHom;
209 m_expInField[f]->GetHomogeneousBasis()->GetZ().size();
212 m_expInField[f]->GetZIDs();
214 for (
size_t n = 0; n < planes.size(); ++n)
216 auto planeExp = m_expInField[f]->GetPlane(planes[n]);
217 coeff = planeExp->GetExp(elmtid)->StdPhysEvaluate(
218 Lcoords, planeExp->GetPhys() + offset);
223 else if (planes[n] == 1)
225 value += cos(0.5 * nPlanes * BetaT) * coeff;
227 else if (planes[n] % 2 == 0)
229 NekDouble phase = (planes[n] >> 1) * BetaT;
230 value += cos(phase) * coeff;
234 NekDouble phase = (planes[n] >> 1) * BetaT;
235 value += -sin(phase) * coeff;
241 value = m_expInField[f]->GetExp(elmtid)->StdPhysEvaluate(
242 Lcoords, m_expInField[f]->GetPhys() + offset);
245 if ((boost::math::isnan)(value))
247 ASSERTL0(
false,
"new value is not a number");
251 m_ptsOutField->SetPointVal(m_ptsOutField->GetDim() + f, i,
258 for (
int f = 0; f < m_expInField.size(); ++f)
260 m_ptsOutField->SetPointVal(m_ptsOutField->GetDim() + f, i,
265 int progress = int(100 * i / nOutPts);
266 if (m_progressCallback && progress > lastProg)
268 m_progressCallback(i, nOutPts);
282 void Interpolator::Interpolate(
284 vector<MultiRegions::ExpListSharedPtr> &expOutField)
286 ASSERTL0(expOutField.size() == ptsInField->GetNFields(),
287 "number of fields does not match");
288 ASSERTL0(ptsInField->GetDim() <= GetDim(),
"too many dimesions in inField");
289 ASSERTL0(expOutField[0]->GetCoordim(0) <= GetDim(),
290 "too many dimesions in outField");
292 m_ptsInField = ptsInField;
293 m_expOutField = expOutField;
295 int nFields = max((
int)ptsInField->GetNFields(), (
int)m_expOutField.size());
296 int nOutPts = m_expOutField[0]->GetTotPoints();
297 int outNumHomDir = 0;
307 int outDim = m_expOutField[0]->GetCoordim(0) + outNumHomDir;
311 for (
int i = 0; i < outDim; ++i)
317 m_expOutField[0]->GetCoords(pts[0]);
319 else if (outDim == 2)
321 m_expOutField[0]->GetCoords(pts[0], pts[1]);
323 else if (outDim == 3)
325 m_expOutField[0]->GetCoords(pts[0], pts[1], pts[2]);
330 for (
int f = 0; f < expOutField.size(); ++f)
332 tmpPts->AddField(m_expOutField[f]->GetPhys(),
333 m_ptsInField->GetFieldName(f));
337 LibUtilities::Interpolator::Interpolate(m_ptsInField, tmpPts);
340 for (
int i = 0; i < nFields; i++)
342 int ptsi = outDim + i;
343 for (
int j = 0; j < nOutPts; ++j)
345 m_expOutField[i]->UpdatePhys()[j] = tmpPts->GetPointVal(ptsi, j);
353 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
The above copyright notice and this permission notice shall be included.