Is there a way to create an array and assign values to its elements dynamically during a simulation? Say we have a model with daily timesteps that has 4 catchments and want to keep a log of the runoff produced in each catchment on each timestep? I need to have the flexibility of say making reference to the runoff produced from catchment #1 in timestep #4 while the model is running.
-
Amir,
In addition to what Rick said, if you look at the "vectorized" version of our AWBM model, you will see that it already generates an output hydrograph for each catchment. If you open the tabular view Time History Result showing the vector of runoff rates for each catchment, then you will see the outputs of all items in the vector, at all time steps of the simulation, as it progresses through time. You can certainly reference this vector result in downstream elements. This is really the whole point of using this model. Let me know if that is useful.
Australian Water Balance Model (AWBM) For Multiple Catchments – GoldSim Help Center
-Jason
-
Thanks Rick and Jason for your prompt responses. The catchment runoff was just an example and my problem is not actually about runoff. Imagine there is an element in the model that takes different values in each time step. I would like to be able to keep a record of those values in each time step and dynamically make reference to them. For example as the model is running and gets to day 5, I want it to look up for the calculated values of that element in days 2 and 3 and adds them together. This requires that a log (vector or matrix) of the historical calculated values of that element in each time step is dynamically created as the model runs so they can be referenced to in later time steps.
-
Amir,
You can dynamically reference any vector output but if you are also talking about referencing period statistics and totals, I would point you to another example. For example, let's say you want the average streamflow for each month of all the years of the simulation. If you want something like this, I would suggest this daily to monthly and annual arrays model: Monthly and Annual Totals – GoldSim Help Center
But if you just need to look at a rolling average of all vector items, it would be very simple. As you probably also know, it is easy to collect the cumulative sums of vectors.
Your example mentioned getting the day 2 and 3 outputs on day 5 and add them together. This could be done in a few different ways. If you don't have to look at too many different places in the historic time period (the time the model already simulated up to this point) then Material or Information Delay elements might be good. That way, you just use 2 Delay elements to access the day 2 and day 3 outputs and add them together.
Another option is to append the vector output values during each time point to successive rows in a matrix. This is a similar approach to the example I mentioned at the start of this message. If all you want is a matrix where the columns are the items of your vector and the rows are time, then this would be pretty straightforward to build this matrix on the fly. Once this is done, you just use the item access syntax to get any row, column that you need at any time. For example: My_Matrix[4,3]. That syntax would result in one output (scalar) from the My_Matrix matrix, row 4, column 3. This would be quite simple to build but potentially a lot of data being passed around unnecessarily.
Please sign in to leave a comment.
Comments
4 comments