zoomy_core.model.models.basisfunctions module#
Module zoomy_core.model.models.basisfunctions.
- class zoomy_core.model.models.basisfunctions.Basisfunction(level=0, **kwargs)#
Bases:
objectBasisfunction. (class).
- name = 'Basisfunction'#
- bounds()#
Bounds.
- basis_definition()#
Basis definition.
- weight(z)#
Weight.
- mean_coefficients()#
Return coefficients c_k such that sum(c_k * phi_k(z)) = 1.
- Used for computing the depth-averaged velocity:
u_mean = sum(c_k * alpha_k)
Default: c = [1, 0, 0, …] (assumes phi_0 = 1). Override for bases where the constant function is a non-trivial combination (e.g., B-splines: c = [1, 1, 1, …]).
- weight_eval(z)#
Weight eval.
- get(k)#
Get.
- eval(k, _z)#
Eval.
- eval_psi(k, _z)#
Eval psi.
- get_lambda(k)#
Get lambda.
- plot(ax)#
Plot.
- reconstruct_velocity_profile(alpha, N=100)#
Reconstruct velocity profile.
- reconstruct_velocity_profile_at(alpha, z)#
Reconstruct velocity profile at.
- reconstruct_alpha(velocities, z)#
Reconstruct alpha.
- project_onto_basis(Y)#
Project onto basis.
- get_diff_basis()#
Get diff basis.
- class zoomy_core.model.models.basisfunctions.Monomials(level=0, **kwargs)#
Bases:
BasisfunctionMonomials. (class).
- name = 'Monomials'#
- class zoomy_core.model.models.basisfunctions.Legendre_shifted(level=0, **kwargs)#
Bases:
BasisfunctionLegendre shifted. (class).
- name = 'Legendre_shifted'#
- basis_definition()#
Basis definition.
- analytical_weighted_integral(poly_expr, var)#
Compute int_0^1 poly_expr(z) * 1 dz exactly via antiderivative.
Since the Legendre weight is 1, this is just the polynomial antiderivative evaluated at the bounds. ~100x faster than sympy.integrate for polynomial integrands.
- class zoomy_core.model.models.basisfunctions.Chebyshevu(level=0, **kwargs)#
Bases:
BasisfunctionChebyshevu. (class).
- name = 'Chebyshevu'#
- bounds()#
Bounds.
- weight(z)#
Weight.
- basis_definition()#
Basis definition.
- class zoomy_core.model.models.basisfunctions.Chebyshevu_shifted(level=0, **kwargs)#
Bases:
BasisfunctionChebyshev U polynomials shifted to [0,1] with phi_0 = 1.
phi_k(z) = U_k(2z - 1) (unnormalized Chebyshev of the second kind) weight = sqrt(z * (1 - z)) domain = [0, 1]
Properties: - phi_0 = 1 (recovers SWE at level 0) - Orthogonal: M[i,j] = (pi/8) * delta_{ij} - Analytical quadrature nodes: z_k = (1 + cos(k*pi/(n+1))) / 2
- name = 'Chebyshevu_shifted'#
- bounds()#
Bounds.
- weight(z)#
Weight.
- basis_definition()#
Basis definition.
- analytical_weighted_integral(poly_expr, var)#
Compute int_0^1 poly_expr(z) * sqrt(z*(1-z)) dz exactly.
Uses Chebyshev U orthogonality: expand poly_expr in the U_k(2z-1) basis, then int U_k * w dz = pi/8 * delta_{k,0}.
Returns c_0 * pi/8 where c_0 is the U_0 expansion coefficient. Returns None if poly_expr is not a polynomial.
- quadrature_nodes(n=None)#
Gauss-Chebyshev U quadrature on [0,1].
Integrates integral(f(z) * sqrt(z*(1-z)), 0, 1) exactly for polynomial f of degree <= 2*n + 1.
Uses n+1 nodes. Default n = 2*(level+1) for safety with triple products.
- class zoomy_core.model.models.basisfunctions.Legendre_DN(level=0, **kwargs)#
Bases:
BasisfunctionLegendre DN. (class).
- name = 'Legendre_DN - satifying no-slip and no-stress. This is a non-SWE basis'#
- bounds()#
Bounds.
- basis_definition()#
Basis definition.
- class zoomy_core.model.models.basisfunctions.GalerkinBasis(level=0, parent='legendre', bc_bottom='slip', bc_top='nostress', slip_length=None, **kwargs)#
Bases:
BasisfunctionGeneral BC-aware basis via Shen-type recombination.
Constructs basis functions from a parent polynomial family where: - phi_0 = 1 (constant, for mass conservation / SWE limit) - phi_k (k >= 1) are linear combinations of parent polynomials that
automatically satisfy user-specified linear boundary conditions
Supported BC types at bottom (z=bounds[0]) and top (z=bounds[1]): - ‘free’: no constraint (free surface, du/dz = 0 implied by no BC) - ‘noslip’: u(z_bc) = 0 - ‘nostress’: du/dz(z_bc) = 0 - ‘slip’: du/dz(z_bc) = u(z_bc) / slip_length
The BC-satisfying basis is built by solving a small linear system for each k, combining parent polynomials P_k, P_{k+1}, P_{k+2} with coefficients that enforce the two BCs.
- Usage:
basis = GalerkinBasis(level=3, parent=’legendre’, bc_bottom=’noslip’, bc_top=’nostress’) basis = GalerkinBasis(level=2, parent=’chebyshev’, bc_bottom=’slip’, bc_top=’free’,
slip_length=0.5)
- name = 'GalerkinBasis'#
- bounds()#
Bounds.
- weight(z)#
Weight.
- basis_definition()#
Basis definition.
- class zoomy_core.model.models.basisfunctions.SplineBasis(level=0, degree=1, **kwargs)#
Bases:
BasisfunctionB-spline basis on [0,1] using raw B-splines (nodal DOFs).
phi_k = B_k (k-th B-spline hat function) - phi_0 peaks at z=0 (bottom): phi_0(0) = 1 - phi_{n-1} peaks at z=1 (top): phi_{n-1}(1) = 1 - Interior phi_k peak at internal knots
The partition of unity (sum B_k = 1) means: - Depth-averaged velocity = weighted sum of nodal velocities - Mass flux = h * sum(alpha_k * integral(B_k)) - Bottom velocity = alpha_0 (direct nodal access)
Provides get_knot_spans() for piecewise integration.
- name = 'SplineBasis'#
- bounds()#
Bounds.
- weight(z)#
Weight.
- basis_definition()#
Basis definition.
- get_knot_spans()#
Return list of (a, b) intervals between consecutive knot values.
- mean_coefficients()#
B-splines form a partition of unity: sum(B_k) = 1, so c_k = 1 for all k.
- class zoomy_core.model.models.basisfunctions.Spline(level=0, **kwargs)#
Bases:
BasisfunctionSpline. (class). Legacy — use SplineBasis instead.
- name = 'Spline'#
- basis_definition(degree=1, knots=[0, 0, 0.001, 1, 1])#
Basis definition.
- class zoomy_core.model.models.basisfunctions.OrthogonalSplineWithConstant(level=0, **kwargs)#
Bases:
BasisfunctionOrthogonalSplineWithConstant. (class).
- name = 'OrthogonalSplineWithConstant'#
- basis_definition(degree=1, knots=[0, 0, 0.5, 1, 1])#
Basis definition.