6 : mField(m_field), moab(m_field.get_moab()), problemName(problem_name),
17 auto core_log = logging::core::get();
61 CHKERR VecGhostUpdateBegin(u, INSERT_VALUES, SCATTER_FORWARD);
62 CHKERR VecGhostUpdateEnd(u, INSERT_VALUES, SCATTER_FORWARD);
63 CHKERR VecGhostUpdateBegin(u_t, INSERT_VALUES, SCATTER_FORWARD);
64 CHKERR VecGhostUpdateEnd(u_t, INSERT_VALUES, SCATTER_FORWARD);
68 auto zero_ghost_vec = [](
Vec g) {
76 for (
int i = 0;
i != s; ++
i)
79 CHKERR VecGhostRestoreLocalForm(
g, &
l);
87 #if PETSC_VERSION_GE(3, 8, 0)
88 CHKERR TSGetStepNumber(ts, &step);
90 CHKERR TSGetTimeStepNumber(ts, &step);
93 auto cache_ptr = boost::make_shared<CacheTuple>();
96 auto set = [&](
auto &fe) {
109 CHKERR TSGetSNES(ts, &fe.snes);
110 CHKERR SNESGetKSP(fe.snes, &fe.ksp);
112 fe.cacheWeakPtr = cache_ptr;
116 auto unset = [&](
auto &fe) {
138 *(lit.second),
nullptr,
155 CHKERR VecGhostUpdateBegin(
F, ADD_VALUES, SCATTER_REVERSE);
156 CHKERR VecGhostUpdateEnd(
F, ADD_VALUES, SCATTER_REVERSE);
170 Mat
A, Mat B,
void *ctx) {
175 CHKERR VecGhostUpdateBegin(u, INSERT_VALUES, SCATTER_FORWARD);
176 CHKERR VecGhostUpdateEnd(u, INSERT_VALUES, SCATTER_FORWARD);
177 CHKERR VecGhostUpdateBegin(u_t, INSERT_VALUES, SCATTER_FORWARD);
178 CHKERR VecGhostUpdateEnd(u_t, INSERT_VALUES, SCATTER_FORWARD);
185 #if PETSC_VERSION_GE(3, 8, 0)
186 CHKERR TSGetStepNumber(ts, &step);
188 CHKERR TSGetTimeStepNumber(ts, &step);
193 auto cache_ptr = boost::make_shared<CacheTuple>();
196 auto set = [&](
auto &fe) {
211 CHKERR TSGetSNES(ts, &fe.snes);
212 CHKERR SNESGetKSP(fe.snes, &fe.ksp);
214 fe.cacheWeakPtr = cache_ptr;
218 auto unset = [&](
auto &fe) {
239 *(lit.second),
nullptr,
256 CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
257 CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
268 CHKERR VecGhostUpdateBegin(u, INSERT_VALUES, SCATTER_FORWARD);
269 CHKERR VecGhostUpdateEnd(u, INSERT_VALUES, SCATTER_FORWARD);
273 auto cache_ptr = boost::make_shared<CacheTuple>();
276 auto set = [&](
auto &fe) {
281 fe.ts_F = PETSC_NULL;
287 CHKERR TSGetSNES(ts, &fe.snes);
288 CHKERR SNESGetKSP(fe.snes, &fe.ksp);
290 fe.cacheWeakPtr = cache_ptr;
294 auto unset = [&](
auto &fe) {
310 *(lit.second),
nullptr,
331 CHKERR VecGhostUpdateBegin(u, INSERT_VALUES, SCATTER_FORWARD);
332 CHKERR VecGhostUpdateEnd(u, INSERT_VALUES, SCATTER_FORWARD);
336 auto zero_ghost_vec = [](
Vec g) {
344 for (
int i = 0;
i != s; ++
i)
347 CHKERR VecGhostRestoreLocalForm(
g, &
l);
353 auto cache_ptr = boost::make_shared<CacheTuple>();
357 #if PETSC_VERSION_GE(3, 8, 0)
358 CHKERR TSGetStepNumber(ts, &step);
360 CHKERR TSGetTimeStepNumber(ts, &step);
363 auto set = [&](
auto &fe) {
374 fe.cacheWeakPtr = cache_ptr;
378 auto unset = [&](
auto &fe) {
399 *(lit.second),
nullptr,
416 CHKERR VecGhostUpdateBegin(
F, ADD_VALUES, SCATTER_REVERSE);
417 CHKERR VecGhostUpdateEnd(
F, ADD_VALUES, SCATTER_REVERSE);
435 CHKERR VecGhostUpdateBegin(u, INSERT_VALUES, SCATTER_FORWARD);
436 CHKERR VecGhostUpdateEnd(u, INSERT_VALUES, SCATTER_FORWARD);
446 auto cache_ptr = boost::make_shared<CacheTuple>();
450 #if PETSC_VERSION_GE(3, 8, 0)
451 CHKERR TSGetStepNumber(ts, &step);
453 CHKERR TSGetTimeStepNumber(ts, &step);
456 auto set = [&](
auto &fe) {
468 fe.cacheWeakPtr = cache_ptr;
472 auto unset = [&](
auto &fe) {
494 *(lit.second),
nullptr,
511 CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
512 CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
520 PetscReal
a, PetscReal aa, Mat
A, Mat B,
526 CHKERR VecGhostUpdateBegin(u, INSERT_VALUES, SCATTER_FORWARD);
527 CHKERR VecGhostUpdateEnd(u, INSERT_VALUES, SCATTER_FORWARD);
528 CHKERR VecGhostUpdateBegin(u_t, INSERT_VALUES, SCATTER_FORWARD);
529 CHKERR VecGhostUpdateEnd(u_t, INSERT_VALUES, SCATTER_FORWARD);
530 CHKERR VecGhostUpdateBegin(u_tt, INSERT_VALUES, SCATTER_FORWARD);
531 CHKERR VecGhostUpdateEnd(u_tt, INSERT_VALUES, SCATTER_FORWARD);
538 #if PETSC_VERSION_GE(3, 8, 0)
539 CHKERR TSGetStepNumber(ts, &step);
541 CHKERR TSGetTimeStepNumber(ts, &step);
546 auto cache_ptr = boost::make_shared<CacheTuple>();
549 auto set = [&](
auto &fe) {
567 CHKERR TSGetSNES(ts, &fe.snes);
568 CHKERR SNESGetKSP(fe.snes, &fe.ksp);
571 fe.cacheWeakPtr = cache_ptr;
575 auto unset = [&](
auto &fe) {
596 *(lit.second),
nullptr,
613 CHKERR MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY);
614 CHKERR MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY);
625 CHKERR VecGhostUpdateBegin(u, INSERT_VALUES, SCATTER_FORWARD);
626 CHKERR VecGhostUpdateEnd(u, INSERT_VALUES, SCATTER_FORWARD);
627 CHKERR VecGhostUpdateBegin(u_t, INSERT_VALUES, SCATTER_FORWARD);
628 CHKERR VecGhostUpdateEnd(u_t, INSERT_VALUES, SCATTER_FORWARD);
629 CHKERR VecGhostUpdateBegin(u_tt, INSERT_VALUES, SCATTER_FORWARD);
630 CHKERR VecGhostUpdateEnd(u_tt, INSERT_VALUES, SCATTER_FORWARD);
634 auto zero_ghost_vec = [](
Vec g) {
642 for (
int i = 0;
i != s; ++
i)
645 CHKERR VecGhostRestoreLocalForm(
g, &
l);
651 auto cache_ptr = boost::make_shared<CacheTuple>();
655 #if PETSC_VERSION_GE(3, 8, 0)
656 CHKERR TSGetStepNumber(ts, &step);
658 CHKERR TSGetTimeStepNumber(ts, &step);
661 auto set = [&](
auto &fe) {
675 CHKERR TSGetSNES(ts, &fe.snes);
676 CHKERR SNESGetKSP(fe.snes, &fe.ksp);
679 fe.cacheWeakPtr = cache_ptr;
683 auto unset = [&](
auto &fe) {
705 *(lit.second),
nullptr,
722 CHKERR VecGhostUpdateBegin(
F, ADD_VALUES, SCATTER_REVERSE);
723 CHKERR VecGhostUpdateEnd(
F, ADD_VALUES, SCATTER_REVERSE);
757 : alpha(0.75), gamma(0.5), desiredIt(6), offApat(PETSC_FALSE) {
765 <<
"TS adaptivity: alpha = " <<
alpha <<
", gamma = " <<
gamma
770 PetscInt *next_sc, PetscReal *next_h,
771 PetscBool *accept, PetscReal *wlte,
772 PetscReal *wltea, PetscReal *wlter) {
775 auto ts_adapt_mofem = boost::make_shared<TSAdaptMoFEM>();
782 *accept = PETSC_TRUE;
785 if (!ts_adapt_mofem->offApat) {
788 CHKERR TSGetSNES(ts, &snes);
790 SNESConvergedReason reason;
791 CHKERR SNESGetConvergedReason(snes, &reason);
794 CHKERR SNESGetIterationNumber(snes, &it);
797 h *= ts_adapt_mofem->alpha;
800 "TSWORLD", Sev::warning,
801 "\tDiverged set step length: it = %d, h = %3.4g set h = %3.4g \n", it,
803 }
else if (reason > 0) {
804 h *= pow((
static_cast<double>(ts_adapt_mofem->desiredIt) /
805 static_cast<double>(it + 1)),
806 static_cast<double>(ts_adapt_mofem->gamma));
807 *next_h = PetscClipInterval(
h, adapt->dt_min, adapt->dt_max);
809 "TSWORLD", Sev::inform,
810 "\tConverged set step length: it = %d, h = %3.4g set h = %3.4g \n",
820 PetscFunctionReturn(0);
834 PetscFunctionReturn(0);