.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/basic/poisson_eq.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_examples_basic_poisson_eq.py: Define and solve user equation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Basic example that shows how to define the Poisson equation :math:`-\Delta U = f` from its weak form and how to solve it with Dirichlet boundary conditions. Here :math:`f = 0` (Laplace equation), so the solution is the linear field :math:`U = X`. .. GENERATED FROM PYTHON SOURCE LINES 10-13 .. code-block:: Python import fedoo as fd .. GENERATED FROM PYTHON SOURCE LINES 14-16 Define a modeling space and add a variable "U" to this space. A "2D" problem includes by default the coordinates "X" and "Y". .. GENERATED FROM PYTHON SOURCE LINES 16-19 .. code-block:: Python space = fd.ModelingSpace("2D") U = space.new_variable("U") .. GENERATED FROM PYTHON SOURCE LINES 20-26 Set the equation to solve on a weak form ---------------------------------------- The ``space.derivative`` and ``space.variable`` functions create differential operators that can be combined with the +, - and * operators to build the weak form. The ``virtual`` property sets the variable as virtual (test function, in the sense of weak equations). .. GENERATED FROM PYTHON SOURCE LINES 26-31 .. code-block:: Python dU_dX = space.derivative("U", "X") dU_dY = space.derivative("U", "Y") wf = fd.WeakForm(dU_dX.virtual * dU_dX + dU_dY.virtual * dU_dY, name="Poisson Equation") .. GENERATED FROM PYTHON SOURCE LINES 32-33 Define the integration domain (mesh) .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: Python mesh = fd.mesh.rectangle_mesh() .. GENERATED FROM PYTHON SOURCE LINES 36-38 Assemble the global matrix, define a linear problem, add boundary conditions and solve the problem .. GENERATED FROM PYTHON SOURCE LINES 38-48 .. code-block:: Python fd.Assembly.create(wf, mesh, name="assembly") pb = fd.problem.Linear("assembly") pb.bc.add("Dirichlet", "left", "U", 0) pb.bc.add("Dirichlet", "right", "U", 1) pb.solve() res = pb.get_results("assembly", ["U"]) res.plot("U") .. image-sg:: /examples/basic/images/sphx_glr_poisson_eq_001.png :alt: poisson eq :srcset: /examples/basic/images/sphx_glr_poisson_eq_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.232 seconds) .. _sphx_glr_download_examples_basic_poisson_eq.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: poisson_eq.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: poisson_eq.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: poisson_eq.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_