sympde.utilities package¶
Submodules¶
sympde.utilities.utils module¶
- sympde.utilities.utils.lambdify_sympde(variables, expr)[source]¶
Custom lambify function that covers the shortcomings of sympy’s lambdify. Most notably, this function uses numpy broadcasting rules to compute the shape of the output.
Parameters¶
- variablessympy.core.symbol.Symbol or list of sympy.core.symbol.Symbol
variables that appear in the expression
- expr :
Sympy expression
Returns¶
- lambda_fcallable
Lambdified function built using numpy.
Notes¶
Compared to Sympy’s lambdify, this function is capable of properly handling constant values, and array_like structures where not all components depend on all variables. See below.
Examples¶
>>> import numpy as np >>> from sympy import symbols, Matrix >>> from sympde.utilities.utils import lambdify_sympde >>> x, y = symbols("x,y") >>> expr = Matrix([[x, x + y], [0, y]]) >>> f = lambdify_sympde([x,y], expr) >>> f(np.array([[0, 1]]), np.array([[2], [3]])) array([[[[0., 1.], [0., 1.]],
- [[2., 3.],
[3., 4.]]],
- [[[0., 0.],
[0., 0.]],
- [[2., 2.],
[3., 3.]]]])
- sympde.utilities.utils.plot_2d(domain, draw=True, isolines=False, refinement=40)[source]¶
Plot a 2D domain
Parameters¶
- domainsympde.topology.Domain
Domain to plot
- drawbool
if true, plt.show() will be called.
- refinementint
Number of straight line segments used to approximate each boundary edge.
- sympde.utilities.utils.plot_2d_single_patch(patch, mapping, ax, isolines=False, refinement=40)[source]¶
Plots a singe patch in a 2D domain
Parameters¶
patch : sympde.topology.InteriorDomain
mapping : sympde.topology.mapping
- axmatplotlib.axes.Axes
Axes object on which the patch is drawn.
- isolinesbool, default=False
If true also plots some iso-lines
- refinementint, default=40
Number of straight line segments used to approximate each boundary edge.
- sympde.utilities.utils.plot_3d(domain, draw=True, refinement=15)[source]¶
Plot a 3D domain
Parameters¶
- domainsympde.topology.Domain
Domain to plot
- drawbool
if true, plt.show() will be called.
- refinementint
Number of straight line segments used to approximate each boundary edge.
- sympde.utilities.utils.plot_3d_single_patch(patch, mapping, ax, refinement=15)[source]¶
Plot a singe patch in a 3D domain
Parameters¶
patch : sympde.topology.InteriorDomain
mapping : sympde.topology.mapping
- axmpl_toolkits.mplot3d.axes3d.Axes3D
Axes object on which the patch is drawn.
- refinementint, default=15
Number of straight line segments used to approximate each boundary edge.
- sympde.utilities.utils.plot_domain(domain, draw=True, isolines=False, refinement=None)[source]¶
Plots a 2D or 3D domain using matplotlib
Parameters¶
- domainsympde.topology.Domain
Domain to plot
- drawbool, default=True
If true, plt.show() will be called.
- isolinesbool, default=False
If true and the domain is 2D, also plots iso-lines.
- refinementint or None
Number of straight line segments used to approximate each boundary edge. If None, uses 15 for 3D domains and 40 for 2D domains