14eb8e494SKris Buschelman /*
24eb8e494SKris Buschelman Provides an interface to the LUSOL package of ....
34eb8e494SKris Buschelman
44eb8e494SKris Buschelman */
5c6db04a5SJed Brown #include <../src/mat/impls/aij/seq/aij.h>
64eb8e494SKris Buschelman
74eb8e494SKris Buschelman #if defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
84eb8e494SKris Buschelman #define LU1FAC lu1fac_
94eb8e494SKris Buschelman #define LU6SOL lu6sol_
104eb8e494SKris Buschelman #define M1PAGE m1page_
114eb8e494SKris Buschelman #define M5SETX m5setx_
124eb8e494SKris Buschelman #define M6RDEL m6rdel_
134eb8e494SKris Buschelman #elif !defined(PETSC_HAVE_FORTRAN_CAPS)
144eb8e494SKris Buschelman #define LU1FAC lu1fac
154eb8e494SKris Buschelman #define LU6SOL lu6sol
164eb8e494SKris Buschelman #define M1PAGE m1page
174eb8e494SKris Buschelman #define M5SETX m5setx
184eb8e494SKris Buschelman #define M6RDEL m6rdel
194eb8e494SKris Buschelman #endif
204eb8e494SKris Buschelman
214eb8e494SKris Buschelman /*
224eb8e494SKris Buschelman Dummy symbols that the MINOS files mi25bfac.f and mi15blas.f may require
234eb8e494SKris Buschelman */
M1PAGE()24d71ae5a4SJacob Faibussowitsch PETSC_EXTERN void M1PAGE()
25d71ae5a4SJacob Faibussowitsch {
264eb8e494SKris Buschelman ;
274eb8e494SKris Buschelman }
M5SETX()28d71ae5a4SJacob Faibussowitsch PETSC_EXTERN void M5SETX()
29d71ae5a4SJacob Faibussowitsch {
304eb8e494SKris Buschelman ;
314eb8e494SKris Buschelman }
324eb8e494SKris Buschelman
M6RDEL()33d71ae5a4SJacob Faibussowitsch PETSC_EXTERN void M6RDEL()
34d71ae5a4SJacob Faibussowitsch {
354eb8e494SKris Buschelman ;
364eb8e494SKris Buschelman }
374eb8e494SKris Buschelman
389371c9d4SSatish Balay PETSC_EXTERN void LU1FAC(int *m, int *n, int *nnz, int *size, int *luparm, double *parmlu, double *data, int *indc, int *indr, int *rowperm, int *colperm, int *collen, int *rowlen, int *colstart, int *rowstart, int *rploc, int *cploc, int *rpinv, int *cpinv, double *w, int *inform);
394eb8e494SKris Buschelman
409371c9d4SSatish Balay PETSC_EXTERN void LU6SOL(int *mode, int *m, int *n, double *rhs, double *x, int *size, int *luparm, double *parmlu, double *data, int *indc, int *indr, int *rowperm, int *colperm, int *collen, int *rowlen, int *colstart, int *rowstart, int *inform);
414eb8e494SKris Buschelman
42f0c56d0fSKris Buschelman typedef struct {
434eb8e494SKris Buschelman double *data;
444eb8e494SKris Buschelman int *indc;
454eb8e494SKris Buschelman int *indr;
464eb8e494SKris Buschelman
474eb8e494SKris Buschelman int *ip;
484eb8e494SKris Buschelman int *iq;
494eb8e494SKris Buschelman int *lenc;
504eb8e494SKris Buschelman int *lenr;
514eb8e494SKris Buschelman int *locc;
524eb8e494SKris Buschelman int *locr;
534eb8e494SKris Buschelman int *iploc;
544eb8e494SKris Buschelman int *iqloc;
554eb8e494SKris Buschelman int *ipinv;
564eb8e494SKris Buschelman int *iqinv;
574eb8e494SKris Buschelman double *mnsw;
584eb8e494SKris Buschelman double *mnsv;
594eb8e494SKris Buschelman
604eb8e494SKris Buschelman double elbowroom;
614eb8e494SKris Buschelman double luroom; /* Extra space allocated when factor fails */
624eb8e494SKris Buschelman double parmlu[30]; /* Input/output to LUSOL */
634eb8e494SKris Buschelman
644eb8e494SKris Buschelman int n; /* Number of rows/columns in matrix */
654eb8e494SKris Buschelman int nz; /* Number of nonzeros */
664eb8e494SKris Buschelman int nnz; /* Number of nonzeros allocated for factors */
674eb8e494SKris Buschelman int luparm[30]; /* Input/output to LUSOL */
684eb8e494SKris Buschelman
69ace3abfcSBarry Smith PetscBool CleanUpLUSOL;
704eb8e494SKris Buschelman
71f0c56d0fSKris Buschelman } Mat_LUSOL;
724eb8e494SKris Buschelman
73*4ee01570SBarry Smith /*
74*4ee01570SBarry Smith LUSOL input/Output Parameters (Description uses C-style indexes
75*4ee01570SBarry Smith
76*4ee01570SBarry Smith Input parameters Typical value
77*4ee01570SBarry Smith luparm(0) = nout File number for printed messages. 6
78*4ee01570SBarry Smith luparm(1) = lprint Print level. 0
79*4ee01570SBarry Smith < 0 suppresses output.
80*4ee01570SBarry Smith = 0 gives error messages.
81*4ee01570SBarry Smith = 1 gives debug output from some of the
82*4ee01570SBarry Smith other routines in LUSOL.
83*4ee01570SBarry Smith >= 2 gives the pivot row and column and the
84*4ee01570SBarry Smith no. of rows and columns involved at
85*4ee01570SBarry Smith each elimination step in lu1fac.
86*4ee01570SBarry Smith luparm(2) = maxcol lu1fac: maximum number of columns 5
87*4ee01570SBarry Smith searched allowed in a Markowitz-type
88*4ee01570SBarry Smith search for the next pivot element.
89*4ee01570SBarry Smith For some of the factorization, the
90*4ee01570SBarry Smith number of rows searched is
91*4ee01570SBarry Smith maxrow = maxcol - 1.
92*4ee01570SBarry Smith
93*4ee01570SBarry Smith Output parameters:
94*4ee01570SBarry Smith
95*4ee01570SBarry Smith luparm(9) = inform Return code from last call to any LU routine.
96*4ee01570SBarry Smith luparm(10) = nsing No. of singularities marked in the
97*4ee01570SBarry Smith output array w(*).
98*4ee01570SBarry Smith luparm(11) = jsing Column index of last singularity.
99*4ee01570SBarry Smith luparm(12) = minlen Minimum recommended value for lena.
100*4ee01570SBarry Smith luparm(13) = maxlen ?
101*4ee01570SBarry Smith luparm(14) = nupdat No. of updates performed by the lu8 routines.
102*4ee01570SBarry Smith luparm(15) = nrank No. of nonempty rows of U.
103*4ee01570SBarry Smith luparm(16) = ndens1 No. of columns remaining when the density of
104*4ee01570SBarry Smith the matrix being factorized reached dens1.
105*4ee01570SBarry Smith luparm(17) = ndens2 No. of columns remaining when the density of
106*4ee01570SBarry Smith the matrix being factorized reached dens2.
107*4ee01570SBarry Smith luparm(18) = jumin The column index associated with dumin.
108*4ee01570SBarry Smith luparm(19) = numl0 No. of columns in initial L.
109*4ee01570SBarry Smith luparm(20) = lenl0 Size of initial L (no. of nonzeros).
110*4ee01570SBarry Smith luparm(21) = lenu0 Size of initial U.
111*4ee01570SBarry Smith luparm(22) = lenl Size of current L.
112*4ee01570SBarry Smith luparm(23) = lenu Size of current U.
113*4ee01570SBarry Smith luparm(24) = lrow Length of row file.
114*4ee01570SBarry Smith luparm(25) = ncp No. of compressions of LU data structures.
115*4ee01570SBarry Smith luparm(26) = mersum lu1fac: sum of Markowitz merit counts.
116*4ee01570SBarry Smith luparm(27) = nutri lu1fac: triangular rows in U.
117*4ee01570SBarry Smith luparm(28) = nltri lu1fac: triangular rows in L.
118*4ee01570SBarry Smith luparm(29) =
119*4ee01570SBarry Smith
120*4ee01570SBarry Smith Input parameters Typical value
121*4ee01570SBarry Smith parmlu(0) = elmax1 Max multiplier allowed in L 10.0
122*4ee01570SBarry Smith during factor.
123*4ee01570SBarry Smith parmlu(1) = elmax2 Max multiplier allowed in L 10.0
124*4ee01570SBarry Smith during updates.
125*4ee01570SBarry Smith parmlu(2) = small Absolute tolerance for eps**0.8
126*4ee01570SBarry Smith treating reals as zero. IBM double: 3.0d-13
127*4ee01570SBarry Smith parmlu(3) = utol1 Absolute tol for flagging eps**0.66667
128*4ee01570SBarry Smith small diagonals of U. IBM double: 3.7d-11
129*4ee01570SBarry Smith parmlu(4) = utol2 Relative tol for flagging eps**0.66667
130*4ee01570SBarry Smith small diagonals of U. IBM double: 3.7d-11
131*4ee01570SBarry Smith parmlu(5) = uspace Factor limiting waste space in U. 3.0
132*4ee01570SBarry Smith In lu1fac, the row or column lists
133*4ee01570SBarry Smith are compressed if their length
134*4ee01570SBarry Smith exceeds uspace times the length of
135*4ee01570SBarry Smith either file after the last compression.
136*4ee01570SBarry Smith parmlu(6) = dens1 The density at which the Markowitz 0.3
137*4ee01570SBarry Smith strategy should search maxcol columns
138*4ee01570SBarry Smith and no rows.
139*4ee01570SBarry Smith parmlu(7) = dens2 the density at which the Markowitz 0.6
140*4ee01570SBarry Smith strategy should search only 1 column
141*4ee01570SBarry Smith or (preferably) use a dense LU for
142*4ee01570SBarry Smith all the remaining rows and columns.
143*4ee01570SBarry Smith
144*4ee01570SBarry Smith Output parameters:
145*4ee01570SBarry Smith parmlu(9) = amax Maximum element in A.
146*4ee01570SBarry Smith parmlu(10) = elmax Maximum multiplier in current L.
147*4ee01570SBarry Smith parmlu(11) = umax Maximum element in current U.
148*4ee01570SBarry Smith parmlu(12) = dumax Maximum diagonal in U.
149*4ee01570SBarry Smith parmlu(13) = dumin Minimum diagonal in U.
150*4ee01570SBarry Smith parmlu(14) =
151*4ee01570SBarry Smith parmlu(15) =
152*4ee01570SBarry Smith parmlu(16) =
153*4ee01570SBarry Smith parmlu(17) =
154*4ee01570SBarry Smith parmlu(18) =
155*4ee01570SBarry Smith parmlu(19) = resid lu6sol: residual after solve with U or U'.
156*4ee01570SBarry Smith ...
157*4ee01570SBarry Smith parmlu(29) =
1584eb8e494SKris Buschelman */
1594eb8e494SKris Buschelman
1604eb8e494SKris Buschelman #define Factorization_Tolerance 1e-1
1614eb8e494SKris Buschelman #define Factorization_Pivot_Tolerance pow(2.2204460492503131E-16, 2.0 / 3.0)
1624eb8e494SKris Buschelman #define Factorization_Small_Tolerance 1e-15 /* pow(DBL_EPSILON, 0.8) */
1634eb8e494SKris Buschelman
MatDestroy_LUSOL(Mat A)16466976f2fSJacob Faibussowitsch static PetscErrorCode MatDestroy_LUSOL(Mat A)
165d71ae5a4SJacob Faibussowitsch {
166f0c56d0fSKris Buschelman Mat_LUSOL *lusol = (Mat_LUSOL *)A->spptr;
1674eb8e494SKris Buschelman
1684eb8e494SKris Buschelman PetscFunctionBegin;
169bf0cc555SLisandro Dalcin if (lusol && lusol->CleanUpLUSOL) {
1709566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->ip));
1719566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->iq));
1729566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->lenc));
1739566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->lenr));
1749566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->locc));
1759566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->locr));
1769566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->iploc));
1779566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->iqloc));
1789566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->ipinv));
1799566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->iqinv));
1809566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->mnsw));
1819566063dSJacob Faibussowitsch PetscCall(PetscFree(lusol->mnsv));
1829566063dSJacob Faibussowitsch PetscCall(PetscFree3(lusol->data, lusol->indc, lusol->indr));
1834eb8e494SKris Buschelman }
1849566063dSJacob Faibussowitsch PetscCall(PetscFree(A->spptr));
1859566063dSJacob Faibussowitsch PetscCall(MatDestroy_SeqAIJ(A));
1863ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1874eb8e494SKris Buschelman }
1884eb8e494SKris Buschelman
MatSolve_LUSOL(Mat A,Vec b,Vec x)18966976f2fSJacob Faibussowitsch static PetscErrorCode MatSolve_LUSOL(Mat A, Vec b, Vec x)
190d71ae5a4SJacob Faibussowitsch {
191f0c56d0fSKris Buschelman Mat_LUSOL *lusol = (Mat_LUSOL *)A->spptr;
192d9ca1df4SBarry Smith double *xx;
193d9ca1df4SBarry Smith const double *bb;
1944eb8e494SKris Buschelman int mode = 5;
1956849ba73SBarry Smith int i, m, n, nnz, status;
1964eb8e494SKris Buschelman
1974eb8e494SKris Buschelman PetscFunctionBegin;
1989566063dSJacob Faibussowitsch PetscCall(VecGetArray(x, &xx));
1999566063dSJacob Faibussowitsch PetscCall(VecGetArrayRead(b, &bb));
2004eb8e494SKris Buschelman
2014eb8e494SKris Buschelman m = n = lusol->n;
2024eb8e494SKris Buschelman nnz = lusol->nnz;
2034eb8e494SKris Buschelman
2042205254eSKarl Rupp for (i = 0; i < m; i++) lusol->mnsv[i] = bb[i];
2054eb8e494SKris Buschelman
2069371c9d4SSatish Balay LU6SOL(&mode, &m, &n, lusol->mnsv, xx, &nnz, lusol->luparm, lusol->parmlu, lusol->data, lusol->indc, lusol->indr, lusol->ip, lusol->iq, lusol->lenc, lusol->lenr, lusol->locc, lusol->locr, &status);
2074eb8e494SKris Buschelman
20828b400f6SJacob Faibussowitsch PetscCheck(!status, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "solve failed, error code %d", status);
2094eb8e494SKris Buschelman
2109566063dSJacob Faibussowitsch PetscCall(VecRestoreArray(x, &xx));
2119566063dSJacob Faibussowitsch PetscCall(VecRestoreArrayRead(b, &bb));
2123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2134eb8e494SKris Buschelman }
2144eb8e494SKris Buschelman
MatLUFactorNumeric_LUSOL(Mat F,Mat A,const MatFactorInfo * info)21566976f2fSJacob Faibussowitsch static PetscErrorCode MatLUFactorNumeric_LUSOL(Mat F, Mat A, const MatFactorInfo *info)
216d71ae5a4SJacob Faibussowitsch {
2174eb8e494SKris Buschelman Mat_SeqAIJ *a;
218719d5645SBarry Smith Mat_LUSOL *lusol = (Mat_LUSOL *)F->spptr;
2194eb8e494SKris Buschelman int m, n, nz, nnz, status;
2206849ba73SBarry Smith int i, rs, re;
2214eb8e494SKris Buschelman int factorizations;
2224eb8e494SKris Buschelman
2234eb8e494SKris Buschelman PetscFunctionBegin;
2249566063dSJacob Faibussowitsch PetscCall(MatGetSize(A, &m, &n));
2254eb8e494SKris Buschelman a = (Mat_SeqAIJ *)A->data;
2264eb8e494SKris Buschelman
22708401ef6SPierre Jolivet PetscCheck(m == lusol->n, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "factorization struct inconsistent");
2284eb8e494SKris Buschelman
2294eb8e494SKris Buschelman factorizations = 0;
2302205254eSKarl Rupp do {
2314eb8e494SKris Buschelman /*******************************************************************/
2324eb8e494SKris Buschelman /* Check the workspace allocation. */
2334eb8e494SKris Buschelman /*******************************************************************/
2344eb8e494SKris Buschelman
2354eb8e494SKris Buschelman nz = a->nz;
2364eb8e494SKris Buschelman nnz = PetscMax(lusol->nnz, (int)(lusol->elbowroom * nz));
2374eb8e494SKris Buschelman nnz = PetscMax(nnz, 5 * n);
2384eb8e494SKris Buschelman
2394eb8e494SKris Buschelman if (nnz < lusol->luparm[12]) {
2404eb8e494SKris Buschelman nnz = (int)(lusol->luroom * lusol->luparm[12]);
2414eb8e494SKris Buschelman } else if ((factorizations > 0) && (lusol->luroom < 6)) {
2424eb8e494SKris Buschelman lusol->luroom += 0.1;
2434eb8e494SKris Buschelman }
2444eb8e494SKris Buschelman
2454eb8e494SKris Buschelman nnz = PetscMax(nnz, (int)(lusol->luroom * (lusol->luparm[22] + lusol->luparm[23])));
2464eb8e494SKris Buschelman
2474eb8e494SKris Buschelman if (nnz > lusol->nnz) {
2489566063dSJacob Faibussowitsch PetscCall(PetscFree3(lusol->data, lusol->indc, lusol->indr));
2499566063dSJacob Faibussowitsch PetscCall(PetscMalloc3(nnz, &lusol->data, nnz, &lusol->indc, nnz, &lusol->indr));
2504eb8e494SKris Buschelman lusol->nnz = nnz;
2514eb8e494SKris Buschelman }
2524eb8e494SKris Buschelman
2534eb8e494SKris Buschelman /* Fill in the data for the problem. (1-based Fortran style) */
2544eb8e494SKris Buschelman nz = 0;
2552205254eSKarl Rupp for (i = 0; i < n; i++) {
2564eb8e494SKris Buschelman rs = a->i[i];
2574eb8e494SKris Buschelman re = a->i[i + 1];
2584eb8e494SKris Buschelman
2592205254eSKarl Rupp while (rs < re) {
2602205254eSKarl Rupp if (a->a[rs] != 0.0) {
2614eb8e494SKris Buschelman lusol->indc[nz] = i + 1;
2624eb8e494SKris Buschelman lusol->indr[nz] = a->j[rs] + 1;
2634eb8e494SKris Buschelman lusol->data[nz] = a->a[rs];
2644eb8e494SKris Buschelman nz++;
2654eb8e494SKris Buschelman }
2664eb8e494SKris Buschelman rs++;
2674eb8e494SKris Buschelman }
2684eb8e494SKris Buschelman }
2694eb8e494SKris Buschelman
2704eb8e494SKris Buschelman /* Do the factorization. */
2719371c9d4SSatish Balay LU1FAC(&m, &n, &nz, &nnz, lusol->luparm, lusol->parmlu, lusol->data, lusol->indc, lusol->indr, lusol->ip, lusol->iq, lusol->lenc, lusol->lenr, lusol->locc, lusol->locr, lusol->iploc, lusol->iqloc, lusol->ipinv, lusol->iqinv, lusol->mnsw, &status);
2724eb8e494SKris Buschelman
2732205254eSKarl Rupp switch (status) {
274d71ae5a4SJacob Faibussowitsch case 0: /* factored */
275d71ae5a4SJacob Faibussowitsch break;
2764eb8e494SKris Buschelman
277d71ae5a4SJacob Faibussowitsch case 7: /* insufficient memory */
278d71ae5a4SJacob Faibussowitsch break;
2794eb8e494SKris Buschelman
2804eb8e494SKris Buschelman case 1:
281d71ae5a4SJacob Faibussowitsch case -1: /* singular */
282d71ae5a4SJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Singular matrix");
2834eb8e494SKris Buschelman
2844eb8e494SKris Buschelman case 3:
285d71ae5a4SJacob Faibussowitsch case 4: /* error conditions */
286d71ae5a4SJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "matrix error");
2874eb8e494SKris Buschelman
288d71ae5a4SJacob Faibussowitsch default: /* unknown condition */
289d71ae5a4SJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "matrix unknown return code");
2904eb8e494SKris Buschelman }
2914eb8e494SKris Buschelman
2924eb8e494SKris Buschelman factorizations++;
2934eb8e494SKris Buschelman } while (status == 7);
294719d5645SBarry Smith F->ops->solve = MatSolve_LUSOL;
295719d5645SBarry Smith F->assembled = PETSC_TRUE;
296719d5645SBarry Smith F->preallocated = PETSC_TRUE;
2973ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2984eb8e494SKris Buschelman }
2994eb8e494SKris Buschelman
MatLUFactorSymbolic_LUSOL(Mat F,Mat A,IS r,IS c,const MatFactorInfo * info)30066976f2fSJacob Faibussowitsch static PetscErrorCode MatLUFactorSymbolic_LUSOL(Mat F, Mat A, IS r, IS c, const MatFactorInfo *info)
301d71ae5a4SJacob Faibussowitsch {
302*4ee01570SBarry Smith /*
303*4ee01570SBarry Smith Input
304*4ee01570SBarry Smith A - matrix to factor
305*4ee01570SBarry Smith r - row permutation (ignored)
306*4ee01570SBarry Smith c - column permutation (ignored)
307*4ee01570SBarry Smith
308*4ee01570SBarry Smith Output
309*4ee01570SBarry Smith F - matrix storing the factorization;
310*4ee01570SBarry Smith */
311f0c56d0fSKris Buschelman Mat_LUSOL *lusol;
312dfbe8321SBarry Smith int i, m, n, nz, nnz;
3134eb8e494SKris Buschelman
3144eb8e494SKris Buschelman PetscFunctionBegin;
3154eb8e494SKris Buschelman /* Check the arguments. */
3169566063dSJacob Faibussowitsch PetscCall(MatGetSize(A, &m, &n));
3174eb8e494SKris Buschelman nz = ((Mat_SeqAIJ *)A->data)->nz;
3184eb8e494SKris Buschelman
3194eb8e494SKris Buschelman /* Create the factorization. */
32035bd34faSBarry Smith F->ops->lufactornumeric = MatLUFactorNumeric_LUSOL;
321f4f49eeaSPierre Jolivet lusol = (Mat_LUSOL *)F->spptr;
3224eb8e494SKris Buschelman
3234eb8e494SKris Buschelman /* Initialize parameters */
3242205254eSKarl Rupp for (i = 0; i < 30; i++) {
3254eb8e494SKris Buschelman lusol->luparm[i] = 0;
3264eb8e494SKris Buschelman lusol->parmlu[i] = 0;
3274eb8e494SKris Buschelman }
3284eb8e494SKris Buschelman
3294eb8e494SKris Buschelman lusol->luparm[1] = -1;
3304eb8e494SKris Buschelman lusol->luparm[2] = 5;
3314eb8e494SKris Buschelman lusol->luparm[7] = 1;
3324eb8e494SKris Buschelman
3334eb8e494SKris Buschelman lusol->parmlu[0] = 1 / Factorization_Tolerance;
3344eb8e494SKris Buschelman lusol->parmlu[1] = 1 / Factorization_Tolerance;
3354eb8e494SKris Buschelman lusol->parmlu[2] = Factorization_Small_Tolerance;
3364eb8e494SKris Buschelman lusol->parmlu[3] = Factorization_Pivot_Tolerance;
3374eb8e494SKris Buschelman lusol->parmlu[4] = Factorization_Pivot_Tolerance;
3384eb8e494SKris Buschelman lusol->parmlu[5] = 3.0;
3394eb8e494SKris Buschelman lusol->parmlu[6] = 0.3;
3404eb8e494SKris Buschelman lusol->parmlu[7] = 0.6;
3414eb8e494SKris Buschelman
3424eb8e494SKris Buschelman /* Allocate the workspace needed by LUSOL. */
3434eb8e494SKris Buschelman lusol->elbowroom = PetscMax(lusol->elbowroom, info->fill);
3444eb8e494SKris Buschelman nnz = PetscMax((int)(lusol->elbowroom * nz), 5 * n);
3454eb8e494SKris Buschelman
3464eb8e494SKris Buschelman lusol->n = n;
3474eb8e494SKris Buschelman lusol->nz = nz;
3484eb8e494SKris Buschelman lusol->nnz = nnz;
3494eb8e494SKris Buschelman lusol->luroom = 1.75;
3504eb8e494SKris Buschelman
351d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->ip));
352d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->iq));
353d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->lenc));
354d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->lenr));
355d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->locc));
356d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->locr));
357d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->iploc));
358d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->iqloc));
359d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->ipinv));
360d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(int) * n, &lusol->iqinv));
361d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(double) * n, &lusol->mnsw));
362d0609cedSBarry Smith PetscCall(PetscMalloc(sizeof(double) * n, &lusol->mnsv));
3639566063dSJacob Faibussowitsch PetscCall(PetscMalloc3(nnz, &lusol->data, nnz, &lusol->indc, nnz, &lusol->indr));
3642205254eSKarl Rupp
3654eb8e494SKris Buschelman lusol->CleanUpLUSOL = PETSC_TRUE;
36635bd34faSBarry Smith F->ops->lufactornumeric = MatLUFactorNumeric_LUSOL;
3673ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3684eb8e494SKris Buschelman }
3694eb8e494SKris Buschelman
MatFactorGetSolverType_seqaij_lusol(Mat A,MatSolverType * type)37066976f2fSJacob Faibussowitsch static PetscErrorCode MatFactorGetSolverType_seqaij_lusol(Mat A, MatSolverType *type)
371d71ae5a4SJacob Faibussowitsch {
37235bd34faSBarry Smith PetscFunctionBegin;
3732692d6eeSBarry Smith *type = MATSOLVERLUSOL;
3743ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
37535bd34faSBarry Smith }
37635bd34faSBarry Smith
MatGetFactor_seqaij_lusol(Mat A,MatFactorType ftype,Mat * F)377d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MatGetFactor_seqaij_lusol(Mat A, MatFactorType ftype, Mat *F)
378d71ae5a4SJacob Faibussowitsch {
379b24902e0SBarry Smith Mat B;
380f0c56d0fSKris Buschelman Mat_LUSOL *lusol;
38135bd34faSBarry Smith int m, n;
3824eb8e494SKris Buschelman
3834eb8e494SKris Buschelman PetscFunctionBegin;
3849566063dSJacob Faibussowitsch PetscCall(MatGetSize(A, &m, &n));
3859566063dSJacob Faibussowitsch PetscCall(MatCreate(PetscObjectComm((PetscObject)A), &B));
3869566063dSJacob Faibussowitsch PetscCall(MatSetSizes(B, PETSC_DECIDE, PETSC_DECIDE, m, n));
3879566063dSJacob Faibussowitsch PetscCall(MatSetType(B, ((PetscObject)A)->type_name));
3889566063dSJacob Faibussowitsch PetscCall(MatSeqAIJSetPreallocation(B, 0, NULL));
3894eb8e494SKris Buschelman
3904dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&lusol));
391b24902e0SBarry Smith B->spptr = lusol;
3922f71e704SKris Buschelman
39366e17bc3SBarry Smith B->trivialsymbolic = PETSC_TRUE;
394f0c56d0fSKris Buschelman B->ops->lufactorsymbolic = MatLUFactorSymbolic_LUSOL;
395f0c56d0fSKris Buschelman B->ops->destroy = MatDestroy_LUSOL;
3962205254eSKarl Rupp
3979566063dSJacob Faibussowitsch PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatFactorGetSolverType_C", MatFactorGetSolverType_seqaij_lusol));
3982205254eSKarl Rupp
399d5f3da31SBarry Smith B->factortype = MAT_FACTOR_LU;
4009566063dSJacob Faibussowitsch PetscCall(PetscFree(B->solvertype));
4019566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(MATSOLVERLUSOL, &B->solvertype));
4023ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
403f0c56d0fSKris Buschelman }
404f0c56d0fSKris Buschelman
MatSolverTypeRegister_Lusol(void)405d1f0640dSPierre Jolivet PETSC_INTERN PetscErrorCode MatSolverTypeRegister_Lusol(void)
406d71ae5a4SJacob Faibussowitsch {
40742c9c57cSBarry Smith PetscFunctionBegin;
4089566063dSJacob Faibussowitsch PetscCall(MatSolverTypeRegister(MATSOLVERLUSOL, MATSEQAIJ, MAT_FACTOR_LU, MatGetFactor_seqaij_lusol));
4093ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
41042c9c57cSBarry Smith }
41142c9c57cSBarry Smith
4122f71e704SKris Buschelman /*MC
41311a5261eSBarry Smith MATSOLVERLUSOL - "lusol" - Provides direct solvers, LU, for sequential matrices
4142f71e704SKris Buschelman via the external package LUSOL.
4152f71e704SKris Buschelman
41611a5261eSBarry Smith Works with `MATSEQAIJ` matrices
4172f71e704SKris Buschelman
4182f71e704SKris Buschelman Level: beginner
4192f71e704SKris Buschelman
4201cc06b55SBarry Smith .seealso: [](ch_matrices), `Mat`, `PCLU`, `PCFactorSetMatSolverType()`, `MatSolverType`
4212f71e704SKris Buschelman M*/
422