v0.14.0
Loading...
Searching...
No Matches
TsCtx.hpp
Go to the documentation of this file.
1/** \file TsCtx.hpp
2 * \brief Context for PETSc Time Stepping
3 */
4
5#ifndef __TSCTX_HPP__
6#define __TSCTX_HPP__
7
8#include <petsc/private/tsimpl.h>
9
10#define TSADAPTMOFEM "TSMoFEMAdapt"
11
12namespace MoFEM {
13
14/** \brief Interface for Time Stepping (TS) solver
15 * \ingroup mofem_petsc_solvers
16 */
17struct TsCtx {
18
20 moab::Interface &moab;
21
22 std::string problemName;
23 MoFEMTypes bH; ///< If set to MF_EXIST check if element exist
24
28
44
46
47 TsCtx(MoFEM::Interface &m_field, const std::string &problem_name);
48
49 virtual ~TsCtx() = default;
50
51 /**
52 * @brief Get the loops to do IFunction object
53 *
54 * It is sequence of finite elements used to evaluate the right hand side of
55 * implicit time solver.
56 *
57 * @return FEMethodsSequence&
58 */
60
61 /**
62 * @brief Get the loops to do RHSFunction object
63 *
64 * It is sequence of finite elements used to evaluate the right hand side of
65 * implicit time solver.
66 *
67 * @return FEMethodsSequence&
68 */
70
71 /**
72 * @brief Get the loops to do IJacobian object
73 *
74 * It is sequence of finite elements used to evalite the left hand sie of
75 * implicit time solver.
76 *
77 * @return FEMethodsSequence&
78 */
80
81 /**
82 * @brief Get the loops to do RHSJacobian object
83 *
84 * It is sequence of finite elements used to evalite the left hand sie of
85 * implicit time solver.
86 *
87 * @return FEMethodsSequence&
88 */
90
91 /**
92 * @brief Get the loops to do Monitor object
93 *
94 * It is sequence used to monitor solution of time solver.
95 *
96 * @return FEMethodsSequence&
97 */
99
100 /**
101 * @brief Get the preProcess to do IFunction object
102 *
103 * @return BasicMethodsSequence&
104 */
106
107 /**
108 * @brief Get the postProcess to do IFunction object
109 *
110 * @return BasicMethodsSequence&
111 */
114 }
115
116 /**
117 * @brief Get the preProcess to do IJacobian object
118 *
119 * @return BasicMethodsSequence&
120 */
122
123 /**
124 * @brief Get the postProcess to do IJacobian object
125 *
126 * @return BasicMethodsSequence&
127 */
130 }
131
132 /**
133 * @brief Get the preProcess to do Monitor object
134 *
135 * @return BasicMethodsSequence&
136 */
138
139 /**
140 * @brief Get the postProcess to do Monitor object
141 *
142 * @return BasicMethodsSequence&
143 */
145
146 /**
147 * @brief Get the preProcess to do RHSJacobian object
148 *
149 * @return BasicMethodsSequence&
150 */
153 }
154
155 /**
156 * @brief Get the postProcess to do RHSJacobian object
157 *
158 * @return BasicMethodsSequence&
159 */
162 }
163
164 /**
165 * @brief Get the preProcess to do RHSFunction object
166 *
167 * @return BasicMethodsSequence&
168 */
171 }
172
173 /**
174 * @brief Get the postProcess to do RHSFunction object
175 *
176 * @return BasicMethodsSequence&
177 */
180 }
181
182 /**
183 * @brief Clear loops
184 *
185 * @return MoFEMErrorCode
186 */
188
189 friend PetscErrorCode TsSetIFunction(TS ts, PetscReal t, Vec u, Vec u_t,
190 Vec F, void *ctx);
191 friend PetscErrorCode TsSetIJacobian(TS ts, PetscReal t, Vec u, Vec U_t,
192 PetscReal a, Mat A, Mat B, void *ctx);
193 friend PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u,
194 void *ctx);
195 friend PetscErrorCode TsSetRHSFunction(TS ts, PetscReal t, Vec u, Vec F,
196 void *ctx);
197 friend PetscErrorCode TsSetRHSJacobian(TS ts, PetscReal t, Vec u, Mat A,
198 Mat B, void *ctx);
199
200 friend PetscErrorCode TsSetI2Function(TS ts, PetscReal t, Vec U, Vec U_t,
201 Vec U_tt, Vec F, void *ctx);
202
203 friend PetscErrorCode TsSetI2Jacobian(TS ts, PetscReal t, Vec U, Vec U_t,
204 Vec U_tt, PetscReal v, PetscReal a,
205 Mat J, Mat P, void *ctx);
206
207private:
215
216 boost::movelib::unique_ptr<bool> vecAssembleSwitch;
217 boost::movelib::unique_ptr<bool> matAssembleSwitch;
218};
219
220/**
221 * @brief Set IFunction for TS solver
222 *
223 * <a
224 * href=https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetIFunction.html>See
225 * petsc for details</a>
226 *
227 * @param ts
228 * @param t
229 * @param u
230 * @param u_t
231 * @param F
232 * @param ctx
233 * @return PetscErrorCode
234 */
235PetscErrorCode TsSetIFunction(TS ts, PetscReal t, Vec u, Vec u_t, Vec F,
236 void *ctx);
237
238/**
239 * @brief Set function evaluating jacobian in TS solver
240 *
241 * <a
242 * href=https://www.mcs.anl.gov/petsc/petsc-3.1/docs/manualpages/TS/TSSetIJacobian.html>See
243 * PETSc for details</a>
244 *
245 * @param ts
246 * @param t
247 * @param u
248 * @param u_t
249 * @param a
250 * @param A
251 * @param B
252 * @param ctx
253 * @return PetscErrorCode
254 */
255PetscErrorCode TsSetIJacobian(TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a,
256 Mat A, Mat B, void *ctx);
257
258/**
259 * @brief Set monitor for TS solver
260 *
261 * <a
262 * href=https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSMonitorSet.html>See
263 * PETSc for details</a>
264 *
265 * @param ts
266 * @param step
267 * @param t
268 * @param u
269 * @param ctx
270 * @return PetscErrorCode
271 */
272PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u,
273 void *ctx);
274
275/**
276 * @brief TS solver function
277 *
278 * <a
279 * href=https://www.mcs.anl.gov/petsc/petsc-3.11/docs/manualpages/TS/TSSetRHSFunction.html#TSSetRHSFunction>See
280 * PETSc for details</a>
281 *
282 * @param ts
283 * @param t
284 * @param u
285 * @param F
286 * @param ctx
287 * @return PetscErrorCode
288 */
289PetscErrorCode TsSetRHSFunction(TS ts, PetscReal t, Vec u, Vec F, void *ctx);
290
291/**
292 * @brief TS solver function
293 *
294 * <a
295 * href=https://www.mcs.anl.gov/petsc/petsc-3.11/docs/manualpages/TS/TSSetRHSJacobian.html#TSSetRHSJacobian>See
296 * PETSc for details</a>
297 *
298 * @param ts
299 * @param t
300 * @param u
301 * @param A
302 * @param B
303 * @param ctx
304 * @return PetscErrorCode
305 */
306PetscErrorCode TsSetRHSJacobian(TS ts, PetscReal t, Vec u, Mat A, Mat B,
307 void *ctx);
308
309/**
310 * @brief Calculation Jacobian for second order PDE in time
311 *
312 * <a
313 * href=https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetI2Jacobian.html>See
314 * PETSc for details</a>
315 *
316 * @param ts
317 * @param t time at step/stage being solved
318 * @param u state vectora
319 * @param u_t time derivative of state vector
320 * @param u_tt second time derivative of state vector
321 * @param a shift for u_t
322 * @param aa shift for u_tt
323 * @param A Jacobian of G(U) = F(t,U,W+v*U,W'+a*U), equivalent to dF/dU +
324 * v*dF/dU_t + a*dF/dU_tt
325 * @param B preconditioning matrix for J, may be same as J
326 * @param ctx TsCtx context for matrix evaluation routine
327 * @return PetscErrorCode
328 */
329PetscErrorCode TsSetI2Jacobian(TS ts, PetscReal t, Vec u, Vec u_t, Vec u_tt,
330 PetscReal a, PetscReal aa, Mat A, Mat B,
331 void *ctx);
332
333/**
334 * @brief Calculation the right hand side for second order PDE in time
335 *
336 * <a
337 * href=https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/TS/TSSetI2Function.html>PETSc
338 * for details</a>
339 *
340 * @param ts
341 * @param t
342 * @param u
343 * @param u_t
344 * @param u_tt
345 * @param F
346 * @param ctx
347 * @return PetscErrorCode
348 */
349PetscErrorCode TsSetI2Function(TS ts, PetscReal t, Vec u, Vec u_t, Vec u_tt,
350 Vec F, void *ctx);
351
352/** \brief Custom TSAdaptivity in MoFEM
353 *
354 * \code
355 * CHKERR TSAdaptRegister(TSADAPTMOFEM, TSAdaptCreateMoFEM);
356 * TSAdapt adapt;
357 * CHKERR TSGetAdapt(solver, &adapt);
358 * CHKERR TSAdaptSetType(adapt, TSADAPTMOFEM);
359 * \endcode
360 *
361 */
363
364 TSAdaptMoFEM();
365
366 double alpha; //< step reduction if divergence
367 double gamma; //< adaptivity exponent
368 int desiredIt; //< desired number of iterations
369 PetscBool offApat; //< off adaptivity
370};
371
372static PetscErrorCode TSAdaptChooseMoFEM(TSAdapt adapt, TS ts, PetscReal h,
373 PetscInt *next_sc, PetscReal *next_h,
374 PetscBool *accept, PetscReal *wlte,
375 PetscReal *wltea, PetscReal *wlter);
376static PetscErrorCode TSAdaptResetMoFEM(TSAdapt adapt);
377
378static PetscErrorCode TSAdaptDestroyMoFEM(TSAdapt adapt);
379
380/**
381 * @brief Craete MOFEM adapt
382 *
383 * \code
384 * CHKERR TSAdaptRegister(TSADAPTMOFEM, TSAdaptCreateMoFEM);
385 * TSAdapt adapt;
386 * CHKERR TSGetAdapt(solver, &adapt);
387 * CHKERR TSAdaptSetType(adapt, TSADAPTMOFEM);
388 * \endcode
389 *
390 * @param adapt
391 * @return PetscErrorCode
392 */
393PetscErrorCode TSAdaptCreateMoFEM(TSAdapt adapt);
394
395} // namespace MoFEM
396
397#endif // __TSCTX_HPP__
static Index< 'J', 3 > J
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:97
@ F
const double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
PetscErrorCode TsSetIJacobian(TS ts, PetscReal t, Vec u, Vec u_t, PetscReal a, Mat A, Mat B, void *ctx)
Set function evaluating jacobian in TS solver.
Definition: TsCtx.cpp:165
PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
Definition: TsCtx.cpp:259
PetscErrorCode TsSetI2Function(TS ts, PetscReal t, Vec u, Vec u_t, Vec u_tt, Vec F, void *ctx)
Calculation the right hand side for second order PDE in time.
Definition: TsCtx.cpp:612
PetscErrorCode TsSetRHSFunction(TS ts, PetscReal t, Vec u, Vec F, void *ctx)
TS solver function.
Definition: TsCtx.cpp:323
PetscErrorCode TSAdaptChooseMoFEM(TSAdapt adapt, TS ts, PetscReal h, PetscInt *next_sc, PetscReal *next_h, PetscBool *accept, PetscReal *wlte, PetscReal *wltea, PetscReal *wlter)
Definition: TsCtx.cpp:737
PetscErrorCode TsSetIFunction(TS ts, PetscReal t, Vec u, Vec u_t, Vec F, void *ctx)
Set IFunction for TS solver.
Definition: TsCtx.cpp:56
PetscErrorCode TSAdaptDestroyMoFEM(TSAdapt adapt)
Definition: TsCtx.cpp:791
std::deque< BasicMethodPtr > BasicMethodsSequence
Definition: AuxPETSc.hpp:57
PetscErrorCode TsSetI2Jacobian(TS ts, PetscReal t, Vec u, Vec u_t, Vec u_tt, PetscReal a, PetscReal aa, Mat A, Mat B, void *ctx)
Calculation Jacobian for second order PDE in time.
Definition: TsCtx.cpp:511
PetscErrorCode TSAdaptResetMoFEM(TSAdapt adapt)
Definition: TsCtx.cpp:786
std::deque< PairNameFEMethodPtr > FEMethodsSequence
Definition: AuxPETSc.hpp:56
PetscErrorCode TsSetRHSJacobian(TS ts, PetscReal t, Vec u, Mat A, Mat B, void *ctx)
TS solver function.
Definition: TsCtx.cpp:422
PetscErrorCode TSAdaptCreateMoFEM(TSAdapt adapt)
Craete MOFEM adapt.
Definition: TsCtx.cpp:797
constexpr AssemblyType A
double h
constexpr double t
plate stiffness
Definition: plate.cpp:59
Deprecated interface functions.
Custom TSAdaptivity in MoFEM.
Definition: TsCtx.hpp:362
PetscBool offApat
Definition: TsCtx.hpp:369
Interface for Time Stepping (TS) solver.
Definition: TsCtx.hpp:17
BasicMethodsSequence & getPostProcessRHSFunction()
Get the postProcess to do RHSFunction object.
Definition: TsCtx.hpp:178
PetscLogEvent MOFEM_EVENT_TsCtxI2Jacobian
Definition: TsCtx.hpp:214
MoFEM::BasicMethodsSequence BasicMethodsSequence
Definition: TsCtx.hpp:27
FEMethodsSequence loopsIJacobian
Definition: TsCtx.hpp:29
bool zeroMatrix
Definition: TsCtx.hpp:45
MoFEMTypes bH
If set to MF_EXIST check if element exist.
Definition: TsCtx.hpp:23
moab::Interface & moab
Definition: TsCtx.hpp:20
PetscLogEvent MOFEM_EVENT_TsCtxRHSJacobian
Definition: TsCtx.hpp:209
BasicMethodsSequence & getPostProcessIJacobian()
Get the postProcess to do IJacobian object.
Definition: TsCtx.hpp:128
MoFEM::FEMethodsSequence FEMethodsSequence
Definition: TsCtx.hpp:26
friend PetscErrorCode TsSetIFunction(TS ts, PetscReal t, Vec u, Vec u_t, Vec F, void *ctx)
Set IFunction for TS solver.
Definition: TsCtx.cpp:56
FEMethodsSequence loopsRHSFunction
Definition: TsCtx.hpp:33
friend PetscErrorCode TsSetI2Jacobian(TS ts, PetscReal t, Vec U, Vec U_t, Vec U_tt, PetscReal v, PetscReal a, Mat J, Mat P, void *ctx)
Calculation Jacobian for second order PDE in time.
Definition: TsCtx.cpp:511
PetscLogEvent MOFEM_EVENT_TsCtxMonitor
Definition: TsCtx.hpp:212
BasicMethodsSequence postProcessRHSFunction
Definition: TsCtx.hpp:43
FEMethodsSequence & getLoopsMonitor()
Get the loops to do Monitor object.
Definition: TsCtx.hpp:98
BasicMethodsSequence & getPreProcessMonitor()
Get the preProcess to do Monitor object.
Definition: TsCtx.hpp:137
BasicMethodsSequence preProcessMonitor
Definition: TsCtx.hpp:38
BasicMethodsSequence & getPostProcessRHSJacobian()
Get the postProcess to do RHSJacobian object.
Definition: TsCtx.hpp:160
PetscLogEvent MOFEM_EVENT_TsCtxRHSFunction
Definition: TsCtx.hpp:208
BasicMethodsSequence & getPostProcessIFunction()
Get the postProcess to do IFunction object.
Definition: TsCtx.hpp:112
BasicMethodsSequence preProcessIJacobian
Definition: TsCtx.hpp:34
friend PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
Definition: TsCtx.cpp:259
BasicMethodsSequence & getPreProcessRHSFunction()
Get the preProcess to do RHSFunction object.
Definition: TsCtx.hpp:169
BasicMethodsSequence postProcessIFunction
Definition: TsCtx.hpp:37
friend PetscErrorCode TsSetRHSJacobian(TS ts, PetscReal t, Vec u, Mat A, Mat B, void *ctx)
TS solver function.
Definition: TsCtx.cpp:422
FEMethodsSequence & getLoopsIFunction()
Get the loops to do IFunction object.
Definition: TsCtx.hpp:59
FEMethodsSequence & getLoopsRHSJacobian()
Get the loops to do RHSJacobian object.
Definition: TsCtx.hpp:89
friend PetscErrorCode TsSetIJacobian(TS ts, PetscReal t, Vec u, Vec U_t, PetscReal a, Mat A, Mat B, void *ctx)
Set function evaluating jacobian in TS solver.
Definition: TsCtx.cpp:165
FEMethodsSequence loopsIFunction
Definition: TsCtx.hpp:30
FEMethodsSequence loopsRHSJacobian
Definition: TsCtx.hpp:32
BasicMethodsSequence preProcessIFunction
Definition: TsCtx.hpp:36
FEMethodsSequence loopsMonitor
Definition: TsCtx.hpp:31
virtual ~TsCtx()=default
MoFEM::PairNameFEMethodPtr PairNameFEMethodPtr
Definition: TsCtx.hpp:25
friend PetscErrorCode TsSetI2Function(TS ts, PetscReal t, Vec U, Vec U_t, Vec U_tt, Vec F, void *ctx)
Calculation the right hand side for second order PDE in time.
Definition: TsCtx.cpp:612
BasicMethodsSequence postProcessMonitor
Definition: TsCtx.hpp:39
BasicMethodsSequence preProcessRHSJacobian
Definition: TsCtx.hpp:40
boost::movelib::unique_ptr< bool > vecAssembleSwitch
Definition: TsCtx.hpp:216
BasicMethodsSequence & getPreProcessIFunction()
Get the preProcess to do IFunction object.
Definition: TsCtx.hpp:105
PetscLogEvent MOFEM_EVENT_TsCtxIJacobian
Definition: TsCtx.hpp:211
FEMethodsSequence & getLoopsRHSFunction()
Get the loops to do RHSFunction object.
Definition: TsCtx.hpp:69
FEMethodsSequence & getLoopsIJacobian()
Get the loops to do IJacobian object.
Definition: TsCtx.hpp:79
boost::movelib::unique_ptr< bool > matAssembleSwitch
Definition: TsCtx.hpp:217
MoFEMErrorCode clearLoops()
Clear loops.
Definition: TsCtx.cpp:36
BasicMethodsSequence & getPreProcessRHSJacobian()
Get the preProcess to do RHSJacobian object.
Definition: TsCtx.hpp:151
std::string problemName
Definition: TsCtx.hpp:22
MoFEM::Interface & mField
Definition: TsCtx.hpp:19
friend PetscErrorCode TsSetRHSFunction(TS ts, PetscReal t, Vec u, Vec F, void *ctx)
TS solver function.
Definition: TsCtx.cpp:323
BasicMethodsSequence preProcessRHSFunction
Definition: TsCtx.hpp:41
BasicMethodsSequence postProcessIJacobian
Definition: TsCtx.hpp:35
BasicMethodsSequence & getPostProcessMonitor()
Get the postProcess to do Monitor object.
Definition: TsCtx.hpp:144
PetscLogEvent MOFEM_EVENT_TsCtxIFunction
Definition: TsCtx.hpp:210
BasicMethodsSequence & getPreProcessIJacobian()
Get the preProcess to do IJacobian object.
Definition: TsCtx.hpp:121
BasicMethodsSequence postProcessRHSJacobian
Definition: TsCtx.hpp:42
PetscLogEvent MOFEM_EVENT_TsCtxI2Function
Definition: TsCtx.hpp:213