Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Timers;
- using System.ComponentModel.Design;
- using System.Threading;
- using System.Windows;
- namespace Obiekt1
- {
- class Tank
- {
- public double WYP = 0.63;
- public static double PI = 3.14;
- private static double G = 9.81;
- private static double TM = 6;
- private static double QM = 11;
- private static double X1 = 0.6;
- private static double X2 = 1.3;
- private static double X3 = 1.9;
- static int x1 = 0, x2 = 0, x3 = 0;
- public static double hT = 2; // wysokość zbiornika w m2
- static double r = 0.5; // promień zbiornika w m
- public static double sT = PI * r * r; // powierzchnia podstawy zbiornika w m2
- public double vT = sT * hT; // objętość zbiornika w m3
- public double hW = 0.0; // poziom wody w zbiorniku w m
- static double vW = 0; // objętość wody w zbiorniku w m3 50litra max objętość
- public int overflowed = 0; // czujnik przelania
- public void check()
- {
- if (hW > hT) overflowed = 1;
- else overflowed = 0;
- if (hW >= X1)
- x1 = 1;
- else
- x1 = 0;
- if (hW >= X2)
- x2 = 2;
- else
- x2 = 0;
- if (hW >= X3)
- x3 = 3;
- else
- x3 = 0;
- vW = sT * hW;
- }
- }
- class Valve
- {
- private static double PI = 3.14;
- private static double QM = 11;
- public int status = 0; // 1 nalewa/ 0 nic nie robi
- static double r = 0.03; // promień przekorju zaworu w m
- static double sV = PI * r * r; // przekrój otworu w m2
- public double rSV = sV; // Obecny przekrój
- public void qV(double x)
- {
- if (x != QM)
- {
- rSV = sV / x;
- }
- else
- {
- rSV = 0;
- }
- }
- }
- class Heater
- {
- static int status = 0; // 1 grzeje/ o nie grzeje
- static int p;
- }
- class Program
- {
- private static System.Timers.Timer aTimer;
- public static double TM = 6;
- public static double G = 9.81;
- public static double WYP = 0.63;
- static double PI = 3.14;
- static double hT = 2; // wysokość zbiornika w m2
- static double r = 0.5; // promień zbiornika w m
- static double sT = PI * r * r; // powierzchnia podstawy zbiornika w m2
- static double vT = sT * hT; // objętość zbiornika w m3
- static double hW = 0.0; // poziom wody w zbiorniku w m
- static double vW = 0; // objętość wody w zbiorniku w m3 50litra max objętość
- static double sV = PI * r * r; // przekrój otworu w m2
- static double rSV = sV; // Obecny przekrój
- static void Main(string[] args)
- {
- Tank t1 = new Tank();
- Tank t2 = new Tank();
- Tank t3 = new Tank();
- Tank t4 = new Tank();
- Valve v1 = new Valve();
- Valve v2 = new Valve();
- Valve v3 = new Valve();
- Valve v4 = new Valve();
- Valve v5 = new Valve();
- Valve v6 = new Valve();
- v1.status = 1;
- SetTimer(t1, t2, t3, t4, v1, v2, v3, v4, v5, v6);
- while (true) { }
- }
- private static void SetTimer(Tank t1, Tank t2, Tank t3, Tank t4, Valve v1, Valve v2, Valve v3, Valve v4, Valve v5, Valve v6)
- {
- // Create a timer with a two second interval.
- aTimer = new System.Timers.Timer(100);
- // Hook up the Elapsed event for the timer.
- aTimer.Elapsed += (source, e) => OnTimedEvent(source,e,t1, t2, t3, t4, v1, v2, v3, v4, v5, v6);
- aTimer.AutoReset = true;
- aTimer.Enabled = true;
- }
- private static void OnTimedEvent(Object source, ElapsedEventArgs e, Tank t1, Tank t2, Tank t3, Tank t4, Valve v1, Valve v2, Valve v3, Valve v4, Valve v5, Valve v6)
- {
- loop(t1, t2, t3, t4, v1, v2, v3, v4, v5, v6);
- }
- long currentTime = 0;
- long previousTime = 0;
- long deltaTime = 0;
- double[] data;
- static double d1 = 0; // różnica w poziomie wodym w całym cyklu
- static double d2 = 0; // różnica w poziomie wodym w całym cyklu
- static double d3 = 0; // różnica w poziomie wodym w całym cyklu
- static double d4 = 0; // różnica w poziomie wodym w całym cyklu
- public static double bind(Tank t, Valve v, int s, double h = 1000)
- {
- double d, q;
- if (v.rSV == 0)
- return 0;
- if (h == 1000)
- {
- q = WYP * v.rSV * Math.Sqrt(2 * G * (h / 1000));
- }
- else
- {
- q = WYP * v.rSV * Math.Sqrt(2 * G * h);
- } // natężenie wypływu w m3/s
- d = TM * q / Tank.sT;
- if (h < 1000)
- if (d >= h)
- d = h;
- if (d >= h) d = h;
- if (s == -1)
- {
- return -d;
- }
- return d;
- }
- static void loop(Tank t1, Tank t2, Tank t3, Tank t4, Valve v1, Valve v2, Valve v3, Valve v4, Valve v5, Valve v6)
- {
- v1.qV(3);
- v2.qV(3);
- v3.qV(3);
- v4.qV(3);
- v5.qV(3);
- v6.qV(3);
- //v1.status = 1;
- if (v1.status == 1)
- {
- d1 += bind(t1, v1, 1);
- }
- else
- {
- d1 += 0;
- }
- if (v2.status == 1)
- {
- d1 += bind(t1, v2, -1, t1.hW);
- }
- else
- {
- d1 += 0;
- }
- if (v2.status == 1)
- {
- d2 += bind(t2, v2, 1, t1.hW);
- }
- else
- {
- d2 += 0;
- }
- t1.hW += d1;
- d1 = 0;
- if (v3.status == 1)
- {
- d1 += bind(t1, v3, -1, t1.hW);
- }
- else
- {
- d1 += 0;
- }
- if (v4.status == 1)
- {
- d2 += bind(t2, v4, -1, t2.hW);
- }
- else
- {
- d2 += 0;
- }
- if (v3.status == 1)
- {
- d3 += bind(t3, v3, 1, t1.hW);
- }
- else
- {
- d3 += 0;
- }
- if (v5.status == 1)
- {
- d3 += bind(t3, v5, -1, t3.hW);
- }
- else
- {
- d3 += 0;
- }
- if (v4.status == 1)
- {
- d4 += bind(t4, v4, 1, t2.hW);
- }
- else
- {
- d4 += 0;
- }
- if (v5.status == 1)
- {
- d4 += bind(t4, v5, 1, t3.hW);
- }
- else
- {
- d4 += 0;
- }
- if (v6.status == 1)
- {
- d4 += bind(t4, v6, -1, t4.hW);
- }
- else
- {
- d4 += 0;
- }
- t1.hW += d1;
- t2.hW += d2;
- t3.hW += d3;
- t4.hW += d4;
- t1.check();
- t2.check();
- t3.check();
- t4.check();
- if (t1.overflowed == 1)
- {
- t1.hW = 2;
- }
- if (t2.overflowed == 1)
- {
- t2.hW = 2;
- }
- d1 = 0;
- d2 = 0;
- d3 = 0;
- d4 = 0;
- Console.WriteLine(t1.hW);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement