示例#1
0
void assemble_LHS ( RBFFD& der, Grid& grid, STL_Sparse_Mat& A){

    unsigned int N = grid.getNodeListSize();
    unsigned int n = grid.getMaxStencilSize();

    //A_ptr = new MatType( N );
    //    MatType& A     = *A_ptr;

    for (unsigned int i = 0; i < N; i++) {
        StencilType& sten = grid.getStencil(i);
        double* lapl = der.getStencilWeights(RBFFD::LSFC, i);

        // Off diagonals
        for (unsigned int j = 0; j < n; j++) {
            A[i][sten[j]] = -lapl[j];
        }
    }
}
示例#2
0
void assemble_System_Stokes( RBFFD& der, Grid& grid, UBLAS_MAT_t& A, UBLAS_VEC_t& F, UBLAS_VEC_t& U_exact, UBLAS_VEC_t& U_exact_compressed){
    double eta = 1.;
    //double Ra = 1.e6;

    // We have different nb_stencils and nb_nodes when we parallelize. The subblocks might not be full
    unsigned int nb_stencils = grid.getStencilsSize();
   // unsigned int nb_nodes = grid.getNodeListSize();
   // unsigned int max_stencil_size = grid.getMaxStencilSize();
    unsigned int N = nb_stencils;
    unsigned int nb_bnd = grid.getBoundaryIndicesSize();
    // ---------------------------------------------------

    //------------- Fill the RHS of the System -------------
    // This is our manufactured solution:
    SphericalHarmonic::Sph32 UU;
    SphericalHarmonic::Sph32105 VV;
    SphericalHarmonic::Sph32 WW;
    SphericalHarmonic::Sph32 PP;

    std::vector<NodeType>& nodes = grid.getNodeList();

    //------------- Fill F -------------

    // U
    for (unsigned int j = 0; j < nb_bnd; j++) {
        unsigned int row_ind = j + 0*(N);
        NodeType& node = nodes[j];
        double Xx = node.x();
        double Yy = node.y();
        double Zz = node.z();

        U_exact(row_ind) = UU.eval(Xx, Yy, Zz);
    }
    for (unsigned int j = nb_bnd; j < N; j++) {
        unsigned int row_ind = j + 0*(N-nb_bnd);
        unsigned int uncompressed_row_ind = j + 0*(N);
        NodeType& node = nodes[j];
        double Xx = node.x();
        double Yy = node.y();
        double Zz = node.z();

        U_exact(uncompressed_row_ind) = UU.eval(Xx,Yy,Zz);
        U_exact_compressed(row_ind-nb_bnd) = UU.eval(Xx,Yy,Zz);
        F(row_ind-nb_bnd) = -eta * UU.lapl(Xx,Yy,Zz) + PP.d_dx(Xx,Yy,Zz);
    }

    // V
    for (unsigned int j = 0; j < nb_bnd; j++) {
        unsigned int row_ind = j + 1*(N);
        NodeType& node = nodes[j];
        double Xx = node.x();
        double Yy = node.y();
        double Zz = node.z();

        U_exact(row_ind) = VV.eval(Xx,Yy,Zz);
    }
    for (unsigned int j = nb_bnd; j < N; j++) {
        unsigned int row_ind = j + 1*(N-nb_bnd);
        unsigned int uncompressed_row_ind = j + 1*(N);
        NodeType& node = nodes[j];
        double Xx = node.x();
        double Yy = node.y();
        double Zz = node.z();

        U_exact(uncompressed_row_ind) = VV.eval(Xx,Yy,Zz);
        U_exact_compressed(row_ind-nb_bnd) = VV.eval(Xx,Yy,Zz);
        F(row_ind-nb_bnd) = -eta * VV.lapl(Xx,Yy,Zz) + PP.d_dy(Xx,Yy,Zz);
    }


    // W
    for (unsigned int j = 0; j < nb_bnd; j++) {
        unsigned int row_ind = j + 2*(N);
        NodeType& node = nodes[j];
        double Xx = node.x();
        double Yy = node.y();
        double Zz = node.z();

        U_exact(row_ind) = WW.eval(Xx,Yy,Zz);
    }

    for (unsigned int j = nb_bnd; j < N; j++) {
        unsigned int row_ind = j + 2*(N-nb_bnd);
        unsigned int uncompressed_row_ind = j + 2*(N);
        NodeType& node = nodes[j];
        double Xx = node.x();
        double Yy = node.y();
        double Zz = node.z();

        U_exact(uncompressed_row_ind) = WW.eval(Xx,Yy,Zz);
        U_exact_compressed(row_ind-nb_bnd) = WW.eval(Xx,Yy,Zz);
        F(row_ind-nb_bnd) = -eta * WW.lapl(Xx,Yy,Zz) + PP.d_dz(Xx,Yy,Zz);
    }

    // P
    for (unsigned int j = 0; j < nb_bnd; j++) {
        unsigned int row_ind = j + 3*(N);
        NodeType& node = nodes[j];
        double Xx = node.x();
        double Yy = node.y();
        double Zz = node.z();

        U_exact(row_ind) = PP.eval(Xx,Yy,Zz);
    }


    for (unsigned int j = nb_bnd; j < N; j++) {
        unsigned int row_ind = j + 3*(N-nb_bnd);
        unsigned int uncompressed_row_ind = j + 3*(N);
        NodeType& node = nodes[j];
        double Xx = node.x();
        double Yy = node.y();
        double Zz = node.z();

        U_exact(uncompressed_row_ind) = PP.eval(Xx,Yy,Zz);
        U_exact_compressed(row_ind-nb_bnd) = PP.eval(Xx,Yy,Zz);
        F(row_ind-nb_bnd) = UU.d_dx(Xx,Yy,Zz) + VV.d_dy(Xx,Yy,Zz) + WW.d_dz(Xx,Yy,Zz);
    }

    // -----------------  Fill LHS --------------------
    //
    // U (block)  row
    for (unsigned int i = nb_bnd; i < N; i++) {
        StencilType& st = grid.getStencil(i);

        // System has form:
        // -lapl(U) + grad(P) = f
        // div(U) = 0

        // TODO: change these to *SFC weights (when computed)
        double* ddx = der.getStencilWeights(RBFFD::XSFC, i);
        double* lapl = der.getStencilWeights(RBFFD::LSFC, i);

        unsigned int diag_row_ind = i + 0*(N-nb_bnd);

        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 0*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                // Need the exact solution at stencil node j
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= -eta * UU.lapl(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = -eta * lapl[j];
            }
        }
        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 3*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                // Need the exact solution at stencil node j
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= PP.d_dx(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = ddx[j];
            }
        }
    }


    // V (block)  row
    for (unsigned int i = nb_bnd; i < N; i++) {
        StencilType& st = grid.getStencil(i);
        double* ddy = der.getStencilWeights(RBFFD::YSFC, i);
        double* lapl = der.getStencilWeights(RBFFD::LSFC, i);

        unsigned int diag_row_ind = i + 1*(N-nb_bnd);

        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 1*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                // Need the exact solution at stencil node j
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= -eta * VV.lapl(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = -eta * lapl[j];
            }
        }
        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 3*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                // Need the exact solution at stencil node j
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= PP.d_dy(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = ddy[j];
            }
        }
    }

    // W (block)  row
    for (unsigned int i = nb_bnd; i < N; i++) {
        StencilType& st = grid.getStencil(i);
        double* ddz = der.getStencilWeights(RBFFD::ZSFC, i);
        double* lapl = der.getStencilWeights(RBFFD::LSFC, i);

        unsigned int diag_row_ind = i + 2*(N-nb_bnd);

        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 2*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= -eta * WW.lapl(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = -eta * lapl[j];
            }
        }
        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 3*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= PP.d_dz(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = ddz[j];
            }
        }
    }

    // P (block)  row
    for (unsigned int i = nb_bnd; i < N; i++) {
        StencilType& st = grid.getStencil(i);
        double* ddx = der.getStencilWeights(RBFFD::XSFC, i);
        double* ddy = der.getStencilWeights(RBFFD::YSFC, i);
        double* ddz = der.getStencilWeights(RBFFD::ZSFC, i);

        unsigned int diag_row_ind = i + 3*(N-nb_bnd);

        // ddx(U)-component
        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 0*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= UU.d_dx(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = ddx[j];
            }
        }

        // ddy(V)-component
        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 1*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= VV.d_dx(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = ddy[j];
            }
        }

        // ddz(W)-component
        for (unsigned int j = 0; j < st.size(); j++) {
            unsigned int diag_col_ind = st[j] + 2*(N-nb_bnd);

            if (st[j] < (int)nb_bnd) {
                NodeType& node = nodes[st[j]];
                double Xx = node.x();
                double Yy = node.y();
                double Zz = node.z();

                F[diag_row_ind-nb_bnd] -= WW.d_dx(Xx, Yy, Zz);
            } else {
                A(diag_row_ind-nb_bnd, diag_col_ind-nb_bnd) = ddz[j];
            }
        }
    }
}