Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 202 additions & 0 deletions .basedpyright/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,192 @@
}
}
],
"./examples/plot-padua-nodes.py": [
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 10,
"endColumn": 20,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 4,
"endColumn": 11,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 4,
"endColumn": 11,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 12,
"endColumn": 20,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 22,
"endColumn": 30,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 11,
"endColumn": 13,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 27,
"endColumn": 34,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 27,
"endColumn": 34,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 8,
"endColumn": 15,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 16,
"endColumn": 24,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 26,
"endColumn": 34,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 8,
"endColumn": 15,
"lineCount": 1
}
},
{
"code": "reportCallIssue",
"range": {
"startColumn": 21,
"endColumn": 27,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 4,
"endColumn": 15,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 4,
"endColumn": 12,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 21,
"endColumn": 31,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 21,
"endColumn": 31,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 33,
"endColumn": 42,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 33,
"endColumn": 42,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 44,
"endColumn": 54,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 44,
"endColumn": 54,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 56,
"endColumn": 67,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 56,
"endColumn": 67,
"lineCount": 1
}
}
],
"./examples/plot-quadrature-nodes.py": [
{
"code": "reportMissingTypeStubs",
Expand Down Expand Up @@ -3795,6 +3981,22 @@
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 4,
"endColumn": 11,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 11,
"endColumn": 55,
"lineCount": 1
}
},
{
"code": "reportUnusedParameter",
"range": {
Expand Down
75 changes: 75 additions & 0 deletions examples/plot-padua-nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import matplotlib.pyplot as plt
import numpy as np

import modepy as mp


if TYPE_CHECKING:
from modepy.typing import ArrayF


def _first_padua_curve(n: int, t: ArrayF) -> ArrayF:
return np.vstack([-np.cos((n + 1) * t), -np.cos(n * t)])


def _second_padua_curve(n: int, t: ArrayF) -> ArrayF:
return np.vstack([-np.cos(n * t), -np.cos((n + 1) * t)])


def _third_padua_curve(n: int, t: ArrayF) -> ArrayF:
return np.vstack([np.cos((n + 1) * t), np.cos(n * t)])


def _fourth_padua_curve(n: int, t: ArrayF) -> ArrayF:
return np.vstack([np.cos(n * t), np.cos((n + 1) * t)])


def plot_padua_nodes(alpha: float, beta: float, order: int, family: str) -> None:
if family == "first":
curve_fn = _first_padua_curve
elif family == "second":
curve_fn = _second_padua_curve
elif family == "third":
curve_fn = _third_padua_curve
elif family == "fourth":
curve_fn = _fourth_padua_curve
else:
raise ValueError(f"Unknown Padua curve family: '{family}'")

t = np.linspace(0, np.pi, 512)
curve = curve_fn(order, t)
nodes = mp.padua_jacobi_nodes(alpha, beta, order, family)
assert nodes.shape[1] == ((order + 1) * (order + 2) // 2)

fig = plt.figure()
ax = fig.gca()
ax.grid()

ax.plot(curve[0], curve[1])
for i, xi in enumerate(nodes.T):
ax.plot(nodes[0], nodes[1], "ko", markersize=8)
ax.text(*xi, str(i), color="k", fontsize=24, fontweight="bold")

ax.set_xlim((-1, 1))
ax.set_ylim((-1, 1))
ax.set_aspect("equal")
fig.savefig(f"padua_nodes_order_{order:02d}_family_{family}")
plt.show()


if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--order", type=int, default=5)
parser.add_argument("--family", default="first",
choices=["first", "second", "third", "fourth"])
parser.add_argument("--alpha", type=float, default=-0.5)
parser.add_argument("--beta", type=float, default=-0.5)
args = parser.parse_args()

plot_padua_nodes(args.alpha, args.beta, args.order, args.family)
4 changes: 4 additions & 0 deletions modepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
legendre_gauss_lobatto_tensor_product_nodes,
legendre_gauss_tensor_product_nodes,
node_tuples_for_space,
padua_jacobi_nodes,
padua_nodes,
random_nodes_for_shape,
tensor_product_nodes,
warp_and_blend_nodes,
Expand Down Expand Up @@ -168,6 +170,8 @@
"nodal_quadrature_test_matrix",
"node_tuples_for_space",
"orthonormal_basis_for_space",
"padua_jacobi_nodes",
"padua_nodes",
"quadrature_for_space",
"random_nodes_for_shape",
"resampling_matrix",
Expand Down
Loading
Loading