.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/boundary_conditions/multi_mesh_example.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_boundary_conditions_multi_mesh_example.py: Analysis and visualization of a multi-mesh model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example combines quadrilateral and triangular elements that share the same node array. Each element block has its own assembly, while their sum is used to solve a single mechanical problem. Results requested from the assembly sum are stored in a :class:`fedoo.MultiMesh`. Fedoo can therefore visualize all element blocks directly with one :meth:`fedoo.DataSet.plot` call. .. GENERATED FROM PYTHON SOURCE LINES 13-17 .. code-block:: Python import fedoo as fd import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 18-23 Build a mesh containing different element types ----------------------------------------------- A ``MultiMesh`` owns one common node array and an ordered collection of element blocks. Named entries make each submesh easy to retrieve later. The tuple associated with each name contains its element type and connectivity. .. GENERATED FROM PYTHON SOURCE LINES 23-66 .. code-block:: Python nodes = np.array( [ [0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0], [0.5, 1.866], ] ) mesh = fd.MultiMesh( nodes, { "quadrilateral": ("quad4", np.array([[0, 1, 3, 2]])), "triangle": ("tri3", np.array([[2, 3, 4]])), }, node_sets={"left": np.array([0, 2]), "right": np.array([1, 3])}, name="mixed_mesh", ) # Define equations as usual (constitutivelaw + weakform) fd.ModelingSpace("2Dstress") material = fd.constitutivelaw.ElasticIsotrop(2e5, 0.3) wf = fd.weakform.StressEquilibrium(material) # Create a global assembly # Assemblies are created on the individual element blocks and then combined # into the assembly used by the problem. assembly1 = fd.Assembly.create(wf, mesh["quadrilateral"]) assembly2 = fd.Assembly.create(wf, mesh["triangle"]) assembly = assembly1 + assembly2 # Define a new static problem pb = fd.problem.Linear(assembly) # Clamp the left side and prescribe a horizontal displacement on the right. pb.bc.add("Dirichlet", mesh.node_sets["left"], "Disp", 0) pb.bc.add("Dirichlet", mesh.node_sets["right"], "DispX", 0.5) # Solve problem pb.solve() .. GENERATED FROM PYTHON SOURCE LINES 67-73 Extract and plot multi-mesh results ----------------------------------- ``get_results`` collects the fields from both elementary assemblies. The resulting dataset retains the quadrilateral and triangular submeshes and their element data independently. Nevertheless, the complete model can be drawn directly with the usual Fedoo plotting function. .. GENERATED FROM PYTHON SOURCE LINES 73-85 .. code-block:: Python results = pb.get_results(["Stress", "Disp", "Strain"]) plotter = results.plot( "Stress", component="vm", data_type="Node", show=False, show_edges=True, show_nodes=True, title="Von Mises stress on a MultiMesh", ) plotter.show() .. image-sg:: /examples/boundary_conditions/images/sphx_glr_multi_mesh_example_001.png :alt: multi mesh example :srcset: /examples/boundary_conditions/images/sphx_glr_multi_mesh_example_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.253 seconds) .. _sphx_glr_download_examples_boundary_conditions_multi_mesh_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: multi_mesh_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: multi_mesh_example.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: multi_mesh_example.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_