# Lesson 4 – Representing Complex Flow Systems

As we have noted throughout the Course, the Contaminant Transport Module is used to model the movement of contaminant mass through the system.  This movement is typically dominated by the movement of media (e.g., water) through the system. This results in the advection of contaminant mass through the system (e.g., dissolved or suspended in the moving water).

The key point here is that the Contaminant Transport Module requires the media flows through the system as input.  That is, it solves equations based on specified media flow rates.  It does not solve for the media flow rates themselves. This means that you are required to create a flow model (using the basic GoldSim framework) that produces the media flow rates that can subsequently be used by the Contaminant Transport Module.

The flow systems driving the advective transport in the models we have discussed in this Course have been simple. In particular, we have often assumed constant (i.e., steady-state) flow rates. In some cases, even for complex models, assuming simplified steady-state flow models may be appropriate (e.g., for models with extremely long time-frames such as those associated with evaluating radioactive waste disposal facilities – which have time frames of tens or hundreds of thousands of years).

In many cases, however, it is necessary to model flow systems in greater detail and represent their transient behavior. When doing so, there are basically three general approaches (of increasing complexity) that you can take:

• Create the flow system using the basic GoldSim framework;
• Model the flow system outside of GoldSim using a complex flow solver and abstract the outputs of this tool into GoldSim (e.g., using Lookup Tables or Time Series elements); or
• Model the flow system inside GoldSim using a complex flow solver (i.e., dynamically link the other flow solver directly into the GoldSim as a DLL using an External element).

We will discuss each of these approaches below.

## Use GoldSim elements to model flow system

The simplest approach is to create the flow system using the basic GoldSim framework (e.g., using Pools, Reservoirs, Expressions). For surface water systems (e.g., ponds and reservoirs at a mine) this will generally need to be done in any case as part of computing a water balance for the site. In fact, we have already looked at several models like this, such as in Unit 6, Lesson 10 (ExampleCT8_Two_Ponds.gsm in the “Examples” subfolder of the “Contaminant Transport Course” folder) and Unit 7, Lesson 2 (ExampleCT9_Dynamic_Ponds.gsm in the “Examples” subfolder of the “Contaminant Transport Course” folder).

These two examples were for surface water systems. But some groundwater flow systems can also be modeled in a similar way. As an example, consider this model: This particular model is of a paleochannel aquifer (i.e., a deposit of sediment filling the course of an ancient river). We will assume that the paleochannel can be approximated as a one-dimensional flow system (since flow is largely restricted to the transmissive channel), flowing from the left to right in this figure. This paleochannel contains ore deposits that are to be mined over several decades. Doing so (e.g., digging open pits) obviously impacts the flow system. In particular, as a pit is mined, water flows into the pit (from both directions) and evaporates. This, in turn, increases the salt content of the water. Let’s assume we want to predict the salt concentration along the paleochannel resulting from this mining operation.

To model this system, we have discretized the paleochannel into finite volumes (that is what each Container represents).  At each of these locations (i.e., finite volumes), we can compute a water volume and a hydraulic head. We can then use Darcy’s Law to compute the flow between the locations (based on the head difference). The mining operation at a particular location (and the resulting evaporation) dynamically impacts the volume (and head) at that location, and hence the flow system. All of this (the time-variable mining operation, evaporation from pits, the volume and head at each location, and the flows) can easily be represented using standard GoldSim elements (e.g., Pools, Reservoirs, Expressions). This allows us to represent the complex transient flow behavior (and resulting impacts on salt concentrations) of this groundwater system. Note that this just represents the flow model; for the mass transport model, each section of the paleochannel would be represented by a Cell pathway.

As a general rule, this simple representation would need to be compared to a more detailed groundwater flow model to see if it provides an adequately accurate description of the behavior. But as noted in the George Box quote at the beginning of this Unit, the important question is not whether or not it is correct (it is not; and no model is) but whether or not it is good enough to be useful.

