Esempio n. 1
0
        public static NCGrid_Distribution operator *(double scale, NCGrid_Distribution A)
        {
            NCGrid_Distribution output = A.Clone();

            for (int i = 0; i < A.Xcount; i++)
            {
                for (int j = 0; j < A.Ycount; j++)
                {
                    output.assign_value_at(i, j, scale * A[i, j].Value);
                }
            }
            return(output);
        }
Esempio n. 2
0
        public NCGrid_Distribution Clone()
        {
            NCGrid_Distribution n = new NCGrid_Distribution(bounds, x_node_count, y_node_count);

            for (int i = 0; i < x_node_count; i++)
            {
                for (int j = 0; j < y_node_count; j++)
                {
                    n.assign_value_at(i, j, this[i, j].Value);
                    n[i, j].X = this[i, j].X;
                    n[i, j].Y = this[i, j].Y;
                }
            }
            return(n);
        }
Esempio n. 3
0
        public static NCGrid_Distribution MakeMagnitude(NCGrid_Distribution A, NCGrid_Distribution B)
        {
            NCGrid_Distribution output = A.Clone();

            for (int i = 0; i < A.Xcount; i++)
            {
                for (int j = 0; j < B.Ycount; j++)
                {
                    double x = A[i, j].Value;
                    double y = B[i, j].Value;
                    output.assign_value_at(i, j, Math.Sqrt((x * x) + (y * y)));
                }
            }
            output.force_extrema_update();
            return(output);
        }
Esempio n. 4
0
        public NCGrid_Distribution SolveSRDD()
        {
            Matrix system_matrix, RHS;
            NCGrid_Distribution dist = discretization.Clone();

            dist.ApplyBoundary(boundary_conditions);
            buildsystem(out system_matrix, out RHS);
            Matrix results = RunExteriorSolve(system_matrix, RHS);

            for (int i = 0; i < RHS.Rows; i++)
            {
                int offset = discretization.Ycount - 2;
                int J      = i % offset;
                int I      = (i - J) / offset;
                dist.assign_value_at(I + 1, J + 1, results[i]);
            }
            return(dist);
        }
