.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\mf6\hondsrug_partitioning.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_mf6_hondsrug_partitioning.py: Partitioning a regional model ============================= This example shows how a model can be partitioned into submodels. This will allow parallelization when solving the model. The example used is the Hondsrug model. It is partitioned into 3 rectangular parts. In the example we first run the original, unpartitioned model. Then we partition the model and run the resulting simulation. Finally we merge the head output of the submodels into a head array for the whole grid. we print both the heads obtained without partitioning, and the merged heads of the partitioned simulation, ' for comparison. .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: Python import matplotlib.pyplot as plt import imod from imod.mf6.multimodel.partition_generator import get_label_array .. GENERATED FROM PYTHON SOURCE LINES 22-26 Obtain the simulation, write it, run it, and plot some heads. There is a separate example contained in :doc:`hondsrug ` that you should look at if you are interested in the model building .. GENERATED FROM PYTHON SOURCE LINES 26-30 .. code-block:: Python tmpdir = imod.util.temporary_directory() gwf_simulation = imod.data.hondsrug_simulation(tmpdir / "hondsrug_saved") .. GENERATED FROM PYTHON SOURCE LINES 31-33 Write the model and run it (before partitioning, so we can compare if the results are similar). .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: Python original_modeldir = tmpdir / "original" gwf_simulation.write(original_modeldir) gwf_simulation.run() .. GENERATED FROM PYTHON SOURCE LINES 39-40 Plot the simulation results of the unpartitioned model. .. GENERATED FROM PYTHON SOURCE LINES 40-46 .. code-block:: Python hds_original = gwf_simulation.open_head() fig, ax = plt.subplots() hds_original.sel(layer=3).isel(time=6).plot(ax=ax) ax.set_title("hondsrug original ") .. image-sg:: /examples/mf6/images/sphx_glr_hondsrug_partitioning_001.png :alt: hondsrug original :srcset: /examples/mf6/images/sphx_glr_hondsrug_partitioning_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'hondsrug original ') .. GENERATED FROM PYTHON SOURCE LINES 47-48 Now we partition the Hondsrug model .. GENERATED FROM PYTHON SOURCE LINES 48-52 .. code-block:: Python idomain = gwf_simulation["GWF"].domain number_partitions = 16 submodel_labels = get_label_array(gwf_simulation, number_partitions) .. GENERATED FROM PYTHON SOURCE LINES 53-54 plot the partitioning array. It shows how the model will be partitioned. .. GENERATED FROM PYTHON SOURCE LINES 54-60 .. code-block:: Python fig, ax = plt.subplots() submodel_labels.plot(ax=ax) ax.set_title("hondsrug partitioning geometry") split_simulation = gwf_simulation.split(submodel_labels) .. image-sg:: /examples/mf6/images/sphx_glr_hondsrug_partitioning_002.png :alt: hondsrug partitioning geometry :srcset: /examples/mf6/images/sphx_glr_hondsrug_partitioning_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 61-62 Now we write and run the partitioned model .. GENERATED FROM PYTHON SOURCE LINES 62-68 .. code-block:: Python split_modeldir = tmpdir / "split" split_simulation.write(split_modeldir) split_simulation.run() .. GENERATED FROM PYTHON SOURCE LINES 69-70 Load and plot the simulation results. Also plot the differences with the original model .. GENERATED FROM PYTHON SOURCE LINES 70-81 .. code-block:: Python hds_split = split_simulation.open_head()["head"] fig, ax = plt.subplots() hds_split.sel(layer=3).isel(time=6).plot(ax=ax) ax.set_title("hondsrug partitioned ") diff = hds_split - hds_original diff_for_plot = diff.max(dim=["time", "layer"]) fig, ax = plt.subplots() diff_for_plot.plot(ax=ax) ax.set_title("hondsrug diff ") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/mf6/images/sphx_glr_hondsrug_partitioning_003.png :alt: hondsrug partitioned :srcset: /examples/mf6/images/sphx_glr_hondsrug_partitioning_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/mf6/images/sphx_glr_hondsrug_partitioning_004.png :alt: hondsrug diff :srcset: /examples/mf6/images/sphx_glr_hondsrug_partitioning_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'hondsrug diff ') .. rst-class:: sphx-glr-timing **Total running time of the script:** (5 minutes 1.721 seconds) .. _sphx_glr_download_examples_mf6_hondsrug_partitioning.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: hondsrug_partitioning.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: hondsrug_partitioning.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: hondsrug_partitioning.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_