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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2548 - (hide annotations)
Mon Jul 20 06:20:06 2009 UTC (10 years, 3 months ago) by jfenwick
File MIME type: text/plain
File size: 4935 byte(s)
Updating copyright notices
1 ksteube 1312
2     /*******************************************************
3 ksteube 1811 *
4 jfenwick 2548 * Copyright (c) 2003-2009 by University of Queensland
5 ksteube 1811 * 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 dhawcroft 631
14 ksteube 1811
15 jgs 150 /**************************************************************/
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 gross 1369 #include "mmio.h"
28 jgs 150
29     void Paso_SystemMatrix_saveMM(Paso_SystemMatrix * A_p, char * fileName_p) {
30 gross 1028 FILE * fileHandle_p = NULL;
31 gross 1369 dim_t N,M,i, iptr_ij;
32     MM_typecode matcode;
33 jgs 150
34 ksteube 1312 if (A_p->mpi_info->size > 1) {
35 gross 1369 Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_saveMM: currently single processor runs are supported.\n");
36 ksteube 1312 return;
37     }
38 artak 1780 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 gross 1369 return;
45     }
46    
47 gross 415 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 jgs 150 /* open the file */
52 gross 1028 fileHandle_p = fopen(fileName_p, "w");
53 jgs 150 if (fileHandle_p==NULL) {
54     Paso_setError(IO_ERROR,"file could not be opened for writing");
55     return;
56     }
57    
58 gross 415 if (A_p->type & MATRIX_FORMAT_CSC) {
59 gross 1369 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 artak 1780 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 gross 1369
76 artak 1780 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 gross 1369 for (iptr_ij=A_p->mainBlock->pattern->ptr[i];iptr_ij<A_p->mainBlock->pattern->ptr[i+1]; ++iptr_ij) {
89 artak 1780 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 jgs 150 }
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