Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
Nektar::LibUtilities::BasisDataCreator Class Reference

#include <BasisDataWarehouse.hpp>

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

Public Member Functions

 ~BasisDataCreator () override=default
 
template<typename MemSpace , typename TData >
MemoryRegion< TData > Create (const BasisDataKey< TData > &basisDataKey)
 
- Public Member Functions inherited from Nektar::LibUtilities::DataCreatorClass
virtual ~DataCreatorClass ()=default
 

Static Public Attributes

static const std::string m_name = "BasisDataCreator"
 

Detailed Description

Definition at line 94 of file BasisDataWarehouse.hpp.

Constructor & Destructor Documentation

◆ ~BasisDataCreator()

Nektar::LibUtilities::BasisDataCreator::~BasisDataCreator ( )
overridedefault

Member Function Documentation

◆ Create()

template<typename MemSpace , typename TData >
MemoryRegion< TData > Nektar::LibUtilities::BasisDataCreator::Create ( const BasisDataKey< TData > &  basisDataKey)

make an orthonormal projection from one set of points specified in the basis key to a lower number given by m_npts.

Project to Orthonormal basis: fB[p][i] = Ortho_p(x_i} 0 <= i,p,<npFrom (square matrix) so fB \hat{u}_p = u_i --> \hat{u}_p = inv(fB) u_i filter top modes: \hat{u}^f = diag(F)(\hat{u}} = diag(F) inv(fB) u_i Evaluate at lower points: tB[q][j] = Ortho_p(x_j) 0 <= j,q < npTo u^to_i = tB \hat{u}^f = tB diag(F) inv(fB) u_i

make an orthonormal projection from one set of points specified in the basis key to a lower order given by m_npts and return the projection back to the original points

Definition at line 49 of file BasisDataWarehouseDef.hpp.

