PN vs QN¶
Copyright (C) 2026 Andreas Kloeckner
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Based on Cubature, Approximation, and Isotropy in the Hypercube. (Trefethen)
In [19]:
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
import modepy as mp
import modepy.tools as mp_tools
In [32]:
shape = mp.Hypercube(2)
space = mp.QN(2, 60)
nodes = mp.edge_clustered_nodes_for_space(space, shape)
basis = mp.basis_for_space(space, shape)
plt.plot(nodes[0], nodes[1], "o")
Out[32]:
[<matplotlib.lines.Line2D at 0x7f2816c50c20>]
In [52]:
vdm = mp.vandermonde(basis.functions, nodes)
r = la.norm(nodes, 2, axis=0)
gauss_coeffs = la.solve(vdm, np.exp(-(r/0.2)**2))
In [53]:
coeffs_reshaped = mp_tools.reshape_array_for_tensor_product_space(space, gauss_coeffs, axis=0)
In [54]:
plt.imshow(np.log10(1e-15+np.abs(coeffs_reshaped)))
plt.colorbar()
Out[54]:
<matplotlib.colorbar.Colorbar at 0x7f281657d160>
In [55]:
plt.imshow(np.log10(1e-15+np.abs(coeffs_reshaped[::2, ::2])))
plt.colorbar()
Out[55]:
<matplotlib.colorbar.Colorbar at 0x7f28166252b0>
In [ ]: