.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/00_grids/plot_mesh1.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_00_grids_plot_mesh1.py: Creating and handling meshes 1 ============================== Unstructured meshes (with triangular cells) for CRTomo can be created in various ways. We now support two ways: * using the :py:meth:`crtomo.crt_grid.create_surface_grid` function * using the command line command :py:mod:`cr_trig_create` * there is a new (2026) interface to :py:mod:`cr_trig_create`, :py:class:`crtomo.mesh_interface.CRTomoGMSHMeshGenerator`. Please refer to the corresponding example for more information: :ref:`sphx_glr__examples_00_grids_plot_mesh_generation.py` This example only shows the usage of the first approach. .. note:: The CRTomo documentation is inconsistent in the use of the terms `mesh` and `grid`. Usually, a grid refers to a mesh with regularly spaced node locations in x and z direction. CRTomo also supports triangular meshes, which are still referred to as *grids* throughout the code and documentation. .. GENERATED FROM PYTHON SOURCE LINES 29-30 The top level crtomo import suffices for most tasks .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python import crtomo .. GENERATED FROM PYTHON SOURCE LINES 33-34 Create a simple surface mesh using the following wrapper .. GENERATED FROM PYTHON SOURCE LINES 34-47 .. code-block:: Python mesh0 = crtomo.crt_grid.create_surface_grid( nr_electrodes=10, spacing=1.5, ) mesh0.plot() # number the electrodes (useful for numerical studies) mesh0.plot_grid(plot_electrode_numbers=True) # save this grid to disc mesh0.save_elem_file('elem.dat') mesh0.save_elec_file('elec.dat') .. rst-class:: sphx-glr-horizontal * .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_mesh1_001.png :alt: plot mesh1 :srcset: /_examples/00_grids/images/sphx_glr_plot_mesh1_001.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_mesh1_002.png :alt: plot mesh1 :srcset: /_examples/00_grids/images/sphx_glr_plot_mesh1_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found .. GENERATED FROM PYTHON SOURCE LINES 48-49 The mesh can be read from disk: .. GENERATED FROM PYTHON SOURCE LINES 49-53 .. code-block:: Python mesh1 = crtomo.crt_grid('elem.dat', 'elec.dat') print(mesh1) mesh1.plot() .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_mesh1_003.png :alt: plot mesh1 :srcset: /_examples/00_grids/images/sphx_glr_plot_mesh1_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found CRMod/CTRomo grid instance number of elements: 1332 number of nodes: 722 number of electrodes: 10 mesh dimensions: X: -3.375 16.875 Z: -6.75 0.0 .. GENERATED FROM PYTHON SOURCE LINES 54-55 Create a grid with layering .. GENERATED FROM PYTHON SOURCE LINES 55-62 .. code-block:: Python mesh = crtomo.crt_grid.create_surface_grid( nr_electrodes=10, spacing=1.5, lines=[0.5, 1], ) print(mesh) mesh.plot() .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_mesh1_004.png :alt: plot mesh1 :srcset: /_examples/00_grids/images/sphx_glr_plot_mesh1_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [[-3.375 -1. 11. ] [-3.375 -0.5 11. ]] [[16.875 -0.5 11. ] [16.875 -1. 11. ]] This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found CRMod/CTRomo grid instance number of elements: 1412 number of nodes: 762 number of electrodes: 10 mesh dimensions: X: -3.375 16.875 Z: -6.75 0.0 .. GENERATED FROM PYTHON SOURCE LINES 63-78 Some notes on characteristic lengths ------------------------------------ You have some control over the final mesh cell size during mesh generation using the **char_lengths** parameter. This parameter is either one float, or a list/tuple of 4 floats. If four values are provided, they determine the requested cell size at: * the electrodes * the boundaries * extra lines * extra nodes .. warning:: Always make sure to at least put one node between adjacent electrodes. Better, two. .. GENERATED FROM PYTHON SOURCE LINES 78-120 .. code-block:: Python mesh = crtomo.crt_grid.create_surface_grid( nr_electrodes=10, spacing=1.5, char_lengths=[1.7, 1.7, 1.7, 1.7], ) mesh.plot( title='Same char. length everywhere', figsize=(8 / 2.54, 4 / 2.54), dpi=150 ) mesh = crtomo.crt_grid.create_surface_grid( nr_electrodes=10, spacing=1.5, char_lengths=2, ) mesh.plot( title='Same char. length everywhere, simplified', figsize=(8 / 2.54, 4 / 2.54), dpi=150 ) mesh = crtomo.crt_grid.create_surface_grid( nr_electrodes=10, spacing=1.5, char_lengths=[0.25, 1, 1, 1], ) mesh.plot( title='refinement at electrodes', figsize=(8 / 2.54, 4 / 2.54), dpi=150 ) mesh = crtomo.crt_grid.create_surface_grid( nr_electrodes=10, spacing=1.5, lines=[2], char_lengths=[1, 1, 0.25, 1], ) print(mesh) mesh.plot( title="refinement at extra line", figsize=(8 / 2.54, 4 / 2.54), dpi=150 ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_mesh1_005.png :alt: Same char. length everywhere :srcset: /_examples/00_grids/images/sphx_glr_plot_mesh1_005.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_mesh1_006.png :alt: Same char. length everywhere, simplified :srcset: /_examples/00_grids/images/sphx_glr_plot_mesh1_006.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_mesh1_007.png :alt: refinement at electrodes :srcset: /_examples/00_grids/images/sphx_glr_plot_mesh1_007.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_mesh1_008.png :alt: refinement at extra line :srcset: /_examples/00_grids/images/sphx_glr_plot_mesh1_008.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found [[-3.375 -2. 11. ]] [[16.875 -2. 11. ]] This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found CRMod/CTRomo grid instance number of elements: 1577 number of nodes: 826 number of electrodes: 10 mesh dimensions: X: -3.375 16.875 Z: -6.75 0.0 .. _sphx_glr_download__examples_00_grids_plot_mesh1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mesh1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mesh1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_mesh1.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_