Welcome to WEAP's Website WEAP
WEAP is an initiative of the Stockholm Environment Institute.


About WEAP

Home
Why WEAP?
Features
What's New?
Sample Screens
Demonstration
Publications
History and Credits

Using WEAP
Download
Licensing
User Guide
Tutorial
Videos (YouTube)

User Forum
Discussions
Members List
Edit Profile

Additional Support
Training
University Courses
Collaboration

About Us
SEI-US Water Resources Program
Please Contact Us

LEAP
Interested in Energy?
Read about LEAP: SEI's software for energy planning.

Link WEAP and LEAP for combined Water-Energy planning.
Watch a video demo!
   

User Forum

All Topics | Topic "MODFLOW - WEAP LINKAGE"
Log in to post new messages or reply to existing messages.
 
Author Message
Mrs. Resmy K

Subject: MODFLOW - WEAP LINKAGE   
Posted: 5/18/2021 Viewed: 5372 times
Can we stop MODFLOW in between simulation, and update the input recharge file through WEAP?
Mr. Markus Huber

Subject: Re: MODFLOW - WEAP LINKAGE   
Posted: 6/7/2021 Viewed: 5059 times
Dear Resmy,

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


sDestRechFile = sMFFolder & "!MF!" & sMFModelName & "_S" & iScen & "_" & iYear & "_" & iMonth & ".rch"


set fso=CreateObject("Scripting.FileSystemObject")

fso.deletefile sDestRechFile
fso.copyfile sCCRechFile, sDestRechFile


set fso = nothing


'---- end script ----
Mr. Dinh Ty Nguyen

Subject: Re: MODFLOW - WEAP LINKAGE   
Posted: 1/6/2022 Viewed: 4593 times
Dear Markus,
Can we let WEAP use river water level from Modflow at all time steps?
Mr. Markus Huber

Subject: Re: MODFLOW - WEAP LINKAGE   
Posted: 1/10/2022 Viewed: 4574 times
Dear Markus,

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: 4538 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

sMFModelName = "TransientModelResult"
sMFFolder = WEAP.ActiveArea.Directory & "MODFLOW\"
sCCRechFolder = WEAP.ActiveArea.Directory & "River stage"

'--- 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 +2013

iMonth = CalcTS +1

if len(iMonth)<2 then iMonth = "0" & iMonth

sCCRechFile = sCCRechFolder & "\" & sScen & "\" & iYear & "_" & iMonth & ".riv"
'print sCCRechFile'
sDestRechFile = sMFFolder & "!MF!" & sMFModelName & "_S" & iScen & "_" & iYear & "_" & iMonth & ".riv"
'print sDestRechFile'
set fso=CreateObject("Scripting.FileSystemObject")

fso.deletefile sDestRechFile
fso.copyfile sCCRechFile, sDestRechFile

set fso = nothing

Mr. Markus Huber

Subject: Re: MODFLOW - WEAP LINKAGE   
Posted: 1/15/2022 Viewed: 4534 times
Dear Markus,

I have two suggestions:

1. I would suspect the line:

-> sCCRechFolder = WEAP.ActiveArea.Directory & "River stage"

may require a "\" at the end.

2. Are you sure that your "iYear" formula produces the correct year? If your calculated year is 2020, this formula would return year 4033!

Please let me know if that helped.
Best regards
Markus

Mr. Dinh Ty Nguyen

Subject: Re: MODFLOW - WEAP LINKAGE   
Posted: 1/16/2022 Viewed: 4528 times
Dear Huber,

Thank you for your reply,

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: 4500 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

sMFModelName = "TransientModelResult"
sMFFolder = WEAP.ActiveArea.Directory & "MODFLOW\"
sCCRechFolder = WEAP.ActiveArea.Directory & "River stage"

'--- 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 & ".riv"
'print sCCRechFile '
sDestRechFile = sMFFolder & "!MF!" & sMFModelName & "_S" & iScen & "_" & iYear & "_" & iMonth & ".riv"
print sDestRechFile

set fso=CreateObject("Scripting.FileSystemObject")

'fso.deletefile sDestRechFile'
fso.copyfile sCCRechFile, sDestRechFile

set fso = nothing
Topic "MODFLOW - WEAP LINKAGE"