51{
52 const auto basis = BasisManager()[basisDataKey.m_basisKey];
53 const auto basisDataType = basisDataKey.m_basisDataType;
54
55 switch (basisDataType)
56 {
57 case eBasis:
58 {
59 return MemoryRegion<TData>::template FromArray<MemSpace>(
60 basis->GetBdata());
61 break;
62 }
64 {
65 return MemoryRegion<TData>::template FromArray<MemSpace>(
66 basis->GetDbdata());
67 break;
68 }
69 case eWeights:
70 {
71 auto ndata = basis->GetW().size();
72 Array<OneD, double> wTmp(ndata);
73
74 switch (basis->GetBasisType())
75 {
76 case eModified_B:
77 case eOrtho_B:
78 {
79 if (basis->GetPointsType() == eGaussRadauMAlpha1Beta0 ||
80 basis->GetPointsType() == eGaussGaussAlpha1Beta0)
81 {
82 Vmath::Smul(ndata, 0.5, basis->GetW().data(), 1,
83 wTmp.data(), 1);
84 }
85 else
86 {
87 const auto z = basis->GetZ();
88 const auto w = basis->GetW();
89 for (unsigned int i = 0; i < ndata; ++i)
90 {
91 wTmp[i] = 0.5 * (1 - z[i]) * w[i];
92 }
93 }
94 }
95 break;
96 case eModified_C:
97 case eModifiedPyr_C:
98 case eOrtho_C:
99 case eOrthoPyr_C:
100 {
101 if (basis->GetPointsType() == eGaussRadauMAlpha2Beta0)
102 {
103 Vmath::Smul(ndata, 0.25, basis->GetW().data(), 1,
104 wTmp.data(), 1);
105 }
106 else if (basis->GetPointsType() ==
107 eGaussRadauMAlpha1Beta0 ||
108 basis->GetPointsType() == eGaussGaussAlpha1Beta0)
109 {
110 const auto z = basis->GetZ();
111 const auto w = basis->GetW();
112 for (unsigned int i = 0; i < ndata; ++i)
113 {
114 wTmp[i] = 0.25 * (1 - z[i]) * w[i];
115 }
116 }
117 else
118 {
119 const auto z = basis->GetZ();
120 const auto w = basis->GetW();
121 for (unsigned int i = 0; i < ndata; ++i)
122 {
123 wTmp[i] = 0.25 * (1 - z[i]) * (1 - z[i]) * w[i];
124 }
125 }
126 break;
127 }
128 default:
129 {
130 Vmath::Vcopy(ndata, basis->GetW().data(), 1, wTmp.data(),
131 1);
132 break;
133 }
134 }
135
136 return MemoryRegion<TData>::template FromArray<MemSpace>(wTmp);
137 }
138 break;
139 case eZeros:
140 {
141 return MemoryRegion<TData>::template FromArray<MemSpace>(
142 basis->GetZ());
143 }
144 break;
145 case eDerivative:
146 {
147 return MemoryRegion<TData>::template FromArray<MemSpace>(
148 basis->GetD()->GetPtr());
149 }
150 break;
151 case eInterpDerivative: // interpolation of nodal derivative matrix
152 {
153 const auto npTo = basisDataKey.m_npts;
154 // Check if we interpolate to
155 // a different PointsType specified via m_pointsToType
156 // or use the basis' PointsType
158 basisDataKey.m_toPointsType == LibUtilities::eNoPointsType
159 ? basis->GetPointsType()
160 : basisDataKey.m_toPointsType;
161 LibUtilities::PointsKey toPkey(npTo, ptype);
162
163 // use points manager to get correct interpolation matrix
164 auto I = LibUtilities::PointsManager()[basis->GetPointsKey()]
165 ->GetI(toPkey)
166 ->GetPtr();
167
168 auto D = basis->GetD()->GetPtr();
169
170 auto npFrom = basis->GetNumPoints();
171 Array<OneD, double> ID(npTo * npFrom);
172
173 // calcaulate I x D
174 for (unsigned i = 0; i < npTo; ++i)
175 {
176 for (unsigned j = 0; j < npFrom; ++j)
177 {
178 double sum = 0.0;
179 for (unsigned k = 0; k < npFrom; ++k)
180 {
181 sum += I[i + k * npTo] * D[k + j * npFrom];
182 }
183 ID[i + npTo * j] = sum;
184 }
185 }
186
187 return MemoryRegion<TData>::template FromArray<MemSpace>(ID);
188 }
189 break;
190 case eInterp:
191 {
192 const auto npTo = basisDataKey.m_npts;
193 // Check if we interpolate to
194 // a different PointsType specified via m_pointsToType
195 // or use the basis' PointsType
196 PointsType ptype = basisDataKey.m_toPointsType == eNoPointsType
197 ? basis->GetPointsType()
198 : basisDataKey.m_toPointsType;
199 PointsKey toPkey(npTo, ptype);
200
201 // Need points manager to get correct interpolation matrix
202 auto I =
203 PointsManager()[basis->GetPointsKey()]->GetI(toPkey)->GetPtr();
204
205 return MemoryRegion<TData>::template FromArray<MemSpace>(I);
206 }
207 break;
208 case eInterpTranspose:
209 {
210 const auto npTo = basisDataKey.m_npts;
211 // Check if we interpolate to
212 // a different PointsType specified via m_pointsToType
213 // or use the basis' PointsType
214 PointsType ptype = basisDataKey.m_toPointsType == eNoPointsType
215 ? basis->GetPointsType()
216 : basisDataKey.m_toPointsType;
217 PointsKey toPkey(npTo, ptype);
218
219 // Need points manager to get correct interpolation matrix
220 auto I =
221 PointsManager()[basis->GetPointsKey()]->GetI(toPkey)->GetPtr();
222
223 // Transpose interpolation matrix
224 const auto npFrom = basis->GetPointsKey().GetNumPoints();
225 Array<OneD, double> tmpI(npFrom * npTo);
226 for (int i = 0; i < npFrom; ++i)
227 {
228 for (int j = 0; j < npTo; ++j)
229 {
230 tmpI[i + j * npFrom] = I[j + i * npTo];
231 }
232 }
233
234 return MemoryRegion<TData>::template FromArray<MemSpace>(tmpI);
235 }
236 break;
237 case eGalerkinProject:
238 {
239 const auto npFrom = basisDataKey.m_npts;
240 // Check if the source (over-integrated) grid uses a
241 // different PointsType than the basis' native PointsType.
243 basisDataKey.m_toPointsType == LibUtilities::eNoPointsType
244 ? basis->GetPointsType()
245 : basisDataKey.m_toPointsType;
246 LibUtilities::PointsKey fromPkey(npFrom, ptype);
247
248 // Galerkin projection matrix from the finer (npFrom) grid
249 // down to this basis' native quadrature points. Unlike
250 // GetI(), GetGalerkinProjection() is already returned
251 // oriented [native rows x npFrom cols] (see
252 // GaussPoints::CalculateGalerkinProjectionMatrix), so it
253 // can be used directly as out = GP * in without the
254 // manual transpose eInterpTranspose above needs for
255 // GetI().
256 auto GP = LibUtilities::PointsManager()[basis->GetPointsKey()]
257 ->GetGalerkinProjection(fromPkey)
258 ->GetPtr();
259
260 return MemoryRegion<TData>::template FromArray<MemSpace>(GP);
261 }
262 break;
263 /// make an orthonormal projection from one set of points
264 /// specified in the basis key to a lower number given by
265 /// m_npts.
266 ///
267 /// Project to Orthonormal basis:
268 /// fB[p][i] = Ortho_p(x_i} 0 <= i,p,<npFrom (square matrix)
269 /// so fB \hat{u}_p = u_i --> \hat{u}_p = inv(fB) u_i
270 /// filter top modes:
271 /// \hat{u}^f = diag(F)(\hat{u}} = diag(F) inv(fB) u_i
272 /// Evaluate at lower points: tB[q][j] = Ortho_p(x_j) 0 <= j,q < npTo
273 /// u^to_i = tB \hat{u}^f = tB diag(F) inv(fB) u_i
274 case eOrthoProject:
275 {
276 ASSERTL1(basisDataKey.m_toPointsType != LibUtilities::eNoPointsType,
277 "Need to define a points key to project down to");
278
279 const auto npTo = basisDataKey.m_npts;
280 const auto npFrom = basisDataKey.m_basisKey.GetNumPoints();
281
282 ASSERTL1(npTo < npFrom, "This method assumes you are projecting to "
283 "a lower number of points");
284
285 // construct an orthonormal square basis matrix and invert
286 LibUtilities::BasisKey fromOrth(
288 basisDataKey.m_basisKey.GetPointsKey());
290 LibUtilities::BasisManager()[fromOrth];
291
292 // Convert to a NekMatrix and invert
293 Array<OneD, double> fB_data = fbasis->GetBdata();
294 NekMatrix<double> fBinv(npFrom, npFrom, fB_data);
295 fBinv.Invert();
296
297 // Filter off the unwanted high frequency modes. fBinv has its
298 // rows indexed by mode and its columns by point, and NekMatrix
299 // stores column major, so the modes to drop are a stride npFrom
300 // apart rather than a contiguous block: zeroing contiguously here
301 // would discard whole points instead of modes.
302 for (unsigned j = 0; j < npFrom; ++j)
303 {
304 Vmath::Zero(npFrom - npTo,
305 fBinv.GetRawPtr() + j * npFrom + npTo, 1);
306 }
307
308 // construct an orthonormal basis at "to" points
309 LibUtilities::PointsKey toPkey(npTo, basisDataKey.m_toPointsType);
310 LibUtilities::BasisKey toOrth(LibUtilities::eOrtho_A, npFrom,
311 toPkey);
314 Array<OneD, double> tB_data = tbasis->GetBdata();
315
316 // finally multiply by filtered matrix by backwards
317 // transform to points
318 Array<OneD, double> tmpI(npFrom * npTo);
319 for (unsigned i = 0; i < npTo; ++i)
320 {
321 for (unsigned j = 0; j < npFrom; ++j)
322 {
323 double sum = 0.0;
324 for (unsigned k = 0; k < npFrom; ++k)
325 {
326 sum += tB_data[k * npTo + i] * fBinv.GetValue(k, j);
327 }
328 tmpI[i + j * npTo] = sum;
329 }
330 }
331 return LibUtilities::MemoryRegion<TData>::template FromArray<
332 MemSpace>(tmpI);
333 }
334 break;
335 /// make an orthonormal projection from one set of points
336 /// specified in the basis key to a lower order given by
337 /// m_npts and return the projection back to the original points
339 {
340 ASSERTL1(basisDataKey.m_toPointsType != LibUtilities::eNoPointsType,
341 "Need to define a points key to project down to");
342
343 const auto npFilter = basisDataKey.m_npts;
344 const auto np = basisDataKey.m_basisKey.GetNumPoints();
345
346 ASSERTL1(npFilter < np, "This method assumes you are filtering to "
347 "a lower number of points");
348
349 // construct an orthonormal square basis matrix and invert
350 LibUtilities::BasisKey fromOrth(
352 basisDataKey.m_basisKey.GetPointsKey());
354 LibUtilities::BasisManager()[fromOrth];
355
356 // Convert to a NekMatrix and invert
357 Array<OneD, double> fB_data = fbasis->GetBdata();
358 NekMatrix<double> fBinv(np, np, fB_data);
359 fBinv.Invert();
360
361 // Filter off the unwanted high frequency modes; see the note in
362 // eOrthoProject on why this is strided rather than contiguous.
363 for (unsigned j = 0; j < np; ++j)
364 {
365 Vmath::Zero(np - npFilter,
366 fBinv.GetRawPtr() + j * np + npFilter, 1);
367 }
368
369 // construct an orthonormal basis at "to" points
370 LibUtilities::PointsKey toPkey(np, basisDataKey.m_toPointsType);
371 LibUtilities::BasisKey toOrth(LibUtilities::eOrtho_A, np, toPkey);
374 Array<OneD, double> tB_data = tbasis->GetBdata();
375
376 // finally multiply by filtered matrix by backwards
377 // transform to points
378 Array<OneD, double> tmpI(np * np);
379 for (unsigned i = 0; i < np; ++i)
380 {
381 for (unsigned j = 0; j < np; ++j)
382 {
383 double sum = 0.0;
384 for (unsigned k = 0; k < np; ++k)
385 {
386 sum += tB_data[k * np + i] * fBinv.GetValue(k, j);
387 }
388 tmpI[j * np + i] = sum;
389 }
390 }
391 return LibUtilities::MemoryRegion<TData>::template FromArray<
392 MemSpace>(tmpI);
393 }
394 break;
396 {
397 const auto z = basis->GetZ();
398 Array<OneD, double> Tmp(z.size());
399
400 for (unsigned int i = 0; i < z.size(); ++i)
401 {
402 Tmp[i] = 0.5 * (1.0 + z[i]);
403 }
404
405 return MemoryRegion<TData>::template FromArray<MemSpace>(Tmp);
406 }
407 break;
409 {
410 const auto z = basis->GetZ();
411 auto n = z.size();
412 Array<OneD, double> Tmp(n);
413
414 for (unsigned int i = 0; i < n; ++i)
415 {
416 Tmp[i] = 2 / (1.0 - z[i]);
417 }
418
419 return MemoryRegion<TData>::template FromArray<MemSpace>(Tmp);
420 }
421 break;
422 default:
423 NEKERROR(ErrorUtil::efatal, "invalid basis data requested.");
424 return MemoryRegion<TData>(0);
425 break;
426 }
427}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
std::map< int64_t, double > sum
BasisManagerT & BasisManager(void)
std::shared_ptr< Basis > BasisSharedPtr
PointsManagerT & PointsManager(void)
@ eGaussGaussAlpha1Beta0
1D Gauss-Jacobi quadrature points,
Definition PointsType.h:100
@ eModified_B
Principle Modified Functions .
Definition BasisType.h:49
@ eOrtho_A
Principle Orthogonal Functions .
Definition BasisType.h:42
@ eModified_C
Principle Modified Functions .
Definition BasisType.h:50
@ eOrtho_C
Principle Orthogonal Functions .
Definition BasisType.h:46
@ eModifiedPyr_C
Principle Modified Functions.
Definition BasisType.h:53
@ eOrtho_B
Principle Orthogonal Functions .
Definition BasisType.h:44
@ eOrthoPyr_C
Principle Orthogonal Functions .
Definition BasisType.h:51
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition Vmath.hpp:102
void Zero(int n, T *x, const int incx)
Zero vector.
Definition Vmath.hpp:275
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828

