Assignment
Objectives and description**
The objective of this assignment is to create a python program that computes the concentration of sulfate in time in the water in a tailings management facility (TMF) at a mine site.
The goal is to describe the computational approach to the resolution of a typical "0D" problem. In the end, the goal is to understand how the computational approach corresponds to the resolution of an ODE. We will investigate that ODE and study its solutions. That will allow us to compare the accuracy of the numerical solution, because mathematics allowed us to know, in this particular case, the exact solution of a problem.
This assignment is built so that the concepts of the accuracy of a solution are naturally introduced. In the end, you will realize that you will have implemented what is called the forward Euler approach.
Problem description and conceptual model
Sulfate is one of the “major” dissolved constituents in most terrestrial waters (the others being sodium, calcium, magnesium, bicarbonate and chloride). Sulfate is not poisonous, but much in the same way that too much salt makes water undrinkable, too much sulfate can be too and is thus an environmental concern.
Furthermore, high sulfate concentrations are usually associated with acidic conditions (think about sulfuric acid producing sulfates). In acidic conditions, heavy metals (which are poisonous) might be released from rock dissolution, ... Therefore, monitoring and predicting the sulfate content in groundwater is an essential environmental concern.
We will go back to the TMF problem, where we want to know and assess the sulfate concentration evolution through time.
Identification of sulfate sources
To compute the concentration of sulfate in the TMF water, we need to know where it is coming from and going to and use that knowledge to develop a conceptual model describing the fate of sulfate in our system. That conceptual model will be translated into a computational model.
The figure below is a conceptual sketch of the main sources and losses of sulfate in the TMF water:
From the pit. To keep the pit dry, water is constantly pumped out of the pit and put into the TMF at a rate (L/s of water). The pit water has a sulfate concentration of in mg/L.
From the mill. The tailings are pumped into the TMF as a slurry of tailings particles (fine, sand-size ground rock) and water. Assume that the water from the mill enters the TMF at a rate of (L/s of water), with a sulfate concentration of (mg/L).
Diffusing from the tailings porewater at the bottom of the TMF into the water column above. Sulfate dissolves from the tailings particles into the adjacent porewater by oxidation of the sulfide minerals in the particles. Because the ratio of rock to water is high in the tailings sediments at the bottom, the porewater sulfate concentration in the tailings, , is always higher than in the water in the TMF. Accordingly, sulfate tends to diffuse into the TMF water from the bottom porewater at a rate proportional to the difference in concentration between the porewater concentration and the concentration in the TMF, That is, the flux of sulfate from the bottom can be written (a positive quantity when sulfate is entering into the TMF):
where is the flux rate of sulfate per unit area of the bottom of the TMF and is the flux coefficient with units of . To compute , the total mass flux rate for the whole TMF, with units of , we must multiply the rate per unit area by the total area of the TMF bottom in :
Leaving via the discharge ditch. Sulfate leaves the TMF with the water that is discharged at a rate (L/s) from the TMF to the environment. SIMPLIFYING ASSUMPTION: if we assume that the water in the TMF is well mixed at all times, then the concentration in the TMF, is the same at all points in the TMF, and therefore the water leaving the TMF has that same concentration .
Parameters
You will need these parameters for your model
Symbol | Symbol Units | Description | Value |
---|---|---|---|
Concentration of sulfate in pit water (assume constant) | |||
Flow rate of water from the pit into TMF (assume constant) | 30 | ||
Concentration of sulfate in mill water (assume constant) | |||
Flow rate of water from mill into TMF (assume constant) | 14 | ||
Flow rate of water from TMF to environment (assume constant) | 44 | ||
Concentration of sulfate in porewater at bottom of pond | 2000 | ||
Flux coefficient from porewater to water column | |||
Total area of TMF bottom | |||
Volume of water in TMF at start of simulation | |||
Concentration of sulfate in TMF water at start of simulation |
Evolution of the mass of water
First, we will check the evolution of the volume of water in the TMF. Let us denote by the volume of water in the TMF at every time step.
The flux from the pit and the mill are positive source terms for the volume of water, while the discharge is a negative source term (a sink term).
Over a certain time , the amount of water (in L) which is coming in/out the TMF are denoted , , and are equal to
Therefore, the volume of water in the TMF over the period [; is:
How does the volume of water change with time?
Considering the values given, we have:
Indicating that the volume of water is constant through time!
Let's assigne a variable whose value is the volume of water in the TMF:
Evolution of the mass of sulfates
We have 4 main processes impacting the quantity of sulfates in the TMF. We will compute the evolution of this mass over time. First, initialize the required variable (initial mass, and the different input parameters).
What is the initial mass of sulfates? (in mg)
Advective flux from the pit and the mill
We have a source of sulfates from the pit. Over a certain time , the volume of water coming from the pit is . This volume of water has a sulfate concentration corresponding to the pit concentration. So, the total mass of sulfate from the pit which arrived in the pit over the same period, is simply:
You can always check the units:
Compute the mass of sulfates after 1 day if the pit is the only source of sulfate. Create a variable S_pit corresponding to the mass (mg) of sulfates brought by the pit in one day.
Advective flux from the mill
If we only consider the mill as a sulfate source, how will the mass of sulfates evolve in one day. Assign this value in variable named S_mill (in mg).
Discharge flux from the TMF
The same development can be performed for the discharge of water. The volume of water leaving the TMF over a certain period is . The concentration of sulfates in this volume corresponds to the concentration of sulfates in the TMF , so that we can write:
How will the discharge change the mass of sulfates over one day? Create a variable called S_dis which stores that value (in mg).
First order mass transfer
The mass flux was written as: which is in the units of mg/s. If this flux is constant over time, the added mass of sulfates over a certain time corresponds to the latter quantity multiplied by the the quantity multiplied by :
How will this mass transfer impact the mass of sulfate? Create a variable S_pore which stores the value (in mg) of the sulfate brought by this first order mass transfer.
Now, compute the total evolution of the mass of sulfates after one day, and print its value and how it has changed. Store that value (in mg) in a variable called m1.
This is the mass after 1 day (in mg). What is the concentration after one day? Store that value in a variable called c1 (in mg/L).
We can see that concentration has increased by only 0.2%.
We have computed the evolution of the mass of sulfates in the TMF after one day. How would you do that after another day?
We will use a loop to do that calculation, to compute the evolution of the concentration over a large period of time (10 years, for example), using daily timesteps again.
At the end, we want to plot the evolution of the concentration, so we have to store its values in an array, whose size corresponds to the amount of timesteps required.
Using daily timesteps, what size would that array need to be if we want to monitor the concentration for 10 years. That size is an integer called n.
Then, we need to compute these terms at every timesteps, by looping over the different times
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-42-8161f5926ad9> in <module>()
----> 1 assert_almost_equal(discharge[n-1],4.584599422624083e+06,decimal=1)
/usr/local/lib/python3.6/dist-packages/numpy/testing/_private/utils.py in assert_almost_equal(actual, desired, decimal, err_msg, verbose)
582 pass
583 if abs(desired - actual) >= 1.5 * 10.0**(-decimal):
--> 584 raise AssertionError(_build_err_msg())
585
586
AssertionError:
Arrays are not almost equal to 1 decimals
ACTUAL: 4586022.146993127
DESIRED: 4584599.422624083
The calculation is now performed, let us look at the results using matplotlib. Design 3 vertically stacked plots
The first should show the evolution of the concentration over time
The second should show the relative importance of the different sources/sinks
The third should show the cumulative discharge (in kg) of sulfates
Mass balance
Associated ODE
We can (and you will!) show that this problem can be described by a linear non-homogeneous 1st order ODE. We can (and you will) verify that the solution to this ODE is given by:
where
Find the value of A so that the initial condition is satisfied.
% A = 0 Assign A to its real value so that the previous solution matches the initial ccondition of the problem
Again, we want a triple vertical plots (with time as x-axis).
The first plot shows the computed solution vs the analytical solution
The second plot shows the absolute error (computed_solution - real solution)
The third plot shows the relative error (computed_solution-real_solution)/real_solution
To do that, you need to compute the real solution and store it in an array. You also have to compute the error and relative error. The next cell should contain the analytical calculation of the real solution and every plot material.
Influence of the timestep
The error is arising from the timestepping approach we have used. During one timestep, we have computed the discharge flux and the source-term from the "pore" as if the concentration was constant through the timestep. This is actually not true. So, the bigger the timesteps, the bigger the error.
Try the same methods used above for different timesteps (0.1 day, 1 day, 10 days, 50 days) and compare each of these solutions to the real solution and comment on the error.
How would you change the method if the volume of water was not constant?