How to run Modflow 6 models on the background with Flopy, Linux and Nohup - Tutorial

If by chance you ended up working with large scale models with long execution times on JupyterLab you might find some restrictions related to the interface itself. Since the model execution is related to the session your computer can go into suspension before the process has finished or you need to keep a tab open to ensure the process is running smoothly. We have explored alternatives to run the model on the background, having some resources to reach the simulation progress and monitoring the process.

This tutorial shows the process to turn the Jupyter notebook into a Python script and run it with Noup.

You would need the MODFLOW executables compiled for Linux:

hatarilabs.com/ih-en/a-place-to-find-modflow-executables-for-any-operating-system

Tutorial


Code

This is the Nohup sentence to run the model on the background:

nohup python -u modelSplitter.py > flopyLog.txt

The code used to read, change workspace, write simulation, and runs the model.

#!/usr/bin/env python
# coding: utf-8

# In[1]:


import os
import sys
import time

import flopy
import matplotlib.pyplot as plt
import numpy as np

from flopy.mf6.utils import Mf6Splitter
from flopy.plot import styles
from flopy.utils.geometry import LineString, Polygon


# In[2]:


simulation_ws = os.path.abspath("../model/Update")
sim = flopy.mf6.MFSimulation.load(sim_ws=simulation_ws)


# In[ ]:


print("Create new workspace and write simulation")
workspace = os.path.abspath("../model/Work")
sim.set_sim_path(workspace)
sim.exe_name = '../bin/mf6'
sim.write_simulation()


# In[ ]:


print("Start model simulation")
startTime = time.time()
sim.run_simulation()
endTime = time.time()

print(("--- %s seconds ---")%(startTime - endTime))
Comment

Saul Montoya

Saul Montoya es Ingeniero Civil graduado de la Pontificia Universidad Católica del Perú en Lima con estudios de postgrado en Manejo e Ingeniería de Recursos Hídricos (Programa WAREM) de la Universidad de Stuttgart con mención en Ingeniería de Aguas Subterráneas y Hidroinformática.

 

Suscribe to our online newsletter

Subscribe for free newsletter, receive news, interesting facts and dates of our courses in water resources.