v0.14.0
Loading...
Searching...
No Matches
TSEPAdapt.hpp
Go to the documentation of this file.
1/**
2 * \file TSEPAdapt.hpp
3 * \brief Step adaptation
4 *
5 * \brief Problem implementation for mix element for large-strain elasticity
6 *
7 * \todo Implementation of plasticity
8 */
9
10#ifndef __TSEPADAPT_HPP__
11#define __TSEPADAPT_HPP__
12
13#include <petsc/private/tsimpl.h>
14
15#define TSADAPTEP "ep"
16
17struct TSAdapt_EP {};
18
19static PetscErrorCode TSAdaptChoose_EP(TSAdapt adapt, TS ts, PetscReal h,
20 PetscInt *next_sc, PetscReal *next_h,
21 PetscBool *accept, PetscReal *wlte,
22 PetscReal *wltea, PetscReal *wlter) {
23 PetscFunctionBegin;
24
25 TSAdapt_EP *basic = static_cast<TSAdapt_EP *>(adapt->data);
26
27 *next_sc = 0; /* Reuse the same order scheme */
28 *wlte = -1; /* Weighted local truncation error was not evaluated */
29 *wltea = -1; /* Weighted absolute local truncation error is not used */
30 *wlter = -1; /* Weighted relative local truncation error is not used */
31
32 *accept = PETSC_TRUE;
33 *next_h = h; /* Reuse the old step */
34
35 SNES snes;
36 ierr = TSGetSNES(ts, &snes);
38
39 SNESConvergedReason reason;
40 ierr = SNESGetConvergedReason(snes, &reason);
42
43 int it;
44 ierr = SNESGetIterationNumber(snes, &it);
46
47 if (reason < 0) {
48 h *= 0.75;
49 *next_h = h;
50 PetscPrintf(
51 PETSC_COMM_WORLD,
52 "\tDiverged set step length: it = %d, h = %3.4g set h = %3.4g \n", it,
53 h, *next_h);
54 } else if (reason > 0) {
55
56 int its_d = 6;
57 ierr = PetscOptionsGetInt(PETSC_NULL, "", "-desired_nb_of_its", &its_d,
58 PETSC_NULL);
60
61 h *= 1;//sqrt(static_cast<double>(its_d) / static_cast<double>(it + 1));
62 *next_h = PetscClipInterval(h, adapt->dt_min, adapt->dt_max);
63 PetscPrintf(
64 PETSC_COMM_WORLD,
65 "\tConverged set step length: it = %d, h = %3.4g set h = %3.4g \n", it,
66 h, *next_h);
67 }
68
69 PetscFunctionReturn(0);
70}
71
72static PetscErrorCode TSAdaptReset_EP(TSAdapt adapt) {
73 TSAdapt_EP *basic = static_cast<TSAdapt_EP *>(adapt->data);
74 PetscFunctionBegin;
75 PetscFunctionReturn(0);
76}
77
78static PetscErrorCode TSAdaptDestroy_EP(TSAdapt adapt) {
79 PetscFunctionBegin;
80 ierr = TSAdaptReset_EP(adapt);
82 ierr = PetscFree(adapt->data);
84 PetscFunctionReturn(0);
85}
86
87PetscErrorCode TSAdaptCreate_EP(TSAdapt adapt) {
88 TSAdapt_EP *ep;
89 PetscFunctionBegin;
90 ierr = PetscNewLog(adapt, &ep);
92 adapt->data = (void *)ep;
93 adapt->ops->choose = TSAdaptChoose_EP;
94 adapt->ops->reset = TSAdaptReset_EP;
95 adapt->ops->destroy = TSAdaptDestroy_EP;
96 PetscFunctionReturn(0);
97}
98
99#endif // __TSEPADAPT_HPP__
static PetscErrorCode TSAdaptReset_EP(TSAdapt adapt)
Definition: TSEPAdapt.hpp:72
static PetscErrorCode TSAdaptChoose_EP(TSAdapt adapt, TS ts, PetscReal h, PetscInt *next_sc, PetscReal *next_h, PetscBool *accept, PetscReal *wlte, PetscReal *wltea, PetscReal *wlter)
Definition: TSEPAdapt.hpp:19
PetscErrorCode TSAdaptCreate_EP(TSAdapt adapt)
Definition: TSEPAdapt.hpp:87
static PetscErrorCode TSAdaptDestroy_EP(TSAdapt adapt)
Definition: TSEPAdapt.hpp:78
static PetscErrorCode ierr
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:483
double h