Ejemplo n.º 1
0
        public static double[,] EvalMatrixD_OneThread(AsyncArg arg, IExpression expr, DependencySpace depSpace, string[] deps,
                                                      string var1, double len1, int steps1, string var2, double len2, int steps2)
        {
            expr = ExprUtils.GetCopy_Slow(expr);
            foreach (string dep in deps)
            {
                Complex?val = depSpace.Get(dep);
                if (val.HasValue)
                {
                    expr = ExprSimplifier.Substitute(expr, dep, new ExprConst(val.Value.Real.ToString("f15")));
                }
            }
            double[,] res = new double[steps1, steps2]; // t, x
            for (int n = 0; n < steps1; n++)
            {
                if (arg.Token.IsCancellationRequested)
                {
                    return(null);
                }

                double      v1           = len1 * n / steps1;
                IExpression substituted1 = ExprSimplifier.Substitute(expr, var1, new ExprConst(v1.ToString("f15")));
                for (int j = 0; j < steps2; j++)
                {
                    double      v2           = len2 * j / steps2;
                    IExpression substituted2 = ExprSimplifier.Substitute(substituted1, var2, new ExprConst(v2.ToString("f15")));
                    substituted2 = ExprSimplifier.Simplify(substituted2);
                    res[n, j]    = ExprDoubleSimplifier.CalcConstExpr(substituted2);
                }

                arg.Progress?.Report((n + 1) / (float)steps1);
            }
            return(res);
        }
Ejemplo n.º 2
0
        private static void EvalMatrixD(AsyncArg arg, IExpression exprV1V2, double[,] res, int steps1, int[] progress, int index,
                                        string var1, double step1, int start1, int end1, string var2, double step2, int steps2)
        {
            for (int n = start1; n < end1; n++)
            {
                if (arg.Token.IsCancellationRequested)
                {
                    return;
                }

                double      v1           = step1 * n;
                IExpression substituted1 = ExprSimplifier.Substitute(exprV1V2, var1, new ExprConst(v1.ToString("f15")));
                for (int j = 0; j < steps2; j++)
                {
                    double      v2           = step2 * j;
                    IExpression substituted2 = ExprSimplifier.Substitute(substituted1, var2, new ExprConst(v2.ToString("f15")));
                    substituted2 = ExprSimplifier.Simplify(substituted2);
                    res[n, j]    = ExprDoubleSimplifier.CalcConstExpr(substituted2);
                }

                lock (progress)
                {
                    progress[index]++;
                    int steps = 0;
                    foreach (int s in progress)
                    {
                        steps += s;
                    }
                    arg.Progress?.Report(steps / (float)steps1);
                }
            }
        }
Ejemplo n.º 3
0
 public static double[] EvalArrayD(IExpression expr, DependencySpace depSpace, string[] deps, string varName, double length, int sections)
 {
     expr = ExprUtils.GetCopy_Slow(expr);
     foreach (string dep in deps)
     {
         Complex?val = depSpace.Get(dep);
         if (val.HasValue)
         {
             expr = ExprSimplifier.Substitute(expr, dep, new ExprConst(val.Value.Real.ToString("f15")));
         }
     }
     double[] u0 = new double[sections];
     for (int j = 0; j < u0.Length; j++)
     {
         double      v           = length * j / u0.Length;
         IExpression substituted = ExprSimplifier.Substitute(expr, varName, new ExprConst(v.ToString("f15")));
         substituted = ExprSimplifier.Simplify(substituted);
         u0[j]       = ExprDoubleSimplifier.CalcConstExpr(substituted);
     }
     return(u0);
 }