+ All Categories
Home > Documents > Project 2. Supply enough clean drinking...

Project 2. Supply enough clean drinking...

Date post: 20-Jan-2021
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
28
Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty, Design, and Optimization Department of Civil & Environmental Engineering Duke University Henri P. Gavin due: Friday, April 10, 2020 1 Stochastic Optimization The performance of systems designed to operate within natural environments depends (to a greater or lesser extent) upon the variability of their environments. A system is said to have robust performance with respect to variability in environmental conditions if its performance is not critically sensitive to changes in its environmental conditions. As you have seen, systems that are finely tuned to a particular (assumed) set of conditions can fail almost surely (“a.s.”) under slightly different conditions. The design and optimization of systems for robust performance with respect to variable environments must therefore inherently involve a model for the variability in the system’s operating environment. Unlike deterministic optimization, in which all attributes within any analysis are presumed to be known precisely and in which a unique value of the objective can be computed precisely for a particular operating environment, stochastic optimization can be applied to systems in which the system objective and its constraints depend on random aspects of the problem, and can therefore be estimated only with statistics. Methods that are highly efficient for deterministic optimization problems (i.e., methods that rely on accurate gradient and Hessian computations) tend to not perform as efficiently on stochastic problems. On the other hand, stochastic optimization methods will usually find a good solution to stochastic problems, but will be less efficient in the solution of deterministic optimization problems. Stochastic optimization methods generally require only approximate measures of the gradient of the objective with respect to the parameters. Stochastic optimization methods can be tuned to converge quickly for a particular problem, but the convergence rate can be very sensitive to the tuning. In most stochastic optimization problems, the set of design parameters at iteration i, x (i) is updated through the addition of a set of random variables d (i) , x (i+1) = x (i) + d (i) in which d (i) has a particular probability density function, f D (d (i) ). In most algorithms the pdf of D changes from one iteration to the next, usually by reducing its variance. The updated set of parameters is analyzed and if it provides better performance, then it is assigned to the set of optimal parameters. Various stochastic optimization methods differ in the details of how the sequence of perturbation vectors d (i) evolves. One class of stochastic optimization methods requires the simultaneous and inter- related evolution of several initial guesses to a particular solution. Such methods are highly
Transcript
Page 1: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Project 2. Supply enough clean drinking water.CEE 201L. Uncertainty, Design, and Optimization

Department of Civil & Environmental EngineeringDuke UniversityHenri P. Gavin

due: Friday, April 10, 2020

1 Stochastic Optimization

The performance of systems designed to operate within natural environments depends(to a greater or lesser extent) upon the variability of their environments. A system issaid to have robust performance with respect to variability in environmental conditions ifits performance is not critically sensitive to changes in its environmental conditions. As youhave seen, systems that are finely tuned to a particular (assumed) set of conditions can failalmost surely (“a.s.”) under slightly different conditions.

The design and optimization of systems for robust performance with respect to variableenvironments must therefore inherently involve a model for the variability in the system’soperating environment. Unlike deterministic optimization, in which all attributes within anyanalysis are presumed to be known precisely and in which a unique value of the objective canbe computed precisely for a particular operating environment, stochastic optimization canbe applied to systems in which the system objective and its constraints depend on randomaspects of the problem, and can therefore be estimated only with statistics. Methods that arehighly efficient for deterministic optimization problems (i.e., methods that rely on accurategradient and Hessian computations) tend to not perform as efficiently on stochastic problems.On the other hand, stochastic optimization methods will usually find a good solution tostochastic problems, but will be less efficient in the solution of deterministic optimizationproblems.

Stochastic optimization methods generally require only approximate measures of thegradient of the objective with respect to the parameters. Stochastic optimization methodscan be tuned to converge quickly for a particular problem, but the convergence rate can bevery sensitive to the tuning. In most stochastic optimization problems, the set of designparameters at iteration i, x(i) is updated through the addition of a set of random variablesd(i),

x(i+1) = x(i) + d(i)

in which d(i) has a particular probability density function, fD(d(i)). In most algorithmsthe pdf of D changes from one iteration to the next, usually by reducing its variance. Theupdated set of parameters is analyzed and if it provides better performance, then it isassigned to the set of optimal parameters. Various stochastic optimization methods differ inthe details of how the sequence of perturbation vectors d(i) evolves.

One class of stochastic optimization methods requires the simultaneous and inter-related evolution of several initial guesses to a particular solution. Such methods are highly

Page 2: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

2 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

computationally intensive since they involve the parallel analyses of multiple potential solu-tions. Such evolutionary methods go by names such as genetic algorithms, particle swarm,and ant colony optimization.

Constraints in stochastic optimization problems are usually incorporated via a penaltymethod.

The optimized step size random search (OSSRS) method of B.V. Sheela (CMAME19(1): 99-106 (1979)), and the Nelder-Mead method (CJ 7(4): 308-313 (1965)) can be appliedto problems in stochastic optimization, since neither method requires precise computation ofthe gradients of the objective and the constraints with respect to the parameters. In applyingthese methods to stochastic optimization problems, it can be helpful to characterize both theexpected value of the performance and its variability. To that end, the performance of a trialdesign in iteration (i) (quantified by values of the design parameters x(i)), will be evaluatedin terms of its sample statistics (the average and sample standard deviation). Specifically, foreach trial design (x(i)), the scalar objective function f(x(i)) and the m inequality constraintsg(x(i)) are analyzed N times, each time using a different simulation for the random aspectsof the problem. For each of the N analyses, a the penalized cost function is computed

JA(x(i)) = f(x(i)) + P

m∑j=1

⟨gj(x(i))

⟩q

,

where P is a positive penalty factor and q is a positive penalty exponent. The sample averageavg(JA(x(i))) and the sample coefficient of variation cov(JA(x(i))) will be computed from thesample of N values of JA. The quantity to be minimized for the stochastic optimization inthis project is

minxJS = avg(JA(x)) (1 + cov(JA(x)))

This objective is the 84th percentile of the distribution of costs. There are three benefits ofquantifying the stochastic performance like this.

• This performance metric inherently recognizes that the performance can be known onlyin terms of its statistics.

• This performance metric increases with the mean (expected) performance and its vari-ability. Systems with volatile performance are assigned a higher cost.

• If the system is to be optimized for conditions corresponding to a particular hazardlevel, only operating environments exceeding a particular extreme should be consid-ered. In such cases the 84th quantile of the sampling distribution of the mean responsecorresponding to the extreme hazard is a good performance criteria; so the cov of theperformance should be divided by

