Subject: MODFLOW - WEAP LINKAGE Posted: 5/18/2021 Viewed: 5852 times
Can we stop MODFLOW in between simulation, and update the input recharge file through WEAP?
yes, there is a pretty workaround calling a vb-script at the right interupt-event. I've developed exactly what you are asking for shortly and it works like a charm.
1. Use the event-manager (Advanced -> Scripting -> Edit Events) and enter "Call( ExchangeRCHFile.vbs )" in the textbox besides "Before MODFLOW". This event fires AFTER Weap has produced its own set of MODFLOW files, but hasn't yet started MODFLOW. This is the right moment to replace the recharge file with your own.
2. Go to Advanced -> Scripting -> Edit Scripts and paste the lines below into a new document and save as ExchangeRCHFile.vbs. You will need to replace the words in brackets [] with what fits to your setup!
3. The script requires:
- that you have a folder containing all recharge files under the Area Directory
- that there is one folder for each scenario underneath
- the RCH-files are named "YYYY_MM.rch"
- the formats of the RCH-files match with the formats of the files produced by WEAP
Good luck and all the best
Markus
'---- Script:----
Option Explicit
Dim sCCRechFolder, sCCRechFile, sDestRechFile, sMFModelname, sMFFolder
Dim sScen, iScen, iYear, iMonth
Dim fso
sMFModelName = "[ENTER THE NAME OF YOUR MODFLOW MODEL HERE]"
sMFFolder = WEAP.ActiveArea.Directory & "MODFLOW\"
sCCRechFolder = WEAP.ActiveArea.Directory & "[ENTER THE FOLDERNAME WHERE THE RECHARGE FILES ARE]\"
'--- Generate FileNames based on current Scenario and Timestep'
sScen = WEAP.ActiveScenario.Name
iScen = Weap.ActiveScenario.ID
if len(iScen)<2 then iScen = "0" & iScen
iYear = CalcYear
iMonth = CalcTS
if len(iMonth)<2 then iMonth = "0" & iMonth
sCCRechFile = sCCRechFolder & "\" & sScen & "\" & iYear & "_" & iMonth & ".rch" 'you either need to follow this pattern in your file system, or you change the code here accordingly
Subject: Re: MODFLOW - WEAP LINKAGE Posted: 1/6/2022 Viewed: 5073 times
Dear Markus,
Can we let WEAP use river water level from Modflow at all time steps?
similar to groundwater recharge, WEAP writes a separate river package file for each time step, based on the calculated flow and the flow-stage-width formulation. MODFLOW then determines the flow direction and volumes out of or into the groundwater along the river course. I am not aware that MODFLOW can also provide groundwater levels as a result.
If you want to use your own river package (input-) files instead of the ones created by WEAP, you could replace the files on the fly as described for the recharge package above.
Best regards
Markus
Mr. Dinh Ty Nguyen
Subject: Re: MODFLOW - WEAP LINKAGE Posted: 1/15/2022 Viewed: 5018 times
Dear Huber,
I had applied the code with the change of RCH to RIV in my case, but the error happens (belows). I did change and the format of the script to meet pattern of my file. To my understand, the error inform that the file 'sDestRechFile' does not exist in system, but I already checked to make sure the file does exists. Please take a look in the error and script belows and help me if I make any mistake.
Thank you in advance!
Error: File not found
Script file: ExchangeRIVFile.vbs
Language: VBScript
Line: 30
script:
Option Explicit
Dim sCCRechFolder, sCCRechFile, sDestRechFile, sMFModelname, sMFFolder
Dim sScen, iScen, iYear, iMonth
Dim fso
I checked two problems that you suggested by putting a "print" command and run the code inside Script editor:
1. for the 1st suggestion, if I put "\" at the end, then it will double at the printed result of "sCCRechFile".
2. for 2nd suggestion, I don't know why in my case it output
the same format with Weap's output in it's Modflow folder.
My early problem still exists.
Hope to hear any other suggestion,
Best regards
Mr. Dinh Ty Nguyen
Subject: Re: MODFLOW - WEAP LINKAGE Posted: 1/26/2022 Viewed: 4980 times
Dear all,
I had modified the Script and it worked. The script follows the instruction that Mr. Markus Huber mentioned above, and in my case, the data is river data, then all data and name file change from RCH -> RIV.
In the river-package file "YYYY_MM.riv", the unit (last number in the first row) has to be as same as the unit of CCF-package that showed in *.nam file for each timestep period. In my case they are different, maybe the reason is as my Modflow model generated by Python.
The script is as follow, hope it make help to someone:
Option Explicit
Dim sCCRechFolder, sCCRechFile, sDestRechFile, sMFModelname, sMFFolder
Dim sScen, iScen, iYear, iMonth
Dim fso