예제 #1
0
        public FilterFormulas(Grid filterPanel, DependencySpace dependencies)
        {
            Dependencies = dependencies;

            filterPanel.Children.Clear();
            filterPanel.RowDefinitions.Clear();
            filterPanel.RowDefinitions.Add(RowPixelDefinition(20));
            filterPanel.RowDefinitions.Add(RowStarDefinition(1));
            filterPanel.ColumnDefinitions.Clear();
            filterPanel.ColumnDefinitions.Add(ColumnStarDefinition(1));

            TextBlock infoBlock = new TextBlock();

            infoBlock.Text = "ρ(k, n),   -1-Dn^2 = d,   iK|Ao|^2 = I";
            filterPanel.Children.Add(infoBlock);

            elemPanel             = new WrapPanel();
            elemPanel.Orientation = Orientation.Vertical;
            Grid.SetRow(elemPanel, 1);
            filterPanel.Children.Add(elemPanel);

            AddSlot(1, 1);

            AddButton = new Button()
            {
                Content  = "+", VerticalContentAlignment = VerticalAlignment.Stretch,
                MinWidth = 20, Height = 20,
                Margin   = new Thickness(0, 0, 5, 0) // TODO use styles
            };
            AddButton.Click += (a, b) => AddButton_Clicked();
            TextBlock rhoText = new TextBlock()
            {
                Text = "ρ"
            };

            rhoText.Margin = new Thickness(0, 0, 3, 0);
            Thickness topMargin = new Thickness(0, 10, 0, 0);

            IndexK = new TextBox()
            {
                Text = "0", Margin = topMargin, MinWidth = 15
            };
            IndexN = new TextBox()
            {
                Text = "0", Margin = topMargin, MinWidth = 15
            };
            IndexK.TextChanged += (a, b) => CheckIndices();
            IndexN.TextChanged += (a, b) => CheckIndices();
            AddPanel            = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            AddPanel.Children.Add(AddButton);
            AddPanel.Children.Add(rhoText);
            AddPanel.Children.Add(IndexK);
            AddPanel.Children.Add(IndexN);
            elemPanel.Children.Add(AddPanel);
        }
예제 #2
0
        public static double[,] EvalMatrixD(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

            if (!ExprSimplifier.IsDependsOn(expr, var1))
            {
                double[] xArr = EvalArrayD(expr, depSpace, deps, var2, len2, steps2);
                for (int j = 0; j < steps2; j++)
                {
                    for (int i = 0; i < steps1; i++)
                    {
                        res[i, j] = xArr[j];
                    }
                }
                return(res);
            }
            if (!ExprSimplifier.IsDependsOn(expr, var2))
            {
                double[] xArr = EvalArrayD(expr, depSpace, deps, var1, len1, steps1);
                for (int i = 0; i < steps1; i++)
                {
                    for (int j = 0; j < steps2; j++)
                    {
                        res[i, j] = xArr[i];
                    }
                }
                return(res);
            }

            int[] progress = new int[Environment.ProcessorCount];
            int   interval = (int)Math.Ceiling(steps1 / (double)progress.Length);

            Parallel.For(0, progress.Length, (index) => EvalMatrixD(arg, expr, res, steps1, progress, index,
                                                                    var1, len1 / steps1, index * interval, Math.Min((index + 1) * interval, steps1), var2, len2 / steps2, steps2));
            return(res);
        }
예제 #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Logger.Destination = log;
            RenderOptions.SetBitmapScalingMode(scopeImage, BitmapScalingMode.NearestNeighbor);

            RadioButton[] filterModeButtons = { matrixRadioButton, formulaRadioButton };
            FilterModeGroup          = new RadioButtonGroup(filterModeButtons);
            FilterModeGroup.Changed += FillModeChanged;

            RadioButton[] solMethodButtons = { explicitRadioButton, implicitRadioButton };
            SolutionMethodGroup          = new RadioButtonGroup(solMethodButtons);
            SolutionMethodGroup.Changed += SolutionMethodChanged;

            Dependencies = new DependencySpace();
            AddParam("D", "D");
            AddParam("A_0", "A0");
            AddParam("K", "K");
            AddParam("T", "T");
            AddParam("t_count", "time");
            AddParam("x_count", "spatial");
            AddParam("u_0", "u0(x)");
            AddLabel("");
            AddParam("v", "v(x, t)");
            AddButton("Draw v(x,t)", (a, b) => DrawExpectedSolution());
            SolutionInput defaultInput = new SolutionInput();

            defaultInput.SetInput(parameters);

            if (defaultInput.IsFilterGrid)
            {
                FilterGrid filterGrid = new FilterGrid(filterPanel);
                filterGrid.Set(defaultInput.FilterGrid);
                filterBuilder = filterGrid;
            }
            else
            {
                FilterFormulas filterFormulas = new FilterFormulas(filterPanel, Dependencies);
                filterFormulas.Deserialize(defaultInput.FilterFormulas);
                filterBuilder = filterFormulas;
            }
        }
예제 #4
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);
 }
예제 #5
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);
        }