19 #include "libmesh/getpot.h" 20 #include "libmesh/libmesh.h" 21 #include "libmesh/libmesh_logging.h" 22 #include "libmesh/linear_solver.h" 23 #include "libmesh/numeric_vector.h" 24 #include "libmesh/sparse_matrix.h" 28 void usage(
const std::string & prog_name);
33 int main(
int argc,
char ** argv)
41 GetPot command_line (argc, argv);
43 std::string matfile, rhsfile;
44 if (command_line.search(1,
"-m"))
45 matfile = command_line.next(matfile);
49 if (command_line.search(1,
"-r"))
50 rhsfile = command_line.next(rhsfile);
56 LOG_CALL(
"mat.read()",
"main", mat->read(matfile));
58 libMesh::out <<
"Loaded " << mat->m() <<
" by " << mat->n() <<
59 " matrix " << matfile << std::endl;
64 LOG_CALL(
"rhs.read()",
"main", rhs->read_matlab(rhsfile));
67 " vector " << rhsfile << std::endl;
69 solution->init(rhs->size(), rhs->local_size());
74 if (command_line.search(1,
"-t"))
75 tol = command_line.next(tol);
77 unsigned int n_iters = 1e3;
78 if (command_line.search(1,
"-n"))
79 n_iters = command_line.next(n_iters);
81 auto [iters, res] = solver->
solve(*mat, *solution, *rhs, tol, n_iters);
83 libMesh::out <<
"Finished in " << iters <<
" iterations with " << res
84 <<
" residual " << std::endl;
90 void usage(
const std::string & prog_name)
92 std::ostringstream helpList;
94 "Usage: " << prog_name <<
98 " -m <string> Matrix filename (required)\n" 99 " -r <string> RHS Vector filename (required)\n" 100 " -t <tol> Linear Solver tolerance (default 1e-9)\n" 101 " -n <n_iter> Linear Solver max iterations (default 1e3)\n";
static std::unique_ptr< LinearSolver< T > > build(const libMesh::Parallel::Communicator &comm_in, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a LinearSolver using the linear solver package specified by solver_package.
int main(int argc, char **argv)
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package(), const MatrixBuildType matrix_build_type=MatrixBuildType::AUTOMATIC)
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const std::optional< double > tol=std::nullopt, const std::optional< unsigned int > m_its=std::nullopt)=0
This function calls the solver _solver_type preconditioned with the _preconditioner_type precondition...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
void usage(const std::string &prog_name)