public static string[] GetDependencies(IExpression init) { HashSet <string> deps = new HashSet <string>(); foreach (IExpression expr in init.GetArgs()) { if (expr is ExprRegFunc) { ExprRegFunc func = expr as ExprRegFunc; if (!IsDefaultFunction(func)) { deps.Add(MathAliases.ConvertName(func.Name)); } } if (expr.GetArgsCount() > 0) { string[] internalDeps = GetDependencies(expr); foreach (string dep in internalDeps) { deps.Add(dep); } } } return(deps.ToArray()); }
static MainParser() { Parser = new ExprParser(); Parser.AddAliases(MathAliases.GetDefaultFunctions()); Parser.AddAlias(MathAliases.ConvertName("i"), 0); Parser.AddAlias(MathAliases.ConvertName("t"), 0); Parser.AddAlias(MathAliases.ConvertName("x"), 0); Parser.AddAlias(MathAliases.ConvertName("chi"), 0); Parser.AddAlias(MathAliases.ConvertName("rho"), 2); Parser.AddAlias(MathAliases.ConvertName("P"), 2); }
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; } }
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); }); }); }