Beispiel #1
0
        private void TextChanged()
        {
            Expr = MainParser.Parse(Source.Text);
            CurrentDependencies = MainParser.GetDependencies(Expr);

            DependenciesChanged?.Invoke(CurrentDependencies); // TODO send only changes
            ValueChanged?.Invoke(Expr);
        }
Beispiel #2
0
        private void DrawExpectedSolution()
        {
            SolutionInput input = BuildInput();
            IExpression   expr  = MainParser.Parse(input.v);

            string[] deps = MainParser.GetDependencies(expr);
            double   T    = double.Parse(input.T);
            int      M    = int.Parse(input.t_count);
            int      N    = int.Parse(input.x_count);

            if (M > VISUALIZATION_HEIGHT)
            {
                M = VISUALIZATION_HEIGHT;
            }
            if (N > VISUALIZATION_WIDTH)
            {
                N = VISUALIZATION_WIDTH;
            }

            if (Dependencies.Get(MathAliases.ConvertName("chi")) == null)
            {
                Dependencies.Set(MathAliases.ConvertName("chi"), 0);
            }

            SwitchDrawButton(true);
            calcBar.Value = 0;
            var calcProgress = new Progress <double>(value => calcBar.Value = value);

            ShowProgress();

            Task.Run(() =>
            {
                AsyncArg arg  = new AsyncArg(calcProgress, solveCancellation.Token);
                double[,] sol = MainParser.EvalMatrixD(arg, expr, Dependencies, deps, "t", T, M, "x", 2 * Math.PI, N);
                if (arg.Token.IsCancellationRequested)
                {
                    return;
                }

                this.Dispatcher.Invoke(() =>
                {
                    UpdateVisualization(sol, "U(x,t)");
                    SwitchDrawButton(false);
                });
            });
        }
Beispiel #3
0
        private void BuildSolver()
        {
            SolutionInput input = BuildInput();
            Filter        P     = input.Filter;

            Solver newSolver;
            string errorElem = "";

            try
            {
                int n = P.Size;
                errorElem = "D";
                double D = double.Parse(input.D);
                errorElem = "A0";
                Complex A0 = ComplexUtils.Parse(input.A_0);
                errorElem = "K";
                double K = double.Parse(input.K);
                errorElem = "T";
                double T = double.Parse(input.T);
                errorElem = "M";
                int M = int.Parse(input.t_count);
                errorElem = "N";
                int N = int.Parse(input.x_count);

                double chi = Solver.GetChi(K, P[n, n], A0);
                Dependencies.Set(MathAliases.ConvertName("chi"), chi);

                errorElem = "u0";
                IExpression expr = MainParser.Parse(input.u_0);
                textBlock_u0.Text = "u0 = " + expr.AsString();

                string[] deps = MainParser.GetDependencies(expr);
                double[] u0   = MainParser.EvalArrayD(expr, Dependencies, deps, "x", 2 * Math.PI, N);

                errorElem = "solver";
                newSolver = new Solver(P, T, N, M);
                ModelParams param = new ModelParams(A0, K, u0, D);
                newSolver.SetParams(param);
                curSolver = newSolver;
            }
            catch (Exception ex)
            {
                Logger.Write(errorElem + ": " + ex.Message);
                return;
            }
        }
Beispiel #4
0
 private void OnValueChanged(IExpression expr)
 {
     Value = MainParser.Eval(expr, DependsOn);
     Expr  = expr;
     ValueChanged?.Invoke(Value);
 }