.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_function_spaces.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_function_spaces.py: Function Space Examples ======================= This example demonstrates how to create and visualize different function spaces. .. GENERATED FROM PYTHON SOURCE LINES 7-12 .. code-block:: Python import numpy as np from fdg import BasisSpecs, FunctionSpace from matplotlib import pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 13-19 2D Function Space Example ------------------------- This example creates a 2D function space using Bernstein basis functions of degrees 2 and 3, then plots the basis functions over a grid. .. GENERATED FROM PYTHON SOURCE LINES 19-41 .. code-block:: Python x, y = np.meshgrid(np.linspace(-1, 1, 51), np.linspace(-1, 1, 51)) space_2d = FunctionSpace( BasisSpecs("bernstein", 2), BasisSpecs("bernstein", 3), ) bv = space_2d.evaluate(x, y) assert np.allclose((np.sum(bv, axis=(-2, -1))), 1.0) # Should be all ones orders = space_2d.orders fig_2d, axes_2d = plt.subplots(orders[0] + 1, orders[1] + 1, figsize=(12, 6)) for i in range(orders[0] + 1): for j in range(orders[1] + 1): ax = axes_2d[i, j] c = ax.contourf(x, y, bv[:, :, i, j], levels=11, cmap="viridis", vmin=0, vmax=1) fig_2d.colorbar(c, ax=ax) ax.set_title(f"2D Basis Function {i}, {j}") fig_2d.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_function_spaces_001.png :alt: 2D Basis Function 0, 0, 2D Basis Function 0, 1, 2D Basis Function 0, 2, 2D Basis Function 0, 3, 2D Basis Function 1, 0, 2D Basis Function 1, 1, 2D Basis Function 1, 2, 2D Basis Function 1, 3, 2D Basis Function 2, 0, 2D Basis Function 2, 1, 2D Basis Function 2, 2, 2D Basis Function 2, 3 :srcset: /auto_examples/images/sphx_glr_plot_function_spaces_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.176 seconds) .. _sphx_glr_download_auto_examples_plot_function_spaces.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_function_spaces.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_function_spaces.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_function_spaces.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_