< All Topics

Returning Storage Elevation curves from Muk3D to GoldSim

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.  

FieldValueDescription
Length1Single value sent from GoldSim representing the pond elevation
TypeDoubleFloating point number
NamePond_elevationThe name of the input
mceclip7.png
FieldValueDescription
Length (row 1)1Single value sent from GoldSim representing the pond elevation
Length (row 2)50The lookup table will have 50 rows in it.
Type (row 1)DoubleFloating point number
Type (row 2)1-D Lookup TableSets the lookup table format as the return type.
Name (row 1)Pond_volumeThe name of the output
Name (row 2)Storage_curveThe name of the output
mceclip8.png

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.

FieldValueDescription
Install DLL filesTrueCreates a subdirectory with the required files to run the GoldSim interface.
Create empty GoldSim modelTrueCreates 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 namemodel.gsmThe name of the GoldSim model.
ModelsStorage_curve.gs_definitionThe name of the GoldSim model to use.
mceclip9.png

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.

mceclip21.png

First, set the simulation length to be 10 days.

mceclip34.png

Settings for the Time Series are shown below.

mceclip11.png
mceclip12.png

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.

mceclip13.png
mceclip10.png
mceclip14.png

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.

mceclip15.png
mceclip16.png

Settings for the Expression to interpolate the pond volume from the Lookup Table are shown below.

mceclip19.png

Finally, add a Time History element.

mceclip20.png

Record macro

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.

mceclip22.png
  • 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.

mceclip29.png

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

mceclip30.png

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 

mceclip33.png

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.

mceclip32.png

Save the script file.

Running the model

Run the command Simulation/Start GoldSim server. Go to GoldSim and run the model.

Table of Contents