32 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
33 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
38 MPI_Comm comm = PetscObjectComm((PetscObject)
f);
39 PetscSynchronizedPrintf(comm,
"SNES Verify x\n");
48 auto zero_ghost_vec = [](
Vec g) {
56 for (
int i = 0;
i != s; ++
i)
59 CHKERR VecGhostRestoreLocalForm(
g, &
l);
65 auto cache_ptr = boost::make_shared<CacheTuple>();
69 auto set = [&](
auto &fe) {
77 CHKERR SNESGetKSP(snes, &fe.ksp);
79 fe.cacheWeakPtr = cache_ptr;
82 auto unset = [&](
auto &fe) {
101 snes_ctx->
problemName, lit.first, *lit.second,
nullptr, snes_ctx->
bH,
108 MPI_Comm comm = PetscObjectComm((PetscObject)
f);
109 PetscSynchronizedPrintf(comm,
"SNES Verify f FE < %s >\n",
130 CHKERR VecGhostUpdateBegin(
f, ADD_VALUES, SCATTER_REVERSE);
131 CHKERR VecGhostUpdateEnd(
f, ADD_VALUES, SCATTER_REVERSE);
139 PetscErrorCode
SnesMat(SNES snes,
Vec x, Mat
A, Mat B,
void *ctx) {
148 auto cache_ptr = boost::make_shared<CacheTuple>();
152 auto set = [&](
auto &fe) {
161 CHKERR SNESGetKSP(snes, &fe.ksp);
163 fe.cacheWeakPtr = cache_ptr;
166 auto unset = [&](
auto &fe) {
173 CHKERR VecGhostUpdateBegin(x, INSERT_VALUES, SCATTER_FORWARD);
174 CHKERR VecGhostUpdateEnd(x, INSERT_VALUES, SCATTER_FORWARD);
192 snes_ctx->
problemName, lit.first, *(lit.second),
nullptr, snes_ctx->
bH,
219 CHKERR SNESGetApplicationContext(snes, &snes_ctx);
227 CHKERR SNESGetApplicationContext(snes, &snes_ctx);
235 auto &m_field = snes_ctx->
mField;
237 auto fields_ptr = m_field.get_fields();
240 std::vector<double> lnorms(fields_ptr->size(), 0),
241 norms(fields_ptr->size(), 0);
244 CHKERR SNESGetFunction(snes, &res, NULL, NULL);
247 CHKERR VecGetArrayRead(res, &
r);
250 for (
auto fi : *fields_ptr) {
253 const auto hi = dofs->get<
Unique_mi_tag>().upper_bound(hi_uid);
254 for (
auto lo = dofs->get<
Unique_mi_tag>().lower_bound(lo_uid); lo != hi;
256 const DofIdx loc_idx = (*lo)->getPetscLocalDofIdx();
257 if (loc_idx >= 0 && loc_idx < problem_ptr->nbLocDofsRow) {
258 lnorms[
f] += PetscRealPart(PetscSqr(
r[loc_idx]));
264 CHKERR VecRestoreArrayRead(res, &
r);
266 MPIU_Allreduce(&*lnorms.begin(), &*norms.begin(), lnorms.size(), MPIU_REAL,
267 MPIU_SUM, PetscObjectComm((PetscObject)snes));
271 CHKERR PetscObjectGetTabLevel((PetscObject)snes, &tl);
272 for (
auto t = 0;
t != tl; ++
t)
274 s << its <<
" Function norm " << boost::format(
"%14.12e") % (
double)fgnorm
278 for (
auto fi : *fields_ptr) {
281 s << boost::format(
"%14.12e") % (
double)PetscSqrtReal(norms[
f]);
287 MOFEM_LOG(
"SNES_WORLD", Sev::inform) << s.str();