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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26