Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_IO_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Xpetra: A linear algebra interface package
4//
5// Copyright 2012 NTESS and the Xpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef PACKAGES_XPETRA_SUP_UTILS_XPETRA_IO_HPP_
11#define PACKAGES_XPETRA_SUP_UTILS_XPETRA_IO_HPP_
12
13#include <fstream>
14#include "Xpetra_ConfigDefs.hpp"
15
17#include <Tpetra_RowMatrixTransposer.hpp>
18#include <TpetraExt_MatrixMatrix.hpp>
19#include <Xpetra_TpetraMultiVector.hpp>
20#include <Xpetra_TpetraCrsGraph.hpp>
21#include <Xpetra_TpetraCrsMatrix.hpp>
22#include <Xpetra_TpetraBlockCrsMatrix.hpp>
23#include "Tpetra_Util.hpp"
24
25#include "Xpetra_Matrix.hpp"
26#include "Xpetra_MatrixMatrix.hpp"
27#include "Xpetra_Helpers.hpp"
28#include "Xpetra_CrsGraph.hpp"
29#include "Xpetra_CrsMatrixWrap.hpp"
30#include "Xpetra_BlockedCrsMatrix.hpp"
31
32#include "Xpetra_Map.hpp"
33#include "Xpetra_StridedMap.hpp"
34#include "Xpetra_StridedMapFactory.hpp"
35#include "Xpetra_MapExtractor.hpp"
36#include "Xpetra_MatrixFactory.hpp"
37
39#include <Teuchos_MatrixMarket_Raw_Writer.hpp>
40#include <Teuchos_MatrixMarket_Raw_Reader.hpp>
41#include <string>
42
43namespace Xpetra {
44
49template <class Scalar,
50 class LocalOrdinal = int,
51 class GlobalOrdinal = LocalOrdinal,
52 class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
53class IO {
54 private:
55#undef XPETRA_IO_SHORT
57
58 public:
60 // @{
61 /*static RCP<const Tpetra::MultiVector<SC,LO,GO,NO> > MV2TpetraMV(RCP<MultiVector> const vec);
62 static RCP< Tpetra::MultiVector<SC,LO,GO,NO> > MV2NonConstTpetraMV(RCP<MultiVector> vec);
63 static RCP< Tpetra::MultiVector<SC,LO,GO,NO> > MV2NonConstTpetraMV2(MultiVector& vec);
64
65 static const Tpetra::MultiVector<SC,LO,GO,NO>& MV2TpetraMV(const MultiVector& vec);
66 static Tpetra::MultiVector<SC,LO,GO,NO>& MV2NonConstTpetraMV(MultiVector& vec);
67
68 static RCP<const Tpetra::CrsMatrix<SC,LO,GO,NO> > Op2TpetraCrs(RCP<const Matrix> Op);
69 static RCP< Tpetra::CrsMatrix<SC,LO,GO,NO> > Op2NonConstTpetraCrs(RCP<Matrix> Op);
70
71 static const Tpetra::CrsMatrix<SC,LO,GO,NO>& Op2TpetraCrs(const Matrix& Op);
72 static Tpetra::CrsMatrix<SC,LO,GO,NO>& Op2NonConstTpetraCrs(Matrix& Op);
73
74 static RCP<const Tpetra::RowMatrix<SC,LO,GO,NO> > Op2TpetraRow(RCP<const Matrix> Op);
75 static RCP< Tpetra::RowMatrix<SC,LO,GO,NO> > Op2NonConstTpetraRow(RCP<Matrix> Op);*/
76
78
80
81
82 static void Write(const std::string& fileName, const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>& M);
83
85 static void Write(const std::string& fileName, const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& vec);
86
87 // CAG:
88 // The class is templated on the usual SC-LO-GO-NO.
89 // Instead of instantiating the entire class using Scalar=LO or GO and then dealing with the headaches that integer-valued CrsMatrix creates, we use these two methods.
90
92 static void WriteLOMV(const std::string& fileName, const Xpetra::MultiVector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>& vec);
93
95 static void WriteGOMV(const std::string& fileName, const Xpetra::MultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>& vec);
96
98 static void Write(const std::string& fileName, const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Op, const bool& writeAllMaps = false);
99
101 static void WriteLocal(const std::string& fileName, const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Op);
102
117 static void WriteBlockedCrsMatrix(const std::string& fileName, const Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Op, const bool& writeAllMaps = false);
118
120 static Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> Read(const std::string& fileName, Xpetra::UnderlyingLib lib, const RCP<const Teuchos::Comm<int>>& comm, bool binary = false);
121
127 Read(const std::string& filename,
129 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> colMap = Teuchos::null,
130 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> domainMap = Teuchos::null,
131 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> rangeMap = Teuchos::null,
132 const bool callFillComplete = true,
133 const bool binary = false,
134 const bool tolerant = false,
135 const bool debug = false);
136
148 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> domainMap = Teuchos::null,
149 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> rangeMap = Teuchos::null,
150 const bool callFillComplete = true,
151 const bool binary = false,
152 const bool tolerant = false,
153 const bool debug = false);
155
157 static RCP<MultiVector> ReadMultiVector(const std::string& fileName,
158 const RCP<const Map>& map,
159 const bool binary = false);
160
163 const RCP<const Map>& map,
164 const bool binary = false);
165
166 static RCP<const Map> ReadMap(const std::string& fileName,
168 const RCP<const Teuchos::Comm<int>>& comm,
169 const bool binary = false);
170
185
187 template <class T>
188 static std::string toString(const T& what);
189};
190
191} // end namespace Xpetra
192
193#define XPETRA_IO_SHORT
194
195#endif /* PACKAGES_XPETRA_SUP_UTILS_XPETRA_IO_HPP_ */
Xpetra utility class containing IO routines to read/write vectors, matrices etc...
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Read(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, bool binary=false)
Read matrix from file in Matrix Market or binary format.
static RCP< const Map > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, const bool binary=false)
static RCP< MultiVector > ReadMultiVector(const std::string &fileName, const RCP< const Map > &map, const bool binary=false)
Read a MultiVector from file in Matrix Matrix or binary format.
static const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > Map2TpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
Helper utility to pull out the underlying Tpetra objects from an Xpetra object.
static void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
Read/Write methods.
static RCP< const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadBlockedCrsMatrix(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
Read block matrix from one file per block in Matrix Market format.
static Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > ReadLocal(const std::string &filename, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > rowMap, RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > colMap, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > domainMap=Teuchos::null, const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > rangeMap=Teuchos::null, const bool callFillComplete=true, const bool binary=false, const bool tolerant=false, const bool debug=false)
Read matrix from local files in Matrix Market or binary format.
static void WriteBlockedCrsMatrix(const std::string &fileName, const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const bool &writeAllMaps=false)
Save block matrix to one file per block in Matrix Market format.
static void WriteGOMV(const std::string &fileName, const Xpetra::MultiVector< GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &vec)
Save multivector with Scalar=GlobalOrdinal to file in Matrix Market format.
static void WriteLocal(const std::string &fileName, const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Save local parts of matrix to files in Matrix Market format.
static RCP< Xpetra::MultiVector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > > ReadMultiVectorLO(const std::string &fileName, const RCP< const Map > &map, const bool binary=false)
Read a MultiVector with Scalar=LocalOrdinal from file in Matrix Matrix or binary format.
static void WriteLOMV(const std::string &fileName, const Xpetra::MultiVector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > &vec)
Save multivector with Scalar=LocalOrdinal to file in Matrix Market format.
static std::string toString(const T &what)
Little helper function to convert non-string types to strings.
Xpetra-specific matrix class.