Esempio n. 5
0
        public NCGrid_Distribution SolveSlow()
        {
            int m           = discretization.Xcount;
            int n           = discretization.Ycount;
            int total_nodes = (m - 2) * (n - 2);
            //NCGrid_Distribution dist = new NCGrid_Distribution(boundary_conditions.Bounds, discretization.Xcount, discretization.Ycount);
            NCGrid_Distribution dist = discretization.Clone();

            dist.ApplyBoundary(boundary_conditions);
            Matrix        system_matrix = new Matrix(total_nodes, total_nodes);
            Matrix        RHS           = new Matrix(total_nodes, 1);
            int           neg_y         = 0;
            int           pos_y         = 0;
            int           neg_x         = 0;
            int           pos_x         = 0;
            int           body          = 0;
            int           ll_corner     = 0;
            int           lr_corner     = 0;
            int           ur_corner     = 0;
            int           ul_corner     = 0;
            List <string> indices       = new List <string>();

            if (console_output)
            {
                Console.WriteLine("Populating linear system...");
            }
            for (int i = 1; i < m - 1; i++)
            {
                if (console_output && i % (m - 1) / 13 == 0)
                {
                    Console.WriteLine((100 * i / (m - 1)).ToString() + "%");
                }
                for (int j = 1; j < n - 1; j++)
                {
                    double rhs_here = 0;
                    indices.Add(i.ToString() + "," + j.ToString());
                    //for now, assume zero forcing function.
                    BoundaryCase _case;
                    bool         interior     = !isCloseToBoundary(i, j, m, n, out _case);
                    int          surplusi     = 1;
                    int          surplusj     = 1;
                    Matrix       b            = dist.GetTaylorSystemCoeffs(i, j, surplusi, surplusj);
                    double       uijterm      = 0;
                    double       ui1jterm     = 0;
                    double       uij1term     = 0;
                    double       ui_1jterm    = 0;
                    double       uij_1term    = 0;
                    double       usurplusterm = 0;
                    int          row          = (m - 2) * (i - 1) + j - 1;
                    for (int h = 0; h < 5; h++)
                    {
                        ui1jterm     += b[h, 0] * lin_operator[h];
                        uij1term     += b[h, 1] * lin_operator[h];
                        ui_1jterm    += b[h, 2] * lin_operator[h];
                        uij_1term    += b[h, 3] * lin_operator[h];
                        usurplusterm += b[h, 4] * lin_operator[h];
                        double temp_ij = 0;
                        for (int k = 0; k < 5; k++)
                        {
                            temp_ij += b[h, k];
                        }
                        uijterm += lin_operator[h] * temp_ij;
                    }
                    switch (_case)
                    {
                    case BoundaryCase.NegativeYBoundary:
                    {
                        rhs_here -= dist[i, j - 1].Value * uij_1term;
                        uij_1term = 0;
                        neg_y++;
                        break;
                    }

                    case BoundaryCase.PositiveYBoundary:
                    {
                        rhs_here    -= dist[i, j + 1].Value * uij1term;
                        rhs_here    -= dist[i + surplusi, j + surplusj].Value * usurplusterm;
                        usurplusterm = 0;
                        uij1term     = 0;
                        pos_y++;
                        break;
                    }

                    case BoundaryCase.NegativeXBoundary:
                    {
                        rhs_here -= dist[i - 1, j].Value * ui_1jterm;
                        ui_1jterm = 0;
                        neg_x++;
                        break;
                    }

                    case BoundaryCase.PositiveXBoundary:
                    {
                        rhs_here    -= dist[i + 1, j].Value * ui1jterm;
                        rhs_here    -= dist[i + surplusi, j + surplusj].Value * usurplusterm;
                        usurplusterm = 0;
                        ui1jterm     = 0;
                        pos_x++;
                        break;
                    }

                    case BoundaryCase.ULCorner:
                    {
                        rhs_here    -= dist[i, j + 1].Value * uij1term;
                        rhs_here    -= dist[i - 1, j].Value * ui_1jterm;
                        rhs_here    -= dist[i + surplusi, j + surplusj].Value * usurplusterm;
                        uij1term     = 0;
                        ui_1jterm    = 0;
                        usurplusterm = 0;
                        ul_corner++;
                        break;
                    }

                    case BoundaryCase.LLCorner:
                    {
                        rhs_here -= dist[i - 1, j].Value * ui_1jterm;
                        rhs_here -= dist[i, j - 1].Value * uij_1term;
                        ui_1jterm = 0;
                        uij_1term = 0;
                        ll_corner++;
                        break;
                    }

                    case BoundaryCase.URCorner:
                    {
                        rhs_here    -= dist[i + 1, j].Value * ui1jterm;
                        rhs_here    -= dist[i, j + 1].Value * uij1term;
                        rhs_here    -= dist[i + surplusi, j + surplusj].Value * usurplusterm;
                        ui1jterm     = 0;
                        uij1term     = 0;
                        usurplusterm = 0;
                        ur_corner++;
                        break;
                    }

                    case BoundaryCase.LRCorner:
                    {
                        rhs_here    -= dist[i, j - 1].Value * uij_1term;
                        rhs_here    -= dist[i + 1, j].Value * ui1jterm;
                        rhs_here    -= dist[i + surplusj, j + surplusj].Value * usurplusterm;
                        uij_1term    = 0;
                        ui1jterm     = 0;
                        usurplusterm = 0;
                        lr_corner++;
                        break;
                    }

                    case BoundaryCase.Body:
                    {
                        body++;
                        break;
                    }
                    }
                    system_matrix[row, map2Dto1D(i - 1, j - 1, m - 1, n - 1)] = -1 * uijterm;
                    if (ui1jterm != 0)
                    {
                        system_matrix[row, map2Dto1D(i, j - 1, m - 1, n - 1)] = ui1jterm;
                    }
                    if (uij1term != 0)
                    {
                        system_matrix[row, map2Dto1D(i - 1, j, m - 1, n - 1)] = uij1term;
                    }
                    if (ui_1jterm != 0)
                    {
                        system_matrix[row, map2Dto1D(i - 2, j - 1, m - 1, n - 1)] = ui_1jterm;
                    }
                    if (uij_1term != 0)
                    {
                        system_matrix[row, map2Dto1D(i - 1, j - 2, m - 1, n - 1)] = uij_1term;
                    }
                    if (usurplusterm != 0)
                    {
                        system_matrix[row, map2Dto1D(i - 1 + surplusi, j - 1 + surplusj, m - 1, n - 1)] = usurplusterm;
                    }
                    RHS[row] = rhs_here;
                }
            }
            if (console_output)
            {
                Console.WriteLine("System populated.");
            }
            Matrix results = Matrix.solve_system(system_matrix, RHS, Matrix.SystemSolvingScheme.Basic, true, true);

            for (int i = 0; i < total_nodes; i++)
            {
                int offset = n - 2;
                int J      = i % offset;
                int I      = (i - J) / offset;
                dist.assign_value_at(I + 1, J + 1, results[i]);
            }
            return(dist);
        }