√N . This performance metric decreases with the

number of analyses (N). By analyzing the behavior of the trial designs more thor-oughly, the confidence in the estimate of the mean increases, effectively reducing theimpact of variability.

Page 3: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 3

2 Problem Statement Abstract

In this project, you will design the capacities and controls for a drinking water supplysystem. The water supply system is to be designed to serve a growing community for50 years. The performance of the system depends on its design (prescribed by you) andthe naturally random operating environment (specifically, precipitation, temperature, andpopulation). In this project the system will be modeled as a discrete-time dynamic system,in which the state of the system changes from day to day as a function of the flows intoand out-of three subsystems: an aquifer, a reservoir, and a water treatment plant. Thestate of the system on any given day is quantified in terms of the volumes of water andthe concentrations of contaminants (biological, sediments, petro-chemical) in the three sub-systems. Many of these flows (precipitation, evaporation, water consumption) are random,or depend on random quantities (temperature, population, human behavior). The randomquantities in this problem can be simulated from a set of probability distributions thatcapture the statistical nature of these random quantities. Part of the problem involvesoptimizing the capacities of the system, and part of the problem involves determining howmeasurements of the state of the system can be used to control how much water is processedon any given day, and how aggressively the water needs to be decontaminated. Threetreatment types (chlorine, filters, and activated carbon) have different degrees of effectivenesson the three pollutants. The performance of the system will be monetized in terms of a capitalcost (that depends on the optimized capacities) and an operating cost (that depends on thewater plant control method, and the randomness of the operating environment).

3 Model for a Drinking Water Supply and Treatment System

The idealized drinking water supply system modeled in this study consists of a water-shed and an aquifer which supply water to a reservoir which, in turn, feeds water to a watertreatment plant. The water treatment plant consists of a tank of untreated water whichfeeds water through three treatment processes to a treated water tank, where the water isheld until the community draws from it. This system is shown schematically in Figure 1.

������������������������������

������������������������������

������������������������������

������������������������������

Cp

Vu, Cu Vt, CtVu_max Vt_maxVr_max

Vr, Cr

q1 q2 q3Qr_minQe

Cu

Qu,oQr,o Qt,o

Qr

watershed area

transpiration

Qt

evaporation

water treatment

treated wateruntreated waterreservoir

river supplyT, P

overflowoverflow

river flow

Vg_maxVg

groundwater storage community waterdemand

Qs, Cs

Qg

Qi

input precipitation

Qp QpQu

Qd������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������

Figure 1. Schematic of a water treatment system.

Page 4: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

4 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

This idealized water supply and treatment system is modeled using mass balance equa-tions, with the assumption that the pollutants are always evenly mixed within each volume,and that the flow is incompressible. If on a particular day, d, a tank contains a volume V (d),with pollutant concentration C(d), receives an average inflow of Qi(d), with concentrationsCi(d), and delivers an average outflow of Qo(d), (Mgal/day), then on day d + 1 the tankcontains a volume of

V (d+ 1) = V (d) +Qi(d)−Qo(d) , (1)

with concentrations

C(d+ 1) = [C(d)V (d) + Ci(d)Qi(d)− C(d)Qo(d)] / V (d+ 1) . (2)

4 Precipitation, Transpiration, Groundwater flow, Stream flow, and Evaporation

4.1 Rainfall Simulation

Precipitation falling into the watershed is transpired through vegetation, is stored asground water, or is otherwise passed directly to a reservoir through streams.

The total rainfall on a day is the product of the two random variables, W , whetheror not there is rain on that day (W ∈ (0, 1)), and R, the amount of rain on that day, ininches. These two random variables will be modeled based on measured observations of localprecipitation.

Data from the USGS raingage station at the Falls Lake Dam, (USGS 02087182), areshown in Figure 2. From 1998-01-01 to 2020-03-26 there were 2480 days with rain out of atotal of 8118 days, giving 3.24 days between rainfalls (on average). This is called the returnperiod Tr for a day with rain.

Tr = total number of daystotal number of days with rain = 3.24 days between days with rain . (3)

To model the random occurances of precipitation, it is convenient to assume theseoccurances to be independent of the occurance of precipitation on previous or subsequentdays. With these assumptions, we can model the probability of rain on any given day as

Prob[ a wet day ] = Prob[W = 1] = 1/Tr = Prob[U ≤ 1/Tr] , (4)

where U is a standard uniformly-distributed variable between 0 and 1.

The total cumulative precipitation from 1998-01-01 to 2020-03-26 was 764.6 inches or0.094 inches per day (on average). But the amount of any given rainfall is random and thedistribution of rainfall amounts can be deduced from records of daily rainfall. For the datashown in Figure 2, the average amount of rain per rainfall can be calculated as

r̄ = (764.58 cumulative inches of rain)/(2480 days with rain) = 0.305 inches per rainfall .(5)

Page 5: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 5

2000 2005 2010 2015 2020-15-10

-505

101520

1/2-

yr S

PI,

in

2000 2005 2010 2015 2020-20

-10

0

10

20

1-yr

SP

I, in

2000 2005 2010 2015 2020-30

-20

-10

0

10

20

2-yr

SP

I, in

Figure 2. Rainfall data and specific precipitation indices, USGS 02087182, 1998-2020

The coefficient of variation for the amount of rain per rainfall from this data is 1.47. Figure 3plots the PDF and CDF of this rainfall data along with the exponential distribution1 and thegamma distribution2. Note that the exponential distribution underestimates the likelihoodof very small rainfalls and very large rainfalls, but the gamma distribution captures thevariability in rainfall amounts very well. The exponential distribution has only one parameter(the mean rainfall rate), whereas the gamma distribution has two parameters (the mean r̄and the coefficient of variation cr). We will use the gamma distribution to simulate dailyrainfall amounts in this project.

The deviation of rainfall from the yearly average can be reported as the cumulative sumof rainfall for the last 365 days minus the average yearly rainfall. This quantity is referredto as the one-year specific precipitation index (SPI) and has units of inches of rainfall. Theone-year and the two-year SPI for the USGS Falls Lake rainguage are plotted in Figure 2.Note that prior to the “drought of 2007-2008”, this region had exceptionally high rainfall.

Over the next century rainfall return periods Tr and the amount of rain per rainfall r̄

1http://en.wikipedia.org/wiki/Exponential distribution2http://en.wikipedia.org/wiki/Gamma distribution

Page 6: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

6 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

0 0.5 1 1.5 2 2.5 310

