v0.14.0
Loading...
Searching...
No Matches
PipelineManager.cpp
Go to the documentation of this file.
1/** \file PipelineManager.cpp
2 * \brief Implementation of basic interface
3 * \ingroup mofem_basic_interface
4 */
5
6
7namespace MoFEM {
8
10PipelineManager::query_interface(boost::typeindex::type_index type_index,
11 UnknownInterface **iface) const {
12 *iface = const_cast<PipelineManager *>(this);
13 return 0;
14}
15
17 : cOre(const_cast<Core &>(core)) {}
18
21 Interface &m_field = cOre;
22 Simple *simple = m_field.getInterface<Simple>();
23 if (!dm)
24 dm = simple->getDM();
25
26 // Add element to calculate lhs of stiff part
27 if (feDomainLhs)
28 CHKERR DMoFEMLoopFiniteElements(dm, simple->getDomainFEName(), feDomainLhs);
29 if (feBoundaryLhs)
30 CHKERR DMoFEMLoopFiniteElements(dm, simple->getBoundaryFEName(),
32 if (feSkeletonLhs)
33 CHKERR DMoFEMLoopFiniteElements(dm, simple->getSkeletonFEName(),
35
36 // Add element to calculate rhs of stiff part
37 if (feDomainRhs)
38 CHKERR DMoFEMLoopFiniteElements(dm, simple->getDomainFEName(), feDomainRhs);
39 if (feBoundaryRhs)
40 CHKERR DMoFEMLoopFiniteElements(dm, simple->getBoundaryFEName(),
42 if (feSkeletonRhs)
43 CHKERR DMoFEMLoopFiniteElements(dm, simple->getSkeletonFEName(),
45
47}
48
50 Interface &m_field = cOre;
51 Simple *simple = m_field.getInterface<Simple>();
52
53 auto copy_dm_struture = [&](auto simple_dm) {
54 MPI_Comm comm;
55 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
56 DMType type;
57 CHKERR DMGetType(simple_dm, &type);
58 dm = createDM(comm, type);
59 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
60 return dm;
61 };
62
63 if (!dm)
64 dm = copy_dm_struture(simple->getDM());
65
66 const MoFEM::Problem *prb_ptr;
67 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
68
69 auto set_dm_section = [&](auto dm) {
71 auto section =
72 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
73 CHKERR DMSetSection(dm, section);
75 };
76 CHKERR set_dm_section(dm);
77
78 boost::shared_ptr<FEMethod> null;
79
80 getDMKspCtx(dm)->clearLoops();
81
82 // Add element to calculate lhs of stiff part
83 if (feDomainLhs)
84 CHKERR DMMoFEMKSPSetComputeOperators(dm, simple->getDomainFEName(),
85 feDomainLhs, null, null);
86 if (feBoundaryLhs)
87 CHKERR DMMoFEMKSPSetComputeOperators(dm, simple->getBoundaryFEName(),
88 feBoundaryLhs, null, null);
89 if (feSkeletonLhs)
90 CHKERR DMMoFEMKSPSetComputeOperators(dm, simple->getSkeletonFEName(),
91 feSkeletonLhs, null, null);
92
93 // Add element to calculate rhs of stiff part
94 if (feDomainRhs)
95 CHKERR DMMoFEMKSPSetComputeRHS(dm, simple->getDomainFEName(), feDomainRhs,
96 null, null);
97 if (feBoundaryRhs)
98 CHKERR DMMoFEMKSPSetComputeRHS(dm, simple->getBoundaryFEName(),
99 feBoundaryRhs, null, null);
100 if (feSkeletonRhs)
101 CHKERR DMMoFEMKSPSetComputeRHS(dm, simple->getSkeletonFEName(),
102 feSkeletonRhs, null, null);
103
104 auto ksp = MoFEM::createKSP(m_field.get_comm());
105 CHKERR KSPSetDM(ksp, dm);
106 return ksp;
107}
108
110 Interface &m_field = cOre;
111 Simple *simple = m_field.getInterface<Simple>();
112
113 auto copy_dm_struture = [&](auto simple_dm) {
114 MPI_Comm comm;
115 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
116 DMType type;
117 CHKERR DMGetType(simple_dm, &type);
118 dm = createDM(comm, type);
119 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
120 return dm;
121 };
122
123 if (!dm)
124 dm = copy_dm_struture(simple->getDM());
125
126 const MoFEM::Problem *prb_ptr;
127 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
128
129 auto set_dm_section = [&](auto dm) {
131 auto section =
132 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
133 CHKERR DMSetSection(dm, section);
135 };
136 CHKERR set_dm_section(dm);
137
138 getDMSnesCtx(dm)->clearLoops();
139
140 boost::shared_ptr<FEMethod> null;
141
142 // Add element to calculate lhs of stiff part
143 if (feDomainLhs)
144 CHKERR DMMoFEMSNESSetJacobian(dm, simple->getDomainFEName(), feDomainLhs,
145 null, null);
146 if (feBoundaryLhs)
147 CHKERR DMMoFEMSNESSetJacobian(dm, simple->getBoundaryFEName(),
148 feBoundaryLhs, null, null);
149 if (feSkeletonLhs)
150 CHKERR DMMoFEMSNESSetJacobian(dm, simple->getSkeletonFEName(),
151 feSkeletonLhs, null, null);
152
153 // Add element to calculate rhs of stiff part
154 if (feDomainRhs)
155 CHKERR DMMoFEMSNESSetFunction(dm, simple->getDomainFEName(), feDomainRhs,
156 null, null);
157 if (feBoundaryRhs)
158 CHKERR DMMoFEMSNESSetFunction(dm, simple->getBoundaryFEName(),
159 feBoundaryRhs, null, null);
160 if (feSkeletonRhs)
161 CHKERR DMMoFEMSNESSetFunction(dm, simple->getSkeletonFEName(),
162 feSkeletonRhs, null, null);
163
164 auto snes = MoFEM::createSNES(m_field.get_comm());
165 CHKERR SNESSetDM(snes, dm);
166 return snes;
167}
168
171 switch (type) {
172 case EX:
173 return createTSEX(dm);
174 break;
175 case IM:
176 return createTSIM(dm);
177 break;
178 case IM2:
179 return createTSIM2(dm);
180 break;
181 case IMEX:
182 return createTSIMEX(dm);
183 break;
184 default:
186 "TS solver handling not implemented");
187 break;
188 }
189 return SmartPetscObj<TS>();
190}
191
193 Interface &m_field = cOre;
194 Simple *simple = m_field.getInterface<Simple>();
195
196 auto copy_dm_struture = [&](auto simple_dm) {
197 MPI_Comm comm;
198 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
199 DMType type;
200 CHKERR DMGetType(simple_dm, &type);
201 dm = createDM(comm, type);
202 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
203 return dm;
204 };
205
206 if (!dm)
207 dm = copy_dm_struture(simple->getDM());
208
209 const MoFEM::Problem *prb_ptr;
210 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
211
212 auto set_dm_section = [&](auto dm) {
214 auto section =
215 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
216 CHKERR DMSetSection(dm, section);
218 };
219 CHKERR set_dm_section(dm);
220
221 boost::shared_ptr<FEMethod> null;
222
223 getDMTsCtx(dm)->clearLoops();
224
225 // Add element to calculate rhs of slow part
227 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getDomainFEName(),
228 feDomainExplicitRhs, null, null);
230 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getBoundaryFEName(),
231 feBoundaryExplicitRhs, null, null);
233 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getSkeletonFEName(),
234 feSkeletonExplicitRhs, null, null);
235
236 // Note: More cases for explict, and implicit time interation cases can be
237 // implemented here.
238
239 auto ts = MoFEM::createTS(m_field.get_comm());
240 CHKERR TSSetDM(ts, dm);
241 return ts;
242}
243
245 Interface &m_field = cOre;
246 Simple *simple = m_field.getInterface<Simple>();
247
248 auto copy_dm_struture = [&](auto simple_dm) {
249 MPI_Comm comm;
250 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
251 DMType type;
252 CHKERR DMGetType(simple_dm, &type);
253 dm = createDM(comm, type);
254 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
255 return dm;
256 };
257
258 if (!dm)
259 dm = copy_dm_struture(simple->getDM());
260
261 const MoFEM::Problem *prb_ptr;
262 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
263
264 auto set_dm_section = [&](auto dm) {
266 auto section =
267 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
268 CHKERR DMSetSection(dm, section);
270 };
271 CHKERR set_dm_section(dm);
272
273 boost::shared_ptr<FEMethod> null;
274
275 // Add element to calculate lhs of stiff part
276 if (feDomainLhs)
277 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getDomainFEName(), feDomainLhs,
278 null, null);
279 if (feBoundaryLhs)
280 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getBoundaryFEName(), feBoundaryLhs,
281 null, null);
282 if (feSkeletonLhs)
283 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getSkeletonFEName(), feSkeletonLhs,
284 null, null);
285
286 // Add element to calculate rhs of stiff part
287 if (feDomainRhs)
288 CHKERR DMMoFEMTSSetIFunction(dm, simple->getDomainFEName(), feDomainRhs,
289 null, null);
290 if (feBoundaryRhs)
291 CHKERR DMMoFEMTSSetIFunction(dm, simple->getBoundaryFEName(), feBoundaryRhs,
292 null, null);
293 if (feSkeletonRhs)
294 CHKERR DMMoFEMTSSetIFunction(dm, simple->getSkeletonFEName(), feSkeletonRhs,
295 null, null);
296
297 // Note: More cases for explict, and implicit time interation cases can be
298 // implemented here.
299
300 auto ts = MoFEM::createTS(m_field.get_comm());
301 CHKERR TSSetDM(ts, dm);
302 return ts;
303}
304
306 Interface &m_field = cOre;
307 Simple *simple = m_field.getInterface<Simple>();
308
309 auto copy_dm_struture = [&](auto simple_dm) {
310 MPI_Comm comm;
311 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
312 DMType type;
313 CHKERR DMGetType(simple_dm, &type);
314 dm = createDM(comm, type);
315 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
316 return dm;
317 };
318
319 if (!dm)
320 dm = copy_dm_struture(simple->getDM());
321
322 const MoFEM::Problem *prb_ptr;
323 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
324
325 auto set_dm_section = [&](auto dm) {
327 auto section =
328 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
329 CHKERR DMSetSection(dm, section);
331 };
332 CHKERR set_dm_section(dm);
333
334 boost::shared_ptr<FEMethod> null;
335
336 // Add element to calculate lhs of stiff part
337 if (feDomainLhs)
338 CHKERR DMMoFEMTSSetI2Jacobian(dm, simple->getDomainFEName(), feDomainLhs,
339 null, null);
340 if (feBoundaryLhs)
341 CHKERR DMMoFEMTSSetI2Jacobian(dm, simple->getBoundaryFEName(),
342 feBoundaryLhs, null, null);
343 if (feSkeletonLhs)
344 CHKERR DMMoFEMTSSetI2Jacobian(dm, simple->getSkeletonFEName(),
345 feSkeletonLhs, null, null);
346
347 // Add element to calculate rhs of stiff part
348 if (feDomainRhs)
349 CHKERR DMMoFEMTSSetI2Function(dm, simple->getDomainFEName(), feDomainRhs,
350 null, null);
351 if (feBoundaryRhs)
352 CHKERR DMMoFEMTSSetI2Function(dm, simple->getBoundaryFEName(),
353 feBoundaryRhs, null, null);
354 if (feSkeletonRhs)
355 CHKERR DMMoFEMTSSetI2Function(dm, simple->getSkeletonFEName(),
356 feSkeletonRhs, null, null);
357
358 // Note: More cases for explict, and implicit time interation cases can be
359 // implemented here.
360
361 auto ts = MoFEM::createTS(m_field.get_comm());
362 CHKERR TSSetDM(ts, dm);
363 return ts;
364}
365
367 Interface &m_field = cOre;
368 Simple *simple = m_field.getInterface<Simple>();
369
370 auto copy_dm_struture = [&](auto simple_dm) {
371 MPI_Comm comm;
372 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
373 DMType type;
374 CHKERR DMGetType(simple_dm, &type);
375 dm = createDM(comm, type);
376 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
377 return dm;
378 };
379
380 if (!dm)
381 dm = copy_dm_struture(simple->getDM());
382
383 const MoFEM::Problem *prb_ptr;
384 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
385
386 auto set_dm_section = [&](auto dm) {
388 auto section =
389 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
390 CHKERR DMSetSection(dm, section);
392 };
393 CHKERR set_dm_section(dm);
394
395 boost::shared_ptr<FEMethod> null;
396
397 // Add element to calculate lhs of stiff part
398 if (feDomainLhs)
399 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getDomainFEName(), feDomainLhs,
400 null, null);
401 if (feBoundaryLhs)
402 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getBoundaryFEName(), feBoundaryLhs,
403 null, null);
404 if (feSkeletonLhs)
405 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getSkeletonFEName(), feSkeletonLhs,
406 null, null);
407
408 // Add element to calculate rhs of stiff part
409 if (feDomainRhs)
410 CHKERR DMMoFEMTSSetIFunction(dm, simple->getDomainFEName(), feDomainRhs,
411 null, null);
412 if (feBoundaryRhs)
413 CHKERR DMMoFEMTSSetIFunction(dm, simple->getBoundaryFEName(), feBoundaryRhs,
414 null, null);
415 if (feSkeletonRhs)
416 CHKERR DMMoFEMTSSetIFunction(dm, simple->getSkeletonFEName(), feSkeletonRhs,
417 null, null);
418
419 // Add element to calculate rhs of stiff part
421 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getDomainFEName(),
422 feDomainExplicitRhs, null, null);
424 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getBoundaryFEName(),
425 feBoundaryExplicitRhs, null, null);
427 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getSkeletonFEName(),
428 feSkeletonExplicitRhs, null, null);
429
430 // Note: More cases for explict, and implicit time interation cases can be
431 // implemented here.
432
433 auto ts = MoFEM::createTS(m_field.get_comm());
434 CHKERR TSSetDM(ts, dm);
435 return ts;
436}
437
438} // namespace MoFEM
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
PetscErrorCode DMMoFEMSNESSetFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES residual evaluation function
Definition DMMoFEM.cpp:704
PetscErrorCode DMMoFEMTSSetIFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set TS implicit function evaluation function
Definition DMMoFEM.cpp:786
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition DMMoFEM.cpp:412
PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set SNES Jacobian evaluation function
Definition DMMoFEM.cpp:745
PetscErrorCode DMMoFEMKSPSetComputeRHS(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set KSP right hand side evaluation function
Definition DMMoFEM.cpp:623
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition DMMoFEM.cpp:572
PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
Definition DMMoFEM.cpp:839
PetscErrorCode DMMoFEMTSSetI2Jacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
Definition DMMoFEM.cpp:1003
PetscErrorCode DMMoFEMTSSetI2Function(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS implicit function evaluation function
Definition DMMoFEM.cpp:961
PetscErrorCode DMMoFEMKSPSetComputeOperators(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
Set KSP operators and push mofem finite element methods.
Definition DMMoFEM.cpp:664
MoFEMErrorCode loopFiniteElements(SmartPetscObj< DM > dm=nullptr)
Iterate finite elements.
SmartPetscObj< SNES > createSNES(SmartPetscObj< DM > dm=nullptr)
Create SNES (nonlinear) solver.
SmartPetscObj< TS > createTSIM(SmartPetscObj< DM > dm=nullptr)
Create TS (time) implicit solver.
SmartPetscObj< TS > createTSIM2(SmartPetscObj< DM > dm=nullptr)
Create TS (time) solver for second order equation in time.
SmartPetscObj< KSP > createKSP(SmartPetscObj< DM > dm=nullptr)
Create KSP (linear) solver.
SmartPetscObj< TS > createTSIMEX(SmartPetscObj< DM > dm=nullptr)
Create TS (time) implicit-explicit solver.
SmartPetscObj< TS > createTSEX(SmartPetscObj< DM > dm=nullptr)
Create TS (time) explit solver.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
auto createKSP(MPI_Comm comm)
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition DMMoFEM.hpp:1045
auto createSNES(MPI_Comm comm)
PetscErrorCode DMMoFEMTSSetRHSFunction(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS the right hand side function
Definition DMMoFEM.cpp:868
auto getDMKspCtx(DM dm)
Get KSP context data structure used by DM.
Definition DMMoFEM.hpp:1017
auto createTS(MPI_Comm comm)
PetscObject getPetscObject(T obj)
auto getDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition DMMoFEM.hpp:1031
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
PetscErrorCode DMMoFEMDuplicateDMCtx(DM dm, DM dm_duplicate)
Duplicate internal data struture.
Definition DMMoFEM.cpp:184
virtual MPI_Comm & get_comm() const =0
Core (interface) class.
Definition Core.hpp:82
Deprecated interface functions.
Section manager is used to create indexes and sections.
Definition ISManager.hpp:23
PipelineManager interface.
boost::shared_ptr< FEMethod > feBoundaryRhs
Element to assemble RHS side by integrating boundary.
boost::shared_ptr< FEMethod > feDomainExplicitRhs
Element to assemble explict Rhs for IMEX solver.
boost::shared_ptr< FEMethod > feBoundaryLhs
Element to assemble LHS side by integrating boundary.
boost::shared_ptr< FEMethod > feSkeletonExplicitRhs
SmartPetscObj< TS > createTS(const TSType type, SmartPetscObj< DM > dm=nullptr)
create TS (time) solver
boost::shared_ptr< FEMethod > feSkeletonLhs
Element to assemble LHS side by integrating skeleton.
boost::shared_ptr< FEMethod > feDomainLhs
Element to assemble LHS side by integrating domain.
boost::shared_ptr< FEMethod > feSkeletonRhs
Element to assemble RHS side by integrating skeleton.
boost::shared_ptr< FEMethod > feDomainRhs
Element to assemble RHS side by integrating domain.
boost::shared_ptr< FEMethod > feBoundaryExplicitRhs
PipelineManager(const MoFEM::Core &core)
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
keeps basic data about problem
Simple interface for fast problem set-up.
Definition Simple.hpp:27
intrusive_ptr for managing petsc objects
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.