This tutorial goes through the process of returning a Storage-elevation curve from Muk3D to GoldSim. It requires Muk3D v2019.4.1 or higher to run. Download the example project for the GoldSim tutorials here.
This tutorial also requires GoldSim, if you want to create the model from scratch. If you don't have GoldSim, you can still follow along for most of the tutorial using the GoldSim player and the player file (model.gsp in the project directory).
It is assumed that users are familiar with GoldSim.
Open the Muk3D project and set base/Simple_example as the working directory.
Defining the GoldSim interface
The first step is to define the GoldSim model inputs & outputs.
|Length||1||Single value sent from GoldSim representing the pond elevation|
|Type||Double||Floating point number|
|Name||Pond_elevation||The name of the input|
|Length (row 1)||1||Single value sent from GoldSim representing the pond elevation|
|Length (row 2)||50||The lookup table will have 50 rows in it.|
|Type (row 1)||Double||Floating point number|
|Type (row 2)||1-D Lookup Table||Sets the lookup table format as the return type.|
|Name (row 1)||Pond_volume||The name of the output|
|Name (row 2)||Storage_curve||The name of the output|
Hit OK and the model definition is created.
Creating the GoldSim model
To generate the required files for the GoldSim interface, run Simulation/Create GoldSim project.
|Install DLL files||True||Creates a subdirectory with the required files to run the GoldSim interface.|
|Create empty GoldSim model||True||Creates an empty GoldSim file. If you already have a GoldSim model you want to hook into then there's no need to create a model.|
|GoldSim model name||model.gsm||The name of the GoldSim model.|
|Models||Storage_curve.gs_definition||The name of the GoldSim model to use.|
Hit OK and the required files will be created in the working directory.
Set up a GoldSim model
The GoldSim model used here is going to be a very simple one. The pond elevation will be interpolated from a time series. The Muk3D interface will take the pond elevation, then calculate a pond volume and storage elevation curve and return it. A lookup table is created from the output of the DLL, and then used to interpolate the pond volume based on the current elevation. This will then be compared to the Muk3D volume calculation in the Pond_vol Time History.
First, set the simulation length to be 10 days.
Settings for the Time Series are shown below.
Settings for the External Element are shown below. The Function name and input/output order are given in the GoldSim_model_definition.pdf document in the working directory.
The settings for the Lookup Table are below. The data source for the element is the External DLL, and selecting this option will add the External DLL tab.
Settings for the Expression to interpolate the pond volume from the Lookup Table are shown below.
Finally, add a Time History element.
The next step is to fill the GoldSim script execute method. For this example, we want to be able to calculate the pond volume at an elevation, create a storage-elevation curve, and then return the pond volume and storage curve back to GoldSim.
The easiest way to get started is to record a macro and then copy and paste the code into the GoldSim script. Record a macro with Scripts/Record macro.
- Run Structures/Ponds/Create a pond. Enter an elevation of 375m and select a point in the pond.
- Select the layer pond_outline in the Scene Manager and run View/Unload current layer.
- Select the layer pond in the Scene Manager and run View/Unload current layer.
- Create the basin peels using Grid/Volumes/Create basin peels. Set the max elevation to be 399m (the dam is at EL 400m).
- View/Clear graphics
- End macro recording.
Editing the GoldSim script
Open the GoldSim script by right-clicking on storage_curve.py and selecting Edit.
First, copy the import of set_active_layer to the top of the GoldSim script.
Next, copy the rest of the script and paste into the execute method, just below the definition of Outputs.
In Line 53, the hardwired pond_elevation argument was replaced with the Pond_elevation variable. In Line 61, the value for dont_ask is replaced with True so the user isn't asked to confirm the removal of the layer. In Line 68, the value for dont_ask is replaced with True so the user isn't asked to confirm the removal of the layer. In Line 79, the value for dont_ask is replaced with True so the user isn't asked to confirm the removal of all layers
The next step is to get the pond volume (from Create pond surface) from the return value of the function call in Line 49. This function returns a dictionary with a key
To create the lookup curve, we use a method of the GoldSimFunction class called create_1D_lookup_table_from_file. This takes the results of the Create basin peels function (which creates a csv file called basin.seacurve.csv), loads it and creates the storage elevation curve. This method takes two mandatory arguments - the first is the name of the CSV file to get the storage-elevation data from. The second is the length of the Lookup table to create. In this case it is 50 elements long, and this number must correspond with the value entered when first defining the GoldSim model.
Save the script file.
Running the model
Run the command Simulation/Start GoldSim server. Go to GoldSim and run the model.