.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "integrations/gempy_export_MOOSE.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_integrations_gempy_export_MOOSE.py: Export a geological model from GemPy to use in MOOSE ==================================================== .. GENERATED FROM PYTHON SOURCE LINES 8-10 .. code-block:: python3 import gempy as gp .. GENERATED FROM PYTHON SOURCE LINES 11-19 Creating a geological model --------------------------- The procedure of generating a geological model is presented in detail in `Chapter 1-1 `__ of the GemPy tutorials, so it will only be briefly presented here .. GENERATED FROM PYTHON SOURCE LINES 21-22 Initiate a model .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: python3 geo_model = gp.create_model('tutorial_moose_exp') data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/' .. GENERATED FROM PYTHON SOURCE LINES 26-27 Import data from CSV-files with setting the resolution and model extent .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: python3 gp.init_data(geo_model, [0, 2000., 0, 2000., 0, 2000.], [50, 50, 80], path_o=data_path + "/data/input_data/tut_chapter1/simple_fault_model_orientations.csv", path_i=data_path + "/data/input_data/tut_chapter1/simple_fault_model_points.csv", default_values=True) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Active grids: ['regular'] tutorial_moose_exp 2021-04-18 11:39 .. GENERATED FROM PYTHON SOURCE LINES 33-34 present the units and series .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: python3 geo_model.surfaces .. raw:: html
surface series order_surfaces color id
0 Shale Default series 1 #015482 1
1 Sandstone_1 Default series 2 #9f0052 2
2 Siltstone Default series 3 #ffbe00 3
3 Sandstone_2 Default series 4 #728f02 4
4 Main_Fault Default series 5 #443988 5
5 basement Basement 1 #ff3f20 6


.. GENERATED FROM PYTHON SOURCE LINES 37-38 combine units in series and make two series, as the fault needs its own .. GENERATED FROM PYTHON SOURCE LINES 38-46 .. code-block:: python3 gp.map_stack_to_surfaces(geo_model, {"Fault_Series": 'Main_Fault', "Strat_Series": ('Sandstone_2', 'Siltstone', 'Shale', 'Sandstone_1', 'basement')}, remove_unused_series=True) # set the fault series to be fault object geo_model.set_is_fault(['Fault_Series'], change_color=False) .. raw:: html
order_series BottomRelation isActive isFault isFinite
Fault_Series 1 Fault True True False
Strat_Series 2 Erosion True False False


.. GENERATED FROM PYTHON SOURCE LINES 47-48 check whether series were assigned correctly .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: python3 geo_model.surfaces .. raw:: html
surface series order_surfaces color id
4 Main_Fault Fault_Series 1 #443988 1
0 Shale Strat_Series 1 #015482 2
1 Sandstone_1 Strat_Series 2 #9f0052 3
2 Siltstone Strat_Series 3 #ffbe00 4
3 Sandstone_2 Strat_Series 4 #728f02 5
5 basement Strat_Series 5 #ff3f20 6


