From 02716e163972a32edabe51e4c0f9785af2eb00fc Mon Sep 17 00:00:00 2001 From: Adam Calvert <72354690+acgr96@users.noreply.github.com> Date: Sun, 17 Aug 2025 13:20:41 -0400 Subject: [PATCH 1/3] MIKESHE Water Content Hot Start Script This script allows for using a previous simulation's 3D water content distribution as a hot start condition for another WM simulation by overwriting the water content in the new simulation over the first several timesteps. --- MSHE_HotStart.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 MSHE_HotStart.py diff --git a/MSHE_HotStart.py b/MSHE_HotStart.py new file mode 100644 index 0000000..0692879 --- /dev/null +++ b/MSHE_HotStart.py @@ -0,0 +1,42 @@ +''' +Script to initiate a MIKESHE WM simulation using unsat zone water content from a previous run as a hot start condition. +''' + +print('Importing Required Libraries...') +# Import MIKESHE +import importlib.util +spec = importlib.util.spec_from_file_location('MShePy311', r'C:\Program Files (x86)\DHI\MIKE Zero\2025\bin\x64\MShePy311.pyd') +MShePy = importlib.util.module_from_spec(spec) + +# Import other required libraries including MIKEIO +import mikeio +import numpy as np + +# Load DFS3 Result File of Unsat Zone and get Water Content Array +print('Importing Water Content Data From Previous Model Run...') +uz_data = mikeio.read(r'D:\Projects\MIKESHE_Hotstart\TestModel\TestModel_3DUZ.dfs3') +wc_arr = uz_data['water content in unsaturated zone'] +wc_arr_finalts = wc_arr[-1,:,:,:].values # Access array of 3D water content values at final timestep +#Transpose Z dimensions from first dim of array to last to align with MShePy dataset structure +wc_arr_finalts = np.transpose(wc_arr_finalts, (1, 2, 0)) + +# Initiate MIKE SHE Model +print('Initializing MIKESHE Model...') +model = r'D:\Projects\MIKESHE_Hotstart\TestModel\TestModel.she' +MShePy.wm.initialize(model) +MShePy + +simperiod = MShePy.wm.simPeriod() +start_time = simperiod[0] +end_time = simperiod[-1] +assign_timesteps = 10 # Number of timesteps to execute water content overwrite + +for ts in range(assign_timesteps): + print(ts) + (t0, t1, wc) = MShePy.wm.getValues(MShePy.paramTypes.UZ_WC) + wc[:] = wc_arr_finalts.tolist() + MShePy.wm.setValues(wc) + MShePy.wm.performTimeStep() + +MShePy.wm.runToTime(end_time) +MShePy.wm.terminate(True) \ No newline at end of file From 250bd373bf7658caac358959e043cd90ac3c998d Mon Sep 17 00:00:00 2001 From: Adam Calvert <72354690+acgr96@users.noreply.github.com> Date: Sun, 17 Aug 2025 13:22:00 -0400 Subject: [PATCH 2/3] Moved MSHE_HotStart to Plugins --- MSHE_HotStart.py => Plugins/MSHE_HotStart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename MSHE_HotStart.py => Plugins/MSHE_HotStart.py (95%) diff --git a/MSHE_HotStart.py b/Plugins/MSHE_HotStart.py similarity index 95% rename from MSHE_HotStart.py rename to Plugins/MSHE_HotStart.py index 0692879..747e719 100644 --- a/MSHE_HotStart.py +++ b/Plugins/MSHE_HotStart.py @@ -39,4 +39,4 @@ MShePy.wm.performTimeStep() MShePy.wm.runToTime(end_time) -MShePy.wm.terminate(True) \ No newline at end of file +MShePy.wm.terminate(True) From f68e6acb4787642f672e517ff442b5b4461cd3c7 Mon Sep 17 00:00:00 2001 From: Adam Calvert <72354690+acgr96@users.noreply.github.com> Date: Sun, 17 Aug 2025 13:22:53 -0400 Subject: [PATCH 3/3] Moved MSHE_HotStart.py to Simulation Execution --- {Plugins => SimulationExecution}/MSHE_HotStart.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Plugins => SimulationExecution}/MSHE_HotStart.py (100%) diff --git a/Plugins/MSHE_HotStart.py b/SimulationExecution/MSHE_HotStart.py similarity index 100% rename from Plugins/MSHE_HotStart.py rename to SimulationExecution/MSHE_HotStart.py