CArl
Code Arlequin / C++ implementation
libmesh_solve_linear_system.cpp
Go to the documentation of this file.
2 
3 int main(int argc, char** argv) {
4 
5  // --- Initialize libMesh
6  libMesh::LibMeshInit init(argc, argv);
7 
8  // Do performance log?
9  libMesh::PerfLog perf_log("Main program");
10 
11  // libMesh's C++ / MPI communicator wrapper
12  libMesh::Parallel::Communicator& WorldComm = init.comm();
13 
14  // Number of processors and processor rank.
15  int rank = WorldComm.rank();
16  int nodes = WorldComm.size();
17 
18  // --- Set up inputs
19 
20  // Command line parser
21  GetPot command_line(argc, argv);
22 
23  // File parser
24  GetPot field_parser;
25 
26  // If there is an input file, parse it to get the parameters. Else, parse the command line
27  std::string input_filename;
28  if (command_line.search(2, "--inputfile", "-i")) {
29  input_filename = command_line.next(input_filename);
30  field_parser.parse_input_file(input_filename, "#", "\n", " \t\n");
31  } else {
32  field_parser = command_line;
33  }
34 
36  carl::get_input_params(field_parser, input_params);
37 
38  // Check libMesh installation dimension
39  const unsigned int dim = 3;
40 
41  libmesh_example_requires(dim == LIBMESH_DIM, "3D support");
42 
43  // --- Set the matrix and vectors
44 
45  // Set up the PETSC versions
46  Mat sys_mat_PETSC;
47  Vec sys_rhs_vec_PETSC;
48 
49  MatCreate(WorldComm.get(),&sys_mat_PETSC);
50  VecCreate(WorldComm.get(),&sys_rhs_vec_PETSC);
51 
52  // Read
53  carl::read_PETSC_matrix(sys_mat_PETSC, input_params.sys_matrix_file, WorldComm.get());
54  carl::read_PETSC_vector(sys_rhs_vec_PETSC, input_params.sys_rhs_vec_file, WorldComm.get());
55 
56  // Set up the libMesh versions
57  libMesh::PetscMatrix<libMesh::Number> sys_mat(sys_mat_PETSC,WorldComm);
58  libMesh::PetscVector<libMesh::Number> sys_rhs_vec(sys_rhs_vec_PETSC,WorldComm);
59  libMesh::PetscVector<libMesh::Number> sys_sol_vec(WorldComm);
60  sys_sol_vec.init(sys_rhs_vec);
61 
62  PetscInt local_N;
63  MatGetLocalSize(sys_mat_PETSC,NULL,&local_N);
64 
65  // --- Linear solver
66  libMesh::PetscLinearSolver<libMesh::Number> KSP_solver(WorldComm);
67  KSP_solver.init("sys");
68 
69  // If the nullspace vectors were given, read them
70  if ( input_params.bUseRBVectors )
71  {
72  std::cout << " > Using the " << input_params.nb_of_rb_vectors << " RB modes vectors!" << std::endl;
73  carl::attach_rigid_body_mode_vectors(sys_mat,input_params.path_to_rb_vectors,input_params.nb_of_rb_vectors,dim);
74  std::cout << " > Attached the RB modes vectors!" << std::endl;
75  }
76 
77  // Solve!
78  KSP_solver.solve(sys_mat,sys_sol_vec,sys_rhs_vec,input_params.sys_eps,input_params.sys_iter_div);
79 
80  KSP_solver.print_converged_reason();
81 
82 // Print MatLab debugging output? Variable defined at "carl_headers.h"
83 #ifdef PRINT_MATLAB_DEBUG
84  sys_sol_vec.print_matlab(input_params.output_base + "_sys_sol_vec.m");
85 #endif
86 
87  // Export the solution vector
88  carl::write_PETSC_vector(sys_sol_vec, input_params.output_base + "_sys_sol_vec.petscvec");
89 
90  // --- Cleanup!
91  MatDestroy(&sys_mat_PETSC);
92  VecDestroy(&sys_rhs_vec_PETSC);
93 
94  return 0;
95 }
void get_input_params(GetPot &field_parser, feti_iterate_params &input_params)
Parser function for the coupled solver test programs.
void write_PETSC_vector(libMesh::PetscVector< libMesh::Number > &input_vec, const std::string &filename, int dim=1)
void attach_rigid_body_mode_vectors(libMesh::PetscMatrix< libMesh::Number > &mat_sys, const std::string &filename_base, int nb_of_vecs, int dimension)
bool bUseRBVectors
Use rigid body mode vectors? Default: false.
std::string sys_rhs_vec_file
Path to the system RHS vector file.
void read_PETSC_matrix(Mat input_mat, const std::string &filename, MPI_Comm comm=PETSC_COMM_WORLD)
int main(int argc, char **argv)
std::string path_to_rb_vectors
Path to a folder containing the rigid body mode vectors.
void read_PETSC_vector(libMesh::PetscVector< libMesh::Number > &input_vec, const std::string &filename)