/[escript]/branches/doubleplusgood/paso/src/SparseMatrix_invMain.cpp
ViewVC logotype

Annotation of /branches/doubleplusgood/paso/src/SparseMatrix_invMain.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4324 - (hide annotations)
Wed Mar 20 00:55:44 2013 UTC (6 years, 1 month ago) by jfenwick
File size: 3102 byte(s)
continues
1 gross 3094
2 jfenwick 3981 /*****************************************************************************
3 gross 3094 *
4 jfenwick 4154 * Copyright (c) 2003-2013 by University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 gross 3094 *
7     * Primary Business: Queensland, Australia
8     * Licensed under the Open Software License version 3.0
9     * http://www.opensource.org/licenses/osl-3.0.php
10     *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     * Development since 2012 by School of Earth Sciences
13     *
14     *****************************************************************************/
15 gross 3094
16    
17 jfenwick 3981 /************************************************************************************/
18 gross 3094
19     /* Paso: inverts the main diagonal of a SparseMatrix: */
20    
21 jfenwick 3981 /************************************************************************************/
22 gross 3094
23     /* Author: Lutz Gross, l.gross@uq.edu.au */
24    
25 jfenwick 3981 /************************************************************************************/
26 gross 3094
27     #include "Paso.h"
28     #include "SparseMatrix.h"
29     #include "Solver.h"
30 gross 3120 #include "BlockOps.h"
31 gross 3158 #include "PasoUtil.h"
32 gross 3094
33     void Paso_SparseMatrix_invMain(Paso_SparseMatrix * A_p, double* inv_diag, int* pivot) {
34 gross 3402 index_t failed=0;
35     register double A11;
36     const dim_t n=A_p->numRows;
37     const dim_t n_block=A_p->row_block_size;
38     const dim_t m_block=A_p->col_block_size;
39     const dim_t block_size=A_p->block_size;
40 gross 3094 dim_t i;
41     register index_t iPtr;
42     index_t* main_ptr=Paso_Pattern_borrowMainDiagonalPointer(A_p->pattern);
43     /* check matrix is square */
44     if (m_block != n_block) {
45 jfenwick 3259 Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_invMain: square block size expected.");
46 gross 3094 }
47 jfenwick 3259 if (Esys_noError()) {
48 gross 3094
49     if (n_block==1) {
50     #pragma omp parallel for private(i, iPtr, A11) schedule(static)
51     for (i = 0; i < n; i++) {
52     iPtr= main_ptr[i];
53     A11=A_p->val[iPtr];
54     if ( ABS(A11) > 0.) {
55     inv_diag[i]=1./A11;
56     } else {
57 gross 3402 failed=1;
58 gross 3094 }
59     }
60     } else if (n_block==2) {
61 gross 3402 #pragma omp parallel for private(i, iPtr) schedule(static)
62 gross 3094 for (i = 0; i < n; i++) {
63     iPtr= main_ptr[i];
64 gross 3402 Paso_BlockOps_invM_2(&inv_diag[i*4], &A_p->val[iPtr*4], &failed);
65 gross 3094 }
66     } else if (n_block==3) {
67 gross 3402 #pragma omp parallel for private(i, iPtr) schedule(static)
68 gross 3094 for (i = 0; i < n; i++) {
69     iPtr= main_ptr[i];
70 gross 3402 Paso_BlockOps_invM_3(&inv_diag[i*9], &A_p->val[iPtr*9], &failed);
71 gross 3094 }
72 gross 3402 } else {
73     #pragma omp parallel for private(i, iPtr) schedule(static)
74 gross 3094 for (i = 0; i < n; i++) {
75     iPtr= main_ptr[i];
76 gross 3402 Paso_BlockOps_Cpy_N(block_size, &inv_diag[i*block_size], &A_p->val[iPtr*block_size]);
77     Paso_BlockOps_invM_N(n_block, &inv_diag[i*block_size], &pivot[i*n_block], &failed);
78     }
79 gross 3094 }
80     }
81 gross 3402 if (failed > 0) {
82     Esys_setError(ZERO_DIVISION_ERROR, "Paso_SparseMatrix_invMain: non-regular main diagonal block.");
83     }
84 gross 3094 }
85     void Paso_SparseMatrix_applyBlockMatrix(Paso_SparseMatrix * A_p, double* block_diag, int* pivot, double*x, double *b) {
86     dim_t n=A_p->numRows;
87     dim_t n_block=A_p->row_block_size;
88 gross 3158 Paso_Copy(n_block*n, x,b);
89 gross 3402 Paso_BlockOps_solveAll(n_block,n,block_diag,pivot,x);
90 gross 3094 }
91    

  ViewVC Help
Powered by ViewVC 1.1.26