libMesh
matrixconvert.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 // libmesh includes
19 #include "libmesh/libmesh.h"
20 #include "libmesh/libmesh_logging.h"
21 #include "libmesh/sparse_matrix.h"
22 
23 using namespace libMesh;
24 
25 // Open the matrix named in a command line argument,
26 // and rewrite it out in matlab format (our most portable currently)
27 // to the given output filename.
28 int main(int argc, char ** argv)
29 {
30  LibMeshInit init(argc, argv);
31 
32  if (argc != 3)
33  libmesh_error_msg
34  ("Usage: " << argv[0] <<
35  " inputmatrix outputmatrix");
36 
37  auto mat = SparseMatrix<Number>::build(init.comm());
38 
39  LOG_CALL("mat.read()", "main", mat->read(argv[1]));
40 
41  libMesh::out << "Loaded " << mat->m() << " by " << mat->n() <<
42  " matrix " << argv[1] << std::endl;
43 
44  LOG_CALL("mat.print_matlab()", "main", mat->print_matlab(argv[2]));
45 
46  libMesh::out << "Wrote output " << argv[2] << std::endl;
47 
48  return 0;
49 }
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:90
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.
int main(int argc, char **argv)
Definition: matrixconvert.C:28
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
OStreamProxy out