.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01-simple/poison_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_01-simple_poison_eq.py: Define and solve user equation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Basic example that show how to define the poisson equation and how to solve it with Dirichlet boundary conditions. .. GENERATED FROM PYTHON SOURCE LINES 7-10 .. code-block:: Python import fedoo as fd .. GENERATED FROM PYTHON SOURCE LINES 11-13 Define a modeling space and add a variable "U" to this space A "2D" problem include by default the coordinates "X" and "Y". .. GENERATED FROM PYTHON SOURCE LINES 13-16 .. code-block:: Python space = fd.ModelingSpace("2D") U = space.new_variable("U") .. GENERATED FROM PYTHON SOURCE LINES 17-23 Set the equation to solve on a weak form. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The space.derivative or space.variable functions create a differatial equation that we can combine with the +, - and * operators to build the weak form. the virtual properties set the variable as virtuals (in the sense of weak equations) .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. 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 29-30 Define the integration domain (mesh) .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python mesh = fd.mesh.rectangle_mesh() .. GENERATED FROM PYTHON SOURCE LINES 33-35 Assembly the global matrix, define a linear problem, add boundary conditions and solve the problem .. GENERATED FROM PYTHON SOURCE LINES 35-45 .. 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/01-simple/images/sphx_glr_poison_eq_001.png :alt: poison eq :srcset: /examples/01-simple/images/sphx_glr_poison_eq_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.271 seconds) .. _sphx_glr_download_examples_01-simple_poison_eq.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: poison_eq.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: poison_eq.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: poison_eq.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_