/[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 4154 - (hide annotations)
Tue Jan 22 09:30:23 2013 UTC (6 years, 1 month ago) by jfenwick
Original Path: trunk/paso/src/SparseMatrix_invMain.c
File MIME type: text/plain
File size: 3267 byte(s)
Round 1 of copyright fixes
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     /* Copyrights by ACcESS Australia 2010 */
24     /* Author: Lutz Gross, l.gross@uq.edu.au */
25    
26 jfenwick 3981 /************************************************************************************/
27 gross 3094
28     #include "Paso.h"
29     #include "SparseMatrix.h"
30     #include "Solver.h"
31 gross 3120 #include "BlockOps.h"
32 gross 3158 #include "PasoUtil.h"
33 gross 3094
34     void Paso_SparseMatrix_invMain(Paso_SparseMatrix * A_p, double* inv_diag, int* pivot) {
35 gross 3402 index_t failed=0;
36     register double A11;
37     const dim_t n=A_p->numRows;
38     const dim_t n_block=A_p->row_block_size;
39     const dim_t m_block=A_p->col_block_size;
40     const dim_t block_size=A_p->block_size;
41 gross 3094 dim_t i;
42     register index_t iPtr;
43     index_t* main_ptr=Paso_Pattern_borrowMainDiagonalPointer(A_p->pattern);
44     /* check matrix is square */
45     if (m_block != n_block) {
46 jfenwick 3259 Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_invMain: square block size expected.");
47 gross 3094 }
48 jfenwick 3259 if (Esys_noError()) {
49 gross 3094
50     if (n_block==1) {
51     #pragma omp parallel for private(i, iPtr, A11) schedule(static)
52     for (i = 0; i < n; i++) {
53     iPtr= main_ptr[i];
54     A11=A_p->val[iPtr];
55     if ( ABS(A11) > 0.) {
56     inv_diag[i]=1./A11;
57     } else {
58 gross 3402 failed=1;
59 gross 3094 }
60     }
61     } else if (n_block==2) {
62 gross 3402 #pragma omp parallel for private(i, iPtr) schedule(static)
63 gross 3094 for (i = 0; i < n; i++) {
64     iPtr= main_ptr[i];
65 gross 3402 Paso_BlockOps_invM_2(&inv_diag[i*4], &A_p->val[iPtr*4], &failed);
66 gross 3094 }
67     } else if (n_block==3) {
68 gross 3402 #pragma omp parallel for private(i, iPtr) schedule(static)
69 gross 3094 for (i = 0; i < n; i++) {
70     iPtr= main_ptr[i];
71 gross 3402 Paso_BlockOps_invM_3(&inv_diag[i*9], &A_p->val[iPtr*9], &failed);
72 gross 3094 }
73 gross 3402 } else {
74     #pragma omp parallel for private(i, iPtr) schedule(static)
75 gross 3094 for (i = 0; i < n; i++) {
76     iPtr= main_ptr[i];
77 gross 3402 Paso_BlockOps_Cpy_N(block_size, &inv_diag[i*block_size], &A_p->val[iPtr*block_size]);
78     Paso_BlockOps_invM_N(n_block, &inv_diag[i*block_size], &pivot[i*n_block], &failed);
79     }
80 gross 3094 }
81     }
82 gross 3402 if (failed > 0) {
83     Esys_setError(ZERO_DIVISION_ERROR, "Paso_SparseMatrix_invMain: non-regular main diagonal block.");
84     }
85 gross 3094 }
86     void Paso_SparseMatrix_applyBlockMatrix(Paso_SparseMatrix * A_p, double* block_diag, int* pivot, double*x, double *b) {
87    
88     /* inv_diag=MEMALLOC( A->numRows * A_p-> block_size,double);
89     pivot=MEMALLOC( A->numRows * A->row_block_size */
90     dim_t n=A_p->numRows;
91     dim_t n_block=A_p->row_block_size;
92 gross 3158 Paso_Copy(n_block*n, x,b);
93 gross 3402 Paso_BlockOps_solveAll(n_block,n,block_diag,pivot,x);
94 gross 3094 }
95    

  ViewVC Help
Powered by ViewVC 1.1.26