scimba_torch.plots.plots_nd¶
Plotting functions (generic in geometric dimension) for approximation spaces.
Functions
|
Plot an AbstractApproxSpace on its domain. |
|
Plot a sequence of AbstractApproxSpaces on their domains. |
- plot_abstract_approx_space(space, spatial_domain, parameters_domain=[], time_domain=[], velocity_domain=None, **kwargs)[source]¶
Plot an AbstractApproxSpace on its domain.
- Parameters:
space (
AbstractApproxSpace) – the space to be plotspatial_domain (
VolumetricDomain|Cuboid) – the geometric domain on which space is definedparameters_domain (
Sequence[Sequence[float]]) – the domain of parameters of space, [] meaning no parameters,time_domain (
Sequence[float]) – the time domain of space, [] meaning space is time-independent,velocity_domain (
SurfacicDomain|VolumetricDomain|None) – the velocity domain of space, None meaning space has no velocity arguments,**kwargs – arbitrary keyword arguments
- Keyword Arguments:
parameters_values – a (list of) point(s) in the parameters domain, or “mean” or “random”, defaults to “mean”,
time_values – a (list of) time(s) in the time domain, or “initial” or “final”, defaults to “final”,
velocity_values – a (list of) point(s) in the velocity domain,
components – the list of components of the space to be plot, defaults to the list of all the components,
loss – a GenericLosses object to be plot,
residual – an AbstractPDE object with a residual attribute,
derivatives – a list of strings representing the derivatives to be plot, for instance “uxx”; defaults to [],
solution – a callable depending on the same args as space to be plot,
error – plot the absolute error with respect to the given solution,
cuts – for 2D geometric dim, a list of affine spaces of dimension 1, each given as a tuple of 1 point and a basis
title – a str
... – see examples
Implemented only for 1 and 2 dimensional spaces.
- Raises:
ValueError – some input arguments are not correctly formated
KeyError – bad key in
**kwargsNotImplementedError – some option combinations are not implemented yet
Examples
>>> import matplotlib.pyplot as plt >>> from scimba_torch.plots.plots_nd import plot_AbstractApproxSpace >>> ... >>> def exact_sol(x: LabelTensor, mu: LabelTensor): x1, x2 = x.get_components() mu1 = mu.get_components() return mu1 * torch.sin(2.0 * torch.pi * x1) * torch.sin(2.0 * torch.pi * x2) >>> plot_AbstractApproxSpace( pinns.space, #the approximation space domain_x, #the geometric domain [[1.0, 2.0]], #the parameters domain loss=pinns.losses, #the loss residual=pde, #the residual solution=exact_sol, #the reference solution error=exact_sol, #the ref. sol. to plot absolute error derivatives=["ux", "uy"], #a list of string for derivatives cuts=[ #a list of 2 1D cuts ([0.0, 0.0], [-0.5, 0.5]), ([0.0, 0.2], [0.0, 1.0]), ], draw_contours=True, #whether to draw level lines n_drawn_contours=20, #number of level lines title="Learned solution to 2D Laplacian in strong form with weak boundary conditions", ) >>> plt.show()
- plot_abstract_approx_spaces(spaces, spatial_domains, parameters_domains=([],), time_domains=([],), velocity_domains=None, **kwargs)[source]¶
Plot a sequence of AbstractApproxSpaces on their domains.
- Parameters:
spaces (
AbstractApproxSpace|Sequence[AbstractApproxSpace]) – the (sequence of) space(s) to be plotspatial_domains (
VolumetricDomain|Cuboid|Sequence[VolumetricDomain|Cuboid]) – the (sequence of) geometric domain(s) on which spaces are definedparameters_domains (
Sequence[Sequence[float]] |Sequence[Sequence[Sequence[float]]]) – the (sequence of) domain(s) of parameters of space(s), ([],) meaning no parameters,time_domains (
Sequence[float] |Sequence[Sequence[float]]) – the (sequence of) time domain(s) of space(s), ([],) meaning spaces is time-independent,velocity_domains (
SurfacicDomain|None|Sequence[SurfacicDomain|None]) – the the (sequence of) velocity domain(s) of space(s), None meaning space has no velocity arguments,**kwargs – arbitrary keyword arguments
- Keyword Arguments:
title – the main title of the figure
titles – a sequence of titles (1 for each approximation space)
... – same keyword arguments as in plot_AbstractApproxSpace, are to be given as sequences of n values, where n is the number of spaces; sequences of n same values can be shortcut by the value
- Return type:
None
Implemented only for 1 and 2 dimensional spaces
- Raises:
ValueError – some input arguments are not correctly formated
KeyError – bad key in
**kwargsNotImplementedError – some option combinations are not implemented yet
Examples
>>> import matplotlib.pyplot as plt >>> from scimba_torch.plots.plots_nd import plot_AbstractApproxSpaces >>> ... >>> def exact_sol(x: LabelTensor, mu: LabelTensor): x1, x2 = x.get_components() mu1 = mu.get_components() return mu1 * torch.sin(2.0 * torch.pi * x1) * torch.sin(2.0 * torch.pi * x2) >>> plot_AbstractApproxSpaces( (pinns.space, pinns2.space, pinns3.space,),# a sequence of AbstractSpace domain_x, # shortcut for (domain_x,domain_x,domain_x,) ((1.0, 1.0 + 1e-5),), # the same parameters domain for the 3 spaces loss=( pinns.losses, pinns2.losses, pinns3.losses, ), residual=( pinns.pde, pinns2.pde, pinns3.pde, ), error=exact_sol, draw_contours=True, n_drawn_contours=20, parameters_values="random", ) >>> plt.show()