ug4
mm_type_code.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013: G-CSC, Goethe University Frankfurt
3  * Author: Torbjörn Klatt
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
43 #ifndef __H__UG__LIB_ALGEBRA__MM_TYPE_CODE_H
44 #define __H__UG__LIB_ALGEBRA__MM_TYPE_CODE_H
45 
46 #include <string>
47 
48 #include "common/error.h"
49 
50 namespace ug
51 {
52 
55 
60 {
61  public:
67  enum ClassType {
69  ARRAY = 2 // TODO array/dense matrix not yet implemented
70  };
71 
77  enum NumericType {
78  REAL = 1,
79  COMPLEX = 2, // TODO complex matrices not yet implemented
80  INTEGER = 3, // TODO integer matrices not yet implemented
81  PATTERN = 4 // TODO pattern matrices not yet implemented
82  };
83 
90  GENERAL = 1,
91  SYMMETRIC = 2,
92  SKEW = 3,
93  HERMITIAN = 4 // TODO hermitian matrices not yet implemented
94  };
95 
97  static const int MM_LINE_LENGTH = 1025;
98 #define MM_BANNER_STR "%%MatrixMarket"
99 #define MM_MTX_STR "matrix"
100 #define MM_COORDINATE_STR "coordinate"
101 #define MM_SPARSE_STR "coordinate"
102 #define MM_ARRAY_STR "array"
103 #define MM_DENSE_STR "array"
104 #define MM_REAL_STR "real"
105 #define MM_COMPLEX_STR "complex"
106 #define MM_INTEGER_STR "integer"
107 #define MM_PATTERN_STR "pattern"
108 #define MM_GENERAL_STR "general"
109 #define MM_SYMMETRIC_STR "symmetric"
110 #define MM_SKEW_STR "skew-symmetric"
111 #define MM_HERMITIAN_STR "hermitian"
112 
113  private:
120 
121  public:
129  {}
130 
144  std::string to_string() {
145  std::stringstream out;
146  out << "MatrixMarket Type Codes:\n";
147  out << " ClassType: " << m_class_type << "\n";
148  out << " NumericType: " << m_numeric_type << "\n";
149  out << " AlgebraicType: " << m_algebraic_type;
150  return out.str();
151  }
152 
158  bool is_sparse() const {
159  return ( m_class_type == COORDINATE );
160  }
161 
167  bool is_real() const {
168  return ( m_numeric_type == REAL );
169  }
170 
176  bool is_general() const {
177  return ( m_algebraic_type == GENERAL );
178  }
184  bool is_symmetric() const {
185  return ( m_algebraic_type == SYMMETRIC );
186  }
192  bool is_skew_symmetric() const {
193  return ( m_algebraic_type == SKEW );
194  }
195 
202  void set_class_type( int type ) {
203  switch( type ) {
204  case 1:
206  break;
207  case 2:
209  break;
210  default:
211  UG_THROW( "MatrixMarket Type code is invalid: " << type );
212  }
213  }
220  void set_class_type( std::string type ) {
221  if( type.compare( MM_COORDINATE_STR ) == 0 || type.compare( MM_SPARSE_STR ) == 0 ) {
223  } else if( type.compare( MM_ARRAY_STR ) == 0 || type.compare( MM_DENSE_STR ) == 0 ) {
225  } else {
226  UG_THROW( "MatrixMarket Type is invalid: " << type );
227  }
228  }
229 
236  void set_numeric_type( int type ) {
237  switch( type ) {
238  case 1:
240  break;
241  case 2:
243  break;
244  case 3:
246  break;
247  case 4:
249  break;
250  default:
251  UG_THROW( "MatrixMarket numeric type code is invalid: " << type );
252  }
253  }
261  void set_numeric_type( std::string type ) {
262  if( type.compare( MM_REAL_STR ) == 0 ) {
264  } else if( type.compare( MM_COMPLEX_STR ) == 0 ) {
266  } else if( type.compare( MM_INTEGER_STR ) == 0 ) {
268  } else if( type.compare( MM_PATTERN_STR ) == 0 ) {
270  } else {
271  UG_THROW( "MatrixMarket numeric type is invalid: " << type );
272  }
273  }
274 
281  void set_algebraic_type( int type ) {
282  switch( type ) {
283  case 1:
285  break;
286  case 2:
288  break;
289  case 3:
291  break;
292  case 4:
294  break;
295  default:
296  UG_THROW( "MatrixMarket algebraic type code is invalid: " << type );
297  }
298  }
306  void set_algebraic_type( std::string type ) {
307  if( type.compare( MM_GENERAL_STR ) == 0 ) {
309  } else if( type.compare( MM_SYMMETRIC_STR ) == 0 ) {
311  } else if( type.compare( MM_SKEW_STR ) == 0 ) {
313  } else if( type.compare( MM_HERMITIAN_STR ) == 0 ) {
315  } else {
316  UG_THROW( "MatrixMarket algebraic type is invalid: " << type );
317  }
318  }
319 };
320 
321 // end group matrixio
323 
324 } // namespace ug
325 
326 #endif // __H__UG__LIB_ALGEBRA__MM_TYPE_CODE_H
327 
328 // EOF
Type representation for MatrixMarket matrix exchange files.
Definition: mm_type_code.h:60
void set_numeric_type(std::string type)
Sets a new numeric type from a string.
Definition: mm_type_code.h:261
void set_class_type(int type)
Sets a new class type from an enum value.
Definition: mm_type_code.h:202
int m_numeric_type
Holds a value of MMTypeCode::NumericType (initialized with 0)
Definition: mm_type_code.h:117
bool is_general() const
Tells whether MMTypeCode is general.
Definition: mm_type_code.h:176
bool is_skew_symmetric() const
Tells whether MMTypeCode is skew-symmetric.
Definition: mm_type_code.h:192
std::string to_string()
Pretty prints the three classes and their current value.
Definition: mm_type_code.h:144
void set_numeric_type(int type)
Sets a new numeric type from an enum value.
Definition: mm_type_code.h:236
static const int MM_LINE_LENGTH
Maximum line length in characters as defined by the MatrixMarket specifications.
Definition: mm_type_code.h:97
bool is_real() const
Tells whether MMTypeCode is real.
Definition: mm_type_code.h:167
void set_algebraic_type(int type)
Sets a new algebraic type from an enum value.
Definition: mm_type_code.h:281
bool is_symmetric() const
Tells whether MMTypeCode is symmetric.
Definition: mm_type_code.h:184
void set_algebraic_type(std::string type)
Sets a new algebraic type from a string.
Definition: mm_type_code.h:306
bool is_sparse() const
Tells whether MMTypeCode is sparse.
Definition: mm_type_code.h:158
NumericType
Numeric type of the described matrix.
Definition: mm_type_code.h:77
@ INTEGER
Definition: mm_type_code.h:80
@ COMPLEX
Definition: mm_type_code.h:79
@ REAL
Definition: mm_type_code.h:78
@ PATTERN
Definition: mm_type_code.h:81
AlgebraicType
Algebraic type of the described matrix.
Definition: mm_type_code.h:89
@ GENERAL
Definition: mm_type_code.h:90
@ HERMITIAN
Definition: mm_type_code.h:93
@ SYMMETRIC
Definition: mm_type_code.h:91
@ SKEW
Definition: mm_type_code.h:92
int m_class_type
Holds a value of MMTypeCode::ClassType (initialized with 0)
Definition: mm_type_code.h:115
void set_class_type(std::string type)
Sets a new class type from a string.
Definition: mm_type_code.h:220
ClassType
Class type of the described matrix.
Definition: mm_type_code.h:67
@ ARRAY
Definition: mm_type_code.h:69
@ COORDINATE
Definition: mm_type_code.h:68
MMTypeCode()
Default constructor.
Definition: mm_type_code.h:127
int m_algebraic_type
Holds a value of MMTypeCode::AlgebraicType (initialized with 0)
Definition: mm_type_code.h:119
#define UG_THROW(msg)
Definition: error.h:57
#define MM_PATTERN_STR
Definition: mm_type_code.h:107
#define MM_SKEW_STR
Definition: mm_type_code.h:110
#define MM_GENERAL_STR
Definition: mm_type_code.h:108
#define MM_COMPLEX_STR
Definition: mm_type_code.h:105
#define MM_COORDINATE_STR
Definition: mm_type_code.h:100
#define MM_SPARSE_STR
Definition: mm_type_code.h:101
#define MM_HERMITIAN_STR
Definition: mm_type_code.h:111
#define MM_SYMMETRIC_STR
Definition: mm_type_code.h:109
#define MM_INTEGER_STR
Definition: mm_type_code.h:106
#define MM_ARRAY_STR
Definition: mm_type_code.h:102
#define MM_DENSE_STR
Definition: mm_type_code.h:103
#define MM_REAL_STR
Definition: mm_type_code.h:104
the ug namespace