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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4154 - (show annotations)
Tue Jan 22 09:30:23 2013 UTC (6 years, 2 months 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
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 /************************************************************************************/
18
19 /* Paso: inverts the main diagonal of a SparseMatrix: */
20
21 /************************************************************************************/
22
23 /* Copyrights by ACcESS Australia 2010 */
24 /* Author: Lutz Gross, l.gross@uq.edu.au */
25
26 /************************************************************************************/
27
28 #include "Paso.h"
29 #include "SparseMatrix.h"
30 #include "Solver.h"
31 #include "BlockOps.h"
32 #include "PasoUtil.h"
33
34 void Paso_SparseMatrix_invMain(Paso_SparseMatrix * A_p, double* inv_diag, int* pivot) {
35 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 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 Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_invMain: square block size expected.");
47 }
48 if (Esys_noError()) {
49
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 failed=1;
59 }
60 }
61 } else if (n_block==2) {
62 #pragma omp parallel for private(i, iPtr) schedule(static)
63 for (i = 0; i < n; i++) {
64 iPtr= main_ptr[i];
65 Paso_BlockOps_invM_2(&inv_diag[i*4], &A_p->val[iPtr*4], &failed);
66 }
67 } else if (n_block==3) {
68 #pragma omp parallel for private(i, iPtr) schedule(static)
69 for (i = 0; i < n; i++) {
70 iPtr= main_ptr[i];
71 Paso_BlockOps_invM_3(&inv_diag[i*9], &A_p->val[iPtr*9], &failed);
72 }
73 } else {
74 #pragma omp parallel for private(i, iPtr) schedule(static)
75 for (i = 0; i < n; i++) {
76 iPtr= main_ptr[i];
77 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 }
81 }
82 if (failed > 0) {
83 Esys_setError(ZERO_DIVISION_ERROR, "Paso_SparseMatrix_invMain: non-regular main diagonal block.");
84 }
85 }
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 Paso_Copy(n_block*n, x,b);
93 Paso_BlockOps_solveAll(n_block,n,block_diag,pivot,x);
94 }
95

  ViewVC Help
Powered by ViewVC 1.1.26