Advertisement
Hubert_M

Untitled

May 28th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.48 KB | None | 0 0
  1. using System;
  2. using System.Timers;
  3. using System.ComponentModel.Design;
  4. using System.Threading;
  5. using System.Windows;
  6.  
  7.  
  8. namespace Obiekt1
  9. {
  10.     class Tank
  11.     {
  12.         public double WYP = 0.63;
  13.         public static double PI = 3.14;
  14.         private static double G = 9.81;
  15.         private static double TM = 6;
  16.         private static double QM = 11;
  17.         private static double X1 = 0.6;
  18.         private static double X2 = 1.3;
  19.         private static double X3 = 1.9;
  20.  
  21.         static int x1 = 0, x2 = 0, x3 = 0;
  22.         public static double hT = 2; // wysokość zbiornika w m2
  23.         static double r = 0.5; // promień zbiornika w m
  24.         public static double sT = PI * r * r; // powierzchnia podstawy zbiornika w m2
  25.         public double vT = sT * hT; // objętość zbiornika w m3
  26.         public double hW = 0.0; // poziom wody w zbiorniku w m
  27.         static double vW = 0; // objętość wody w zbiorniku w m3 50litra max objętość
  28.         public int overflowed = 0; // czujnik przelania
  29.  
  30.         public void check()
  31.         {
  32.             if (hW > hT) overflowed = 1;
  33.             else overflowed = 0;
  34.             if (hW >= X1)
  35.                 x1 = 1;
  36.             else
  37.                 x1 = 0;
  38.  
  39.             if (hW >= X2)
  40.                 x2 = 2;
  41.             else
  42.                 x2 = 0;
  43.  
  44.             if (hW >= X3)
  45.                 x3 = 3;
  46.             else
  47.                 x3 = 0;
  48.  
  49.             vW = sT * hW;
  50.         }
  51.  
  52.     }
  53.  
  54.     class Valve
  55.     {
  56.         private static double PI = 3.14;
  57.         private static double QM = 11;
  58.  
  59.         public int status = 0; // 1 nalewa/ 0 nic nie robi
  60.         static double r = 0.03; // promień przekorju zaworu w m
  61.         static double sV = PI * r * r; // przekrój otworu w m2
  62.         public double rSV = sV; // Obecny przekrój
  63.  
  64.         public void qV(double x)
  65.         {
  66.             if (x != QM)
  67.             {
  68.                 rSV = sV / x;
  69.             }
  70.             else
  71.             {
  72.                 rSV = 0;
  73.             }
  74.         }
  75.     }
  76.  
  77.     class Heater
  78.     {
  79.         static int status = 0; // 1 grzeje/ o nie grzeje
  80.         static int p;
  81.     }
  82.  
  83.     class Program
  84.     {
  85.  
  86.         private static System.Timers.Timer aTimer;
  87.  
  88.         public static double TM = 6;
  89.         public static double G = 9.81;
  90.         public static double WYP = 0.63;
  91.         static double PI = 3.14;
  92.         static double hT = 2; // wysokość zbiornika w m2
  93.         static double r = 0.5; // promień zbiornika w m
  94.         static double sT = PI * r * r; // powierzchnia podstawy zbiornika w m2
  95.         static double vT = sT * hT; // objętość zbiornika w m3
  96.         static double hW = 0.0; // poziom wody w zbiorniku w m
  97.         static double vW = 0; // objętość wody w zbiorniku w m3 50litra max objętość
  98.         static double sV = PI * r * r; // przekrój otworu w m2
  99.         static double rSV = sV; // Obecny przekrój
  100.  
  101.  
  102.         static void Main(string[] args)
  103.         {
  104.            
  105.             Tank t1 = new Tank();
  106.             Tank t2 = new Tank();
  107.             Tank t3 = new Tank();
  108.             Tank t4 = new Tank();
  109.             Valve v1 = new Valve();
  110.             Valve v2 = new Valve();
  111.             Valve v3 = new Valve();
  112.             Valve v4 = new Valve();
  113.             Valve v5 = new Valve();
  114.             Valve v6 = new Valve();
  115.             v1.status = 1;
  116.  
  117.            
  118.            SetTimer(t1, t2, t3, t4, v1, v2, v3, v4, v5, v6);
  119.             while (true) { }
  120.  
  121.         }
  122.        
  123.  
  124.  
  125.         private static void SetTimer(Tank t1, Tank t2, Tank t3, Tank t4, Valve v1, Valve v2, Valve v3, Valve v4, Valve v5, Valve v6)
  126.         {
  127.             // Create a timer with a two second interval.
  128.             aTimer = new System.Timers.Timer(100);
  129.             // Hook up the Elapsed event for the timer.
  130.             aTimer.Elapsed += (source, e) => OnTimedEvent(source,e,t1, t2, t3, t4, v1, v2, v3, v4, v5, v6);
  131.             aTimer.AutoReset = true;
  132.             aTimer.Enabled = true;
  133.         }
  134.  
  135.         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)
  136.         {
  137.             loop(t1, t2, t3, t4, v1, v2, v3, v4, v5, v6);
  138.         }
  139.  
  140.  
  141.         long currentTime = 0;
  142.         long previousTime = 0;
  143.         long deltaTime = 0;
  144.         double[] data;
  145.  
  146.  
  147.         static double d1 = 0; // różnica w poziomie wodym w całym cyklu
  148.         static double d2 = 0; // różnica w poziomie wodym w całym cyklu
  149.         static double d3 = 0; // różnica w poziomie wodym w całym cyklu
  150.         static double d4 = 0; // różnica w poziomie wodym w całym cyklu
  151.  
  152.  
  153.         public static double bind(Tank t, Valve v, int s, double h = 1000)
  154.         {
  155.             double d, q;
  156.             if (v.rSV == 0)
  157.                 return 0;
  158.             if (h == 1000)
  159.             {
  160.                 q = WYP * v.rSV * Math.Sqrt(2 * G * (h / 1000));
  161.             }
  162.             else
  163.             {
  164.                 q = WYP * v.rSV * Math.Sqrt(2 * G * h);
  165.             } // natężenie wypływu w m3/s
  166.  
  167.             d = TM * q / Tank.sT;
  168.             if (h < 1000)
  169.                 if (d >= h)
  170.                     d = h;
  171.             if (d >= h) d = h;
  172.             if (s == -1)
  173.             {
  174.                 return -d;
  175.             }
  176.  
  177.             return d;
  178.         }
  179.  
  180.  
  181.  
  182.         static void loop(Tank t1, Tank t2, Tank t3, Tank t4, Valve v1, Valve v2, Valve v3, Valve v4, Valve v5, Valve v6)
  183.         {
  184.                 v1.qV(3);
  185.                 v2.qV(3);
  186.                 v3.qV(3);
  187.                 v4.qV(3);
  188.                 v5.qV(3);
  189.                 v6.qV(3);
  190.                 //v1.status = 1;
  191.  
  192.                 if (v1.status == 1)
  193.                 {
  194.                     d1 += bind(t1, v1, 1);
  195.                 }
  196.                 else
  197.                 {
  198.                     d1 += 0;
  199.                 }
  200.  
  201.                 if (v2.status == 1)
  202.                 {
  203.                     d1 += bind(t1, v2, -1, t1.hW);
  204.                 }
  205.                 else
  206.                 {
  207.                     d1 += 0;
  208.                 }
  209.  
  210.                 if (v2.status == 1)
  211.                 {
  212.                     d2 += bind(t2, v2, 1, t1.hW);
  213.  
  214.                 }
  215.                 else
  216.                 {
  217.                     d2 += 0;
  218.  
  219.                 }
  220.  
  221.                 t1.hW += d1;
  222.                 d1 = 0;
  223.                 if (v3.status == 1)
  224.                 {
  225.                     d1 += bind(t1, v3, -1, t1.hW);
  226.                 }
  227.  
  228.                 else
  229.                 {
  230.  
  231.                     d1 += 0;
  232.  
  233.                 }
  234.  
  235.                 if (v4.status == 1)
  236.                 {
  237.                     d2 += bind(t2, v4, -1, t2.hW);
  238.                 }
  239.                 else
  240.                 {
  241.                     d2 += 0;
  242.                 }
  243.  
  244.                 if (v3.status == 1)
  245.                 {
  246.                     d3 += bind(t3, v3, 1, t1.hW);
  247.                 }
  248.                 else
  249.                 {
  250.                     d3 += 0;
  251.                 }
  252.  
  253.  
  254.                 if (v5.status == 1)
  255.                 {
  256.                     d3 += bind(t3, v5, -1, t3.hW);
  257.                 }
  258.                 else
  259.                 {
  260.                     d3 += 0;
  261.                 }
  262.  
  263.                 if (v4.status == 1)
  264.                 {
  265.                     d4 += bind(t4, v4, 1, t2.hW);
  266.                 }
  267.                 else
  268.                 {
  269.                     d4 += 0;
  270.                 }
  271.  
  272.                 if (v5.status == 1)
  273.                 {
  274.                     d4 += bind(t4, v5, 1, t3.hW);
  275.                 }
  276.                 else
  277.                 {
  278.                     d4 += 0;
  279.                 }
  280.  
  281.                 if (v6.status == 1)
  282.                 {
  283.                     d4 += bind(t4, v6, -1, t4.hW);
  284.                 }
  285.                 else
  286.                 {
  287.                     d4 += 0;
  288.                 }
  289.  
  290.  
  291.                 t1.hW += d1;
  292.                 t2.hW += d2;
  293.                 t3.hW += d3;
  294.                 t4.hW += d4;
  295.  
  296.                 t1.check();
  297.                 t2.check();
  298.                 t3.check();
  299.                 t4.check();
  300.                 if (t1.overflowed == 1)
  301.                 {
  302.                     t1.hW = 2;
  303.                 }
  304.  
  305.                 if (t2.overflowed == 1)
  306.                 {
  307.                     t2.hW = 2;
  308.                 }
  309.  
  310.                 d1 = 0;
  311.                 d2 = 0;
  312.                 d3 = 0;
  313.                 d4 = 0;
  314.                 Console.WriteLine(t1.hW);
  315.            
  316.         }
  317.  
  318.     }
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement