.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/tutorials/parameter_tests.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_gallery_tutorials_parameter_tests.py: 06. Parameter tests =================== The modeller ``emg3d`` has quite a few parameters which can influence the speed of a computation. It can be difficult to estimate which is the best setting. In the case that speed is of utmost importance, and a lot of similar models are going to be computed (e.g. for inversions), it might be worth to do some input parameter testing. **IMPORTANT:** None of the conclusions you can draw from these figures are applicable to other models. What is faster depends on your input. Influence has particularly the degree of anisotropy and of grid stretching. These are simply examples that you can adjust for your problem at hand. .. GENERATED FROM PYTHON SOURCE LINES 17-24 .. code-block:: Python import emg3d import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import LogNorm plt.style.use('bmh') .. GENERATED FROM PYTHON SOURCE LINES 26-43 .. code-block:: Python def plotit(infos, labels): """Simple plotting routine for the tests.""" plt.figure() # Loop over infos. for i, info in enumerate(infos): plt.plot(info['runtime_at_cycle'], info['error_at_cycle']/info1['ref_error'], '.-', label=labels[i]) plt.legend() plt.xlabel('Time (s)') plt.ylabel('Rel. Error $(-)$') plt.yscale('log') .. GENERATED FROM PYTHON SOURCE LINES 44-87 .. code-block:: Python # Survey zwater = 1000 # Water depth. src = [0, 0, 50-zwater, 0, 0] # Source at origin, 50 m above seafloor. freq = 1.0 # Frequency (Hz). # Mesh grid = emg3d.construct_mesh( frequency=freq, min_width_limits=100, properties=[0.3, 1., 1., 0.3], center=(src[0], src[1], -1000), domain=([-1000, 5000], [-500, 500], [-2500, 0]), center_on_edge=False, ) print(grid) # Source-field sfield = emg3d.get_source_field(grid, source=src, frequency=freq) # Create a simple marine model for the tests. # Layered_background res_x = 1e8*np.ones(grid.shape_cells) # Air res_x[:, :, grid.cell_centers_z <= 0] = 0.3 # Water res_x[:, :, grid.cell_centers_z <= -1000] = 1. # Background # Target xt = np.nonzero((grid.cell_centers_x >= -500) & (grid.cell_centers_x <= 5000))[0] yt = np.nonzero((grid.cell_centers_y >= -1000) & (grid.cell_centers_y <= 1000))[0] zt = np.nonzero((grid.cell_centers_z >= -2100) & (grid.cell_centers_z <= -1800))[0] res_x[xt[0]:xt[-1]+1, yt[0]:yt[-1]+1, zt[0]:zt[-1]+1] = 100 # Create a model instance model_iso = emg3d.Model(grid, property_x=res_x, mapping='Resistivity') # Plot it for QC grid.plot_3d_slicer(model_iso.property_x.ravel('F'), pcolor_opts={'norm': LogNorm()}) .. image-sg:: /gallery/tutorials/images/sphx_glr_parameter_tests_001.png :alt: parameter tests :srcset: /gallery/tutorials/images/sphx_glr_parameter_tests_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none TensorMesh: 76,800 cells MESH EXTENT CELL WIDTH FACTOR dir nC min max min max max --- --- --------------------------- ------------------ ------ x 80 -4,233.88 9,146.56 100.00 912.68 1.25 y 24 -3,667.19 5,375.78 100.00 1,708.59 1.50 z 40 -5,764.95 1,752.46 100.00 857.19 1.31 .. GENERATED FROM PYTHON SOURCE LINES 88-90 Test 1: F, W, and V MG cycles ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 90-100 .. code-block:: Python inp = {'model': model_iso, 'sfield': sfield, 'return_info': True, 'sslsolver': False, 'semicoarsening': False, 'linerelaxation': False} _, info1 = emg3d.solve(cycle='F', **inp) _, info2 = emg3d.solve(cycle='W', **inp) _, info3 = emg3d.solve(cycle='V', **inp) plotit([info1, info2, info3], ['F-cycle', 'W-cycle', 'V-cycle']) .. image-sg:: /gallery/tutorials/images/sphx_glr_parameter_tests_002.png :alt: parameter tests :srcset: /gallery/tutorials/images/sphx_glr_parameter_tests_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 101-103 Test 2: semicoarsening, line-relaxation --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 103-114 .. code-block:: Python inp = {'model': model_iso, 'sfield': sfield, 'return_info': True, 'sslsolver': False} _, info1 = emg3d.solve(semicoarsening=False, linerelaxation=False, **inp) _, info2 = emg3d.solve(semicoarsening=True, linerelaxation=False, **inp) _, info3 = emg3d.solve(semicoarsening=False, linerelaxation=True, **inp) _, info4 = emg3d.solve(semicoarsening=True, linerelaxation=True, **inp) plotit([info1, info2, info3, info4], ['MG', 'MG+SC', 'MG+LR', 'MG+SC+LR']) .. image-sg:: /gallery/tutorials/images/sphx_glr_parameter_tests_003.png :alt: parameter tests :srcset: /gallery/tutorials/images/sphx_glr_parameter_tests_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 115-117 Test 3: MG and BiCGstab ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 117-127 .. code-block:: Python inp = {'model': model_iso, 'sfield': sfield, 'return_info': True, 'maxit': 500, 'semicoarsening': True, 'linerelaxation': False} _, info1 = emg3d.solve(cycle='F', sslsolver=False, **inp) _, info2 = emg3d.solve(cycle='F', sslsolver=True, **inp) _, info3 = emg3d.solve(cycle=None, sslsolver=True, **inp) plotit([info1, info2, info3], ['MG', 'MG+BiCGStab', 'BiCGStab']) .. image-sg:: /gallery/tutorials/images/sphx_glr_parameter_tests_004.png :alt: parameter tests :srcset: /gallery/tutorials/images/sphx_glr_parameter_tests_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none * WARNING :: Error in bicgstab (-10) .. GENERATED FROM PYTHON SOURCE LINES 128-130 Test 4: `nu_init`, `nu_pre`, `nu_coarse`, `nu_post` --------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 130-142 .. code-block:: Python inp = {'model': model_iso, 'sfield': sfield, 'return_info': True, 'sslsolver': False, 'semicoarsening': True, 'linerelaxation': False} _, info1 = emg3d.solve(**inp) _, info2 = emg3d.solve(nu_pre=0, **inp) _, info3 = emg3d.solve(nu_post=0, **inp) _, info4 = emg3d.solve(nu_init=2, **inp) plotit([info1, info2, info3, info4], ['{0,2,1,2} (default)', '{0,0,1,2}', '{0,2,1,0}', '{2,1,2,1}']) .. image-sg:: /gallery/tutorials/images/sphx_glr_parameter_tests_005.png :alt: parameter tests :srcset: /gallery/tutorials/images/sphx_glr_parameter_tests_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 143-145 .. code-block:: Python emg3d.Report() .. raw:: html
Wed Feb 11 20:49:18 2026 UTC
OS Linux (Ubuntu 24.04) CPU(s) 16 Machine x86_64
Architecture 64bit RAM 93.6 GiB Environment Python
File system ext4
Python 3.13.12 | packaged by conda-forge | (main, Feb 5 2026, 05:53:46) [GCC 14.3.0]
numpy 2.3.5 scipy 1.17.0 numba 0.63.1
emg3d 1.8.7 empymod 2.6.0 xarray 2026.1.0
discretize 0.12.0 h5py 3.15.1 matplotlib 3.10.8
tqdm 4.67.3
Intel(R) oneAPI Math Kernel Library Version 2025.3-Product Build 20251007 for Intel(R) 64 architecture applications


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 45.962 seconds) **Estimated memory usage:** 229 MB .. _sphx_glr_download_gallery_tutorials_parameter_tests.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: parameter_tests.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: parameter_tests.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: parameter_tests.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_