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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
<center><a href="https://gitlab.com/petsc/petsc/-/blob/9fe822445bcdd45fb93170ff68fa7403d3f52f09/src/ksp/pc/impls/factor/cholesky/cholesky.c">Actual source code: cholesky.c</a></center><br>
<html>
<head>
<title></title>
<meta name="generator" content="c2html 0.9.6">
<meta name="date" content="2025-03-28T21:10:55+00:00">
</head>
<body bgcolor="#FFFFFF">
<pre width=80>
<a name="line1"> 1: </a><font color="#B22222">/*</font>
<a name="line2"> 2: </a><font color="#B22222"> Defines a direct factorization preconditioner for any <a href="../../../../../../manualpages/Mat/Mat.html">Mat</a> implementation</font>
<a name="line3"> 3: </a><font color="#B22222"> Note: this need not be considered a preconditioner since it supplies</font>
<a name="line4"> 4: </a><font color="#B22222"> a direct solver.</font>
<a name="line5"> 5: </a><font color="#B22222">*/</font>
<a name="line6"> 6: </a>#include <A href="../../../../src/ksp/pc/impls/factor/factor.h.html"><../src/ksp/pc/impls/factor/factor.h></A>
<a name="line8"> 8: </a><font color="#4169E1">typedef</font> <font color="#4169E1">struct</font> {
<a name="line9"> 9: </a> PC_Factor hdr;
<a name="line10"> 10: </a> <a href="../../../../../../manualpages/IS/IS.html">IS</a> row, col; <font color="#B22222">/* index sets used for reordering */</font>
<a name="line11"> 11: </a>} PC_Cholesky;
<a name="line13"> 13: </a><strong><font color="#4169E1"><a name="PCSetFromOptions_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCSetFromOptions_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc, PetscOptionItems *PetscOptionsObject)</font></strong>
<a name="line14"> 14: </a>{
<a name="line15"> 15: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line16"> 16: </a> <a href="../../../../../../manualpages/Sys/PetscOptionsHeadBegin.html">PetscOptionsHeadBegin</a>(PetscOptionsObject, <font color="#666666">"Cholesky options"</font>);
<a name="line17"> 17: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCSetFromOptions_Factor(pc, PetscOptionsObject));
<a name="line18"> 18: </a> <a href="../../../../../../manualpages/Sys/PetscOptionsHeadEnd.html">PetscOptionsHeadEnd</a>();
<a name="line19"> 19: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line20"> 20: </a>}
<a name="line22"> 22: </a><strong><font color="#4169E1"><a name="PCSetUp_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCSetUp_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc)</font></strong>
<a name="line23"> 23: </a>{
<a name="line24"> 24: </a> <a href="../../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flg;
<a name="line25"> 25: </a> PC_Cholesky *dir = (PC_Cholesky *)pc->data;
<a name="line26"> 26: </a> <a href="../../../../../../manualpages/Mat/MatSolverType.html">MatSolverType</a> stype;
<a name="line27"> 27: </a> <a href="../../../../../../manualpages/Mat/MatFactorError.html">MatFactorError</a> err;
<a name="line28"> 28: </a> const char *prefix;
<a name="line30"> 30: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line31"> 31: </a> pc->failedreason = <a href="../../../../../../manualpages/PC/PCFailedReason.html">PC_NOERROR</a>;
<a name="line32"> 32: </a> <font color="#4169E1">if</font> (dir->hdr.reusefill && pc->setupcalled) ((PC_Factor *)dir)->info.fill = dir->hdr.actualfill;
<a name="line34"> 34: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/PC/PCGetOptionsPrefix.html">PCGetOptionsPrefix</a>(pc, &prefix));
<a name="line35"> 35: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatSetOptionsPrefixFactor.html">MatSetOptionsPrefixFactor</a>(pc->pmat, prefix));
<a name="line37"> 37: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatSetErrorIfFailure.html">MatSetErrorIfFailure</a>(pc->pmat, pc->erroriffailure));
<a name="line38"> 38: </a> <font color="#4169E1">if</font> (dir->hdr.inplace) {
<a name="line39"> 39: </a> <a href="../../../../../../manualpages/Mat/MatFactorType.html">MatFactorType</a> ftype;
<a name="line41"> 41: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatGetFactorType.html">MatGetFactorType</a>(pc->pmat, &ftype));
<a name="line42"> 42: </a> <font color="#4169E1">if</font> (ftype == <a href="../../../../../../manualpages/Mat/MatFactorType.html">MAT_FACTOR_NONE</a>) {
<a name="line43"> 43: </a> <font color="#4169E1">if</font> (dir->row && dir->col && (dir->row != dir->col)) <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&dir->row));
<a name="line44"> 44: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&dir->col));
<a name="line45"> 45: </a> <font color="#B22222">/* This should only get the ordering if needed, but since <a href="../../../../../../manualpages/Mat/MatGetFactor.html">MatGetFactor</a>() is not called we can't know if it is needed */</font>
<a name="line46"> 46: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCFactorSetDefaultOrdering_Factor(pc));
<a name="line47"> 47: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/MatGraphOperations/MatGetOrdering.html">MatGetOrdering</a>(pc->pmat, ((PC_Factor *)dir)->ordering, &dir->row, &dir->col));
<a name="line48"> 48: </a> <font color="#4169E1">if</font> (dir->col && (dir->row != dir->col)) { <font color="#B22222">/* only use row ordering for SBAIJ */</font>
<a name="line49"> 49: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&dir->col));
<a name="line50"> 50: </a> }
<a name="line51"> 51: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatCholeskyFactor.html">MatCholeskyFactor</a>(pc->pmat, dir->row, &((PC_Factor *)dir)->info));
<a name="line52"> 52: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatFactorGetError.html">MatFactorGetError</a>(pc->pmat, &err));
<a name="line53"> 53: </a> <font color="#4169E1">if</font> (err) { <font color="#B22222">/* Factor() fails */</font>
<a name="line54"> 54: </a> pc->failedreason = (<a href="../../../../../../manualpages/PC/PCFailedReason.html">PCFailedReason</a>)err;
<a name="line55"> 55: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line56"> 56: </a> }
<a name="line57"> 57: </a> }
<a name="line58"> 58: </a> ((PC_Factor *)dir)->fact = pc->pmat;
<a name="line59"> 59: </a> } <font color="#4169E1">else</font> {
<a name="line60"> 60: </a> <a href="../../../../../../manualpages/Mat/MatInfo.html">MatInfo</a> info;
<a name="line62"> 62: </a> <font color="#4169E1">if</font> (!pc->setupcalled) {
<a name="line63"> 63: </a> <a href="../../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> canuseordering;
<a name="line65"> 65: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/PC/PCFactorSetUpMatSolverType.html">PCFactorSetUpMatSolverType</a>(pc));
<a name="line66"> 66: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatFactorGetCanUseOrdering.html">MatFactorGetCanUseOrdering</a>(((PC_Factor *)dir)->fact, &canuseordering));
<a name="line67"> 67: </a> <font color="#4169E1">if</font> (canuseordering) {
<a name="line68"> 68: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCFactorSetDefaultOrdering_Factor(pc));
<a name="line69"> 69: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/MatGraphOperations/MatGetOrdering.html">MatGetOrdering</a>(pc->pmat, ((PC_Factor *)dir)->ordering, &dir->row, &dir->col));
<a name="line70"> 70: </a> <font color="#B22222">/* check if dir->row == dir->col */</font>
<a name="line71"> 71: </a> <font color="#4169E1">if</font> (dir->row) {
<a name="line72"> 72: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISEqual.html">ISEqual</a>(dir->row, dir->col, &flg));
<a name="line73"> 73: </a> <a href="../../../../../../manualpages/Sys/PetscCheck.html">PetscCheck</a>(flg, <a href="../../../../../../manualpages/Sys/PETSC_COMM_SELF.html">PETSC_COMM_SELF</a>, <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_ERR_ARG_INCOMP</a>, <font color="#666666">"row and column permutations must be equal"</font>);
<a name="line74"> 74: </a> }
<a name="line75"> 75: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&dir->col)); <font color="#B22222">/* only pass one ordering into CholeskyFactor */</font>
<a name="line77"> 77: </a> flg = <a href="../../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>;
<a name="line78"> 78: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Sys/PetscOptionsGetBool.html">PetscOptionsGetBool</a>(((<a href="../../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)->options, ((<a href="../../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)->prefix, <font color="#666666">"-pc_factor_nonzeros_along_diagonal"</font>, &flg, NULL));
<a name="line79"> 79: </a> <font color="#4169E1">if</font> (flg) {
<a name="line80"> 80: </a> <a href="../../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> tol = 1.e-10;
<a name="line81"> 81: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Sys/PetscOptionsGetReal.html">PetscOptionsGetReal</a>(((<a href="../../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)->options, ((<a href="../../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)->prefix, <font color="#666666">"-pc_factor_nonzeros_along_diagonal"</font>, &tol, NULL));
<a name="line82"> 82: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatReorderForNonzeroDiagonal.html">MatReorderForNonzeroDiagonal</a>(pc->pmat, tol, dir->row, dir->row));
<a name="line83"> 83: </a> }
<a name="line84"> 84: </a> }
<a name="line85"> 85: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatCholeskyFactorSymbolic.html">MatCholeskyFactorSymbolic</a>(((PC_Factor *)dir)->fact, pc->pmat, dir->row, &((PC_Factor *)dir)->info));
<a name="line86"> 86: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatGetInfo.html">MatGetInfo</a>(((PC_Factor *)dir)->fact, <a href="../../../../../../manualpages/Mat/MatInfoType.html">MAT_LOCAL</a>, &info));
<a name="line87"> 87: </a> dir->hdr.actualfill = info.fill_ratio_needed;
<a name="line88"> 88: </a> } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (pc->flag != <a href="../../../../../../manualpages/Mat/MatStructure.html">SAME_NONZERO_PATTERN</a>) {
<a name="line89"> 89: </a> <font color="#4169E1">if</font> (!dir->hdr.reuseordering) {
<a name="line90"> 90: </a> <a href="../../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> canuseordering;
<a name="line92"> 92: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&((PC_Factor *)dir)->fact));
<a name="line93"> 93: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/PC/PCFactorSetUpMatSolverType.html">PCFactorSetUpMatSolverType</a>(pc));
<a name="line94"> 94: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatFactorGetCanUseOrdering.html">MatFactorGetCanUseOrdering</a>(((PC_Factor *)dir)->fact, &canuseordering));
<a name="line95"> 95: </a> <font color="#4169E1">if</font> (canuseordering) {
<a name="line96"> 96: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&dir->row));
<a name="line97"> 97: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCFactorSetDefaultOrdering_Factor(pc));
<a name="line98"> 98: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/MatGraphOperations/MatGetOrdering.html">MatGetOrdering</a>(pc->pmat, ((PC_Factor *)dir)->ordering, &dir->row, &dir->col));
<a name="line99"> 99: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&dir->col)); <font color="#B22222">/* only use dir->row ordering in CholeskyFactor */</font>
<a name="line101">101: </a> flg = <a href="../../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>;
<a name="line102">102: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Sys/PetscOptionsGetBool.html">PetscOptionsGetBool</a>(((<a href="../../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)->options, ((<a href="../../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)->prefix, <font color="#666666">"-pc_factor_nonzeros_along_diagonal"</font>, &flg, NULL));
<a name="line103">103: </a> <font color="#4169E1">if</font> (flg) {
<a name="line104">104: </a> <a href="../../../../../../manualpages/Sys/PetscReal.html">PetscReal</a> tol = 1.e-10;
<a name="line105">105: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Sys/PetscOptionsGetReal.html">PetscOptionsGetReal</a>(((<a href="../../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)->options, ((<a href="../../../../../../manualpages/Sys/PetscObject.html">PetscObject</a>)pc)->prefix, <font color="#666666">"-pc_factor_nonzeros_along_diagonal"</font>, &tol, NULL));
<a name="line106">106: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatReorderForNonzeroDiagonal.html">MatReorderForNonzeroDiagonal</a>(pc->pmat, tol, dir->row, dir->row));
<a name="line107">107: </a> }
<a name="line108">108: </a> }
<a name="line109">109: </a> }
<a name="line110">110: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatCholeskyFactorSymbolic.html">MatCholeskyFactorSymbolic</a>(((PC_Factor *)dir)->fact, pc->pmat, dir->row, &((PC_Factor *)dir)->info));
<a name="line111">111: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatGetInfo.html">MatGetInfo</a>(((PC_Factor *)dir)->fact, <a href="../../../../../../manualpages/Mat/MatInfoType.html">MAT_LOCAL</a>, &info));
<a name="line112">112: </a> dir->hdr.actualfill = info.fill_ratio_needed;
<a name="line113">113: </a> } <font color="#4169E1">else</font> {
<a name="line114">114: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatFactorGetError.html">MatFactorGetError</a>(((PC_Factor *)dir)->fact, &err));
<a name="line115">115: </a> <font color="#4169E1">if</font> (err == MAT_FACTOR_NUMERIC_ZEROPIVOT) {
<a name="line116">116: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatFactorClearError.html">MatFactorClearError</a>(((PC_Factor *)dir)->fact));
<a name="line117">117: </a> pc->failedreason = <a href="../../../../../../manualpages/PC/PCFailedReason.html">PC_NOERROR</a>;
<a name="line118">118: </a> }
<a name="line119">119: </a> }
<a name="line120">120: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatFactorGetError.html">MatFactorGetError</a>(((PC_Factor *)dir)->fact, &err));
<a name="line121">121: </a> <font color="#4169E1">if</font> (err) { <font color="#B22222">/* FactorSymbolic() fails */</font>
<a name="line122">122: </a> pc->failedreason = (<a href="../../../../../../manualpages/PC/PCFailedReason.html">PCFailedReason</a>)err;
<a name="line123">123: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line124">124: </a> }
<a name="line126">126: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatCholeskyFactorNumeric.html">MatCholeskyFactorNumeric</a>(((PC_Factor *)dir)->fact, pc->pmat, &((PC_Factor *)dir)->info));
<a name="line127">127: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatFactorGetError.html">MatFactorGetError</a>(((PC_Factor *)dir)->fact, &err));
<a name="line128">128: </a> <font color="#4169E1">if</font> (err) { <font color="#B22222">/* FactorNumeric() fails */</font>
<a name="line129">129: </a> pc->failedreason = (<a href="../../../../../../manualpages/PC/PCFailedReason.html">PCFailedReason</a>)err;
<a name="line130">130: </a> }
<a name="line131">131: </a> }
<a name="line133">133: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/PC/PCFactorGetMatSolverType.html">PCFactorGetMatSolverType</a>(pc, &stype));
<a name="line134">134: </a> <font color="#4169E1">if</font> (!stype) {
<a name="line135">135: </a> <a href="../../../../../../manualpages/Mat/MatSolverType.html">MatSolverType</a> solverpackage;
<a name="line136">136: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatFactorGetSolverType.html">MatFactorGetSolverType</a>(((PC_Factor *)dir)->fact, &solverpackage));
<a name="line137">137: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/PC/PCFactorSetMatSolverType.html">PCFactorSetMatSolverType</a>(pc, solverpackage));
<a name="line138">138: </a> }
<a name="line139">139: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line140">140: </a>}
<a name="line142">142: </a><strong><font color="#4169E1"><a name="PCReset_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCReset_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc)</font></strong>
<a name="line143">143: </a>{
<a name="line144">144: </a> PC_Cholesky *dir = (PC_Cholesky *)pc->data;
<a name="line146">146: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line147">147: </a> <font color="#4169E1">if</font> (!dir->hdr.inplace && ((PC_Factor *)dir)->fact) <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatDestroy.html">MatDestroy</a>(&((PC_Factor *)dir)->fact));
<a name="line148">148: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&dir->row));
<a name="line149">149: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/IS/ISDestroy.html">ISDestroy</a>(&dir->col));
<a name="line150">150: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line151">151: </a>}
<a name="line153">153: </a><strong><font color="#4169E1"><a name="PCDestroy_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCDestroy_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc)</font></strong>
<a name="line154">154: </a>{
<a name="line155">155: </a> PC_Cholesky *dir = (PC_Cholesky *)pc->data;
<a name="line157">157: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line158">158: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCReset_Cholesky(pc));
<a name="line159">159: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(((PC_Factor *)dir)->ordering));
<a name="line160">160: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(((PC_Factor *)dir)->solvertype));
<a name="line161">161: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCFactorClearComposedFunctions(pc));
<a name="line162">162: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Sys/PetscFree.html">PetscFree</a>(pc->data));
<a name="line163">163: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line164">164: </a>}
<a name="line166">166: </a><strong><font color="#4169E1"><a name="PCApply_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCApply_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../../manualpages/Vec/Vec.html">Vec</a> x, <a href="../../../../../../manualpages/Vec/Vec.html">Vec</a> y)</font></strong>
<a name="line167">167: </a>{
<a name="line168">168: </a> PC_Cholesky *dir = (PC_Cholesky *)pc->data;
<a name="line170">170: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line171">171: </a> <font color="#4169E1">if</font> (dir->hdr.inplace) {
<a name="line172">172: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatSolve.html">MatSolve</a>(pc->pmat, x, y));
<a name="line173">173: </a> } <font color="#4169E1">else</font> {
<a name="line174">174: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatSolve.html">MatSolve</a>(((PC_Factor *)dir)->fact, x, y));
<a name="line175">175: </a> }
<a name="line176">176: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line177">177: </a>}
<a name="line179">179: </a><strong><font color="#4169E1"><a name="PCMatApply_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCMatApply_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../../manualpages/Mat/Mat.html">Mat</a> X, <a href="../../../../../../manualpages/Mat/Mat.html">Mat</a> Y)</font></strong>
<a name="line180">180: </a>{
<a name="line181">181: </a> PC_Cholesky *dir = (PC_Cholesky *)pc->data;
<a name="line183">183: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line184">184: </a> <font color="#4169E1">if</font> (dir->hdr.inplace) {
<a name="line185">185: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatMatSolve.html">MatMatSolve</a>(pc->pmat, X, Y));
<a name="line186">186: </a> } <font color="#4169E1">else</font> {
<a name="line187">187: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatMatSolve.html">MatMatSolve</a>(((PC_Factor *)dir)->fact, X, Y));
<a name="line188">188: </a> }
<a name="line189">189: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line190">190: </a>}
<a name="line192">192: </a><strong><font color="#4169E1"><a name="PCApplySymmetricLeft_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCApplySymmetricLeft_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../../manualpages/Vec/Vec.html">Vec</a> x, <a href="../../../../../../manualpages/Vec/Vec.html">Vec</a> y)</font></strong>
<a name="line193">193: </a>{
<a name="line194">194: </a> PC_Cholesky *dir = (PC_Cholesky *)pc->data;
<a name="line196">196: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line197">197: </a> <font color="#4169E1">if</font> (dir->hdr.inplace) {
<a name="line198">198: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatForwardSolve.html">MatForwardSolve</a>(pc->pmat, x, y));
<a name="line199">199: </a> } <font color="#4169E1">else</font> {
<a name="line200">200: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatForwardSolve.html">MatForwardSolve</a>(((PC_Factor *)dir)->fact, x, y));
<a name="line201">201: </a> }
<a name="line202">202: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line203">203: </a>}
<a name="line205">205: </a><strong><font color="#4169E1"><a name="PCApplySymmetricRight_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCApplySymmetricRight_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../../manualpages/Vec/Vec.html">Vec</a> x, <a href="../../../../../../manualpages/Vec/Vec.html">Vec</a> y)</font></strong>
<a name="line206">206: </a>{
<a name="line207">207: </a> PC_Cholesky *dir = (PC_Cholesky *)pc->data;
<a name="line209">209: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line210">210: </a> <font color="#4169E1">if</font> (dir->hdr.inplace) {
<a name="line211">211: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatBackwardSolve.html">MatBackwardSolve</a>(pc->pmat, x, y));
<a name="line212">212: </a> } <font color="#4169E1">else</font> {
<a name="line213">213: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatBackwardSolve.html">MatBackwardSolve</a>(((PC_Factor *)dir)->fact, x, y));
<a name="line214">214: </a> }
<a name="line215">215: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line216">216: </a>}
<a name="line218">218: </a><strong><font color="#4169E1"><a name="PCApplyTranspose_Cholesky"></a>static <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCApplyTranspose_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../../manualpages/Vec/Vec.html">Vec</a> x, <a href="../../../../../../manualpages/Vec/Vec.html">Vec</a> y)</font></strong>
<a name="line219">219: </a>{
<a name="line220">220: </a> PC_Cholesky *dir = (PC_Cholesky *)pc->data;
<a name="line222">222: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line223">223: </a> <font color="#4169E1">if</font> (dir->hdr.inplace) {
<a name="line224">224: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatSolveTranspose.html">MatSolveTranspose</a>(pc->pmat, x, y));
<a name="line225">225: </a> } <font color="#4169E1">else</font> {
<a name="line226">226: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Mat/MatSolveTranspose.html">MatSolveTranspose</a>(((PC_Factor *)dir)->fact, x, y));
<a name="line227">227: </a> }
<a name="line228">228: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line229">229: </a>}
<a name="line231">231: </a><font color="#B22222">/*@</font>
<a name="line232">232: </a><font color="#B22222"> <a href="../../../../../../manualpages/PC/PCFactorSetReuseOrdering.html">PCFactorSetReuseOrdering</a> - When similar matrices are factored, this</font>
<a name="line233">233: </a><font color="#B22222"> causes the ordering computed in the first factor to be used for all</font>
<a name="line234">234: </a><font color="#B22222"> following factors.</font>
<a name="line236">236: </a><font color="#B22222"> Logically Collective</font>
<a name="line238">238: </a><font color="#B22222"> Input Parameters:</font>
<a name="line239">239: </a><font color="#B22222">+ pc - the preconditioner context</font>
<a name="line240">240: </a><font color="#B22222">- flag - `<a href="../../../../../../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>` to reuse else `<a href="../../../../../../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>`</font>
<a name="line242">242: </a><font color="#B22222"> Options Database Key:</font>
<a name="line243">243: </a><font color="#B22222">. -pc_factor_reuse_ordering - Activate `<a href="../../../../../../manualpages/PC/PCFactorSetReuseOrdering.html">PCFactorSetReuseOrdering</a>()`</font>
<a name="line245">245: </a><font color="#B22222"> Level: intermediate</font>
<a name="line247">247: </a><font color="#B22222">.seealso: [](ch_ksp), `<a href="../../../../../../manualpages/PC/PCLU.html">PCLU</a>`, `<a href="../../../../../../manualpages/PC/PCCHOLESKY.html">PCCHOLESKY</a>`, `<a href="../../../../../../manualpages/PC/PCFactorSetReuseFill.html">PCFactorSetReuseFill</a>()`</font>
<a name="line248">248: </a><font color="#B22222">@*/</font>
<a name="line249">249: </a><strong><font color="#4169E1"><a name="PCFactorSetReuseOrdering"></a><a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../../../../../../manualpages/PC/PCFactorSetReuseOrdering.html">PCFactorSetReuseOrdering</a>(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc, <a href="../../../../../../manualpages/Sys/PetscBool.html">PetscBool</a> flag)</font></strong>
<a name="line250">250: </a>{
<a name="line251">251: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line254">254: </a> <a href="../../../../../../manualpages/Sys/PetscTryMethod.html">PetscTryMethod</a>(pc, <font color="#666666">"PCFactorSetReuseOrdering_C"</font>, (<a href="../../../../../../manualpages/PC/PC.html">PC</a>, <a href="../../../../../../manualpages/Sys/PetscBool.html">PetscBool</a>), (pc, flag));
<a name="line255">255: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line256">256: </a>}
<a name="line258">258: </a><font color="#B22222">/*MC</font>
<a name="line259">259: </a><font color="#B22222"> <a href="../../../../../../manualpages/PC/PCCHOLESKY.html">PCCHOLESKY</a> - Uses a direct solver, based on Cholesky factorization, as a preconditioner</font>
<a name="line261">261: </a><font color="#B22222"> Options Database Keys:</font>
<a name="line262">262: </a><font color="#B22222">+ -pc_factor_reuse_ordering - Activate `<a href="../../../../../../manualpages/PC/PCFactorSetReuseOrdering.html">PCFactorSetReuseOrdering</a>()`</font>
<a name="line263">263: </a><font color="#B22222">. -pc_factor_mat_solver_type - Actives `<a href="../../../../../../manualpages/PC/PCFactorSetMatSolverType.html">PCFactorSetMatSolverType</a>()` to choose the direct solver, like superlu</font>
<a name="line264">264: </a><font color="#B22222">. -pc_factor_reuse_fill - Activates `<a href="../../../../../../manualpages/PC/PCFactorSetReuseFill.html">PCFactorSetReuseFill</a>()`</font>
<a name="line265">265: </a><font color="#B22222">. -pc_factor_fill <fill> - Sets the explected fill amount</font>
<a name="line266">266: </a><font color="#B22222">. -pc_factor_in_place - Activates in-place factorization</font>
<a name="line267">267: </a><font color="#B22222">- -pc_factor_mat_ordering_type <nd,rcm,...> - Sets ordering routine used to determine the order the rows are used in the factorization to reduce fill</font>
<a name="line268">268: </a><font color="#B22222"> and thus be more effective</font>
<a name="line270">270: </a><font color="#B22222"> Level: beginner</font>
<a name="line272">272: </a><font color="#B22222"> Notes:</font>
<a name="line273">273: </a><font color="#B22222"> The Cholesky factorization direct solver, `<a href="../../../../../../manualpages/PC/PCCHOLESKY.html">PCCHOLESKY</a>` is only for symmetric positive-definite (SPD) matrices. For such</font>
<a name="line274">274: </a><font color="#B22222"> SPD matrices it is more efficient than using the LU factorization direct solver, `<a href="../../../../../../manualpages/PC/PCLU.html">PCLU</a>`.</font>
<a name="line276">276: </a><font color="#B22222"> Not all options work for all matrix formats</font>
<a name="line278">278: </a><font color="#B22222"> Usually this will compute an "exact" solution in one iteration and does</font>
<a name="line279">279: </a><font color="#B22222"> not need a Krylov method (i.e. you can use -ksp_type preonly, or</font>
<a name="line280">280: </a><font color="#B22222"> `<a href="../../../../../../manualpages/KSP/KSPSetType.html">KSPSetType</a>`(ksp,`<a href="../../../../../../manualpages/KSP/KSPPREONLY.html">KSPPREONLY</a>`) for the Krylov method</font>
<a name="line282">282: </a><font color="#B22222">.seealso: [](ch_ksp), `<a href="../../../../../../manualpages/PC/PCCreate.html">PCCreate</a>()`, `<a href="../../../../../../manualpages/PC/PCSetType.html">PCSetType</a>()`, `<a href="../../../../../../manualpages/PC/PCType.html">PCType</a>`, `<a href="../../../../../../manualpages/PC/PC.html">PC</a>`,</font>
<a name="line283">283: </a><font color="#B22222"> `<a href="../../../../../../manualpages/PC/PCILU.html">PCILU</a>`, `<a href="../../../../../../manualpages/PC/PCLU.html">PCLU</a>`, `<a href="../../../../../../manualpages/PC/PCICC.html">PCICC</a>`, `<a href="../../../../../../manualpages/PC/PCFactorSetReuseOrdering.html">PCFactorSetReuseOrdering</a>()`, `<a href="../../../../../../manualpages/PC/PCFactorSetReuseFill.html">PCFactorSetReuseFill</a>()`, `<a href="../../../../../../manualpages/PC/PCFactorGetMatrix.html">PCFactorGetMatrix</a>()`,</font>
<a name="line284">284: </a><font color="#B22222"> `<a href="../../../../../../manualpages/PC/PCFactorSetFill.html">PCFactorSetFill</a>()`, `<a href="../../../../../../manualpages/PC/PCFactorSetShiftType.html">PCFactorSetShiftType</a>()`, `<a href="../../../../../../manualpages/PC/PCFactorSetShiftAmount.html">PCFactorSetShiftAmount</a>()`</font>
<a name="line285">285: </a><font color="#B22222"> `<a href="../../../../../../manualpages/PC/PCFactorSetUseInPlace.html">PCFactorSetUseInPlace</a>()`, `<a href="../../../../../../manualpages/PC/PCFactorGetUseInPlace.html">PCFactorGetUseInPlace</a>()`, `<a href="../../../../../../manualpages/PC/PCFactorSetMatOrderingType.html">PCFactorSetMatOrderingType</a>()`, `<a href="../../../../../../manualpages/PC/PCFactorSetReuseOrdering.html">PCFactorSetReuseOrdering</a>()`</font>
<a name="line286">286: </a><font color="#B22222">M*/</font>
<a name="line288">288: </a><strong><font color="#4169E1"><a name="PCCreate_Cholesky"></a>PETSC_EXTERN <a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PCCreate_Cholesky(<a href="../../../../../../manualpages/PC/PC.html">PC</a> pc)</font></strong>
<a name="line289">289: </a>{
<a name="line290">290: </a> PC_Cholesky *dir;
<a name="line292">292: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionBegin.html">PetscFunctionBegin</a>;
<a name="line293">293: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(<a href="../../../../../../manualpages/Sys/PetscNew.html">PetscNew</a>(&dir));
<a name="line294">294: </a> pc->data = (void *)dir;
<a name="line295">295: </a> <a href="../../../../../../manualpages/Sys/PetscCall.html">PetscCall</a>(PCFactorInitialize(pc, <a href="../../../../../../manualpages/Mat/MatFactorType.html">MAT_FACTOR_CHOLESKY</a>));
<a name="line297">297: </a> ((PC_Factor *)dir)->info.fill = 5.0;
<a name="line299">299: </a> pc->ops->destroy = PCDestroy_Cholesky;
<a name="line300">300: </a> pc->ops->reset = PCReset_Cholesky;
<a name="line301">301: </a> pc->ops->apply = PCApply_Cholesky;
<a name="line302">302: </a> pc->ops->matapply = PCMatApply_Cholesky;
<a name="line303">303: </a> pc->ops->applysymmetricleft = PCApplySymmetricLeft_Cholesky;
<a name="line304">304: </a> pc->ops->applysymmetricright = PCApplySymmetricRight_Cholesky;
<a name="line305">305: </a> pc->ops->applytranspose = PCApplyTranspose_Cholesky;
<a name="line306">306: </a> pc->ops->setup = PCSetUp_Cholesky;
<a name="line307">307: </a> pc->ops->setfromoptions = PCSetFromOptions_Cholesky;
<a name="line308">308: </a> pc->ops->view = PCView_Factor;
<a name="line309">309: </a> pc->ops->applyrichardson = NULL;
<a name="line310">310: </a> <a href="../../../../../../manualpages/Sys/PetscFunctionReturn.html">PetscFunctionReturn</a>(<a href="../../../../../../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>);
<a name="line311">311: </a>}
</pre>
</body>
</html>
|