27 #include <boost/numeric/ublas/matrix_sparse.hpp>
46 constexpr
inline bool IsCorrectType<std::complex<double>>(
MM_typecode& mm_code)
55 return fscanf(
f,
"%d %d %lg", &I, &
J, &
V) == 3;
62 const int i = fscanf(
f,
"%d %d %lg %lg", &I, &
J, &real, &imag);
63 V = std::complex<double>(real, imag);
69 typedef typename CompressedMatrixType::value_type ValueType;
76 printf(
"ReadMatrixMarketMatrix(): unable to open %s.\n",
FileName);
85 printf(
"ReadMatrixMarketMatrix(): unable to read MatrixMarket banner.\n");
92 printf(
"ReadMatrixMarketMatrix(): invalid MatrixMarket banner.\n");
100 printf(
"ReadMatrixMarketMatrix(): unsupported MatrixMarket type, \"%s\".\n",
mm_typecode_to_str(mm_code));
106 int size1, size2, nnz;
110 printf(
"ReadMatrixMarketMatrix(): cannot read dimensions and NNZ.\n");
116 int *I =
new int[nnz];
117 int *
J =
new int[nnz];
118 ValueType *
V =
new ValueType[nnz];
121 if (!IsCorrectType<ValueType>(mm_code))
123 printf(
"ReadMatrixMarketMatrix(): MatrixMarket type, \"%s\" does not match provided matrix type.\n",
mm_typecode_to_str(mm_code));
132 for (
int i = 0;
i < nnz;
i++)
134 if (fscanf(
f,
"%d %d", &I[
i], &
J[
i]) != 2)
136 printf(
"ReadMatrixMarketMatrix(): invalid data.\n");
154 for (
int i = 0;
i < nnz;
i++)
158 printf(
"ReadMatrixMarketMatrix(): invalid data.\n");
176 int *
nz =
new int[size1];
178 for (
int i = 0;
i < size1;
i++)
183 for (
int i = 0;
i < nnz;
i++)
194 for (
int i = 0;
i < nnz;
i++)
204 for (
int i = 0;
i < nnz;
i++)
208 nnz2 = diagonals + 2 * (nnz - diagonals);
214 int *filled =
new int[size1];
215 int *indices =
new int[size1];
216 int *columns =
new int[nnz2];
217 ValueType *
values =
new ValueType[nnz2];
220 for (
int i = 1;
i < size1;
i++)
221 indices[
i] = indices[
i - 1] +
nz[
i - 1];
223 for (
int i = 0;
i < size1;
i++)
227 for (
int i = 0;
i < nnz;
i++)
232 index = indices[I[
i]] + filled[I[
i]];
233 columns[index] =
J[
i];
241 index = indices[I[
i]] + filled[I[
i]];
242 columns[index] =
J[
i];
246 index = indices[
J[
i]] + filled[
J[
i]];
247 columns[index] = I[
i];
252 for (
int i = 0;
i < nnz;
i++)
256 index = indices[I[
i]] + filled[I[
i]];
257 columns[index] =
J[
i];
263 CompressedMatrixType *
m =
new CompressedMatrixType(size1, size2, nnz2);
267 for (
int i = 0;
i < size1;
i++)
268 for (
int j = 0;
j <
nz[
i];
j++)
300 return fprintf(
f,
"%d %d %.12e\n", I,
J, entry);
305 return fprintf(
f,
"%d %d %.12e %.12e\n", I,
J, std::real(entry), std::imag(entry));
315 printf(
"WriteMatrixMarketMatrix(): unable to open %s.\n",
FileName);
342 typename CompressedMatrixType::iterator1 a_iterator = M.begin1();
344 for (
unsigned int i = 0;
i < M.size1();
i++)
346 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
347 for (
typename CompressedMatrixType::iterator2 row_iterator = a_iterator.begin(); row_iterator != a_iterator.end(); ++row_iterator)
349 for (
typename CompressedMatrixType::iterator2 row_iterator = begin(a_iterator, iterator1_tag()); row_iterator !=
end(a_iterator, iterator1_tag()); ++row_iterator)
352 if (a_iterator.index1() >= row_iterator.index2())
367 typename CompressedMatrixType::iterator1 a_iterator = M.begin1();
369 for (
unsigned int i = 0;
i < M.size1();
i++)
371 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
372 for (
typename CompressedMatrixType::iterator2 row_iterator = a_iterator.begin(); row_iterator != a_iterator.end(); ++row_iterator)
374 for (
typename CompressedMatrixType::iterator2 row_iterator = begin(a_iterator, iterator1_tag()); row_iterator !=
end(a_iterator, iterator1_tag()); ++row_iterator)
377 int I = a_iterator.index1(),
J = row_iterator.index2();
382 printf(
"WriteMatrixMarketMatrix(): unable to write data.\n");
393 typename CompressedMatrixType::iterator1 a_iterator = M.begin1();
395 for (
unsigned int i = 0;
i < M.size1();
i++)
397 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
398 for (
typename CompressedMatrixType::iterator2 row_iterator = a_iterator.begin(); row_iterator != a_iterator.end(); ++row_iterator)
400 for (
typename CompressedMatrixType::iterator2 row_iterator = begin(a_iterator, iterator1_tag()); row_iterator !=
end(a_iterator, iterator1_tag()); ++row_iterator)
403 int I = a_iterator.index1(),
J = row_iterator.index2();
407 printf(
"WriteMatrixMarketMatrix(): unable to write data.\n");
426 return fscanf(
f,
"%lg", &entry) == 1;
433 const int i = fscanf(
f,
"%lg %lg", &real, &imag);
434 entry = std::complex<double>(real, imag);
447 printf(
"ReadMatrixMarketVector(): unable to open %s.\n",
FileName);
456 printf(
"ReadMatrixMarketVector(): unable to read MatrixMarket banner.\n");
463 printf(
"ReadMatrixMarketVector(): invalid MatrixMarket banner.\n");
471 printf(
"ReadMatrixMarketVector(): unsupported MatrixMarket type, \"%s\".\n",
mm_typecode_to_str(mm_code));
481 printf(
"ReadMatrixMarketVector(): cannot read dimensions.\n");
489 printf(
"ReadMatrixMarketVector(): not a N x 1 array.\n");
498 if (!IsCorrectType<ValueType>(mm_code))
500 printf(
"ReadMatrixMarketVector(): MatrixMarket type, \"%s\" does not match provided vector type.\n",
mm_typecode_to_str(mm_code));
507 for (
int i = 0;
i < size1;
i++)
511 printf(
"ReadMatrixMarketVector(): invalid data.\n");
531 return fprintf(
f,
"%e\n", entry);
536 return fprintf(
f,
"%e %e\n", std::real(entry), std::imag(entry));
546 printf(
"WriteMatrixMarketVector(): unable to open %s.\n",
FileName);
564 for (
unsigned int i = 0;
i <
V.size();
i++)
567 printf(
"WriteMatrixMarketVector(): unable to write data.\n");
double value_type
Definition: array_1d.h:75
#define mm_is_complex(typecode)
Definition: mmio.h:40
int mm_write_banner(FILE *f, MM_typecode matcode)
Definition: mmio.c:387
#define mm_set_complex(typecode)
Definition: mmio.h:61
#define mm_set_array(typecode)
Definition: mmio.h:57
#define mm_set_general(typecode)
Definition: mmio.h:68
char MM_typecode[4]
Definition: mmio.h:18
int mm_write_mtx_array_size(FILE *f, int M, int N)
Definition: mmio.c:250
#define mm_set_symmetric(typecode)
Definition: mmio.h:67
#define mm_set_coordinate(typecode)
Definition: mmio.h:56
#define mm_initialize_typecode(typecode)
Definition: mmio.h:75
#define mm_is_real(typecode)
Definition: mmio.h:41
#define mm_is_array(typecode)
Definition: mmio.h:38
int mm_read_mtx_array_size(FILE *f, int *M, int *N)
Definition: mmio.c:221
#define mm_is_coordinate(typecode)
Definition: mmio.h:36
int mm_is_valid(MM_typecode matcode)
Definition: mmio.c:87
#define mm_is_pattern(typecode)
Definition: mmio.h:42
#define mm_set_matrix(typecode)
Definition: mmio.h:55
int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz)
Definition: mmio.c:190
int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz)
Definition: mmio.c:182
int mm_read_banner(FILE *f, MM_typecode *matcode)
Definition: mmio.c:97
#define mm_is_symmetric(typecode)
Definition: mmio.h:45
char * mm_typecode_to_str(MM_typecode matcode)
Definition: mmio.c:456
#define mm_is_sparse(typecode)
Definition: mmio.h:35
#define mm_set_real(typecode)
Definition: mmio.h:62
end
Definition: DEM_benchmarks.py:180
string FileName
Export to vtk.
Definition: GenerateWind.py:175
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
bool ReadMatrixMarketVectorEntry(FILE *f, double &entry)
Definition: matrix_market_interface.h:424
int WriteMatrixMarketVectorEntry(FILE *f, const double &entry)
Definition: matrix_market_interface.h:529
bool WriteMatrixMarketVector(const char *FileName, VectorType &V)
Definition: matrix_market_interface.h:539
int WriteMatrixMarketMatrixEntry(FILE *f, int I, int J, const double &entry)
Definition: matrix_market_interface.h:298
array_1d< double, 3 > VectorType
Definition: solid_mechanics_application_variables.cpp:19
bool WriteMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M, bool Symmetric)
Definition: matrix_market_interface.h:308
constexpr bool IsCorrectType< double >(MM_typecode &mm_code)
Definition: matrix_market_interface.h:40
bool ReadMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M)
Definition: matrix_market_interface.h:67
void SetMatrixMarketValueTypeCode(MM_typecode &mm_code, const double &value)
Definition: matrix_market_interface.h:288
bool ReadMatrixMarketVector(const char *FileName, VectorType &V)
Definition: matrix_market_interface.h:438
bool ReadMatrixMarketMatrixEntry(FILE *f, int &I, int &J, double &V)
Definition: matrix_market_interface.h:52
constexpr bool IsCorrectType(MM_typecode &mm_code)
list values
Definition: bombardelli_test.py:42
nz
Definition: cube_mesher.py:739
v
Definition: generate_convection_diffusion_explicit_element.py:114
f
Definition: generate_convection_diffusion_explicit_element.py:112
V
Definition: generate_droplet_dynamics.py:256
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
J
Definition: sensitivityMatrix.py:58
integer i
Definition: TensorModule.f:17