HypreSolver3D::HypreSolver3D(ptrdiff_t N0_, double Lz_, ptrdiff_t N1_, double Ly_, ptrdiff_t N2_, double Lx_): N0(N0_), Lz(Lz_), N1(N1_), Ly(Ly_), N2(N2_), Lx(Lx_) { MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &num_procs); N = N0*N1*N2; dz = Lz/(N0+1); dy = Ly/(N1+1); dx = Lx/(N2+1); h2 = dy*dy; nx = N2; ny = N1; int zp = (int)(N0/num_procs); int extra = N0-zp*num_procs; if(myid<extra) { z0 = myid*zp + myid; nz = zp+1; } else { z0 = myid*zp + extra; nz = zp; } local_size = ny*nx*nz; ilower = z0*nx*ny; iupper = ilower+local_size-1; // Build rhs and init x HYPRE_IJVectorCreate(MPI_COMM_WORLD, ilower, iupper, &hv_b); HYPRE_IJVectorSetObjectType(hv_b, HYPRE_PARCSR); HYPRE_IJVectorCreate(MPI_COMM_WORLD, ilower, iupper, &hv_x); HYPRE_IJVectorSetObjectType(hv_x, HYPRE_PARCSR); std::vector<double> rhs_values(local_size, 1.); std::vector<double> x_values(local_size, 0.); rows.resize(local_size); for (int i=0; i<local_size; i++) rows[i] = ilower + i; set_x0(&x_values[0]); set_rhs(&rhs_values[0]); build_A(); build_solver(); }
void ElasticProblem<dim>::assemble_system () { QGauss<dim> quadrature_formula(2); FEValues<dim> fe_values (fe, quadrature_formula, update_values | update_gradients | update_quadrature_points | update_JxW_values); TestESM<dim> test_esm; double coef[2] = {1.0, 1.0}; test_esm .set_coefficient(coef); const unsigned int dofs_per_cell = fe.dofs_per_cell; const unsigned int n_q_points = quadrature_formula.size(); FullMatrix<double> cell_matrix (dofs_per_cell, dofs_per_cell); Vector<double> cell_rhs (dofs_per_cell); std::vector<unsigned int> local_dof_indices (dofs_per_cell); std::vector<double> lambda_values (n_q_points); std::vector<double> mu_values (n_q_points); ConstantFunction<dim> lambda(1.), mu(1.); RightHandSide<dim> right_hand_side; std::vector<Vector<double> > rhs_values (n_q_points, Vector<double>(dim)); typename DoFHandler<dim>::active_cell_iterator cell = dof_handler.begin_active(), endc = dof_handler.end(); for (; cell!=endc; ++cell) { cell_matrix = 0; cell_rhs = 0; fe_values.reinit (cell); lambda.value_list (fe_values.get_quadrature_points(), lambda_values); mu.value_list (fe_values.get_quadrature_points(), mu_values); right_hand_side.vector_value_list (fe_values.get_quadrature_points(), rhs_values); for (unsigned int i=0; i<dofs_per_cell; ++i) { const unsigned int component_i = fe.system_to_component_index(i).first; for (unsigned int j=0; j<dofs_per_cell; ++j) { const unsigned int component_j = fe.system_to_component_index(j).first; // printf("i = %d, j = %d, res = %f\n", i, j, // test_esm (i, j, quadrature_formula, fe_values)); cell_matrix(i,j) += test_esm (i, j, quadrature_formula, fe_values); //// double res = 0; for (unsigned int q_point=0; q_point<n_q_points; ++q_point) { // cell_matrix(i,j) res += ( (fe_values.shape_grad(i,q_point)[component_i] * fe_values.shape_grad(j,q_point)[component_j] * lambda_values[q_point]) + (fe_values.shape_grad(i,q_point)[component_j] * fe_values.shape_grad(j,q_point)[component_i] * mu_values[q_point]) + ((component_i == component_j) ? (fe_values.shape_grad(i,q_point) * fe_values.shape_grad(j,q_point) * mu_values[q_point]) : 0) ) * fe_values.JxW(q_point); //// printf("res=%f\n", res); } } } printf("!!!!!!!!!!!!!\n"); // Assembling the right hand // side is also just as // discussed in the // introduction: for (unsigned int i=0; i<dofs_per_cell; ++i) { const unsigned int component_i = fe.system_to_component_index(i).first; for (unsigned int q_point=0; q_point<n_q_points; ++q_point) cell_rhs(i) += fe_values.shape_value(i,q_point) * rhs_values[q_point](component_i) * fe_values.JxW(q_point); } cell->get_dof_indices (local_dof_indices); for (unsigned int i=0; i<dofs_per_cell; ++i) { for (unsigned int j=0; j<dofs_per_cell; ++j) system_matrix.add (local_dof_indices[i], local_dof_indices[j], cell_matrix(i,j)); system_rhs(local_dof_indices[i]) += cell_rhs(i); } } // hanging_node_constraints.condense (system_matrix); // hanging_node_constraints.condense (system_rhs); for (size_t i = 0; i < system_matrix.m(); ++i) for (size_t j = 0; j < system_matrix.n(); ++j) if (system_matrix .el (i,j)) printf("system_matrix_old(%d,%d)=%f\n", i,j,system_matrix(i,j)); std::map<unsigned int,double> boundary_values; VectorTools::interpolate_boundary_values (dof_handler, 0, ConstantFunction<dim>(0, dim),// //ZeroFunction<dim>(dim), boundary_values); MatrixTools::apply_boundary_values (boundary_values, system_matrix, solution, system_rhs); }