public double Solution()
        {
            var calc = new Sprache.Calc.XtensibleCalculator();

            double result = 0.00;

            double hx = (end_int1 - start_int1) / Nx;
            double hy = (end_int2 - start_int2) / Ny;
            double hz = (end_int3 - start_int3) / Nz;

            double temp_hx = start_int1;

            while (temp_hx <= end_int1 - hx)
            {
                double temp_hy = start_int2;
                while (temp_hy <= end_int2 - hy)
                {
                    double temp_hz = start_int3;
                    while (temp_hz <= end_int3 - hz)
                    {
                        var expr = calc.ParseExpression(text_func, x => temp_hx, y => temp_hy, z => temp_hz);
                        var func = expr.Compile();
                        result  += func();
                        temp_hz += hz;
                    }
                    result  *= hz;
                    temp_hy += hy;
                }
                result  *= hy;
                temp_hx += hx;
            }
            result *= hx;

            return(result);
        }
        private double Solution(string text_func, double temp_hx, double temp_hy, double temp_hz)
        {
            double result = 0;

            var calc = new Sprache.Calc.XtensibleCalculator();
            var expr = calc.ParseExpression(text_func, x => temp_hx, y => temp_hy, z => temp_hz);
            var func = expr.Compile();

            result = func();

            return(result);
        }
Beispiel #3
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string textFunc = Integral.Text;
            int    ni       = Convert.ToInt32(Ni.Text);
            int    nj       = Convert.ToInt32(Nj.Text);
            int    nk       = Convert.ToInt32(Nk.Text);
            double s_i1     = Convert.ToDouble(S_i1.Text);
            double e_i1     = Convert.ToDouble(E_i1.Text);

            double s_i2 = Convert.ToDouble(S_i2.Text);
            double e_i2 = Convert.ToDouble(E_i2.Text);

            double s_i3 = Convert.ToDouble(S_i3.Text);
            double e_i3 = Convert.ToDouble(E_i3.Text);

            List <string> dataSend = new List <string>();

            double hx = (e_i1 - s_i1) / ni;
            double hy = (e_i2 - s_i2) / nj;
            double hz = (e_i3 - s_i3) / nk;

            double result = 0;

            Socket[] sockets = new Socket[serversAdres.Count];

            var calc = new Sprache.Calc.XtensibleCalculator();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            double temp_hx = s_i1;

            while (temp_hx <= e_i1 - hx)
            {
                double temp_hy = s_i2;
                while (temp_hy <= e_i2 - hy)
                {
                    double temp_hz = s_i3;
                    while (temp_hz <= e_i3 - hz)
                    {
                        double temp = temp_hz;
                        for (int i = 0; i < serversAdres.Count; i++)
                        {
                            if (temp < e_i3)
                            {
                                IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse(serversAdres[i]), serversPort[i]);
                                sockets[i] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                                sockets[i].Connect(iPEndPoint);

                                byte[] sendData = Encoding.Unicode.GetBytes(textFunc + ";" + temp_hx + ";" + temp_hy + ";" + temp + ";");
                                sockets[i].Send(sendData);
                                temp += hz;
                            }
                            else
                            {
                                break;
                            }
                        }
                        temp = temp_hz;
                        for (int i = 0; i < serversAdres.Count; i++)
                        {
                            int    bytes    = 0;
                            byte[] recvData = new byte[1024];
                            string recvdata = "";
                            if (temp < e_i3)
                            {
                                do
                                {
                                    bytes = sockets[i].Receive(recvData);
                                    if (bytes != 0)
                                    {
                                        recvdata = Encoding.Unicode.GetString(recvData);
                                        result  += Convert.ToDouble(recvdata);
                                    }
                                } while (sockets[i].Available > 0);

                                sockets[i].Shutdown(SocketShutdown.Both);
                                sockets[i].Close();
                                temp += hz;
                            }
                        }
                        temp_hz += hz * serversAdres.Count;
                    }

                    result  *= hz;
                    temp_hy += hy;
                }
                result  *= hy;
                temp_hx += hx;
            }
            result *= hx;
            stopwatch.Stop();

            resultLabel.Dispatcher.Invoke((Action)(() =>
            {
                resultLabel.Content = result.ToString();
            }));

            ResultTimeNet.Dispatcher.Invoke((Action)(() =>
            {
                ResultTimeNet.Content = Convert.ToString(stopwatch.ElapsedMilliseconds / 1000);
            }));
        }