In this example, due to the nature of the system (effectively one-dimensional), the flow system could actually be represented reasonably accurately by just using the basic GoldSim framework.  But in other cases, this may not be possible. That is, the flow system may be so complex that it may be necessary to model the flow system using a different tool (e.g., a groundwater flow model) to realistically represent it. When doing so, there are two ways to approach this.

## Model flow system outside of GoldSim using a flow solver and abstract the outputs into GoldSim

In the first (and simpler) approach to using an external flow solver, you would run the external model separately from GoldSim (i.e., before you run the GoldSim model).  Typically, you would do this multiple times (representing different flow scenarios or assuming different combinations of controlling parameters, such as precipitation rates).  After doing so, you would then abstract these results into a form that could be used by GoldSim. Let’s consider two different examples of how this could be done.

You might be able to do this simply using response surfaces (i.e., Lookup tables in GoldSim).

For example, assume that a particular flow rate at some location could be approximated to be a function of two key parameters (whose values may vary over time and/or be uncertain). The external model could then be run multiple times (using different combinations of the two key parameters), and this information (the parameter values and the resulting flow rate) could then be entered into a 2D Lookup table in GoldSim.  The two key parameters would be sampled (or may even be modeled as changing with time) in the GoldSim model, and the Lookup table would be used to compute the flow rate. Note that in this case, the two key parameters may impact other things in the model other than the flow rate represented by the Lookup table. Note that you would need a different 2D Lookup Table for each location where you need a flow rate (or a 3D Lookup Table where the third dimension was the location).

Alternatively, you could simulate the flow system externally a large number of times (e.g., using different assumptions), saving the flow rates at particular locations as time series. These could be entered into Time Series elements and sampled (such that a different flow time series was used for each realization). You would need a different Time Series element for each location of interest.

In both of these cases, of course, you would need to ensure that the system was represented consistently and correlations between various flows were properly captured.

## Model flow system inside of GoldSim using an External element flow solver

In the more complex approach to using an external flow solver, you would incorporate the external flow solver directly into the GoldSim model and dynamically call it. In order to do this, you would use an External (DLL) element.

An External element allows you to take an external program or module (e.g., a flow solver) and dynamically link it and run it within GoldSim. The module is linked into GoldSim as a DLL (Dynamic Link Library) at run time. Integrating an external program into GoldSim in this way requires that you develop a "wrapper" (or "shell") around the module (and hence requires some programming), and compile it into a DLL. These user-defined modules are referred to as external functions, and the elements through which they are coupled to GoldSim are called External (DLL) elements.

The External element has an input and output interface, allowing you to send inputs to the module from GoldSim, and create outputs that can then be used in other parts of the GoldSim model. Hence, you can think of this as a “custom GoldSim element”.

You control when the external module is called.  For example, you could call it at the beginning of the simulation or call it every timestep.

A good example of a situation where you might want to use such as approach is when modeling transient flow vertically through an unsaturated zone. In such a case, the flow rate and saturation at any given depth would vary with time (based on transient infiltration due to variations in rainfall and evaporation). You could incorporate an external module that simulated 1D unsaturated flow.  This module would require material properties, and well as rainfall and evaporation data from GoldSim, and would output flow rates and saturations vertically in the column. In the GoldSim model, you would discretize the vertical column appropriately into a number of GoldSim pathways and utilize the flow rates and saturations computed by the module.

The advantage of such an implementation is that it can be directly and fully integrated with all parts of your GoldSim model (e.g., you would likely have a separate part of your model that computes rainfall and evaporation rates). The disadvantage of such an approach is that for complex flow systems, it could be computationally intensive.  Moreover, obviously, carrying out such a linkage requires quite a bit of effort (e.g., you need to understand the use of the external module, and program a “wrapper” so it can communicate with GoldSim).  As such, this is an advanced application. Nevertheless, for some types of applications, you may determine that it is necessary.