33 CHKERR SNESGetSolutionUpdate(snes, &dx);
34 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
35 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
40 MPI_Comm comm = PetscObjectComm((PetscObject)
f);
41 PetscSynchronizedPrintf(comm,
"SNES Verify x\n");
50 auto zero_ghost_vec = [](
Vec g) {
58 for (
int i = 0;
i != s; ++
i)
61 CHKERR VecGhostRestoreLocalForm(
g, &
l);
67 auto cache_ptr = boost::make_shared<CacheTuple>();
71 auto set = [&](
auto &fe) {
80 CHKERR SNESGetKSP(snes, &fe.ksp);
82 fe.cacheWeakPtr = cache_ptr;
85 auto unset = [&](
auto &fe) {
104 snes_ctx->
problemName, lit.first, *lit.second,
nullptr, snes_ctx->
bH,
111 MPI_Comm comm = PetscObjectComm((PetscObject)
f);
112 PetscSynchronizedPrintf(comm,
"SNES Verify f FE < %s >\n",
133 CHKERR VecGhostUpdateBegin(
f, ADD_VALUES, SCATTER_REVERSE);
134 CHKERR VecGhostUpdateEnd(
f, ADD_VALUES, SCATTER_REVERSE);
142 PetscErrorCode
SnesMat(SNES snes,
Vec x, Mat
A, Mat B,
void *ctx) {
151 auto cache_ptr = boost::make_shared<CacheTuple>();
155 CHKERR SNESGetSolutionUpdate(snes, &dx);
157 auto set = [&](
auto &fe) {
168 CHKERR SNESGetKSP(snes, &fe.ksp);
170 fe.cacheWeakPtr = cache_ptr;
173 auto unset = [&](
auto &fe) {
180 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
181 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
199 snes_ctx->
problemName, lit.first, *(lit.second),
nullptr, snes_ctx->
bH,
226 CHKERR SNESGetApplicationContext(snes, &snes_ctx);
234 CHKERR SNESGetApplicationContext(snes, &snes_ctx);
242 auto &m_field = snes_ctx->
mField;
244 auto fields_ptr = m_field.get_fields();
247 std::vector<double> lnorms(fields_ptr->size(), 0),
248 norms(fields_ptr->size(), 0);
251 CHKERR SNESGetFunction(snes, &res, NULL, NULL);
254 CHKERR VecGetArrayRead(res, &
r);
257 for (
auto fi : *fields_ptr) {
260 const auto hi = dofs->get<
Unique_mi_tag>().upper_bound(hi_uid);
261 for (
auto lo = dofs->get<
Unique_mi_tag>().lower_bound(lo_uid); lo != hi;
263 const DofIdx loc_idx = (*lo)->getPetscLocalDofIdx();
264 if (loc_idx >= 0 && loc_idx < problem_ptr->nbLocDofsRow) {
265 lnorms[
f] += PetscRealPart(PetscSqr(
r[loc_idx]));
271 CHKERR VecRestoreArrayRead(res, &
r);
273 MPIU_Allreduce(&*lnorms.begin(), &*norms.begin(), lnorms.size(), MPIU_REAL,
274 MPIU_SUM, PetscObjectComm((PetscObject)snes));
278 CHKERR PetscObjectGetTabLevel((PetscObject)snes, &tl);
279 for (
auto t = 0;
t != tl; ++
t)
281 s << its <<
" Function norm " << boost::format(
"%14.12e") % (
double)fgnorm
285 for (
auto fi : *fields_ptr) {
288 s << boost::format(
"%14.12e") % (
double)PetscSqrtReal(norms[
f]);
294 MOFEM_LOG(
"SNES_WORLD", Sev::inform) << s.str();