.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/00_grids/plot_triag_with_internal_structure_inkscape.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_triag_with_internal_structure_inkscape.py: Using Inkscape to define internal structure =========================================== It is possible to use Inkscape to define some of the internal structure of a FE mesh. This can be used to: * define irregularly-shaped regions within a forward mesh * define internal geometry that is later used for decoupling of the regularization More information: https://geophysics-ubonn.github.io/crtomo_tools/grid_creation.html#introducing-structures-into-a-mesh-using-inkscape The basic procedure is as follows: * Create input files for triangular mesh generation as usual: **boundaries.dat**, **electrodes.dat** * Following that, generate a .svg template of the mesh boundary by running *grid_convert_boundary_to_svg* .. GENERATED FROM PYTHON SOURCE LINES 29-38 .. code-block:: Python import os import shutil import reda import subprocess import numpy as np import crtomo from shapely.geometry import Polygon import matplotlib.pylab as plt .. GENERATED FROM PYTHON SOURCE LINES 39-41 We will store all output of this example in a subdirectory. Delete the directory before proceeding .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python if os.path.isdir('tmp_triag_inkscape'): shutil.rmtree('tmp_triag_inkscape') .. GENERATED FROM PYTHON SOURCE LINES 45-49 Note: We use the contextmanager :py:class:`reda.utils.enter_directory.CreateEnterDirectory` to transparently change our working directory. This ensures that all output files/directories will be placed in the **tmp_triag_inkscape** directory .. GENERATED FROM PYTHON SOURCE LINES 49-67 .. code-block:: Python with reda.CreateEnterDirectory('tmp_triag_inkscape'): with open('electrodes.dat', 'w') as fid: fid.write("""0.0 0.0 5.0 0.0 10.0 0.0 15.0 0.0 """) with open('boundaries.dat', 'w') as fid: fid.write("""-10.0000 0.0000 12 0.0000 0.0000 12 5.0000 0.0000 12 10.0000 0.0000 12 15.0000 0.0000 12 25.0000 0.0000 11 25.0000 -10.0000 11 -10.0000 -10.0000 11""") .. GENERATED FROM PYTHON SOURCE LINES 68-73 The **grid_convert_boundary_to_svg** commands takes a *boundaries.dat* file and turns it into a simple svg file that can be opened with Inkscape. Geometry is now added using straight lines. Each region is stored in a new layer, whose name starts with *region_* The output file is saved as *out_modified2.svg* with the type "Inkscape SVG" .. GENERATED FROM PYTHON SOURCE LINES 73-92 .. code-block:: Python with reda.CreateEnterDirectory('tmp_triag_inkscape'): subprocess.call('grid_convert_boundary_to_svg', shell=True) # note: here we copy a pre-modified svg file with reda.CreateEnterDirectory('tmp_triag_inkscape'): shutil.copy('../data_02/out_modified2.svg', 'out_modified2.svg') # this command parses the out_modified2.svg file and creates multiple output # files with reda.CreateEnterDirectory('tmp_triag_inkscape'): subprocess.call('grid_parse_svg_to_files', shell=True) with reda.CreateEnterDirectory('tmp_triag_inkscape'): shutil.copy('lne_constraint_1.dat', 'extra_lines.dat') with reda.CreateEnterDirectory('tmp_triag_inkscape'): subprocess.call('cr_trig_create grid', shell=True) .. GENERATED FROM PYTHON SOURCE LINES 93-94 Plot the resulting CRMod/CRTomo mesh .. GENERATED FROM PYTHON SOURCE LINES 94-122 .. code-block:: Python with reda.CreateEnterDirectory('tmp_triag_inkscape'): grid = crtomo.crt_grid( elem_file='grid/elem.dat', elec_file='grid/elec.dat', ) pm = crtomo.ParMan(grid) pid = pm.add_empty_dataset(100) region_lines = np.loadtxt('all_constraint_1.dat') poly = Polygon( np.vstack( (region_lines[:, 0:2], region_lines[-1, 2:4]) ) ) pm.modify_polygon(pid, poly, 10) plotman = crtomo.pltMan(pm=pm, grid=grid) fig, ax = plt.subplots() plotman.plot_elements_to_ax( pid, plot_colorbar=True, ax=ax, ) fig.tight_layout() fig.savefig('model.jpg', dpi=300) .. image-sg:: /_examples/00_grids/images/sphx_glr_plot_triag_with_internal_structure_inkscape_001.png :alt: plot triag with internal structure inkscape :srcset: /_examples/00_grids/images/sphx_glr_plot_triag_with_internal_structure_inkscape_001.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 .. GENERATED FROM PYTHON SOURCE LINES 123-127 Now we can create a decouplings.dat file that can be used by CRTomo to decouple regularization between adjacent cells .. program-output:: grid_extralines_gen_decouplings --help .. GENERATED FROM PYTHON SOURCE LINES 127-133 .. code-block:: Python with reda.CreateEnterDirectory('tmp_triag_inkscape'): subprocess.call( 'grid_extralines_gen_decouplings -e grid/elem.dat ' '-l lne_constraint_1.dat --debug_plot --eta 0.7', shell=True ) .. _sphx_glr_download__examples_00_grids_plot_triag_with_internal_structure_inkscape.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_triag_with_internal_structure_inkscape.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_triag_with_internal_structure_inkscape.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_triag_with_internal_structure_inkscape.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_