73 PetscViewer viewer = vf->viewer;
78 PetscReal *lnorms, *norms;
79 PetscInt numFields,
f, pStart, pEnd, p;
82 LogManager::setLog(
"PETSC");
85 PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 4);
86 CHKERR SNESGetFunction(snes, &res, 0, 0);
87 CHKERR SNESGetDM(snes, &dm);
88 CHKERR DMGetDefaultSection(dm, &s);
89 CHKERR PetscSectionGetNumFields(s, &numFields);
90 CHKERR PetscSectionGetChart(s, &pStart, &pEnd);
91 CHKERR PetscCalloc2(numFields, &lnorms, numFields, &norms);
92 CHKERR VecGetArrayRead(res, &
r);
93 for (p = pStart; p < pEnd; ++p) {
94 for (
f = 0;
f < numFields; ++
f) {
95 PetscInt fdof, foff,
d;
97 CHKERR PetscSectionGetFieldDof(s, p,
f, &fdof);
98 CHKERR PetscSectionGetFieldOffset(s, p,
f, &foff);
99 for (
d = 0;
d < fdof; ++
d)
100 lnorms[
f] += PetscRealPart(PetscSqr(
r[foff +
d]));
103 CHKERR VecRestoreArrayRead(res, &
r);
104 CHKERR MPIU_Allreduce(lnorms, norms, numFields, MPIU_REAL, MPIU_SUM,
105 PetscObjectComm((PetscObject)dm));
106 CHKERR PetscViewerPushFormat(viewer, vf->format);
107 CHKERR PetscViewerASCIIAddTab(viewer, ((PetscObject)snes)->tablevel);
108 CHKERR PetscViewerASCIIPrintf(viewer,
"%3D SNES Function norm %14.12e\n", its,
110 for (
f = 0;
f < numFields; ++
f) {
114 (
double)PetscSqrtReal(norms[
f]));
116 CHKERR PetscViewerASCIISubtractTab(viewer, ((PetscObject)snes)->tablevel);
117 CHKERR PetscViewerPopFormat(viewer);
118 CHKERR PetscFree2(lnorms, norms);
120 LogManager::setLog(
"PETSC");