v0.13.1
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 = createSmartDM(comm, type);
59 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
60 return dm;
61 };
62
63 if (!dm)
64 dm = copy_dm_struture(simple->getDM());
65 else
66 dm = copy_dm_struture(dm);
67
68 const MoFEM::Problem *prb_ptr;
69 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
70
71 auto set_dm_section = [&](auto dm) {
73 auto section =
74 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
75 CHKERR DMSetSection(dm, section);
77 };
78 CHKERR set_dm_section(dm);
79
80 boost::shared_ptr<FEMethod> null;
81
82 smartGetDMKspCtx(dm)->clearLoops();
83
84 // Add element to calculate lhs of stiff part
85 if (feDomainLhs)
86 CHKERR DMMoFEMKSPSetComputeOperators(dm, simple->getDomainFEName(),
87 feDomainLhs, null, null);
88 if (feBoundaryLhs)
89 CHKERR DMMoFEMKSPSetComputeOperators(dm, simple->getBoundaryFEName(),
90 feBoundaryLhs, null, null);
91 if (feSkeletonLhs)
92 CHKERR DMMoFEMKSPSetComputeOperators(dm, simple->getSkeletonFEName(),
93 feSkeletonLhs, null, null);
94
95 // Add element to calculate rhs of stiff part
96 if (feDomainRhs)
97 CHKERR DMMoFEMKSPSetComputeRHS(dm, simple->getDomainFEName(), feDomainRhs,
98 null, null);
99 if (feBoundaryRhs)
100 CHKERR DMMoFEMKSPSetComputeRHS(dm, simple->getBoundaryFEName(),
101 feBoundaryRhs, null, null);
102 if (feSkeletonRhs)
103 CHKERR DMMoFEMKSPSetComputeRHS(dm, simple->getSkeletonFEName(),
104 feSkeletonRhs, null, null);
105
106 auto ksp = MoFEM::createKSP(m_field.get_comm());
107 CHKERR KSPSetDM(ksp, dm);
108 return ksp;
109}
110
112 Interface &m_field = cOre;
113 Simple *simple = m_field.getInterface<Simple>();
114
115 auto copy_dm_struture = [&](auto simple_dm) {
116 MPI_Comm comm;
117 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
118 DMType type;
119 CHKERR DMGetType(simple_dm, &type);
120 dm = createSmartDM(comm, type);
121 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
122 return dm;
123 };
124
125 if (!dm)
126 dm = copy_dm_struture(simple->getDM());
127 else
128 dm = copy_dm_struture(dm);
129
130 const MoFEM::Problem *prb_ptr;
131 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
132
133 auto set_dm_section = [&](auto dm) {
135 auto section =
136 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
137 CHKERR DMSetSection(dm, section);
139 };
140 CHKERR set_dm_section(dm);
141
142 smartGetDMSnesCtx(dm)->clearLoops();
143
144 boost::shared_ptr<FEMethod> null;
145
146 // Add element to calculate lhs of stiff part
147 if (feDomainLhs)
148 CHKERR DMMoFEMSNESSetJacobian(dm, simple->getDomainFEName(), feDomainLhs,
149 null, null);
150 if (feBoundaryLhs)
151 CHKERR DMMoFEMSNESSetJacobian(dm, simple->getBoundaryFEName(),
152 feBoundaryLhs, null, null);
153 if (feSkeletonLhs)
154 CHKERR DMMoFEMSNESSetJacobian(dm, simple->getSkeletonFEName(),
155 feSkeletonLhs, null, null);
156
157 // Add element to calculate rhs of stiff part
158 if (feDomainRhs)
159 CHKERR DMMoFEMSNESSetFunction(dm, simple->getDomainFEName(), feDomainRhs,
160 null, null);
161 if (feBoundaryRhs)
162 CHKERR DMMoFEMSNESSetFunction(dm, simple->getBoundaryFEName(),
163 feBoundaryRhs, null, null);
164 if (feSkeletonRhs)
165 CHKERR DMMoFEMSNESSetFunction(dm, simple->getSkeletonFEName(),
166 feSkeletonRhs, null, null);
167
168 auto snes = MoFEM::createSNES(m_field.get_comm());
169 CHKERR SNESSetDM(snes, dm);
170 return snes;
171}
172
175 switch (type) {
176 case EX:
177 return createTSEX(dm);
178 break;
179 case IM:
180 return createTSIM(dm);
181 break;
182 case IM2:
183 return createTSIM2(dm);
184 break;
185 case IMEX:
186 return createTSIMEX(dm);
187 break;
188 default:
190 "TS solver handling not implemented");
191 break;
192 }
193 return SmartPetscObj<TS>();
194}
195
197 Interface &m_field = cOre;
198 Simple *simple = m_field.getInterface<Simple>();
199
200 auto copy_dm_struture = [&](auto simple_dm) {
201 MPI_Comm comm;
202 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
203 DMType type;
204 CHKERR DMGetType(simple_dm, &type);
205 dm = createSmartDM(comm, type);
206 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
207 return dm;
208 };
209
210 if (!dm)
211 dm = copy_dm_struture(simple->getDM());
212 else
213 dm = copy_dm_struture(dm);
214
215 const MoFEM::Problem *prb_ptr;
216 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
217
218 auto set_dm_section = [&](auto dm) {
220 auto section =
221 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
222 CHKERR DMSetSection(dm, section);
224 };
225 CHKERR set_dm_section(dm);
226
227 boost::shared_ptr<FEMethod> null;
228
229 smartGetDMTsCtx(dm)->clearLoops();
230
231 // Add element to calculate rhs of stiff part
232 if (feDomainRhs)
233 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getDomainFEName(),
234 feDomainExplicitRhs, null, null);
235 if (feBoundaryRhs)
236 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getBoundaryFEName(),
237 feBoundaryExplicitRhs, null, null);
239 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getSkeletonFEName(),
240 feSkeletonExplicitRhs, null, null);
241
242 // Note: More cases for explit, and implicit time ingeration cases can be
243 // implemented here.
244
245 auto ts = MoFEM::createTS(m_field.get_comm());
246 CHKERR TSSetDM(ts, dm);
247 return ts;
248}
249
251 Interface &m_field = cOre;
252 Simple *simple = m_field.getInterface<Simple>();
253
254 auto copy_dm_struture = [&](auto simple_dm) {
255 MPI_Comm comm;
256 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
257 DMType type;
258 CHKERR DMGetType(simple_dm, &type);
259 dm = createSmartDM(comm, type);
260 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
261 return dm;
262 };
263
264 if (!dm)
265 dm = copy_dm_struture(simple->getDM());
266 else
267 dm = copy_dm_struture(dm);
268
269 const MoFEM::Problem *prb_ptr;
270 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
271
272 auto set_dm_section = [&](auto dm) {
274 auto section =
275 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
276 CHKERR DMSetSection(dm, section);
278 };
279 CHKERR set_dm_section(dm);
280
281 boost::shared_ptr<FEMethod> null;
282
283 // Add element to calculate lhs of stiff part
284 if (feDomainLhs)
285 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getDomainFEName(), feDomainLhs,
286 null, null);
287 if (feBoundaryLhs)
288 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getBoundaryFEName(), feBoundaryLhs,
289 null, null);
290 if (feSkeletonLhs)
291 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getSkeletonFEName(), feSkeletonLhs,
292 null, null);
293
294 // Add element to calculate rhs of stiff part
295 if (feDomainRhs)
296 CHKERR DMMoFEMTSSetIFunction(dm, simple->getDomainFEName(), feDomainRhs,
297 null, null);
298 if (feBoundaryRhs)
299 CHKERR DMMoFEMTSSetIFunction(dm, simple->getBoundaryFEName(), feBoundaryRhs,
300 null, null);
301 if (feSkeletonRhs)
302 CHKERR DMMoFEMTSSetIFunction(dm, simple->getSkeletonFEName(), feSkeletonRhs,
303 null, null);
304
305 // Note: More cases for explit, and implicit time ingeration cases can be
306 // implemented here.
307
308 auto ts = MoFEM::createTS(m_field.get_comm());
309 CHKERR TSSetDM(ts, dm);
310 return ts;
311}
312
314 Interface &m_field = cOre;
315 Simple *simple = m_field.getInterface<Simple>();
316
317 auto copy_dm_struture = [&](auto simple_dm) {
318 MPI_Comm comm;
319 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
320 DMType type;
321 CHKERR DMGetType(simple_dm, &type);
322 dm = createSmartDM(comm, type);
323 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
324 return dm;
325 };
326
327 if (!dm)
328 dm = copy_dm_struture(simple->getDM());
329 else
330 dm = copy_dm_struture(dm);
331
332 const MoFEM::Problem *prb_ptr;
333 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
334
335 auto set_dm_section = [&](auto dm) {
337 auto section =
338 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
339 CHKERR DMSetSection(dm, section);
341 };
342 CHKERR set_dm_section(dm);
343
344 boost::shared_ptr<FEMethod> null;
345
346 // Add element to calculate lhs of stiff part
347 if (feDomainLhs)
348 CHKERR DMMoFEMTSSetI2Jacobian(dm, simple->getDomainFEName(), feDomainLhs,
349 null, null);
350 if (feBoundaryLhs)
351 CHKERR DMMoFEMTSSetI2Jacobian(dm, simple->getBoundaryFEName(),
352 feBoundaryLhs, null, null);
353 if (feSkeletonLhs)
354 CHKERR DMMoFEMTSSetI2Jacobian(dm, simple->getSkeletonFEName(),
355 feSkeletonLhs, null, null);
356
357 // Add element to calculate rhs of stiff part
358 if (feDomainRhs)
359 CHKERR DMMoFEMTSSetI2Function(dm, simple->getDomainFEName(), feDomainRhs,
360 null, null);
361 if (feBoundaryRhs)
362 CHKERR DMMoFEMTSSetI2Function(dm, simple->getBoundaryFEName(),
363 feBoundaryRhs, null, null);
364 if (feSkeletonRhs)
365 CHKERR DMMoFEMTSSetI2Function(dm, simple->getSkeletonFEName(),
366 feSkeletonRhs, null, null);
367
368 // Note: More cases for explit, and implicit time ingeration cases can be
369 // implemented here.
370
371 auto ts = MoFEM::createTS(m_field.get_comm());
372 CHKERR TSSetDM(ts, dm);
373 return ts;
374}
375
377 Interface &m_field = cOre;
378 Simple *simple = m_field.getInterface<Simple>();
379
380 auto copy_dm_struture = [&](auto simple_dm) {
381 MPI_Comm comm;
382 CHKERR PetscObjectGetComm(getPetscObject(simple_dm.get()), &comm);
383 DMType type;
384 CHKERR DMGetType(simple_dm, &type);
385 dm = createSmartDM(comm, type);
386 CHKERR DMMoFEMDuplicateDMCtx(simple_dm, dm);
387 return dm;
388 };
389
390 if (!dm)
391 dm = copy_dm_struture(simple->getDM());
392 else
393 dm = copy_dm_struture(dm);
394
395 const MoFEM::Problem *prb_ptr;
396 CHKERR DMMoFEMGetProblemPtr(dm, &prb_ptr);
397
398 auto set_dm_section = [&](auto dm) {
400 auto section =
401 m_field.getInterface<ISManager>()->sectionCreate(prb_ptr->getName());
402 CHKERR DMSetSection(dm, section);
404 };
405 CHKERR set_dm_section(dm);
406
407 boost::shared_ptr<FEMethod> null;
408
409 // Add element to calculate lhs of stiff part
410 if (feDomainLhs)
411 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getDomainFEName(), feDomainLhs,
412 null, null);
413 if (feBoundaryLhs)
414 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getBoundaryFEName(), feBoundaryLhs,
415 null, null);
416 if (feSkeletonLhs)
417 CHKERR DMMoFEMTSSetIJacobian(dm, simple->getSkeletonFEName(), feSkeletonLhs,
418 null, null);
419
420 // Add element to calculate rhs of stiff part
421 if (feDomainRhs)
422 CHKERR DMMoFEMTSSetIFunction(dm, simple->getDomainFEName(), feDomainRhs,
423 null, null);
424 if (feBoundaryRhs)
425 CHKERR DMMoFEMTSSetIFunction(dm, simple->getBoundaryFEName(), feBoundaryRhs,
426 null, null);
427 if (feSkeletonRhs)
428 CHKERR DMMoFEMTSSetIFunction(dm, simple->getSkeletonFEName(), feSkeletonRhs,
429 null, null);
430
431 // Add element to calculate rhs of stiff part
433 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getDomainFEName(),
434 feDomainExplicitRhs, null, null);
436 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getBoundaryFEName(),
437 feBoundaryExplicitRhs, null, null);
439 CHKERR DMMoFEMTSSetRHSFunction(dm, simple->getSkeletonFEName(),
440 feSkeletonExplicitRhs, null, null);
441
442 // Note: More cases for explit, and implicit time ingeration cases can be
443 // implemented here.
444
445 auto ts = MoFEM::createTS(m_field.get_comm());
446 CHKERR TSSetDM(ts, dm);
447 return ts;
448}
449
450} // 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.
Definition: definitions.h:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ MOFEM_NOT_IMPLEMENTED
Definition: definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
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: DMMMoFEM.cpp:665
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: DMMMoFEM.cpp:747
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition: DMMMoFEM.cpp:373
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: DMMMoFEM.cpp:706
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: DMMMoFEM.cpp:584
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMMoFEM.cpp:533
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: DMMMoFEM.cpp:800
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: DMMMoFEM.cpp:964
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: DMMMoFEM.cpp:922
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: DMMMoFEM.cpp:625
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.
Definition: Exceptions.hpp:56
implementation of Data Operators for Forces and Sources
Definition: MoFEM.hpp:24
auto createKSP(MPI_Comm comm)
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: DMMMoFEM.cpp:829
auto createSmartDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
auto smartGetDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition: DMMoFEM.hpp:998
auto createTS(MPI_Comm comm)
auto smartGetDMKspCtx(DM dm)
Get KSP context data structure used by DM.
Definition: DMMoFEM.hpp:976
PetscObject getPetscObject(T obj)
PetscErrorCode DMMoFEMDuplicateDMCtx(DM dm, DM dm_duplicate)
Duplicate internal data struture.
Definition: DMMMoFEM.cpp:184
auto smartGetDMSnesCtx(DM dm)
Get SNES context data structure used by DM.
Definition: DMMoFEM.hpp:987
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:26
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.