<jupyter_start><jupyter_text>OUTDATED, the examples moved to the gallery See https://empymod.github.io/emg3d-gallery---- Minimum working exampleThis is a simple minimum working example to get started, along the lines of the one given in https://emg3d.readthedocs.io/en/stable/usage.htmlexample.To see some more realistic models have a look at the other notebooks in this repo.-------------------------------------------------------------------------------This notebooks uses `discretize` to create meshes easily and plot the model as well as the resulting electric field, which also requires `matplotlib`. If you are interested in a basic example that only requires `emg3d` here it is:```pyimport emg3dimport numpy as np Create a simple grid, 8 cells of length 1 in each direction, starting at the origin.grid = emg3d.utils.TensorMesh([np.ones(8), np.ones(8), np.ones(8)], x0=np.array([0, 0, 0])) The model is a fullspace with tri-axial anisotropy.model = emg3d.utils.Model(grid, res_x=1.5, res_y=1.8, res_z=3.3) The source is a x-directed, horizontal dipole at (4, 4, 4), frequency is 10 Hz.sfield = emg3d.utils.get_source_field(grid, src=[4, 4, 4, 0, 0], freq=10.0) Calculate the electric signal.efield = emg3d.solver.solver(grid, model, sfield, verb=3) Get the corresponding magnetic signal.hfield = emg3d.utils.get_h_field(grid, model, efield) ```-------------------------------------------------------------------------------**Requires**- **emg3d >= 0.9.1**- discretize, matplotlibFirst, we load `emg3d` and `discretize` (to create a mesh), along with `numpy` and `matplotlib`:<jupyter_code>import emg3d
import discretize
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
%matplotlib notebook
plt.style.use('ggplot')<jupyter_output><empty_output><jupyter_text>1. MeshFirst, we define the mesh (see `discretize.TensorMesh` for more info). In reality, this task requires some careful considerations. E.g., to avoid edge effects, the mesh should be large enough in order for the fields to dissipate, yet fine enough around source and receiver to accurately model them. This grid is too small, but serves as a minimal example.<jupyter_code>grid = discretize.TensorMesh(
        [[(25, 10, -1.04), (25, 28), (25, 10, 1.04)],
         [(50, 8, -1.03), (50, 16), (50, 8, 1.03)],
         [(30, 8, -1.05), (30, 16), (30, 8, 1.05)]],
        x0='CCC')
grid<jupyter_output><empty_output><jupyter_text>2. ModelNext we define a very simple fullspace model with $\rho_x=1.5\,\Omega\rm{m}$,  $\rho_y=1.8\,\Omega\rm{m}$, and  $\rho_z=3.3\,\Omega\rm{m}$.<jupyter_code>model = emg3d.utils.Model(grid, res_x=1.5, res_y=1.8, res_z=3.3)<jupyter_output><empty_output><jupyter_text>We can plot the model using `discretize`; in this case it is obviously rather a boring plot, as it shows a homogenous fullspace.<jupyter_code>grid.plot_3d_slicer(np.ones(grid.vnC)*model.res_x)  # x-resistivity<jupyter_output><empty_output><jupyter_text>3. Source fieldThe source is an x-directed dipole at the origin, with a 10 Hz signal of 1 A (`src` is defined either as `[x, y, z, dip, azimuth]` or `[x0, x1, y0, y1, z0, z1]`; the strength can be set via the `strength` parameter).<jupyter_code>sfield = emg3d.utils.get_source_field(grid, src=[0, 0, 0, 0, 0], freq=10)<jupyter_output><empty_output><jupyter_text>4. Calculate the electric fieldNow we can calculate the electric field with `emg3d`:<jupyter_code>efield = emg3d.solver.solver(grid, model, sfield, verb=3)<jupyter_output>* WARNING :: ``emg3d.solver.solver()`` is renamed to ``emg3d.solve()``.
             Use the new ``emg3d.solve()``, as ``solver()`` will be
             removed in the future.

:: emg3d START :: 07:31:17 :: v0.9.3.dev17

   MG-cycle       : 'F'                 sslsolver : False
   semicoarsening : False [0]           tol       : 1e-06
   linerelaxation : False [0]           maxit     : 50
   nu_{i,1,c,2}   : 0, 2, 1, 2          verb      : 3
   Original grid  :  48 x  32 x  32     => 49,152 cells
   Coarsest grid  :   3 x   2 x   2     => 12 cells
   Coarsest level :   4 ;   4 ;   4   

   [hh:mm:ss]  rel. error                  [abs. error, last/prev]   l s

       h_
      2h_ \                  /
      4h_  \          /\    / 
      8h_   \    /\  /  \  /  
     16h_    \/\/  \/    \/   

   [07:31:18]   2.623e-02  after   1 F-cycles   [1.464e-06, 0.026]   0 0
   [07:31:18]   2.253e-03  after   2 F-cycles   [1.258e-07, 0.086]   0 0
   [07:31:18]   3.051e-04  after   3 F-cycles   [1[...]<jupyter_text>The calculation requires in this case seven multigrid F-cycles and taken just a few seconds. It was able to coarsen in each dimension four times, where the input grid had 49,152 cells, and the coarsest grid had 12 cells.  5. Plot the resultWe can again utilize the in-built functions of a `discretize`-grid to plot, e.g., the x-directed electric field.<jupyter_code>grid.plot_3d_slicer(efield.fx.ravel('F'), view='abs', vType='Ex', pcolorOpts={'norm': LogNorm()})
emg3d.Report(discretize)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1549940310385993, 'fraction_numerical': 0.05173099880620772, 'mean_word_length': 3.0151757188498403, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '549327', 'license': 'Apache-2.0', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1739, 'n_words': 553, 'path': '0a_Minimum_working_example.ipynb', 'repo_name': 'empymod/emg3d-examples', 'size': '5026'}