/[escript]/trunk/paso/src/SystemMatrix_saveMM.c
ViewVC logotype

Contents of /trunk/paso/src/SystemMatrix_saveMM.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years ago) by ksteube
File MIME type: text/plain
File size: 4935 byte(s)
Copyright updated in all files

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Paso: SystemMatrix is saved to Matrix Market format */
18
19 /**************************************************************/
20
21 /* Copyrights by ACcESS Australia 2003,2004 */
22 /* Author: davies@access.edu.au */
23
24 /**************************************************************/
25
26 #include "SystemMatrix.h"
27 #include "mmio.h"
28
29 void Paso_SystemMatrix_saveMM(Paso_SystemMatrix * A_p, char * fileName_p) {
30 FILE * fileHandle_p = NULL;
31 dim_t N,M,i, iptr_ij;
32 MM_typecode matcode;
33
34 if (A_p->mpi_info->size > 1) {
35 Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_saveMM: currently single processor runs are supported.\n");
36 return;
37 }
38 if (A_p->col_block_size !=A_p->row_block_size) {
39 Paso_setError(TYPE_ERROR, "Paso_SystemMatrix_saveMM: currently only square blocks are supported.");
40 return;
41 }
42 if (A_p->row_block_size>3) {
43 Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_saveMM: currently only block size 3 is supported.\n");
44 return;
45 }
46
47 if (A_p->type & MATRIX_FORMAT_SYM) {
48 Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_saveMM does not support symmetric storage scheme");
49 return;
50 }
51 /* open the file */
52 fileHandle_p = fopen(fileName_p, "w");
53 if (fileHandle_p==NULL) {
54 Paso_setError(IO_ERROR,"file could not be opened for writing");
55 return;
56 }
57
58 if (A_p->type & MATRIX_FORMAT_CSC) {
59 Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_saveMM does not support CSC yet.");
60 } else {
61 mm_initialize_typecode(&matcode);
62 mm_set_matrix(&matcode);
63 mm_set_coordinate(&matcode);
64 mm_set_real(&matcode);
65
66 N= Paso_SystemMatrix_getGlobalNumRows(A_p);
67 M=Paso_SystemMatrix_getGlobalNumCols(A_p);
68 mm_write_banner(fileHandle_p, matcode);
69 mm_write_mtx_crd_size(fileHandle_p, N*A_p->row_block_size, M*A_p->col_block_size, A_p->mainBlock->pattern->ptr[N]*A_p->block_size);
70 if(A_p->row_block_size==1)
71 for (i=0; i<N; i++)
72 for (iptr_ij=A_p->mainBlock->pattern->ptr[i];iptr_ij<A_p->mainBlock->pattern->ptr[i+1]; ++iptr_ij) {
73 fprintf(fileHandle_p, "%d %d %25.15e\n", i+1, A_p->mainBlock->pattern->index[iptr_ij]+1, A_p->mainBlock->val[iptr_ij]);
74 }
75
76 if(A_p->row_block_size==2)
77 for (i=0; i<N; i++) {
78 for (iptr_ij=A_p->mainBlock->pattern->ptr[i];iptr_ij<A_p->mainBlock->pattern->ptr[i+1]; ++iptr_ij) {
79 fprintf(fileHandle_p, "%d %d %25.15e\n", i*2+1, 2*(A_p->mainBlock->pattern->index[iptr_ij])+1, A_p->mainBlock->val[iptr_ij*4]);
80 fprintf(fileHandle_p, "%d %d %25.15e\n", i*2+1, 2*(A_p->mainBlock->pattern->index[iptr_ij])+1+1, A_p->mainBlock->val[iptr_ij*4+2]);
81 fprintf(fileHandle_p, "%d %d %25.15e\n", i*2+1+1, 2*(A_p->mainBlock->pattern->index[iptr_ij])+1, A_p->mainBlock->val[iptr_ij*4+1]);
82 fprintf(fileHandle_p, "%d %d %25.15e\n", i*2+1+1, 2*(A_p->mainBlock->pattern->index[iptr_ij])+1+1, A_p->mainBlock->val[iptr_ij*4+3]);
83 }
84 }
85
86 if(A_p->row_block_size==3)
87 for (i=0; i<N; i++) {
88 for (iptr_ij=A_p->mainBlock->pattern->ptr[i];iptr_ij<A_p->mainBlock->pattern->ptr[i+1]; ++iptr_ij) {
89 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+1, A_p->mainBlock->val[iptr_ij*9]);
90 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+1+1, A_p->mainBlock->val[iptr_ij*9+3]);
91 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+2+1, A_p->mainBlock->val[iptr_ij*9+6]);
92 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+1+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+1, A_p->mainBlock->val[iptr_ij*9+1]);
93 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+1+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+1+1, A_p->mainBlock->val[iptr_ij*9+4]);
94 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+1+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+2+1, A_p->mainBlock->val[iptr_ij*9+7]);
95 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+2+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+1, A_p->mainBlock->val[iptr_ij*9+2]);
96 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+2+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+1+1, A_p->mainBlock->val[iptr_ij*9+5]);
97 fprintf(fileHandle_p, "%d %d %25.15e\n", i*3+2+1, 3*(A_p->mainBlock->pattern->index[iptr_ij])+2+1, A_p->mainBlock->val[iptr_ij*9+8]);
98 }
99 }
100
101 }
102
103 /* close the file */
104 fclose(fileHandle_p);
105
106 return;
107 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26