Courses: The GoldSim Contaminant Transport Module:
Unit 7 - Modeling Complex Transport Processes in Environmental Compartments
Lesson 4 - Addressing Problems Associated with Rapidly Changing Cell Media Quantities
In the previous Lesson, we worked on a simple Exercise in which the volume of water in a Cell was changing (decreasing). In this Lesson, we are going to make a few changes to that model in order to illustrate a numerical problem that can arise in some models and discuss how to address it.
You should have saved the model from previous Lesson (as ExerciseCT7.gsm in the “MyModels” subfolder of the “Contaminant Transport Course” folder on your desktop). Open it now. If you do not have that file, open ExerciseCT7_Changing_Volume.gsm in the “Exercises” subfolder.
Make sure the model is in Edit Mode and we will make two minor changes to this model:
- Change the Duration of the model from 100 day to 200 day.
- Currently, the Outflow is defined as a Data element (equal to 0.175 m3/day). Delete this element an create a new Expression element (with the same name). We are going to decrease the outflow after 160 days. Define it as follows:
(You can find a model with these changes in the “Examples” subfolder named ExampleCT10_Empty_Cell.gsm.)
Now run the model. When you do so, GoldSim will inform you that there were two warning messages. Don’t bother to look at these now (we will do so later in this Lesson), so you can answer No to the Warning dialog.
Now let’s plot the volume:
What we see is that the Tank goes completely empty just after 130 days, and then starts to fill again around 160 days.
Now let’s plot the mass and concentration:
Clearly this looks strange! The concentration shows some unusual “spikes” just as the Tank goes empty and just as it refills. Note also that the mass increases linearly while the tank is empty, then suddenly drops. These results are not correct. They are due to numerical problems that are occurring as the Cell empties (and refills). This is a good example of why this Course has stressed the importance of understanding the basic concepts of how GoldSim (or any model) solves the governing equations. In some unusual or extreme cases (in this case, a Cell going empty), a particular solution algorithm may experience numerical problems that you will need to address. When GoldSim does experience such a problem, it always warns you by writing a Warning Message to the Run Log.
To understand how to address this particular problem, we first need to understand exactly under what conditions it occurs.
There are actually two separate issues here:
- The first is related to the Cell volume significantly changing over a timestep (i.e., a large fractional volume change over a timestep). If the quantity of the medium advecting mass (for most problems, the volume of water) in a Cell is constant (or changing slowly), the solution algorithm used by GoldSim is quite accurate. However, concentration “spikes” can occur if the volume changes significantly over a timestep (e.g., typically by more than 10 or 20%). This is the cause of the first unrealistic “spike” we see here. This error is most common when the amount of media in a Cell is low and decreasing (typically just before emptying), in which case the fractional volume change is by definition high. This, of course, is precisely what is happening in this model.
- The second spike we observe (when the Cell refills) is actually due to a different problem (unrelated to rapidly changing volume). In particular, if a Cell completely empties (the media amount goes to zero), for numerical reasons a small amount of mass will be left in the Cell after it has emptied. But more importantly, if the Cell is empty but still has an inflow with a matching outflow (as it does in this case), mass will accumulate in the Cell. This is because with a zero volume, GoldSim can’t compute a concentration, and hence no mass can be advected out of the Cell, although mass can be advected into the Cell from upstream. When the Cell then refills, any accumulated mass in the Cell is released suddenly (and this results in another spike).
Note: To keep these errors in perspective it should be noted that in the real-world, the behavior of solutes in a system in which a Cell was emptying would likely be very complex, and hence very difficult to model accurately. This is because the processes controlling concentrations as a Cell empties are often difficult to accurately represent. In particular, in many cases, one of the key outflows for a Cell that is emptying (e.g., a pond) would be evaporation. In such a case, solutes would precipitate out of solution before the Cell emptied (and the geochemistry of such a high concentration solution would be quite complex indeed).
If the conditions that can lead to either of these two problems occur (the first is more common than the second), a warning message will be written to the Run Log. In particular, GoldSim monitors the volume of the Reference Fluid and writes a warning message if this is changing in such a way that it could cause erroneous results. It also writes a (separate) warning if the amount of any media (typically the Reference Fluid) goes to zero.
We can see this by looking at the warning messages (that we had previously been ignoring). From the main menu, select Run|View Run Log. At the bottom of the file, you will see these messages:
The first message indicates that starting at 125 days, the fractional change in the volume exceeded 10%. This did not actually cause any problems at that point (the spike did not arise until several days later just before the Cell emptied, by which time the fractional volume change was worse). But the warning is conservatively displayed when the change exceeds 10%.
The second message alerts us to the fact that the Cell has completely emptied at 134 days.
Note: This summarizes under what conditions these errors occur. If you are interested in the numerical details of why these problems occur, a detailed explanation is provided in Appendix B of the Contaminant Transport Module User’s Guide (in the sections entitled Solving the Matrix Equations Numerically and Minimizing Errors for Systems with Rapidly Changing Media Amounts).
Fortunately, when these problems do arise, their impact can be minimized. There are two different approaches for doing so.
In both approaches, it is necessary to define a (small) non-zero Lower Bound for the quantity of media in the Cell (preventing the Cell from going completely empty). Some mass will still be left behind in the Cell when it reaches this Lower Bound, but the error can be minimized by making the Lower bound suitably small.
One of the approaches involves simply using Low Precision when running the model.
This approach is demonstrated in ExampleCT11_Empty_Cell_Corrected1.gsm, which can be found in the “Examples” subfolder of the “Contaminant Transport Course” folder. This model is set to run with Low Precision, and a Lower Bound of 0.1 m3 is defined. Run the model (you will note that there are no longer any warnings. Then plot the mass and concentration result:
As you can see, the spikes are completely eliminated.
Although this approach is very easy to implement, it comes with a downside. Some models (e.g., those with rapidly decaying species, more complex transient behavior, solubility constraints and/or isotopes) benefit greatly from other properties of the Medium or High Precision setting (i.e., the accuracy of the solution improves). That is, Medium Precision is the default setting for good reason. So although you can indeed simply add a Lower Bound and run at Low Precision to avoid concentration spikes (and in many cases this may be an appropriate solution), a more robust approach involves avoiding the spikes while using Medium or High Precision.
In order to do this, a second approach can be used that involves using a higher precision setting (Medium or High), but dynamically adjusting (shortening) the timestep to prevent the media quantity in a Cell from changing rapidly over a timestep. (In most cases, GoldSim timesteps are constant. However, dynamic timestepping is an advanced GoldSim feature that allows you to dynamically change the timestep during a simulation).
This approach is demonstrated in ExampleCT12_Empty_Cell_Corrected2.gsm, which can be found in the “Examples” subfolder of the “Contaminant Transport Course” folder. If you run the model you will note that there are no longer any warnings. If you then plot the mass and concentration result, you will see that, like the first approach, the spikes are eliminated.
Although both of these approaches are straightforward to implement, we won’t discuss the details here (although you are certainly encouraged to explore the models). Our objective is simply to make you aware that such approaches are available and can be used when dealing with rapidly changing Cell media (typically seen when Cells empty) that can result in concentration spikes. Specific instructions for both approaches are described in detail in GoldSim Help.
In this Lesson we have provided an example of a numerical problem that can occur under unusual or extreme circumstances in a model (in this case, a Cell going empty). While this is perhaps the most common numerical problem that you may encounter, there are other situations (typically involving complex models involving solubility constraints) where numerical problems can also occur. In such cases, GoldSim can have trouble solving the equations and you will need to take the appropriate action to remedy the problem. The key point it that when these problems do occur, as illustrated in this Lesson, GoldSim will always alert you to the problem by writing a Warning Message to the Run Log. You can then refer to the GoldSim documentation for a discussion on how to address the problem. Hence, when GoldSim reports at the end of a simulation that it has generated Warning Messages, it is critical that you do not ignore them.