References ASSERTL1, Nektar::LibUtilities::BasisManager(), Nektar::LibUtilities::eBasis, Nektar::LibUtilities::eBasisDerivative, Nektar::LibUtilities::eDerivative, Nektar::ErrorUtil::efatal, Nektar::LibUtilities::eGalerkinProject, Nektar::LibUtilities::eGaussGaussAlpha1Beta0, Nektar::LibUtilities::eHalfMultOnePlusZero, Nektar::LibUtilities::eInterp, Nektar::LibUtilities::eInterpDerivative, Nektar::LibUtilities::eInterpTranspose, Nektar::LibUtilities::eModified_B, Nektar::LibUtilities::eModified_C, Nektar::LibUtilities::eModifiedPyr_C, Nektar::LibUtilities::eNoPointsType, Nektar::LibUtilities::eOrtho_A, Nektar::LibUtilities::eOrtho_B, Nektar::LibUtilities::eOrtho_C, Nektar::LibUtilities::eOrthoProject, Nektar::LibUtilities::eOrthoProjectSamePts, Nektar::LibUtilities::eOrthoPyr_C, Nektar::LibUtilities::eTwoOverOneMinusZero, Nektar::LibUtilities::eWeights, Nektar::LibUtilities::eZeros, Nektar::LibUtilities::BasisKey::GetNumPoints(), Nektar::LibUtilities::BasisKey::GetPointsKey(), Nektar::LibUtilities::BasisDataKey< TData >::m_basisDataType, Nektar::LibUtilities::BasisDataKey< TData >::m_basisKey, Nektar::LibUtilities::BasisDataKey< TData >::m_npts, Nektar::LibUtilities::BasisDataKey< TData >::m_toPointsType, NEKERROR, Nektar::LibUtilities::PointsManager(), Vmath::Smul(), sum, Vmath::Vcopy(), and Vmath::Zero().

Member Data Documentation

◆ m_name

const std::string Nektar::LibUtilities::BasisDataCreator::m_name = "BasisDataCreator"
inlinestatic

Definition at line 102 of file BasisDataWarehouse.hpp.