private void PlotFigure(object sender, RoutedEventArgs e) { FlowData.CalculateSagCurve(flowData, sagCurve, summary); Axis xaxis = ResultFigure.ChartAreas["sag"].AxisX; Axis yaxis = ResultFigure.ChartAreas["sag"].AxisY; xaxis.Minimum = 0; xaxis.Maximum = sagCurve.Last().Key; xaxis.Interval = 1; xaxis.Title = "Time (day)"; yaxis.Minimum = 0; yaxis.Maximum = 10; yaxis.Interval = 1; yaxis.Title = "DO (mg/L)"; Series sagseries = ResultFigure.Series["sag"]; Series sagcurveseries = ResultFigure.Series["sagcurve"]; sagseries.MarkerColor = System.Drawing.Color.Black; sagseries.MarkerStyle = MarkerStyle.Circle; sagcurveseries.Color = System.Drawing.Color.Black; ResultFigure.Series["sag"].Points.DataBindXY(sagCurve.Keys, sagCurve.Values); ResultFigure.Series["sagcurve"].Points.DataBindXY(sagCurve.Keys, sagCurve.Values); SummaryKd.Text = summary["kd"].ToString(); SummaryKr.Text = summary["kr"].ToString(); SummaryTc.Text = summary["tc"].ToString(); SummaryD.Text = summary["dc"].ToString(); SummaryDO.Text = summary["doc"].ToString(); }
public void InitializeData() { flowData = new FlowData { River = new FlowData.RiverData { Flow = 0.5, UltimateBOD = 19, DO = 5.85, Temperature = 25, Speed = 0.1, AverageDepth = 4, BedActivityCoefficient = 0.2 }, Effluent = new FlowData.EffluentData { Flow = 0.05, UltimateBOD = 129.6, DO = 0.9, Temperature = 25, K = 0.05 } }; sagCurve = new Dictionary <double, double>(); summary = new Dictionary <string, double>(); FlowData.CalculateSagCurve(flowData, sagCurve, summary); }
public static void CalculateSagCurve(FlowData flow, Dictionary <double, double> result, Dictionary <string, double> summary) { try { Console.WriteLine("Sag Curve Calculation Start."); // Convert Ultimate BOD from kg/day to mg/L. double lw = flow.Effluent.UltimateBOD / flow.Effluent.Flow / 86.4; Console.WriteLine("lw = " + lw); // Calculate Mixed BOD. double la = (flow.Effluent.Flow * lw + flow.River.Flow * flow.River.UltimateBOD) / (flow.Effluent.Flow + flow.River.Flow); Console.WriteLine("la = " + la); // Calculate initial deficit. double da = 8.38 - (flow.Effluent.Flow * flow.Effluent.DO + flow.River.Flow * flow.River.DO) / (flow.Effluent.Flow + flow.River.Flow); Console.WriteLine("da = " + da); // Calculate Mixed Temperature. double ta = (flow.Effluent.Flow * flow.Effluent.Temperature + flow.River.Flow * flow.River.Temperature) / (flow.Effluent.Flow + flow.River.Flow); Console.WriteLine("ta = " + ta); // Calculate Kd. double kd = flow.Effluent.K + flow.River.Speed * flow.River.BedActivityCoefficient / 2.3 / flow.River.AverageDepth; kd = kd * Math.Pow(1.056, ta - 20.0); Console.WriteLine("kd = " + kd); // Calculate Kr. double kr = 1.7 * Math.Pow(flow.River.Speed, 0.5) / Math.Pow(flow.River.AverageDepth, 1.5); kr = kr * Math.Pow(1.024, ta - 20.0); Console.WriteLine("kr = " + kr); // Calculate the critical point. double tc = 1 / (kr - kd) * Math.Log10(kr / kd * (1 - da * (kr - kd) / kd / la)); double dc = kd * la / (kr - kd) * (Math.Pow(10.0, -kd * tc) - Math.Pow(10.0, -kr * tc)) + da * Math.Pow(10.0, -kr * tc); double doc = 8.38 - dc; Console.WriteLine("tc = " + tc); // Insert curve data. result.Clear(); for (double t = 0; t < tc * 4.0; t += tc / 5.0) { double d = kd * la / (kr - kd) * (Math.Pow(10.0, -kd * t) - Math.Pow(10.0, -kr * t)) + da * Math.Pow(10.0, -kr * t); double y = 8.38 - d; result.Add(t, y); } // Insert summary data. summary.Clear(); summary.Add("kd", kd); summary.Add("kr", kr); summary.Add("tc", tc); summary.Add("dc", dc); summary.Add("doc", doc); Console.WriteLine("End of Sag Curve Calculation."); } catch { result.Clear(); } }