.. GENERATED FROM PYTHON SOURCE LINES 51-57 Model generation ---------------- After loading in the data, we set it up for interpolation and compute the model. .. GENERATED FROM PYTHON SOURCE LINES 59-60 set up interpolator .. GENERATED FROM PYTHON SOURCE LINES 60-65 .. code-block:: python3 gp.set_interpolator(geo_model, compile_theano=True, theano_optimizer='fast_compile', verbose=[]) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Setting kriging parameters to their default values. Compiling theano function... Level of Optimization: fast_compile Device: cpu Precision: float64 Number of faults: 1 Compilation Done! Kriging values: values range 3464.1 $C_o$ 285714.29 drift equations [3, 3] .. GENERATED FROM PYTHON SOURCE LINES 66-67 compute the model .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: python3 gp.compute_model(geo_model, compute_mesh=False); .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Lithology ids [6. 6. 6. ... 2. 2. 2.] .. GENERATED FROM PYTHON SOURCE LINES 70-71 have a look at the data and computed model .. GENERATED FROM PYTHON SOURCE LINES 71-73 .. code-block:: python3 gp.plot_3d(geo_model) .. image:: /integrations/images/sphx_glr_gempy_export_MOOSE_001.png :alt: gempy export MOOSE :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 74-83 Exporting the Model to MOOSE ---------------------------- The voxel-model above already is the same as a model discretized in a hexahedral grid, so my immediately be used as input in a simulation tool, e.g. `MOOSE `__. For this, we need to access to the unit IDs assigned to each voxel in GemPy. The array containing these IDs is called ``lith_block``. .. GENERATED FROM PYTHON SOURCE LINES 85-88 .. code-block:: python3 ids = geo_model.solutions.lith_block print(ids) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [6. 6. 6. ... 2. 2. 2.] .. GENERATED FROM PYTHON SOURCE LINES 89-95 This array has the shape of ``(x,)`` and would be immediately useful, if GemPy and the chosen simulation code would *populate* a grid in the same way. Of course, however, that is not the case. This is why we have to restructure the ``lith_block`` array, so it can be read correctly by MOOSE. .. GENERATED FROM PYTHON SOURCE LINES 97-98 model resolution .. GENERATED FROM PYTHON SOURCE LINES 98-103 .. code-block:: python3 nx, ny, nz = geo_model.grid.regular_grid.resolution # model extent xmin, xmax, ymin, ymax, zmin, zmax = geo_model.grid.regular_grid.extent .. GENERATED FROM PYTHON SOURCE LINES 104-109 These two parameters are important to, a) restructure ``lith_block``, and b) write the input file for MOOSE correctly. For a), we need to reshape ``lith_block`` again to its three dimensions and *re-flatten* it in a *MOOSE-conform* way. .. GENERATED FROM PYTHON SOURCE LINES 111-112 reshape to 3D array .. GENERATED FROM PYTHON SOURCE LINES 112-116 .. code-block:: python3 units = ids.reshape((nx, ny, nz)) # flatten MOOSE conform units = units.flatten('F') .. GENERATED FROM PYTHON SOURCE LINES 117-157 | The importance of ``nx, ny, nz`` is apparent from the cell above. But what about ``xmin``, …, ``zmax``? | A MOOSE input-file for mesh generation has the following syntax: .. code:: python [MeshGenerators] [./gmg] type = GeneratedMeshGenerator dim = 3 nx = 50 ny = 50 nz = 80 xmin = 0.0 xmax = 2000.0 yim = 0.0 ymax = 2000.0 zmin = 0.0 zmax = 2000.0 block_id = '1 2 3 4 5 6' block_name = 'Main_Fault Sandstone_2 Siltstone Shale Sandstone_1 basement' [../] [./subdomains] type = ElementSubdomainIDGenerator input = gmg subdomain_ids = ' ' # here you paste the transformed lith_block vector [../] [] [Mesh] type = MeshGeneratorMesh [] So these parameters are required inputs in the ``[MeshGenerators]`` object in the MOOSE input file. ``GemPy`` has a method to directly create such an input file, stored in ``gempy.utils.export.py``. The following cell shows how to call the method: .. GENERATED FROM PYTHON SOURCE LINES 159-164 .. code-block:: python3 # sphinx_gallery_thumbnail_path = '_static/GemPy_model_combined.png' import gempy.utils.export as export export.export_moose_input(geo_model, path='') .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Successfully exported geological model as moose input to ./ .. GENERATED FROM PYTHON SOURCE LINES 165-207 This method automatically stores a file ``geo_model_units_moose_input.i`` at the specified path. Either this input file could be extended with parameters to directly run a simulation, or it is used just for creating a mesh. In the latter case, the next step would be, to run the compiled MOOSE executable witch the optional flag ``--mesh-only``. E.g. with using the `PorousFlow module `__: .. code:: bash $path_to_moose/moose/modules/porous_flow/porous_flow-opt -i pct_voxel_mesh.i --mesh-only How to compile MOOSE is described in their `documentation `__. The now generated mesh with the name ``geo_model_units_moose_input_in.e`` can be used as input for another MOOSE input file, which contains the main simulation parameters. To call the file with the grid, the following part has to be added in the MOOSE simulation input file: .. code:: python [Mesh] file = geo_model_units_moose_input_in.e [] .. raw:: html
The final output of the simulation may also be such an ``.e``, which can, for instance, be opened with `paraview `__. A simulated temperature field (purely conductive) of the created model would look like this: .. figure:: https://raw.githubusercontent.com/Japhiolite/a-Moose-and-you/master/imgs/GemPy_model_combined.png :alt: gempy_temperature .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 8.698 seconds) .. _sphx_glr_download_integrations_gempy_export_MOOSE.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: gempy_export_MOOSE.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: gempy_export_MOOSE.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_