-2

10-1

100

101

PD

F, f

R(r

)

0.308 inches per rainfall avg

rainfall data

fR(r) ~ gamma

fR(r) ~ exponential

0 0.5 1 1.5 2 2.5 30

0.2

0.4

0.6

0.8

1

precipitation per rainfall, r, in.

CD

F, F

R(r

)

avg i.p.r. = 0.308cov i.p.r. = 1.473

rainfall data

FR(r) ~ gamma

FR(r) ~ exponential

Figure 3. Rainfall probability distributions, USGS 02087182, 1998-2020

are expected to increase so that the total rate r̄/Tr is unchanged at 0.094 inches per day.3The time scale for these climactic changes to transpire is referred to here as the climatechange time scale, CCTS (in years). For this project, the rainfall return period Tr overa several-decade period will be assumed to increase linearly with time according to therelationship

Tr(d) = 3.24 (1 + (d/(CCTS × 365)) . (6)

In other words, the return period for days with rain doubles in CCTS years. Because thecumulative annual rainfall is projected to remain constant, the quantity of rain per rainfallmust increase, so for this project,

(r̄(d) inches per rainfall ) = (0.094 inches per day) (Tr(d) days between rainfalls) (7)

Trends in rainfall from the USGS Falls Lake rain-gauge are plotted in Figure 4. The1/2-year, 1-year and 2-year running averages of the rainfall return period Tr, the amount ofrain per rainfall, r̄, and the average daily rainfall r̄/Tr are plotted. Periods of infrequent rain(droughts in 2002 and 2008) are clearly visible from this time series. Note that just prior

3citation needed.

Page 7: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 7

2000 2005 2010 2015 2020

0.2

0.3

0.4

0.5

inch

es p

er r

ainf

all

2000 2005 2010 2015 20200.1

0.2

0.3

0.4

0.5

rain

falls

per

day

1/2 yr avg

1 yr avg

2 yr avg

2000 2005 2010 2015 2020

0.05

0.1

0.15

0.2

daily

rai

nfal

l

Figure 4. Rainfall trends, USGS 02087182, 1998-2020

to the 2008 drought the rain-gauge recorded a period of very large rainfalls. For this singlerain-gauge, there are no discernible trends over the last twenty-two years. If this rain-gaugeis representative of regional rainfall patterns, then the climate change time scale for regionalrainfall effects is probably around 100 years, or more.

Simulated data from this statistical model qualitatively matches the observed rainfall,as shown in Figures 5 and 6.

The daily input flow of precipitation from the atmosphere to the ground surface, Qi,is the daily rainfall WR multiplied by the rainfall area, Ar. The rainfall area is assumedto be a lognormally distributed random variable, with a median value equal to 80 squaremiles and a coefficient of variation of ninety percent. The watershed area is 200 square milesand the rainfall area cannot exceed the watershed area. The rainfall area is assumed to beun-correlated with the rainfall amount. The rainfall flow is given by Qi = Ar WR, and isconverted to units of Mgal/day.

Page 8: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

8 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

0123456

2000 2010 2020 2030 2040 2050

rain

fall,

in

year

-15-10

-505

101520

2000 2005 2010 2015 2020 2025 2030 2035 2040 2045

1-y

r SPI, in

-30-20-10

0102030

2000 2005 2010 2015 2020 2025 2030 2035 2040 2045

2-y

r SPI, in

2

3

4

5

6

7

2000 2005 2010 2015 2020 2025 2030 2035 2040 2045rain

fall

retu

rn p

eri

od, days CCTS = 100 years

0.20.30.40.50.60.70.80.9

1

2000 2005 2010 2015 2020 2025 2030 2035 2040 2045

inch

es

per

rain

fall

Figure 5. Modeled changes in rainfall frequency and intensity as a non-stationary compoundrandom process.

Page 9: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 9

100

101

102

103

104

0 0.5 1 1.5 2 2.5 3

num

ber

of

rain

-falls

rainfall amount, r, in

simulated data

gamma distribution

0

0.2

0.4

0.6

0.8

1

0 0.5 1 1.5 2 2.5 3

C.D

.F.,

FR(r

)

rainfall amount, r, in

simulated data

gamma distribution

Figure 6. pdf and cdf of precipitation per rainfall as an exponential random variable.

4.2 Temperature Simulation

In this study the temperature has annual variation a seven year variation and a long-term warming trend. The daily maximimum temperature is modeled with

T (d) = T̄ − T1 cos(2π(d− 15)/365) + T7 sin(2πd/(7 · 365) + Tcd/(365× CCTS) + δT , (8)

where T̄ is the mean temperature, T1 is the yearly temperature variation, T7 is a level ofa seven-year temperature variation, Tc represents the change in temperature over a timeperiod of CCTS, d is the day, and δT is the random day-to-day temperature variation. Inorder to capture ’warm spells’ and ’cool spells’ this temperature variation is represented byfiltered Gaussean white noise, where the random temperature variation tomorrow T (d + 1)is a weighted sum of the random temperature variation today T (d) and a standard Gausseanrandom value n(d).

δT (d+ 1) = (0.5) δT (d) + (5.0) n(d) , δT (0) = 0 (9)

where n(d) is an uncorreleated sequence of Gaussean random variables. An example of asimulation of daily temperature variation is shown in Figure 7. This simulation requires the.m-files dlsym.m4 and abcddim.m5.

4http://www.duke.edu/∼hpgavin/m-files/dlsym.m5http://www.duke.edu/∼hpgavin/m-files/abcddim.m

Page 10: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

10 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

20

30

40

50

60

70

80

90

100

2005 2010 2015 2020 2025 2030 2035 2040 2045 2050

tem

p.

deg

F

year

CCTS = 100 years

Figure 7. Simulation of daily temperature variations.

4.3 Population Simulation

The population grows according to

P (d) = Po + P1(d/365) + P2(d/365)2 + δP , (10)

where Po is the initial population and P1 and P2 are population growth coefficients. Thecoefficient P2 is treated as a normally distributed random variable in this study (with a meanof 48 and coefficient of variation of 0.06), and results in a population growth from 150,000in 2010 to somewhere between 350,000 and 400,000 (with 99% confidence) fifty years later.The term δP represents a small random day-to-day variation in population.

The population growth model is calibrated to data from the U.S. Census Bureau.

4.4 Flow modeling

Rainwater flows into streams, is transpired through vegetation, or flows into the ground,as described in the following. The flow into the ground is the daily precipitation less thedaily transpired water, the daily stream flow, and the daily groundwater flow,

Vg(d+ 1) = Vg(d) +Qi(d)−Qt(d)−Qg(d)−Qs(d) , (11)

Page 11: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 11

1980 2000 2020 20400

100

200

300

400

Year

Dur

ham

Cou

nty

NC

Pop

ulat

ion

/ 100

0

P(y) = Po + 1293(y - yo) + (54 +/- 10%)(y - yo)(y - yo) + dP

population growth model+99% prediction interval-99% prediction intervalU.S. Census Bureau Data

Figure 8. Durham County population from 1970 to 2017, and a model for future populationgrowth.

The daily transpired water, Qt(d), depends on temperature, T (d), and the ground moisture,

Qt(d) = (αt + βtT (d)) Vg(d)/Vg,max , (12)

where αt and βt are constant coefficients.

Flow from the ground water to the reservoir, Qg, increases with greater soil moisture.

Qg(d) = αgVg(d)/Vg,max . (13)

The daily flow into streams depends on how wet the ground is. If Vg,max is the capacityof the ground to hold water, and Vg(d) is the current volume of water in the ground, theflow into the streams, Qs, is modeled by

Qs(d) = αsVg(d)/Vg,max + (0.5)〈Vg(d)− Vg,max〉 (14)

where the Macaulay brackets mean that 〈Vg(d)−Vg,max〉 = (Vg(d)−Vg,max) if (Vg(d)−Vg,max) >0 and 〈Vg(d)− Vg,max〉 = 0 otherwise.

The stream flow into the reservoir carries three kinds of pollutants, micro-organisms,suspended solids, and petro-chemicals. The stream flow concentrations of these pollutantsincrease with the regional population, P (d), and with the stream flow Qs(d).

Cs(d) = C̄s + cpP (d) + csQs(d) , (15)

Page 12: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

12 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

where C̄s and cp and cs are constant coefficients.

The reservoir is fed by stream flow, Qs, and ground water, Qg The capacity of thereservoir is Vr,max and the current volume of water in the reservoir is Vr(d), The reservoirsupplies water to a river and to the water treatment plant. The volume of the reservoir atday d+ 1 is,

Vr(d+ 1) = Vr(d) +Qs(d) +Qg(d)−Qe(d)−Qu(d)−Qr,min − 〈Vr(d)− Vr,max〉. (16)where the flow to the river is Qr,min + 〈Vr − Vr,max〉, and the term 〈Vr − Vr,max〉 representswater overflowing the reservoir. The daily evaporation from the reservoir, Qe, depends onthe temperature and the volume held within the reservoir,

Qe(d) = (αe + βeT (d)) Vr(d)/Vr,max . (17)The flow to the untreated water tank, Qu, is controlled by the plant operator. The plantoperator can not take out more water than remains in the reservoir at the end of any givenday. A record of measured reservoir levels is plotted in Figure 9. Note that during droughtsreservoir levels tend to drop over a period of months and that reservoir stores are replenishedquickly once a few heavy rainfalls arrive.

Pollutant concentrations are expressed in terms of volume fractions (volume of con-taminant per volume of water). If on day d the pollutant concentrations in the stream flow,Cs(d) and the pollutant concentrations in the reservoir are Cr(d), then at day d + 1 thepollutant volumes in the reservoir areCr(d+1)Vr(d+1) = Cr(d)Vr(d)+Cs(d)Qs(d)−Cr(d)Qu(d)−Cr(d)Qr,min−Cr(d)〈Vr(d)−Vr,max〉 ,

(18)from which Cr(d+ 1) is easily found.

240

245

250

255

260

265

1998 2000 2002 2004 2006 2008 2010 2012 2014 2016 2018 2020 2022

Falls

Lake

Ele

vati

on, ft

Year

USGS 02087182 FALLS LAKE ABOVE DAM NEAR FALLS, NC 1998-01-01 -- 2018-10-11

Figure 9. Falls Lake elevations, 1998-present, USGS 02087182.

Page 13: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 13

5 Water Treatment and Consumption

At the treatment plant, water is held for processing in an untreated water tank of capac-ity Vu,max and flows through the treatment process at a controlled flow rate Qp. The currentvolume of water in the untreated water tank is Vu(d), and it has pollutant concentrationsCu(d). The volume of water in the untreated tank on day d+ 1 is

Vu(d+ 1) = Vu(d) +Qu(d)−Qp(d)− 〈Vu(d)− Vu,max〉. (19)

where the term 〈Vu − Vu,max〉 represents water overflowing the untreated tank to the river.The pollution volumes in the untreated tank on day d+ 1 are

Cu(d+ 1)Vu(d+ 1) = Cu(d)Vu(d) +Cr(d)Qu(d)−Cu(d)Qp(d)−Cu(d)〈Vu(d)−Vu,max〉 , (20)

from which the concentrations Cu(d+ 1) are readily found.

Three treatment processes, chlorine, filters, and activated carbon, draw the untreatedwater at a controlled daily rate Qp. De-contaminants are injected into the three treatmentprocesses at daily rates of q1, q2, and q3 (qj � Qp). The pollution concentrations after thethree treatments are Cp.

[Cp(d)] = exp [− [R] [q(d)/Qp(d)]] [Cu(d)]. (21)

The terms Rij in the matrix R give the effectiveness of process j in treating pollutant i, sothat the processed water has the concentrations given in eqution (21). The reductions inconcentrations increases with R(q(d)/Qp(d)).

R =

chlorine filters activated carbon

micro-organisms 1000 1000 250suspended solids 50 2500 50petro-chemical 50 250 1000

The treated water is then added to a treated water tank of capacity Vt,max and contain-

ing a volume of treated water Vt with pollutant concentrations Ct. The volume of treatedwater on day d+ 1 is

Vt(d+ 1) = Vt(d) +Qp(d)−Qd(d)− 〈Vt(d)− Vt,max〉 (22)

where the term 〈Vt− Vt,max〉 represents water overflowing the treated tank to the river. Thepollution in the treated water tank on day d+ 1 are

Ct(d+ 1)Vt(d+ 1) = Ct(d)Vt(d) + Cp(d)Qp(d)− Ct(d)Qd(d)− Ct(d)〈Vt(d)− Vt,max〉 , (23)

from which the concentrations in the treated water, Ct(d+ 1) are readily found.

The daily water demand, Qd(d), increases with temperature and population. If thereservoir falls below 50% capacity, then water conservation regulations are enacted and thedaily consumption is reduced a factor Cc. This factor is a random variable in the simulations.

Page 14: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

14 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

A record of Durham water consumption along with drought severity indices are plotted inFigure 10.

Qd(d) = P (d)(100+0.4(T (d)− T̄ )) (1− Cc〈(0.50)Vr,max − Vr(d)〉/(0.50Vr,max − Vr(d)))+δQd

(24)The flow in the river on day d is

Qr(d) = Qr,min + 〈Vr(d)− Vr,max〉+ 〈Vu(d)− Vu,max〉+ 〈Vt(d)− Vt,max〉 . (25)

240

242

244

246

248

250

252

254

256

258

260

262

2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019

Falls

Lake

Ele

vati

on, ft

Year

USGS 02087182 FALLS LAKE ABOVE DAM NEAR FALLS, NC 2007-01-01 -- 2018-10-11

0

5

10

15

20

25

30

35

40

2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017None

D0

D1

D2

D3

D4

Wate

r D

em

and, M

gpd

Dro

ught

Level

Year

www.ncwater.org

Figure 10. Falls Lake elevation, drought index, and Durham County water demand from 2007to present. Note that there is practically no correlation between the drought index and thewater demand.

Page 15: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 15

6 Performance and CostsThe performance of the water supply and treatment system is measured in terms of

the total cost to build and operate the system for fifty years.

The cost of the reservoir (Vr,max) is $0.01/gallon. The installation cost for the un-treated water tank (Vu,max) is $0.5M+$0.10/gal and for the treated water tank (Vt,max) is$0.5M+$0.20/gal. The installation costs for for the treatment system (Qw,max) is $0.10/gal/-day.

The operating costs for the chlorine, filters, and activated carbon are $0.03/gal, $0.01/gal,and $0.05/gal of decontaminant, respectively. If Vt falls below 0.1Vt,max, then a penalty of$0.05 per gallon is charged for the water consumed that day. A penalty of $0.1M per dayis charged for days in which the pollutant concentrations in the treated water exceed theirrespective limits. And a penalty of $0.2M per day is charged for days in which the riverfloods the downstream communities.

7 System DesignIn this project, the design of the plant is specified by the reservoir capacity Vr,max, the

water treatment tank capacities Vu,max and Vt,max, and the maximum allowable flow ratethrough the treatment paths, Qw,max. To get a sense of scale, an Olympic sized pool holdsabout 0.5 Mgal. The operation of the plant is fully specified by a method of utilizing themeasured condition of the system [Vr(d), Vu(d), Vt(d), Cu(d), and Ct(d)] to regulate the flows[Qu(d), q1(d), q2(d), q3(d), and Qp(d)] in order to ensure that enough clean water is availablefor the municipality in a cost-effective manner. In order to succeed in meeting these require-ments, the plant must operate in an uncertain dynamic environment, in which environmentalconditions and water consumption vary from day to day with long-term trends, and withrandom fluctuations.

These issues can be systematically represented as a standard control problem, as illus-trated in Figure 11. This kind of a control system is called a “two-input, two-output” systembecause each of the two inputs to the plant (the environment, w, and the controls, u) andeach of the two outputs (the cost, z, and the measurements, y) have a qualitatively differentinterpretations.

cost

Z

ctrls

y=[Vr, Vu, Vt, Cu, Ct]

msmnts

environment

x=[Vg,Vr,Vu,Vt, Cr,Cu,Ct, Z]

CONTROLLER

YOUR

THE PLANTw=[Qi, Cs, T, Qd]

u=[Qu, q, Qp]

Figure 11. An abstraction of a water treatment plant as a standard control problem.

Page 16: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

16 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

Because the mass-balance equations describing this system are written in a day-by-day format, the mathematical description of this system is a discrete time dynamic system.In a discrete time system, we can determine the condition (or state) of the system at thenext time increment (the next day) based on the current state the current controls, and thecurrent environment. We can compute anything we might possibly want to know about thesystem uniquely from the state. In this water treatment system the state vector, x, containsthe volumes of the reservoir and tanks, the concentrations in these volumes, and the currentcost. The discrete time state equations can be written as

x(d+ 1) = f( x(d), u(d), w(d) ) . (26)

This function is implemented in the .m-function water plant.m:6

function [x tomorrow,msmnts] = water plant(x today,u today,w today,param)

This function simply implements the mass-balance and water purification relationshipsfor this plant, and imposes limits on the volumes of water in the reservoir and tanks, and onthe flow rate through the water treatment processes. The first four elements of the vectorparam are the capacities of the system, [Vr,max, Vu,max, Vt,max, Qp,max]. You may choose toadd additional parameters as you work through the design process. The information in thisassignment should be enough for you to completely understand water plant.m. You shouldbe able to re-derive any of the mass-balance equations implemented in this .m-function.

To simulate the behavior and performance of the water treatment plant over it’s de-sign life, constants describing the system and the initial state of the system x(1) are firstestablished. The initial cost depends on the tank capacities and the treatment flow capac-ities. For each time increment, the current plant controls and operating environment areused to compute the state of the plant on the next time increment using the .m-functionwater plant.m. This simulation is carried out in the .m-function water analysis.m7.

function [cost, constraints, random variables] = water analysis([Vr max,Vu max,Vt max,Qp max])

The four random variables [CCTS, Tc, P2, Cc] are assumed to be log-normally-distributed.median c.o.v.

climate change time scale CCTS 200 y 0.30temperature rise Tc 4 deg/(365× CCTS). 0.20population growth P2 54 people/day2 0.10conservation effectiveness Cc 0.15 0.30

Other random variables have normal, Poisson, exponential or lognormal distributions.temperature δT µ = 0, σ = 5 deg. F normalrainfalls W Tr = 3.24(1 + (d/(CCTS × 365))) days uniformrainfall amnt. R r̄ = 0.094 Tr , cr = 1.47 gammarainfall area Ar med.= 0.6Aw, c.o.v.=0.90 lognormalpopulation δP µ = 0, σ = 1500 people normalconsumption δQd µ = 0, σ = 5 gpppd normal

6http://www.duke.edu/∼hpgavin/cee201/water plant.m7http://www.duke.edu/∼hpgavin/cee201/water analysis.m

Page 17: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 17

Simulating random numbers for these variables makes use of these .m-functions:randn.m, rand.m, gamma rnd.m,8 and logn rnd.m.9

The simulation generates four sets of plots:

1. Trends in statistical averages of rainfall frequency and rainfall intensity;Cumulative precipitation and cumulative transpiration in Mgal; andThe one-year precipitation index

2. Daily ground water flow and daily evaporation in Mgal/day;Volumes Vg, Vr, Vu, and Vt normalized to their capacities; andStream flow and river flow Qs and Qr.

3. The population, P ;The daily water demand, Qd expressed in gallons per person per day; andThe accumulation of the initial costs and operating costs, Z verses time expressed inM$.

4. The concentrations Cs, Cr, Cu, and Ct verses time.These concentrations are normalized by the respective allowable values.A concentration above 1 means that it is in excess of the allowable limit.

8http://www.duke.edu/∼hpgavin/m-files/gamma rnd.m9http://www.duke.edu/∼hpgavin/m-files/logn rnd.m

Page 18: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

18 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

The optimization problem is set-up and executed in the .m-function water opt.m.10

Values assigned in water opt.m may be modified.1 % water opt .m −− opt imize the water treatment system f o r2 % [ Vr max , Vu max , Vt max , Qd max ]34 years = 50 % durat ion o f the a n a l y s i s56 Plots = 0 % 1: draw p l o t s , 0 : don ’ t draw p l o t s78 randomize = 0 % 1: each s imu la t ion uses d i f f e r e n t random v a r i a t i o n s in . . .9 % r a i n f a l l , temperature , popu lat ion , consumption , concen t ra t ions

10 % 0: every s imu la t ion uses the same random v a r i a t i o n in . . .11 % as s p e c i f i e d by ’ my favorite number ’1213 my_favorite_number = 1612 % used to seed the random number genera tors1415 constants = [ years ; Plots ; randomize ; my_favorite_number ];1617 % Vr , max Vu, max Vt , max Qp, max18 % Mg Mg Mg Mg/day19 param_init = [ ????? ; ????? ; ????? ; ????? ]; %% <<< put i n i t i a l guess here202122 % e v a l u a t e the i n i t i a l guess −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−23 constants (2) = 1; % p l o t s on24 f_init = water_analysis ( param_init , constants )2526 return27 i f ( input(’ OK to continue ? [y]/n : ’,’s’)== ’n’) return; end2829 % opt imize the des ign −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−30 %param min = [ ; ; ; ] ; %% <<< put min v a l u e s here31 %param max = [ ; ; ; ] ; %% <<< put max v a l u e s here3233 param_min = 0.5* param_init ;34 param_max = 2.0* param_init ;3536 % a l g o r i t h m i c parameters . . .3738 % d i s p l a y to lX to lF tolG MaxEvals Penal ty Exponent nMax errJ39 options = [ 2 0.10 1.00 1.0 500 1.0 2.0 9 0.1 ];404142 constants (2) = Plots ; % p l o t s on/ o f f43 [ x_opt , f_opt , g_opt , cvg_hst ] = ...44 ORSopt (’water_analysis ’,param_init ,param_min ,param_max ,options , constants );45 % NMAopt( ’ w a t e r a n a l y s i s ’ , param init , param min , param max , opt ions , cons tant s ) ;4647 i f 1, plot_cvg_hst ( cvg_hst , x_opt , 20 ); end4849 % a s s e s s the one example o f the opt imized des ign −−−−−−−−−−−−−−−−−−−−−−−−−−−50 % . . . cons ider a s s e s s i n g the opt imized des ign a few times51 constants (2) = 1; % p l o t s on52 f_opt = water_analysis (x_opt , constants )

To evaluate your initial guess, before embarking on an optimization, and in order to quicklytrack the effects of changes in design parameters during the initial design phase, set years = 10to just simulate the system for a few years, set randomize = 0 to use the same ran-dom sequence of precipitation, temperature, and consumption for each analysis. Thisrandom sequence is specified by the value assigned to my favorite number. Changingmy favorite number will result in a different random sequence. An automated design opti-

10http://www.duke.edu/∼hpgavin/cee201/water opt draft.m

Page 19: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 19

mization will run faster if plots are not displayed. Setting Plots = 0 will suppress plotting.Initially, it may be helpful to try analyses for shorter durations of time by setting years =5 or years = 10. Ultimately, however, your analysis will need to run for years = 50.

Page 20: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

20 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

8 Controlling a Drinking Water Treatment System

The means for controlling the drinking water treatment system will be implemented inyour .m-function my water control.m11

function u today = my water control(msmnts,params)

This function computes the controls for the plant based on some measurements ofthe condition of the water supply system, [Vr, Vu, Vt, Cu, Ct] and the design parameters.Based on these measurements and the parameters, this function calculates the controls tobe used for the day, u today, [Qu, q1, q2, q3, Qp]. These calculations need to be written into my water control.m in the three lines marked in the code. You may choose to addadditional parameters as you work through the design process.

1 function u_today = my_water_control (msmnts , param )2 % my water contro l − determine water system c o n t r o l a c t i o n s3 % based on measurements45 % YOUR NAME, C i v i l Eng ’ g , Duke Univ , THE DATE67 % Resevoir capaci ty , Mgal8 Vr_max = param (1);9

10 % volume capac i t y f o r the untrea ted water s t o r a g e tank , Mgal11 Vu_max = param (2);1213 % volume capac i t y f o r the t r e a t e d water s t o r a g e tank , Mgal14 Vt_max = param (3);1516 % water f l ow capac i t y f o r the water treatment p lant , Mgal/day17 Qp_max = param (4);1819 Vr = msmnts (1); % r e s e v o i r volume20 Vu = msmnts (2); % untreated volume21 Vt = msmnts (3); % t r e a t e d volume22 Cu = msmnts (4:6); % untreated concent ra t ions23 Ct = msmnts (7:9); % t r e a t e d concent ra t ions2425 % use the measurements o f volumes and concent ra t ions26 % ( current v a l u e s and a l l o w a b l e l i m i t s )27 % to determine f l o w s through the treatment p l a n t2829 % f low from r e s e r v o i r i n t o untreated tank30 Qu = ?????3132 % f low processed through the treatment p l a n t33 Qp = ??????3435 % f l o w s f o r each o f the th ree decontaminants36 q = [ ???? ; ???? ; ???? ];3738 u_today = [ Qu ; q ; Qp ];3940 % my water contro l −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 1 Apr 2020

If a tank is nearly full, the control should not call for more water flowing to the tank. Ifa tank is nearly empty, the control should call for more water flowing to the tank. This kindif inverse relationship is presented in figure 12. You may want to incorporate or build-upon

11http://www.duke.edu/∼hpgavin/cee201/my water control draft.m

Page 21: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 21

such ideas in your drinking water control system. You may consider a straight (simple) orsome kind of curved (complicated) inverse relationship, as shown in the figure.

Which tank volume (Vr/Vr,max, Vu/Vu,max, Vt/Vt,max) should be used to determine thedaily flow Qp through the water processing plant?

Which tank volume (Vr/Vr,max, Vu/Vu,max, Vt/Vt,max) should be used to determine thedaily flow Qu into the untreated tank?

The water purification flows, qi could be the same from day to day, or they couldincrease somehow with the pollutant concentrations in the water to be treated and/or theamount of water to be treated.

10

1

10

1

0CV / V V / V ?max? ?max?

const.

kC

?

?

Qu/ Q

p_m

ax

Qp/ Q

p_m

ax

q/Q

p or

q/C

or

both

Figure 12. Qualitative representation of some candidate water control functions.

Page 22: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

22 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

9 Tasks and Design Problems

The following tasks will gude you through the project:

1. How should the plant be operated?On any day, d, given measurements of:

• the current volume of the reservoir storage, Vr(d),• the current volume of the untreated storage, Vu(d),• the current volume of the treated storage, Vt(d),• the untreated contaminant concentrations, Cu(d), and• the treated contaminant concentrations, Ct(d),

determine an economical and appropriate way to regulate the flows (the controls)

• u = [Qu, q1, q2, q3, Qp].

Implement your control policy in the .m-function my water control.m which calculatesu = [Qu, q1, q2, q3, Qp] as a function of y = [Vr, Vu, Vt, Cu, Ct].

2. How big should the water supply system and the treatment plant be?

• How big should the reservoir, Vr,max, be?• How big should local storage be at inlet and at outlet, Vu,max and Vt,max?• How big should the flow capacity in the water treatment plant, Qp,max be?

These four constants are the parameters to water analysis.m,param = [ Vr max, Vu max, Vt max, Qp max ]

Optimize these design parameters in order to economically meet the following criteria:

• to not deplete the reservoir storage;• to not flood down-stream communities;• to meet the water consumption demands of the municipality; and• to supply drinking water that meets standards for allowable pollutant concentra-

tion levels.

3. What is the performance uncertainty associated with your final design?

• Once you have determined the answers to questions (1) and (2) above, determinethe risk of excessive cost overruns due to uncontrollable environmental factors,such as droughts and population growth.• Download the script called water montecarlo.m12.

12http://www.duke.edu/∼hpgavin/cee201/water montecarlo.m

Page 23: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 23

• Enter your best design parameters on line 18 of water montecarlo.m

• Run water montecarlo.m and interpret the plots of the resulting probabilityfunctions.

1 % water montecar lo .m2 % Monte−Carlo a n a l y s i s f o r c o s t and s e n s i t i v i t y o f a water supp ly des ign system34 % on l i n e 19 o f water anays i s .m . . . randomize = 1;5 % on l i n e 25 o f water anays i s .m . . . P lo t s = 0;67 % param (1) Vr max volume of the r e s e v o i r Mgal8 % param (2) Vu max volume of the untrea ted water tank Mgal9 % param (3) Vt max volume of the t r e a t e d water tank Mgal

10 % param (4) Qp max max . f l ow through the water treatment p l a n t Mgal/day11 % . . . e t c . . . i f you have other paramters to i n c l u d e . . .1213 % H.P. Gavin , Dept . C i v i l & Environ . Eng ’ g , Duke Univ .1415 % years ; P l o t s ; randomize ; my favori te number16 constants = [ 50 ; 0 ; 1 ; 1612 ];1718 % Vr , max Vu, max Vt , max Qp, max19 %my best params = [ ?? ; ?? ; ?? ; ?? ] ; % ∗ PUT YOUR BEST PARAMETERS HERE ∗2021 my_best_params = [ 1.2 e4 450 180 170 ];22 legend(’sample ’,’avg+std.dev ’,’average ’)23 more off24 t ic25 for sim = 1: Number_of_Simulations2627 [ cost(sim), g, rv(:, sim) ] = water_analysis ( my_best_params , constants );2829 delta_cost = cost(sim) - avg_cost ;30 avg_cost = avg_cost + delta_cost /sim;31 ssq_cost = ssq_cost + delta_cost *( cost(sim) - avg_cost );32 eta = datestr (now+ secs_left /3600/24 ,14);33 fpr intf (’sim: %3d (%5.1 f%%); %5.2f secs/sim; eta: %s (%5.0 f s) cost: %5.0f %5.0f M$\n’ ,...34 sim ,100* sim/ Number_of_Simulations ,secs/sim ,eta ,secs_left ,cost(sim), cost84 (sim ));3536 i f ˜( cost(sim )>0), disp(’uh oh - non - positive cost!’); break; end37 end3839 % emperica l cumulat ive d i s t r i b u t i o n func t i on . . .4041 eCDF = ([1: Number_of_Simulations ] -0.5) / Number_of_Simulations ;

Page 24: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

24 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

10 Pointers• Start by downloading the .m-files linked in the footnotes of this assignment.

• Before you can run any analysis you will need to come up with a water control method,as described in the previous section, and to enter this method in three (or more?) linesof code in my water control.m Initially the controls can be constant values, but tomake the system run efficiently, you will need to make the controls functions of themeasurements.

• Once you have thought of a control strategy and entered it into my water control.m,you need to think of reasonable volumes for the storage capacities Vr,max, Vu,max, andVt,max, and the treatment capacity, Qp,max. Use estimates of population size and con-sumption in gpppd to get rough guesses for these capacities.

• Evaluate your initial guess of the parameters and your water control method by ex-amining the results of a single analysis. Run water opt and if not satisfied with theresult, enter n in the command window to exit before optimization starts. Try (try)again with another initial guess.

• To find a good initial guess examine the plots and think about how how to improveyour system. Take notes on what you notice and try to learn about what is happeninginside this system.

– If a tank is more than full, water is over-flowing, and draining the reservoir un-necessarily.

– If your tanks are getting close to empty, you might need bigger capacities, Vmax,Qmax.

– If one of the pollutants is excessively high, increase the decontaminant flow, q, tothe process that is most effective for that contaminant.

• Rainfall, temperature, population, stream-flow, concentrations of stream-flow pollu-tants, and the daily water consumption vary in a systematic fashion but also haverandom fluctuations. To repeat the same random fluctuations in consecutive simula-tions, set the variable randomize = 0 in water opt.m. This could be helpful whenstarting to optimize your design. Ultimately, however, if the design is optimized onlyfor a particular time-series of precipitation, population, etc, it may not perform wellunder other situations. Since these environmental conditions can not be predictedprecisely, the optimization should ultimately be carried out for random environmentalconditions. In doing so, it will be helpful to average the results from a few simulationsto compute each analysis point. The eighth element of the algorithm options vectorspecifies the number of stochastic analyses that go into a single average.

• To evaluate your initial guess before optimization, try to get good performance for justa few years. You can shorten the time span of the simulation by changing the valuefor years in water opt.m. Try to get a feel for the effects of changing the controls byplaying around with the simulation. Running short simulations to start with will help

Page 25: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 25

because the shorter simulations take less time to compute, and because you will nothave to contend with long-term and random population and drought trends. Whenthings work well for two years, try for 5 years, 10 years, and finally 50 years.

• Once you have written your function my water control.m, and you are happy withyour initial guess for the four design parameters, you may wish to try to optimize yourwater supply and treatment system using NMAopt.m or ORSopt.m. When using theseoptimization routines with water analysis.m, set randomize = 1 and Plots = 0.(Or you can optimize for fixed sequences of rainfall, temperature, and populationgrowth by setting randomize = 0, but doing so would ignore the natural variabilityin this system. You can expect the optimization of the 50-year cost to take two to fiveminutes on a fast computer running Matlab.

• Once you have optimized your design to be satisfactory for 50-years, set randomize = 1and run water analysis.m several times in order to get a sense of the effects of uncer-tain population growth, uncertain climactic conditions, and uncertain effects of waterrestriction policy.

• The simulation is computed on a day-to-day basis. You can adjust your controls onlyonce a day. So if the tank can hold only one or two days of water, then you couldhave a problem. In actual water treatment plants, controls are adjusted much morefrequently, but in this simulation you can not respond that quickly. Therefore, in thisassignment the tank volumes that work well might be larger than what one woulddesign for in a real treatment plant.

• Emily S. Rueb and Josh Cochran, How New York Gets Its Water, NYT Mar. 24, 2016

• Melanie Burford and Greg Moyer, A Marvel of Engineering Meets the Needs of aThirsty New York, NYT Oct. 16, 2014

• Matt Flegenheimer, After Decades, a Water Tunnel Can Now Serve All of Manhattan,NYT Oct 16, 2013

• Umair Irfan, Eliza Barclay, and Kavya Sukumar, Weather 2050, Vox, 2018-10-31

• USGS Water Use in the United States, USGS, 2020-03-31

• USGS Water Use in North Carolina, 2010 USGS, 2018-03-31

• Have fun!

Page 26: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

26 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

11 Report contents

Each group of two or three people should prepare a report including:

1. A written description of the control volume analysis implemented in lines 73-149 of the.m-function water plant.m (1 - 2 pg).

2. A written description of the method by which you determined what would be a suitablecontrol policy, a description of any additional parameters you used, a sketch of yourwater control functions, such as those shown in Figure 12, (1 - 2 pg).

3. A printout of your .m-function, my water control.m.

4. A written description of the method by which you decided what would be good valuesfor the storage capacities, Vr,max, Vu,max Vt,max, and Qp,max, and your values for thesequantities. (0.5 - 1 pg)

5. A printout and discussion of the four sets of plots from an analysis of your final design.(1 pg)

6. A printout and discussion of the five plots from the Monte-Carlo simulation showingthe variability in life-time operating costs and the correlations of the lifetime operatingcosts with the random quantities assessed, (CCTS, dTc, P2, Cc) as determined fromquestion 3. (1 pg)

7. A written description of problems you had in achieving the goals of the assignment, ifany. (0.5 pg).

8. A table of results for your final design:Vr,max Vu,max Vt,max Qp,max 85th percentile cost

MG MG MG MGPD M$

12 Grading• 10 points: 85th percentile lifetime operating cost, in comparison with other group

projects (from plots generated by water montecarlo.m)

• 20 points: quality of the report: (typed, 11pt or 12 pt, 1.5 space, 1 inch margins, pagenumbers, figure numbers, figure captions, etc.)

• 30 points: completeness and correctness of descriptions and discussions

• 40 points: including all eight parts above.

Page 27: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

Supply enough clean drinking water. 27

0

0.2

0.4

0.6

0.8

1

2010 2015 2020 2025 2030 2035 2040

sta

tistical avera

ges avg. inch per rainfall

avg. percent days with rain

0

200

400

600

800

1000

2010 2015 2020 2025 2030 2035 2040

cum

ula

tive inches

cumulative precipitationcumulative transpiration

-10

-5

0

5

10

15

2010 2015 2020 2025 2030 2035 2040

1-y

r pre

cip

itation index, in

year

Figure 13. Precipitation and Transpiration

0

5

10

15

20

25

30

2010 2015 2020 2025 2030 2035 2040

Mgal / day

groundwater flowevaporation

0

0.2

0.4

0.6

0.8

1

1.2

2010 2015 2020 2025 2030 2035 2040

volu

mes / c

apacitie

s

ground waterreservoir

untreatedtreated

1

10

100

1000

10000

2010 2015 2020 2025 2030 2035 2040

Mgal / day

stream flowriver flow

Figure 14. Evaporation, Ground water flow, Volumes, Stream Flow, and River Flow

Page 28: Project 2. Supply enough clean drinking water.people.duke.edu/~hpgavin/cee201/cee201-Project2.pdf · 2020. 4. 3. · Project 2. Supply enough clean drinking water. CEE 201L. Uncertainty,

28 CEE 201L. – Uncertainty, Design, and Optimization – Duke University – Spring 2020 – H.P. Gavin

406080

100120140160180200220

2010 2015 2020 2025 2030 2035 2040

popula

tion/1

000

60708090

100110120130

2010 2015 2020 2025 2030 2035 2040

consum

ption, gpppd

100

150

200

250

300

2010 2015 2020 2025 2030 2035 2040

cost, M

$

Figure 15. Population, Consumption, Cost

0.001

0.01

0.1

1

10

100

1000

2010 2015 2020 2025 2030 2035 2040

mic

ro-o

rganis

ms

CsCrCuCt

0.001

0.01

0.1

1

10

100

1000

2010 2015 2020 2025 2030 2035 2040

suspended s

olid

s

CsCrCuCt

0.001

0.01

0.1

1

10

100

1000

2010 2015 2020 2025 2030 2035 2040

petr

o-c

hem

ical

CsCrCuCt

Figure 16. Water Quality


Recommended