1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "./LIB/heads.h"
#include "./LIB/protos.h"
/*-----------------------------------------------------------------------*/
void dscale(int , double*, double*, double*);
p4ptr Lvsol2(double *x, int nlev, p4ptr levmat, ilutptr ilusch) ;
int Uvsol2(double *x, int nlev, int n, p4ptr levmat,
ilutptr ilusch);
void SchLsol(ilutptr ilusch, double *y) ;
void SchUsol(ilutptr ilusch, double *y) ;
/*-----------------------------------------------------------------------*/
p4ptr Lvsol2(double *x, int nlev, p4ptr levmat, ilutptr ilusch)
{
/* Macro L-solve -- corresponds to left (L) part of arms
| preconditioning operation --
| on entry :
| x = right- hand side to be operated on by the preconditioner
| on return : x is overwritten
| x = output result of operation
|
| Note : in-place operation -- b and x can occupy the same space..
| --------------------------------------------------------------------*/
/*-------------------- local variables */
int nloc=levmat->n, first, lenB;
p4ptr last=levmat;
/*-------------------- take care of special cases : nlev==0 --> lusol */
if (nlev == 0) {
SchLsol(ilusch,x);
return (last);
}
first = 0;
/*-------------------- descend */
while (levmat) {
nloc=levmat->n;
lenB =levmat->nB;
/*-------------------- left scaling */
if (levmat->D1 != NULL)
dscale(nloc,levmat->D1, &x[first], &x[first]);
/*-------------------- RESTRICTION/ DESCENT OPERATION */
if (lenB)
descend (levmat, &x[first], &x[first]);
first += lenB;
last = levmat;
levmat = levmat->next;
/*---------------------------------------------------------------------
| next level
+--------------------------------------------------------------------*/
}
SchLsol(ilusch,&x[first]);
return last;
}
int Uvsol2(double *x, int nlev, int n, p4ptr levmat,
ilutptr ilusch)
{
/* Macro U-solve -- corresponds to left (L) part of arms
| preconditioning operation --
| on entry :
| b = right- hand side to be operated on by the preconditioner
| on return = x has been overwritten =
| x = output result of operation
|
| Note : in-place operation -- b and x can occupy the same space..
| --------------------------------------------------------------------*/
/*-------------------- local variables */
int nloc, lenB, first;
/*-------------------- work array */
/*-------------------- take care of special cases : nlev==0 --> lusol */
/*-------------------- case of zero levels */
if (nlev == 0) {
SchUsol(ilusch, x);
return(0);
}
/*-------------------- general case */
nloc=levmat->n;
lenB=levmat->nB;
first = n - nloc;
/*-------------------- last level */
first += lenB;
SchUsol(ilusch, &x[first]);
/*-------------------- other levels */
while (levmat) {
nloc = levmat->n;
first -= levmat->nB;
if (levmat->n)
ascend(levmat, &x[first],&x[first]);
/*-------------------- right scaling */
if (levmat->D2 != NULL)
dscale(nloc, levmat->D2, &x[first], &x[first]) ;
levmat = levmat->prev;
}
return 0;
/*-------------------- PROLONGATION/ ASCENT OPERATION */
}
int armsol2(double *x, arms Prec)
{ /* combined preconditioning operation -- combines the
| left and right actions.
|
| on entry :
| x = right- hand side to be operated on by the preconditioner
| on return : x is overwritten -
| x = output result of operation
|
| Note : in-place operation -- b and x can occupy the same space..
| --------------------------------------------------------------------*/
/*-------------------- local variables */
p4ptr levmat = Prec->levmat;
ilutptr ilusch = Prec->ilus;
int nlev = Prec->nlev;
int n = levmat->n;
p4ptr last;
if (nlev == 0) {
n = ilusch->n;
SchLsol(ilusch, x);
SchUsol(ilusch, x);
return 0;
}
last = Lvsol2(x, nlev, levmat, ilusch) ;
Uvsol2(x, nlev, n, last, ilusch) ;
return 0;
}
void SchLsol(ilutptr ilusch, double *y)
{
/*---------------------------------------------------------------------
| Forward solve for Schur complement part =
|----------------------------------------------------------------------
| on entry:
| ilusch = the LU matrix as provided from the ILU functions.
| y = the right-hand-side vector
|
| on return
| y = solution of LU x = y. [overwritten]
|---------------------------------------------------------------------*/
/*-------------------- local variables */
int n = ilusch->n, j, *perm = ilusch->rperm;
double *work = ilusch->wk;
/*-------------------- begin: right scaling */
if (ilusch->D1 != NULL)
dscale(n, ilusch->D1, y, y);
/*-------------------- ONE SIDED ROW PERMS */
if (perm != NULL) {
for (j=0; j<n; j++)
work[perm[j]] = y[j];
/*-------------------- L solve proper */
Lsol(ilusch->L, work, y);
} else
Lsol(ilusch->L, y, y);
/*---------------end of SchLsol---------------------------------------
----------------------------------------------------------------------*/
}
void SchUsol(ilutptr ilusch, double *y)
{
/*---------------------------------------------------------------------
| U-solve for Schur complement -
|----------------------------------------------------------------------
| on entry:
| ilusch = the LU matrix as provided from the ILU functions.
| y = the right-hand-side vector
|
| on return
| y = solution of U x = y. [overwritten on y]
|----------------------------------------------------------------------*/
int n = ilusch->n, j, *perm = ilusch->perm, *cperm;
double *work = ilusch->wk;
/* -------------------- begin by U-solving */
/*-------------------- CASE: column pivoting used (as in ILUTP) */
if (ilusch->perm2 != NULL) {
Usol(ilusch->U, y, y);
cperm = ilusch->perm2;
for (j=0; j<n; j++)
work[cperm[j]] = y[j];
}
else
/*-------------------- CASE: no column pivoting used */
Usol(ilusch->U, y, work);
/*-------------------- generic permutation */
if (perm != NULL) {
for (j=0; j<n; j++)
y[j] = work[perm[j]];
} else
memcpy(y, work,n*sizeof(double));
/*-------------------- case when diagonal scaling is done on columns */
if (ilusch->D2 !=NULL)
dscale(n, ilusch->D2, y, y);
}
/*---------------end of SchUsol---------------------------------------
----------------------------------------------------------------------*/
|