144 Cout <<
" -------- [SNES_JFNK] Solving..." << finl;
148 Cerr <<
"[SNES_JFNK] Cannot solve any other equation than Cahn_Hilliard yet. Needs to be generalized." << finl;
153 if (
ix.size_array() == 0)
156 DoubleTrav residu(result);
168 VecCreate(PETSC_COMM_WORLD, &v);
170 VecSetFromOptions(v);
173 VecSetOption(v, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE);
174 VecSetValues(v,
ix.size_array(), (PetscInt*)
ix.addr(), residu.
addr(), INSERT_VALUES);
181 PetscInt v_size, r_size;
182 VecGetSize(v, &v_size);
183 VecGetSize(r, &r_size);
188 std::pair<Equation_base&, ArrOfTID&>
pair = { ch,
ix };
189 FormFunction(
nullptr, v, r, &
pair);
193 VecNorm(r, NORM_2, &norm);
194 PetscPrintf(PETSC_COMM_WORLD,
"Résidu F(x) = %g\n", (
double)norm);
197 SNESCreate(PETSC_COMM_WORLD, &snes);
199 SNESSetType(snes, SNESNEWTONLS);
202 SNESSetFunction(snes, r, FormFunction, &
pair);
205 SNESLineSearch linesearch;
206 SNESGetLineSearch(snes, &linesearch);
208 SNESLineSearchSetType(linesearch, SNESLINESEARCHNONE);
212 SNESLineSearchGetType(linesearch, &ls_type);
213 PetscPrintf(PETSC_COMM_WORLD,
"Type of Line Search used: %s\n", ls_type);
218 MatCreateSNESMF(snes, &J);
222 MatMFFDSetFunctionError(J,
erel_);
223 MatMFFDSetType(J,
"ds");
224 MatMFFDDSSetUmin(J,
umin_);
226 SNESSetJacobian(snes, J, J, MatMFFDComputeJacobian,
nullptr);
229 MatView(J, PETSC_VIEWER_STDOUT_WORLD);
230 SNESView(snes, PETSC_VIEWER_STDOUT_WORLD);
231 PetscInt local_size, global_size;
232 VecGetLocalSize(v, &local_size);
233 VecGetSize(v, &global_size);
235 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
236 "Proc %d : local=%d, global=%d\n",
237 (
int)PetscGlobalRank, (
int)local_size, (
int)global_size);
238 PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT);
239 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
240 "Proc %d : nb_rows=%d, nb_rows_tot=%d\n",
242 PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT);
253 SNESSetForceIteration(snes, PETSC_TRUE);
254 SNESSetMaxLinearSolveFailures(snes, 200);
258 SNESGetForceIteration(snes, &force_it);
259 PetscPrintf(PETSC_COMM_WORLD,
"Force iteration: %s\n", force_it ?
"ON" :
"OFF");
262 SNESGetKSP(snes, &ksp);
263 KSPSetType(ksp, KSPGMRES);
264 KSPGMRESSetRestart(ksp,
nkr_);
272 PCSetType(pc, PCNONE);
277 SNESMonitorSet(snes, SNESMonitor, &ch,
nullptr);
288 PetscOptionsView(
nullptr, PETSC_VIEWER_STDOUT_WORLD);
289 PetscOptionsLeft(
nullptr);
292 SNESSetOptionsPrefix(snes,
"mysolver_");
294 SNESSetFromOptions(snes);
296 SNESView(snes, PETSC_VIEWER_STDOUT_SELF);
299 SNESSolve(snes,
nullptr, v);
303 const char *reasonstr;
304 SNESGetConvergedReasonString(snes, &reasonstr);
305 Cout <<
"SNES converged for this reason: " << reasonstr << finl;
308 VecGetValues(v,
ix.size_array(), (PetscInt*)
ix.addr(), residu.
addr());