v0.16.3
Loading...
Searching...
No Matches
DMMoFEM.cpp
Go to the documentation of this file.
1
2
3// #undef PETSC_VERSION_RELEASE
4// #define PETSC_VERSION_RELEASE 1
5
6#if PETSC_VERSION_GE(3, 6, 0)
7#include <petsc/private/dmimpl.h> /*I "petscdm.h" I*/
8// #include <petsc/private/vecimpl.h> /*I "petscdm.h" I*/
9#else
10#include <petsc-private/dmimpl.h> /*I "petscdm.h" I*/
11#include <petsc-private/vecimpl.h> /*I "petscdm.h" I*/
12#endif
13
14#include <DMMoFEM.hpp>
15#include <DMCtxImpl.hpp>
16
17namespace MoFEM {
18
19MoFEMErrorCode DMCtx::query_interface(boost::typeindex::type_index type_index,
20 UnknownInterface **iface) const {
21 *iface = const_cast<DMCtx *>(this);
22 return 0;
23}
24
26 if (!LogManager::checkIfChannelExist("DMWORLD")) {
27 auto core_log = logging::core::get();
28 core_log->add_sink(
30 core_log->add_sink(
32 core_log->add_sink(
34 LogManager::setLog("DMWORLD");
35 LogManager::setLog("DMSYNC");
36 LogManager::setLog("DMSELF");
37 MOFEM_LOG_TAG("DMWORLD", "DM");
38 MOFEM_LOG_TAG("DMSYNC", "DM");
39 MOFEM_LOG_TAG("DMSELF", "DM");
40 }
41}
42
43PetscErrorCode DMRegister_MoFEM(const char sname[]) {
45 CHKERR DMRegister(sname, DMCreate_MoFEM);
47}
48
49PetscErrorCode DMSetOperators_MoFEM(DM dm) {
50 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
52
53 dm->ops->createglobalvector = DMCreateGlobalVector_MoFEM;
54 dm->ops->createlocalvector = DMCreateLocalVector_MoFEM;
55 dm->ops->creatematrix = DMCreateMatrix_MoFEM;
56 dm->ops->setup = DMSetUp_MoFEM;
57 dm->ops->destroy = DMDestroy_MoFEM;
58 dm->ops->setfromoptions = DMSetFromOptions_MoFEM;
59 dm->ops->globaltolocalbegin = DMGlobalToLocalBegin_MoFEM;
60 dm->ops->globaltolocalend = DMGlobalToLocalEnd_MoFEM;
61 dm->ops->localtoglobalbegin = DMLocalToGlobalBegin_MoFEM;
62 dm->ops->localtoglobalend = DMLocalToGlobalEnd_MoFEM;
63 dm->ops->createfieldis = DMCreateFieldIS_MoFEM;
64
65 // Default matrix type
66 CHKERR DMSetMatType(dm, MATMPIAIJ);
67
69}
70
71PetscErrorCode DMCreate_MoFEM(DM dm) {
72 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
74 dm->data = new DMCtxImpl();
77}
78
79PetscErrorCode DMMoFEMClearDMCtx(DM dm) {
80 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
82
83 auto *dm_field = static_cast<DMCtxImpl *>(dm->data);
84 if (!dm_field)
86
87 // Clear finite-element pipelines first. They can retain PETSc objects that
88 // reference this DM and therefore keep the context alive through a cycle.
89 if (dm_field->tsCtx)
90 CHKERR dm_field->tsCtx->clearLoops();
91 if (dm_field->snesCtx)
92 CHKERR dm_field->snesCtx->clearLoops();
93 if (dm_field->kspCtx)
94 CHKERR dm_field->kspCtx->clearLoops();
95
96 dm_field->nestedSchurDataPtr.reset();
97 dm_field->blocMatDataPtr.reset();
98 dm_field->tsCtx.reset();
99 dm_field->snesCtx.reset();
100 dm_field->kspCtx.reset();
101
103}
104
105PetscErrorCode DMDestroy_MoFEM(DM dm) {
106 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
107 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
109
110 MPI_Comm comm;
111 CHKERR PetscObjectGetComm((PetscObject)dm, &comm);
112
113 int result;
114 MPI_Comm_compare(comm, PETSC_COMM_SELF, &result);
115 if (result == MPI_IDENT)
116 MOFEM_LOG("DMSELF", Sev::noisy)
117 << "MoFEM DM destroy for problem " << dm_field->problemName
118 << " referenceNumber " << dm_field->referenceNumber;
119 else
120 MOFEM_LOG("DMWORLD", Sev::noisy)
121 << "MoFEM DM destroy for problem " << dm_field->problemName
122 << " referenceNumber " << dm_field->referenceNumber;
123
124 if (dm_field->referenceNumber == 0) {
126
127 if (dm_field->destroyProblem) {
128
129 if (dm_field->mField_ptr->check_problem(dm_field->problemName)) {
130 dm_field->mField_ptr->delete_problem(dm_field->problemName);
131 } // else problem has to be deleted by the user
132 }
133
134 delete static_cast<DMCtxImpl *>(dm->data);
135 dm->data = nullptr;
136
137 } else
138 --dm_field->referenceNumber;
139
141}
142
143PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr,
144 const char problem_name[],
145 const MoFEM::BitRefLevel bit_level,
146 const MoFEM::BitRefLevel bit_mask) {
148
149 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
150 if (!dm->data) {
151 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
152 "data structure for MoFEM not yet created");
153 }
154 if (!m_field_ptr) {
155 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
156 "DM function not implemented into MoFEM");
157 }
158 dm_field->mField_ptr = m_field_ptr;
159 dm_field->problemName = problem_name;
160 if (!m_field_ptr->check_problem(dm_field->problemName)) {
161 // problem is not defined, declare problem internally set bool to
162 // destroyProblem problem with DM
163 dm_field->destroyProblem = PETSC_TRUE;
164 CHKERR dm_field->mField_ptr->add_problem(dm_field->problemName, MF_EXCL,
165 dm_field->verbosity);
166 } else {
167 dm_field->destroyProblem = PETSC_FALSE;
168 }
170 dm_field->problemName, bit_level);
172 dm_field->problemName, bit_mask);
173 dm_field->kspCtx =
174 boost::shared_ptr<KspCtx>(new KspCtx(*m_field_ptr, problem_name));
175 dm_field->snesCtx =
176 boost::shared_ptr<SnesCtx>(new SnesCtx(*m_field_ptr, problem_name));
177 dm_field->tsCtx =
178 boost::shared_ptr<TsCtx>(new TsCtx(*m_field_ptr, problem_name));
179
180 MPI_Comm comm;
181 CHKERR PetscObjectGetComm((PetscObject)dm, &comm);
182 int result = 0;
183 MPI_Comm_compare(comm, m_field_ptr->get_comm(), &result);
184 if (result > MPI_CONGRUENT) {
185 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
186 "MoFEM and DM using different communicators");
187 }
188 MPI_Comm_size(comm, &dm_field->sIze);
189 MPI_Comm_rank(comm, &dm_field->rAnk);
190
191 // problem structure
192 CHKERR dm_field->mField_ptr->get_problem(dm_field->problemName,
193 &dm_field->problemPtr);
194
195 MPI_Comm_compare(comm, PETSC_COMM_SELF, &result);
196 if (result == MPI_IDENT) {
197 MOFEM_LOG("DMSELF", Sev::noisy)
198 << "MoFEM DM created for problem " << dm_field->problemName;
199 MOFEM_LOG("DMSELF", Sev::noisy) << *dm_field->problemPtr;
200 } else {
201 MOFEM_LOG("DMWORLD", Sev::noisy)
202 << "MoFEM DM created for problem " << dm_field->problemName;
203 MOFEM_LOG("DMWORLD", Sev::noisy) << *dm_field->problemPtr;
204 }
205
207}
208
209PetscErrorCode DMMoFEMDuplicateDMCtx(DM dm, DM dm_duplicate) {
211
212 if (!dm->data)
213 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
214 "data structure for MoFEM not yet created");
215
216 if (static_cast<DMCtxImpl *>(dm_duplicate->data)->referenceNumber == 0)
217 delete static_cast<DMCtxImpl *>(dm_duplicate->data);
218
219 dm_duplicate->data = dm->data;
220 ++(static_cast<DMCtxImpl *>(dm_duplicate->data)->referenceNumber);
221
223}
224
225PetscErrorCode DMMoFEMSwapDMCtx(DM dm, DM dm_swap) {
227 if (!dm->data)
228 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
229 "data structure for MoFEM not yet created on dm");
230 if (!dm_swap->data)
231 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
232 "data structure for MoFEM not yet created on swap dm");
233
234 auto *dm_field = static_cast<DMCtxImpl *>(dm->data);
235 auto *dm_field_swap = static_cast<DMCtxImpl *>(dm_swap->data);
236
237 auto tmp_field = dm_field;
238 dm_field = dm_field_swap;
239 dm_field_swap = tmp_field;
240
242}
243
244PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[]) {
246
247 if (!dm->data) {
248 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
249 "data structure for MoFEM not yet created");
250 }
251 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
252
253 CHKERR DMMoFEMCreateMoFEM(subdm, dm_field->mField_ptr, problem_name,
254 dm_field->problemPtr->getBitRefLevel(),
255 dm_field->problemPtr->getBitRefLevelMask());
256
257 DMCtxImpl *subdm_field = (DMCtxImpl *)subdm->data;
258 subdm_field->isSubDM = PETSC_TRUE;
259 subdm_field->problemMainOfSubPtr = dm_field->problemPtr;
260 subdm_field->isPartitioned = dm_field->isPartitioned;
261 subdm_field->isSquareMatrix = PETSC_FALSE;
262 subdm->ops->setup = DMSubDMSetUp_MoFEM;
263
265}
266
267PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[]) {
268 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
270 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
271 if (!dm->data) {
272 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
273 "data structure for MoFEM not yet created");
274 }
275 if (!dm_field->isSubDM) {
276 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "this is not sub-dm");
277 }
278 dm_field->rowSubFields.push_back(field_name);
279 dm_field->mapTypeRow.erase(field_name);
281}
282
283PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, std::string field_name) {
284 return DMMoFEMAddSubFieldRow(dm, field_name.c_str());
285}
286
287PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[],
288 boost::shared_ptr<Range> r_ptr) {
289 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
291 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
292 if (!dm->data) {
293 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
294 "data structure for MoFEM not yet created");
295 }
296 if (!dm_field->isSubDM) {
297 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "this is not sub-dm");
298 }
299 dm_field->rowSubFields.push_back(field_name);
300 dm_field->mapTypeRow[field_name] = r_ptr;
302}
303
304PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, std::string field_name,
305 boost::shared_ptr<Range> r_ptr) {
306 return DMMoFEMAddSubFieldRow(dm, field_name.c_str(), r_ptr);
307}
308
309PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[]) {
310 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
312 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
313 if (!dm->data) {
314 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
315 "data structure for MoFEM not yet created");
316 }
317 if (!dm_field->isSubDM) {
318 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "this is not sub-dm");
319 }
320 dm_field->colSubFields.push_back(field_name);
321 dm_field->mapTypeCol.erase(field_name);
323}
324
325PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, std::string field_name) {
326 return DMMoFEMAddSubFieldCol(dm, field_name.c_str());
327}
328
329PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[],
330 boost::shared_ptr<Range> r_ptr) {
331 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
333 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
334 if (!dm->data) {
335 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
336 "data structure for MoFEM not yet created");
337 }
338 if (!dm_field->isSubDM) {
339 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "this is not sub-dm");
340 }
341 dm_field->colSubFields.push_back(field_name);
342 dm_field->mapTypeCol[field_name] = r_ptr;
344}
345
346PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, std::string field_name,
347 boost::shared_ptr<Range> r_ptr) {
348 return DMMoFEMAddSubFieldCol(dm, field_name.c_str(), r_ptr);
349}
350
351PetscErrorCode DMMoFEMGetIsSubDM(DM dm, PetscBool *is_sub_dm) {
352 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
354 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
355 *is_sub_dm = dm_field->isSubDM;
357}
358
359PetscErrorCode DMMoFEMGetSubRowIS(DM dm, IS *is) {
360 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
362 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
363 if (dm_field->isSubDM != PETSC_TRUE) {
364 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
365 "This DM is not created as a SubDM");
366 }
367 if (dm_field->isProblemBuild != PETSC_TRUE) {
368 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "Problem is not build");
369 }
370 boost::shared_ptr<Problem::SubProblemData> sub_data =
371 dm_field->problemPtr->getSubData();
372 CHKERR sub_data->getRowIs(is);
374}
375
376PetscErrorCode DMMoFEMGetSubColIS(DM dm, IS *is) {
377 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
379 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
380 if (dm_field->isSubDM != PETSC_TRUE) {
381 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
382 "This DM is not created as a SubDM");
383 }
384 if (dm_field->isProblemBuild != PETSC_TRUE) {
385 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "Problem is not build");
386 }
387 boost::shared_ptr<Problem::SubProblemData> sub_data =
388 dm_field->problemPtr->getSubData();
389 CHKERR sub_data->getColIs(is);
391}
392
393PetscErrorCode DMMoFEMAddRowCompositeProblem(DM dm, const char prb_name[]) {
394 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
396 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
397 if (!dm->data) {
398 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
399 "data structure for MoFEM not yet created");
400 }
401 if (!dm_field->isCompDM) {
402 dm_field->isCompDM = PETSC_TRUE;
403 }
404 dm_field->rowCompPrb.push_back(prb_name);
405 if (dm_field->isSquareMatrix) {
406 dm_field->colCompPrb.push_back(prb_name);
407 }
409}
410
411PetscErrorCode DMMoFEMAddColCompositeProblem(DM dm, const char prb_name[]) {
412 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
414 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
415 if (!dm->data) {
416 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
417 "data structure for MoFEM not yet created");
418 }
419 if (!dm_field->isCompDM) {
420 dm_field->isCompDM = PETSC_TRUE;
421 }
422 if (dm_field->isSquareMatrix) {
423 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
424 "No need to add problem on column when problem block structurally "
425 "symmetric");
426 }
427 dm_field->colCompPrb.push_back(prb_name);
429}
430
431PetscErrorCode DMMoFEMGetIsCompDM(DM dm, PetscBool *is_comp_dm) {
432 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
434 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
435 *is_comp_dm = dm_field->isCompDM;
437}
438
439PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr) {
440 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
442 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
443 if (!dm->data) {
444 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
445 "data structure for MoFEM not yet created");
446 }
447 *m_field_ptr = dm_field->mField_ptr;
449}
450
451PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr) {
452 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
454 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
455 if (!dm->data) {
456 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
457 "data structure for MoFEM not yet created");
458 }
459 *problem_ptr = dm_field->problemPtr;
461}
462
463PetscErrorCode DMMoFEMSetDestroyProblem(DM dm, PetscBool destroy_problem) {
464 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
466 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
467 dm_field->destroyProblem = destroy_problem;
469}
470
471PetscErrorCode DMMoFEMGetDestroyProblem(DM dm, PetscBool *destroy_problem) {
472 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
474 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
475 *destroy_problem = dm_field->destroyProblem;
477}
478
479PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem) {
480 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
482 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
483 dm_field->isSquareMatrix = square_problem;
485}
486
487PetscErrorCode DMMoFEMResolveSharedFiniteElements(DM dm, std::string fe_name) {
488 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
490 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
492 ->resolveSharedFiniteElements(dm_field->problemPtr, fe_name);
494}
495
496PetscErrorCode DMMoFEMGetProblemFiniteElementLayout(DM dm, std::string fe_name,
497 PetscLayout *layout) {
498 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
500 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
501
502 MPI_Comm comm;
503 CHKERR PetscObjectGetComm((PetscObject)dm, &comm);
505 layout);
507}
508
509PetscErrorCode DMMoFEMGetSquareProblem(DM dm, PetscBool *square_problem) {
510 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
512 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
513 *square_problem = dm_field->isSquareMatrix;
515}
516
517PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name) {
518 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
520 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
522 dm_field->problemName, fe_name);
524}
525
526PetscErrorCode DMMoFEMAddElement(DM dm, std::vector<std::string> fe_name) {
528 for (auto fe : fe_name) {
530 }
532}
533
534PetscErrorCode DMMoFEMUnSetElement(DM dm, std::string fe_name) {
535 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
537 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
539 dm_field->problemName, fe_name);
541}
542
543PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode,
544 ScatterMode scatter_mode,
545 RowColData rc) {
546 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
548 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
549 CHKERR dm_field->mField_ptr->getInterface<VecManager>()->setLocalGhostVector(
550 dm_field->problemPtr, rc, l, mode, scatter_mode);
552}
553
554PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode,
555 ScatterMode scatter_mode,
556 RowColData rc) {
557 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
559 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
560 ierr = dm_field->mField_ptr->getInterface<VecManager>()->setGlobalGhostVector(
561 dm_field->problemPtr, rc, g, mode, scatter_mode);
563}
564
565PetscErrorCode DMoFEMPreProcessFiniteElements(DM dm, MoFEM::FEMethod *method) {
566 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
568 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
570 dm_field->problemPtr, *method);
571 CHKERRG(ierr);
573}
574
575PetscErrorCode DMoFEMPostProcessFiniteElements(DM dm, MoFEM::FEMethod *method) {
576 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
578 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
580 dm_field->problemPtr, *method);
581 CHKERRG(ierr);
583}
584
585PetscErrorCode
586DMoFEMLoopFiniteElementsUpAndLowRank(DM dm, const char fe_name[],
587 MoFEM::FEMethod *method, int low_rank,
588 int up_rank, CacheTupleWeakPtr cache_ptr) {
590 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
592 dm_field->problemPtr, fe_name, *method, low_rank, up_rank, nullptr,
593 MF_EXIST, cache_ptr);
594 CHKERRG(ierr);
596}
597
599 DM dm, const std::string fe_name, boost::shared_ptr<MoFEM::FEMethod> method,
600 int low_rank, int up_rank, CacheTupleWeakPtr cache_ptr) {
601 return DMoFEMLoopFiniteElementsUpAndLowRank(dm, fe_name.c_str(), method.get(),
602 low_rank, up_rank, cache_ptr);
603}
604
605PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[],
606 MoFEM::FEMethod *method,
607 CacheTupleWeakPtr cache_ptr) {
608 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
610 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
612 dm, fe_name, method, dm_field->rAnk, dm_field->rAnk, cache_ptr);
613 CHKERRG(ierr);
615}
616
617PetscErrorCode
618DMoFEMLoopFiniteElements(DM dm, const std::string fe_name,
619 boost::shared_ptr<MoFEM::FEMethod> method,
620 CacheTupleWeakPtr cache_ptr) {
621 return DMoFEMLoopFiniteElements(dm, fe_name.c_str(), method.get(), cache_ptr);
622}
623
624PetscErrorCode DMoFEMLoopDofs(DM dm, const char field_name[],
625 MoFEM::DofMethod *method) {
626 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
628 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
629 ierr =
630 dm_field->mField_ptr->loop_dofs(dm_field->problemPtr, field_name, COL,
631 *method, dm_field->rAnk, dm_field->rAnk);
632 CHKERRG(ierr);
634}
635
636template <class S, class T0, class T1, class T2>
637static PetscErrorCode DMMoFEMKSPSetComputeRHS(DM dm, S fe_name, T0 method,
638 T1 pre_only, T2 post_only) {
639 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
641 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
642 if (pre_only) {
643 dm_field->kspCtx->getPreProcComputeRhs().push_back(pre_only);
644 }
645 if (method) {
646 dm_field->kspCtx->getComputeRhs().push_back(
647 PairNameFEMethodPtr(fe_name, method));
648 }
649 if (post_only) {
650 dm_field->kspCtx->getPostProcComputeRhs().push_back(post_only);
651 }
652 CHKERR DMKSPSetComputeRHS(dm, KspRhs, dm_field->kspCtx.get());
654}
655
656PetscErrorCode DMMoFEMKSPSetComputeRHS(DM dm, const char fe_name[],
657 MoFEM::FEMethod *method,
658 MoFEM::BasicMethod *pre_only,
659 MoFEM::BasicMethod *post_only) {
660 return DMMoFEMKSPSetComputeRHS<const char *, MoFEM::FEMethod *,
662 dm, fe_name, method, pre_only, post_only);
663}
664
665PetscErrorCode
666DMMoFEMKSPSetComputeRHS(DM dm, const std::string fe_name,
667 boost::shared_ptr<MoFEM::FEMethod> method,
668 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
669 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
670 return DMMoFEMKSPSetComputeRHS<const std::string,
671 boost::shared_ptr<MoFEM::FEMethod>,
672 boost::shared_ptr<MoFEM::BasicMethod>,
673 boost::shared_ptr<MoFEM::BasicMethod>>(
674 dm, fe_name, method, pre_only, post_only);
675}
676
677template <class S, class T0, class T1, class T2>
678static PetscErrorCode DMMoFEMKSPSetComputeOperators(DM dm, S fe_name, T0 method,
679 T1 pre_only, T2 post_only) {
680 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
682 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
683 if (pre_only) {
684 dm_field->kspCtx->getPreProcSetOperators().push_back(pre_only);
685 }
686 if (method) {
687 dm_field->kspCtx->getSetOperators().push_back(
688 PairNameFEMethodPtr(fe_name, method));
689 }
690 if (post_only) {
691 dm_field->kspCtx->getPostProcSetOperators().push_back(post_only);
692 }
693 CHKERR DMKSPSetComputeOperators(dm, KspMat, dm_field->kspCtx.get());
695}
696
697PetscErrorCode DMMoFEMKSPSetComputeOperators(DM dm, const char fe_name[],
698 MoFEM::FEMethod *method,
699 MoFEM::BasicMethod *pre_only,
700 MoFEM::BasicMethod *post_only) {
701 return DMMoFEMKSPSetComputeOperators<const char *, MoFEM::FEMethod *,
704 dm, fe_name, method, pre_only, post_only);
705}
706
707PetscErrorCode
708DMMoFEMKSPSetComputeOperators(DM dm, const std::string fe_name,
709 boost::shared_ptr<MoFEM::FEMethod> method,
710 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
711 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
712 return DMMoFEMKSPSetComputeOperators<const std::string,
713 boost::shared_ptr<MoFEM::FEMethod>>(
714 dm, fe_name, method, pre_only, post_only);
715}
716
717template <class S, class T0, class T1, class T2>
718static PetscErrorCode DMMoFEMSNESSetFunction(DM dm, S fe_name, T0 method,
719 T1 pre_only, T2 post_only) {
720 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
722 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
723 if (pre_only) {
724 dm_field->snesCtx->getPreProcComputeRhs().push_back(pre_only);
725 }
726 if (method) {
727 dm_field->snesCtx->getComputeRhs().push_back(
728 PairNameFEMethodPtr(fe_name, method));
729 }
730 if (post_only) {
731 dm_field->snesCtx->getPostProcComputeRhs().push_back(post_only);
732 }
733 CHKERR DMSNESSetFunction(dm, SnesRhs, dm_field->snesCtx.get());
735}
736
737PetscErrorCode DMMoFEMSNESSetFunction(DM dm, const char fe_name[],
738 MoFEM::FEMethod *method,
739 MoFEM::BasicMethod *pre_only,
740 MoFEM::BasicMethod *post_only) {
741 return DMMoFEMSNESSetFunction<const char *, MoFEM::FEMethod *,
743 dm, fe_name, method, pre_only, post_only);
744}
745
746PetscErrorCode
747DMMoFEMSNESSetFunction(DM dm, const std::string fe_name,
748 boost::shared_ptr<MoFEM::FEMethod> method,
749 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
750 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
751 return DMMoFEMSNESSetFunction<const std::string,
752 boost::shared_ptr<MoFEM::FEMethod>,
753 boost::shared_ptr<MoFEM::BasicMethod>,
754 boost::shared_ptr<MoFEM::BasicMethod>>(
755 dm, fe_name, method, pre_only, post_only);
756}
757
758template <class S, class T0, class T1, class T2>
759static PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, S fe_name, T0 method,
760 T1 pre_only, T2 post_only) {
761 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
763 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
764 if (pre_only) {
765 dm_field->snesCtx->getPreProcSetOperators().push_back(pre_only);
766 }
767 if (method) {
768 dm_field->snesCtx->getSetOperators().push_back(
769 PairNameFEMethodPtr(fe_name, method));
770 }
771 if (post_only) {
772 dm_field->snesCtx->getPostProcSetOperators().push_back(post_only);
773 }
774 CHKERR DMSNESSetJacobian(dm, SnesMat, dm_field->snesCtx.get());
776}
777
778PetscErrorCode DMMoFEMSNESSetJacobian(DM dm, const char fe_name[],
779 MoFEM::FEMethod *method,
780 MoFEM::BasicMethod *pre_only,
781 MoFEM::BasicMethod *post_only) {
782 return DMMoFEMSNESSetJacobian<const char *, MoFEM::FEMethod *,
784 dm, fe_name, method, pre_only, post_only);
785}
786
787PetscErrorCode
788DMMoFEMSNESSetJacobian(DM dm, const std::string fe_name,
789 boost::shared_ptr<MoFEM::FEMethod> method,
790 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
791 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
792 return DMMoFEMSNESSetJacobian<const std::string,
793 boost::shared_ptr<MoFEM::FEMethod>,
794 boost::shared_ptr<MoFEM::BasicMethod>,
795 boost::shared_ptr<MoFEM::BasicMethod>>(
796 dm, fe_name, method, pre_only, post_only);
797}
798
799template <class S, class T0, class T1, class T2>
800static PetscErrorCode DMMoFEMTSSetIFunction(DM dm, S fe_name, T0 method,
801 T1 pre_only, T2 post_only) {
802 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
804 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
805 if (pre_only) {
806 dm_field->tsCtx->getPreProcessIFunction().push_back(pre_only);
807 }
808 if (method) {
809 dm_field->tsCtx->getLoopsIFunction().push_back(
810 PairNameFEMethodPtr(fe_name, method));
811 }
812 if (post_only) {
813 dm_field->tsCtx->getPostProcessIFunction().push_back(post_only);
814 }
815 CHKERR DMTSSetIFunction(dm, TsSetIFunction, dm_field->tsCtx.get());
817}
818
819PetscErrorCode DMMoFEMTSSetIFunction(DM dm, const char fe_name[],
820 MoFEM::FEMethod *method,
821 MoFEM::BasicMethod *pre_only,
822 MoFEM::BasicMethod *post_only) {
823 return DMMoFEMTSSetIFunction<const char *, MoFEM::FEMethod *,
825 dm, fe_name, method, pre_only, post_only);
827}
828
829PetscErrorCode
830DMMoFEMTSSetIFunction(DM dm, const std::string fe_name,
831 boost::shared_ptr<MoFEM::FEMethod> method,
832 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
833 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
834 return DMMoFEMTSSetIFunction<const std::string,
835 boost::shared_ptr<MoFEM::FEMethod>,
836 boost::shared_ptr<MoFEM::BasicMethod>,
837 boost::shared_ptr<MoFEM::BasicMethod>>(
838 dm, fe_name, method, pre_only, post_only);
840}
841
842template <class S, class T0, class T1, class T2>
843static PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, S fe_name, T0 method,
844 T1 pre_only, T2 post_only) {
845 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
847 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
848 if (pre_only) {
849 dm_field->tsCtx->getPreProcessIJacobian().push_back(pre_only);
850 }
851 if (method) {
852 dm_field->tsCtx->getLoopsIJacobian().push_back(
853 PairNameFEMethodPtr(fe_name, method));
854 }
855 if (post_only) {
856 dm_field->tsCtx->getPostProcessIJacobian().push_back(post_only);
857 }
858 CHKERR DMTSSetIJacobian(dm, TsSetIJacobian, dm_field->tsCtx.get());
860}
861
862PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, const char fe_name[],
863 MoFEM::FEMethod *method,
864 MoFEM::BasicMethod *pre_only,
865 MoFEM::BasicMethod *post_only) {
866 return DMMoFEMTSSetIJacobian<const char *, FEMethod *, MoFEM::BasicMethod *,
867 MoFEM::BasicMethod *>(dm, fe_name, method,
868 pre_only, post_only);
869}
870
871PetscErrorCode
872DMMoFEMTSSetIJacobian(DM dm, const std::string fe_name,
873 boost::shared_ptr<MoFEM::FEMethod> method,
874 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
875 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
876 return DMMoFEMTSSetIJacobian<const std::string,
877 boost::shared_ptr<MoFEM::FEMethod>,
878 boost::shared_ptr<MoFEM::BasicMethod>,
879 boost::shared_ptr<MoFEM::BasicMethod>>(
880 dm, fe_name, method, pre_only, post_only);
881}
882
883template <class S, class T0, class T1, class T2>
884static PetscErrorCode DMMoFEMTSSetRHSFunction(DM dm, S fe_name, T0 method,
885 T1 pre_only, T2 post_only) {
886 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
888 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
889 if (pre_only)
890 dm_field->tsCtx->getPreProcessRHSFunction().push_back(pre_only);
891 if (method)
892 dm_field->tsCtx->getLoopsRHSFunction().push_back(
893 PairNameFEMethodPtr(fe_name, method));
894 if (post_only)
895 dm_field->tsCtx->getPostProcessRHSFunction().push_back(post_only);
896 CHKERR DMTSSetRHSFunction(dm, TsSetRHSFunction, dm_field->tsCtx.get());
898}
899
900PetscErrorCode
901DMMoFEMTSSetRHSFunction(DM dm, const std::string fe_name,
902 boost::shared_ptr<MoFEM::FEMethod> method,
903 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
904 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
905 return DMMoFEMTSSetRHSFunction<const std::string,
906 boost::shared_ptr<MoFEM::FEMethod>,
907 boost::shared_ptr<MoFEM::BasicMethod>,
908 boost::shared_ptr<MoFEM::BasicMethod>>(
909 dm, fe_name, method, pre_only, post_only);
911}
912
913PetscErrorCode DMMoFEMTSSetRHSFunction(DM dm, const char fe_name[],
914 MoFEM::FEMethod *method,
915 MoFEM::BasicMethod *pre_only,
916 MoFEM::BasicMethod *post_only) {
917 return DMMoFEMTSSetRHSFunction<const char *, MoFEM::FEMethod *,
919 dm, fe_name, method, pre_only, post_only);
921}
922
923template <class S, class T0, class T1, class T2>
924static PetscErrorCode DMMoFEMTSSetRHSJacobian(DM dm, S fe_name, T0 method,
925 T1 pre_only, T2 post_only) {
926 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
928 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
929 if (pre_only)
930 dm_field->tsCtx->getPreProcessRHSFunction().push_back(pre_only);
931 if (method)
932 dm_field->tsCtx->getLoopsRHSFunction().push_back(
933 PairNameFEMethodPtr(fe_name, method));
934 if (post_only)
935 dm_field->tsCtx->getPostProcessRHSFunction().push_back(post_only);
936 CHKERR DMTSSetRHSJacobian(dm, TsSetRHSJacobian, dm_field->tsCtx.get());
938}
939
940PetscErrorCode
941DMMoFEMTSSetRHSJacobian(DM dm, const std::string fe_name,
942 boost::shared_ptr<MoFEM::FEMethod> method,
943 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
944 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
945 return DMMoFEMTSSetRHSJacobian<const std::string,
946 boost::shared_ptr<MoFEM::FEMethod>,
947 boost::shared_ptr<MoFEM::BasicMethod>,
948 boost::shared_ptr<MoFEM::BasicMethod>>(
949 dm, fe_name, method, pre_only, post_only);
951}
952
953PetscErrorCode DMMoFEMTSSetRHSJacobian(DM dm, const char fe_name[],
954 MoFEM::FEMethod *method,
955 MoFEM::BasicMethod *pre_only,
956 MoFEM::BasicMethod *post_only) {
957 return DMMoFEMTSSetRHSJacobian<const char *, MoFEM::FEMethod *,
959 dm, fe_name, method, pre_only, post_only);
961}
962
963template <class S, class T0, class T1, class T2>
964static PetscErrorCode DMMoFEMTSSetI2Function(DM dm, S fe_name, T0 method,
965 T1 pre_only, T2 post_only) {
966 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
968 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
969 if (pre_only) {
970 dm_field->tsCtx->getPreProcessIFunction().push_back(pre_only);
971 }
972 if (method) {
973 dm_field->tsCtx->getLoopsIFunction().push_back(
974 PairNameFEMethodPtr(fe_name, method));
975 }
976 if (post_only) {
977 dm_field->tsCtx->getPostProcessIFunction().push_back(post_only);
978 }
979 CHKERR DMTSSetI2Function(dm, TsSetI2Function, dm_field->tsCtx.get());
981}
982
983PetscErrorCode DMMoFEMTSSetI2Function(DM dm, const char fe_name[],
984 MoFEM::FEMethod *method,
985 MoFEM::BasicMethod *pre_only,
986 MoFEM::BasicMethod *post_only) {
987 return DMMoFEMTSSetI2Function<const char *, MoFEM::FEMethod *,
989 dm, fe_name, method, pre_only, post_only);
991}
992
993PetscErrorCode
994DMMoFEMTSSetI2Function(DM dm, const std::string fe_name,
995 boost::shared_ptr<MoFEM::FEMethod> method,
996 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
997 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
998 return DMMoFEMTSSetI2Function<const std::string,
999 boost::shared_ptr<MoFEM::FEMethod>,
1000 boost::shared_ptr<MoFEM::BasicMethod>,
1001 boost::shared_ptr<MoFEM::BasicMethod>>(
1002 dm, fe_name, method, pre_only, post_only);
1004}
1005
1006template <class S, class T0, class T1, class T2>
1007static PetscErrorCode DMMoFEMTSSetI2Jacobian(DM dm, S fe_name, T0 method,
1008 T1 pre_only, T2 post_only) {
1009 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1011 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1012 if (pre_only) {
1013 dm_field->tsCtx->getPreProcessIJacobian().push_back(pre_only);
1014 }
1015 if (method) {
1016 dm_field->tsCtx->getLoopsIJacobian().push_back(
1017 PairNameFEMethodPtr(fe_name, method));
1018 }
1019 if (post_only) {
1020 dm_field->tsCtx->getPostProcessIJacobian().push_back(post_only);
1021 }
1022 CHKERR DMTSSetI2Jacobian(dm, TsSetI2Jacobian, dm_field->tsCtx.get());
1024}
1025
1026PetscErrorCode DMMoFEMTSSetI2Jacobian(DM dm, const char fe_name[],
1027 MoFEM::FEMethod *method,
1028 MoFEM::BasicMethod *pre_only,
1029 MoFEM::BasicMethod *post_only) {
1030 return DMMoFEMTSSetI2Jacobian<const char *, FEMethod *, MoFEM::BasicMethod *,
1031 MoFEM::BasicMethod *>(dm, fe_name, method,
1032 pre_only, post_only);
1033}
1034
1035PetscErrorCode
1036DMMoFEMTSSetI2Jacobian(DM dm, const std::string fe_name,
1037 boost::shared_ptr<MoFEM::FEMethod> method,
1038 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
1039 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
1040 return DMMoFEMTSSetI2Jacobian<const std::string,
1041 boost::shared_ptr<MoFEM::FEMethod>,
1042 boost::shared_ptr<MoFEM::BasicMethod>,
1043 boost::shared_ptr<MoFEM::BasicMethod>>(
1044 dm, fe_name, method, pre_only, post_only);
1045}
1046
1047template <class S, class T0, class T1, class T2>
1048static PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, S fe_name, T0 method,
1049 T1 pre_only, T2 post_only) {
1050 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1052 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1053 if (pre_only)
1054 dm_field->tsCtx->getPreProcessMonitor().push_back(pre_only);
1055 if (method)
1056 dm_field->tsCtx->getLoopsMonitor().push_back(
1057 PairNameFEMethodPtr(fe_name, method));
1058 if (post_only)
1059 dm_field->tsCtx->getPostProcessMonitor().push_back(post_only);
1060 CHKERR TSMonitorSet(ts, TsMonitorSet, dm_field->tsCtx.get(), PETSC_NULLPTR);
1062}
1063
1064PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, const char fe_name[],
1065 MoFEM::FEMethod *method,
1066 MoFEM::BasicMethod *pre_only,
1067 MoFEM::BasicMethod *post_only) {
1068 return DMMoFEMTSSetMonitor<const char *, MoFEM::FEMethod *,
1070 dm, ts, fe_name, method, pre_only, post_only);
1072}
1073
1074PetscErrorCode
1075DMMoFEMTSSetMonitor(DM dm, TS ts, const std::string fe_name,
1076 boost::shared_ptr<MoFEM::FEMethod> method,
1077 boost::shared_ptr<MoFEM::BasicMethod> pre_only,
1078 boost::shared_ptr<MoFEM::BasicMethod> post_only) {
1079 return DMMoFEMTSSetMonitor<const std::string,
1080 boost::shared_ptr<MoFEM::FEMethod>,
1081 boost::shared_ptr<MoFEM::BasicMethod>,
1082 boost::shared_ptr<MoFEM::BasicMethod>>(
1083 dm, ts, fe_name, method, pre_only, post_only);
1085}
1086
1087PetscErrorCode DMMoFEMGetKspCtx(DM dm, MoFEM::KspCtx **ksp_ctx) {
1088 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1090 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1091 *ksp_ctx = dm_field->kspCtx.get();
1093}
1094
1095PetscErrorCode
1096DMMoFEMGetKspCtx(DM dm, const boost::shared_ptr<MoFEM::KspCtx> &ksp_ctx) {
1097 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1099 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1100 const_cast<boost::shared_ptr<MoFEM::KspCtx> &>(ksp_ctx) = dm_field->kspCtx;
1102}
1103
1104PetscErrorCode DMMoFEMSetKspCtx(DM dm,
1105 boost::shared_ptr<MoFEM::KspCtx> ksp_ctx) {
1106 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1108 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1109 dm_field->kspCtx = ksp_ctx;
1111}
1112
1113PetscErrorCode DMMoFEMGetSnesCtx(DM dm, MoFEM::SnesCtx **snes_ctx) {
1114 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1116 DMCtxImpl *dm_field = (DMCtxImpl *)dm->data;
1117 *snes_ctx = dm_field->snesCtx.get();
1119}
1120
1121PetscErrorCode
1122DMMoFEMGetSnesCtx(DM dm, const boost::shared_ptr<MoFEM::SnesCtx> &snes_ctx) {
1123 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1125 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1126 const_cast<boost::shared_ptr<MoFEM::SnesCtx> &>(snes_ctx) = dm_field->snesCtx;
1128}
1129
1130PetscErrorCode DMMoFEMSetSnesCtx(DM dm,
1131 boost::shared_ptr<MoFEM::SnesCtx> snes_ctx) {
1132 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1134 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1135 dm_field->snesCtx = snes_ctx;
1137}
1138
1139/** get if read mesh is partitioned
1140 * \ingroup dm
1141 */
1142PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned) {
1143 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1145 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1146 dm_field->isPartitioned = is_partitioned;
1148}
1149
1150/** get if read mesh is partitioned
1151 * \ingroup dm
1152 */
1153PetscErrorCode DMMoFEMGetIsPartitioned(DM dm, PetscBool *is_partitioned) {
1154 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1156 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1157 *is_partitioned = dm_field->isPartitioned;
1159}
1160
1161PetscErrorCode DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx) {
1162 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1164 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1165 *ts_ctx = dm_field->tsCtx.get();
1167}
1168
1169PetscErrorCode DMMoFEMGetTsCtx(DM dm,
1170 const boost::shared_ptr<MoFEM::TsCtx> &ts_ctx) {
1171 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1173 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1174 const_cast<boost::shared_ptr<MoFEM::TsCtx> &>(ts_ctx) = dm_field->tsCtx;
1176}
1177
1178PetscErrorCode DMMoFEMSetTsCtx(DM dm, boost::shared_ptr<MoFEM::TsCtx> ts_ctx) {
1179 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1181 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1182 dm_field->tsCtx = ts_ctx;
1184}
1185
1186PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g) {
1187 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1189 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1190 CHKERR dm_field->mField_ptr->getInterface<VecManager>()->vecCreateGhost(
1191 dm_field->problemName, COL, g);
1192 CHKERR VecSetDM(*g, dm);
1194}
1195
1197 RowColData rc) {
1198 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1200 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1201 CHKERR dm_field->mField_ptr->getInterface<VecManager>()->vecCreateGhost(
1202 dm_field->problemName, rc, g_ptr);
1203 CHKERR VecSetDM(g_ptr, dm);
1205}
1206
1207PetscErrorCode DMCreateLocalVector_MoFEM(DM dm, Vec *l) {
1208 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1210 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1211 CHKERR dm_field->mField_ptr->getInterface<VecManager>()->vecCreateSeq(
1212 dm_field->problemName, COL, l);
1213 CHKERR VecSetDM(*l, dm);
1215}
1216
1217PetscErrorCode DMCreateMatrix_MoFEM(DM dm, Mat *M) {
1218 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1220 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1221
1222 if (strcmp(dm->mattype, MATSHELL) == 0) {
1223
1224 if (dm_field->blocMatDataPtr) {
1226 CHKERR MatSetDM(*M, dm);
1228 } else {
1229 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
1230 "Matrix shell data not set, or matrix type not implemented");
1231 }
1232
1233 } else if (strcmp(dm->mattype, MATMPIAIJ) == 0) {
1235 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>(dm_field->problemName,
1236 M);
1237 } else if (strcmp(dm->mattype, MATAIJ) == 0) {
1239 ->createSeqAIJWithArrays<PetscLocalIdx_mi_tag>(dm_field->problemName,
1240 M);
1241 } else if (strcmp(dm->mattype, MATAIJCUSPARSE) == 0) {
1243 ->createMPIAIJCUSPARSEWithArrays<PetscGlobalIdx_mi_tag>(
1244 dm_field->problemName, M);
1245 } else if (strcmp(dm->mattype, MATSEQAIJCUSPARSE) == 0) {
1247 ->createSeqAIJCUSPARSEWithArrays<PetscLocalIdx_mi_tag>(
1248 dm_field->problemName, M);
1249 } else {
1250 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
1251 "Matrix type not implemented");
1252 }
1253 CHKERR MatSetDM(*M, dm);
1255}
1256
1258 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1260 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1261
1262 if (strcmp(dm->mattype, MATSHELL) == 0) {
1263 if (dm_field->blocMatDataPtr) {
1264 Mat mat_raw;
1265 CHKERR DMMoFEMCreateBlockMat(dm, &mat_raw);
1266 M = SmartPetscObj<Mat>(mat_raw);
1268 } else {
1269 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
1270 "Matrix shell data not set, or matrix type not implemented");
1271 }
1272 } else if (strcmp(dm->mattype, MATMPIAIJ) == 0) {
1274 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>(dm_field->problemName,
1275 M);
1276 } else if (strcmp(dm->mattype, MATAIJ) == 0) {
1278 ->createSeqAIJWithArrays<PetscLocalIdx_mi_tag>(dm_field->problemName,
1279 M);
1280 } else if (strcmp(dm->mattype, MATAIJCUSPARSE) == 0) {
1282 ->createMPIAIJCUSPARSEWithArrays<PetscGlobalIdx_mi_tag>(
1283 dm_field->problemName, M);
1284 } else if (strcmp(dm->mattype, MATSEQAIJCUSPARSE) == 0) {
1286 ->createSeqAIJCUSPARSEWithArrays<PetscLocalIdx_mi_tag>(
1287 dm_field->problemName, M);
1288 } else {
1289 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
1290 "Matrix type not implemented");
1291 }
1292 CHKERR MatSetDM(M, dm);
1294}
1295
1296#if PETSC_VERSION_GE(3, 17, 0)
1297PetscErrorCode DMSetFromOptions_MoFEM(DM dm,
1298 PetscOptionItems *PetscOptionsObject) {
1299#elif PETSC_VERSION_GE(3, 7, 0)
1300PetscErrorCode DMSetFromOptions_MoFEM(PetscOptionItems *PetscOptionsObject,
1301 DM dm) {
1302#elif PETSC_VERSION_GE(3, 5, 3)
1303PetscErrorCode DMSetFromOptions_MoFEM(PetscOptions *PetscOptionsObject, DM dm) {
1304#else
1305PetscErrorCode DMSetFromOptions_MoFEM(DM dm) {
1306#endif
1307
1308 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1310 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1311#if PETSC_VERSION_GE(3, 18, 0)
1312 PetscOptionsHeadBegin(PetscOptionsObject, "DMMoFEM Options");
1313#elif PETSC_VERSION_GE(3, 5, 3)
1314 PetscOptionsHead(PetscOptionsObject, "DMMoFEM Options");
1315#else
1316 PetscOptionsHead("DMMoFEM Options");
1317#endif
1318 ierr = PetscOptionsBool("-dm_is_partitioned",
1319 "set if mesh is partitioned (works which native MOAB "
1320 "file format, i.e. h5m",
1321 "DMSetUp", dm_field->isPartitioned,
1322 &dm_field->isPartitioned, NULL);
1323 CHKERRG(ierr);
1325}
1326
1327PetscErrorCode DMSetUp_MoFEM(DM dm) {
1328 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1329 ProblemsManager *prb_mng_ptr;
1331 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1332 CHKERR dm_field->mField_ptr->getInterface(prb_mng_ptr);
1333
1334 if (dm_field->isCompDM) {
1335 // It is composite probelm
1336 CHKERR prb_mng_ptr->buildComposedProblem(
1337 dm_field->problemName, dm_field->rowCompPrb, dm_field->colCompPrb,
1338 dm_field->isSquareMatrix == PETSC_TRUE, dm_field->verbosity);
1339 } else {
1340 if (dm_field->isPartitioned) {
1342 dm_field->problemName, dm_field->isSquareMatrix == PETSC_TRUE,
1343 dm_field->verbosity);
1344 } else {
1345 CHKERR prb_mng_ptr->buildProblem(dm_field->problemName,
1346 dm_field->isSquareMatrix == PETSC_TRUE,
1347 dm_field->verbosity);
1348 CHKERR prb_mng_ptr->partitionProblem(dm_field->problemName,
1349 dm_field->verbosity);
1350 }
1351 }
1352
1353 // Partition finite elements
1354 if (dm_field->isPartitioned) {
1355 CHKERR prb_mng_ptr->partitionFiniteElements(
1356 dm_field->problemName, true, 0, dm_field->sIze, dm_field->verbosity);
1358 dm_field->problemName, dm_field->verbosity);
1359 } else {
1360 // partition finite elemnets
1361 CHKERR prb_mng_ptr->partitionFiniteElements(dm_field->problemName, false,
1362 -1, -1, dm_field->verbosity);
1363 // Get ghost DOFs
1364 CHKERR prb_mng_ptr->partitionGhostDofs(dm_field->problemName,
1365 dm_field->verbosity);
1366 }
1367
1368 // Set flag that problem is build and partitioned
1369 dm_field->isProblemBuild = PETSC_TRUE;
1370
1372}
1373
1374PetscErrorCode DMSubDMSetUp_MoFEM(DM subdm) {
1375 PetscValidHeaderSpecific(subdm, DM_CLASSID, 1);
1376 ProblemsManager *prb_mng_ptr;
1378
1379 DMCtxImpl *subdm_field = static_cast<DMCtxImpl *>(subdm->data);
1380
1381 // build sub dm problem
1382 CHKERR subdm_field->mField_ptr->getInterface(prb_mng_ptr);
1383
1384 map<std::string, boost::shared_ptr<Range>> *entity_map_row = nullptr;
1385 map<std::string, boost::shared_ptr<Range>> *entity_map_col = nullptr;
1386
1387 if (subdm_field->mapTypeRow.size())
1388 entity_map_row = &subdm_field->mapTypeRow;
1389 if (subdm_field->mapTypeCol.size())
1390 entity_map_col = &subdm_field->mapTypeCol;
1391
1392 CHKERR prb_mng_ptr->buildSubProblem(
1393 subdm_field->problemName, subdm_field->rowSubFields,
1394 subdm_field->colSubFields, subdm_field->problemMainOfSubPtr->getName(),
1395 subdm_field->isSquareMatrix == PETSC_TRUE, entity_map_row, entity_map_col,
1396 subdm_field->verbosity);
1397
1398 // partition problem
1399 subdm_field->isPartitioned = subdm_field->isPartitioned;
1400 if (subdm_field->isPartitioned) {
1401 CHKERR prb_mng_ptr->partitionFiniteElements(subdm_field->problemName, true,
1402 0, subdm_field->sIze,
1403 subdm_field->verbosity);
1404 // set ghost nodes
1406 subdm_field->problemName, subdm_field->verbosity);
1407 } else {
1408 // partition finite elements
1409 CHKERR prb_mng_ptr->partitionFiniteElements(subdm_field->problemName, false,
1410 -1, -1, subdm_field->verbosity);
1411 // set ghost nodes
1412 CHKERR prb_mng_ptr->partitionGhostDofs(subdm_field->problemName,
1413 subdm_field->verbosity);
1414 }
1415
1416 subdm_field->isProblemBuild = PETSC_TRUE;
1417
1419}
1420
1421PetscErrorCode DMGlobalToLocalBegin_MoFEM(DM dm, Vec g, InsertMode mode,
1422 Vec l) {
1423 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1425 CHKERR VecGhostUpdateBegin(g, INSERT_VALUES, SCATTER_FORWARD);
1427}
1428
1429PetscErrorCode DMGlobalToLocalEnd_MoFEM(DM dm, Vec g, InsertMode mode, Vec l) {
1430 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1432
1433 CHKERR VecGhostUpdateEnd(g, INSERT_VALUES, SCATTER_FORWARD);
1434
1435 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1436 int nb_dofs = dm_field->problemPtr->getNbLocalDofsRow();
1437 int nb_ghost = dm_field->problemPtr->getNbGhostDofsRow();
1438
1439 double *array_loc, *array_glob;
1440 CHKERR VecGetArray(l, &array_loc);
1441 CHKERR VecGetArray(g, &array_glob);
1442 switch (mode) {
1443 case INSERT_VALUES:
1444 cblas_dcopy(nb_dofs + nb_ghost, array_glob, 1, array_loc, 1);
1445 break;
1446 case ADD_VALUES:
1447 cblas_daxpy(nb_dofs + nb_ghost, 1, array_glob, 1, array_loc, 1);
1448 break;
1449 default:
1450 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
1451 }
1452 CHKERR VecRestoreArray(l, &array_loc);
1453 CHKERR VecRestoreArray(g, &array_glob);
1455}
1456
1457PetscErrorCode DMLocalToGlobalBegin_MoFEM(DM dm, Vec l, InsertMode mode,
1458 Vec g) {
1459
1460 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1462
1463 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1464 int nb_dofs = dm_field->problemPtr->getNbLocalDofsRow();
1465 int nb_ghost = dm_field->problemPtr->getNbGhostDofsRow();
1466
1467 double *array_loc, *array_glob;
1468 CHKERR VecGetArray(l, &array_loc);
1469 CHKERR VecGetArray(g, &array_glob);
1470 switch (mode) {
1471 case INSERT_VALUES:
1472 cblas_dcopy(nb_dofs + nb_ghost, array_loc, 1, array_glob, 1);
1473 break;
1474 case ADD_VALUES:
1475 cblas_daxpy(nb_dofs + nb_ghost, 1, array_loc, 1, array_glob, 1);
1476 break;
1477 default:
1478 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
1479 }
1480 CHKERR VecRestoreArray(l, &array_loc);
1481 CHKERR VecRestoreArray(g, &array_glob);
1482
1484}
1485
1486PetscErrorCode DMLocalToGlobalEnd_MoFEM(DM, Vec l, InsertMode mode, Vec g) {
1489}
1490
1491PetscErrorCode DMCreateFieldIS_MoFEM(DM dm, PetscInt *numFields,
1492 char ***fieldNames, IS **fields) {
1493 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1495
1496 if (numFields) {
1497 *numFields = 0;
1498 }
1499 if (fieldNames) {
1500 *fieldNames = NULL;
1501 }
1502 if (fields) {
1503 *fields = NULL;
1504 }
1505
1506 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1507 auto fields_ptr = dm_field->mField_ptr->get_fields();
1508 Field_multiIndex::iterator fit, hi_fit;
1509 fit = fields_ptr->begin();
1510 hi_fit = fields_ptr->end();
1511 *numFields = std::distance(fit, hi_fit);
1512
1513 if (fieldNames) {
1514 CHKERR PetscMalloc1(*numFields, fieldNames);
1515 }
1516 if (fields) {
1517 CHKERR PetscMalloc1(*numFields, fields);
1518 }
1519
1520 for (int f = 0; fit != hi_fit; fit++, f++) {
1521 if (fieldNames) {
1522 CHKERR PetscStrallocpy(fit->get()->getName().c_str(),
1523 (char **)&(*fieldNames)[f]);
1524 }
1525 if (fields) {
1527 ->isCreateProblemFieldAndRank(
1528 dm_field->problemPtr->getName(), ROW, fit->get()->getName(), 0,
1529 fit->get()->getNbOfCoeffs(), &(*fields)[f]);
1530 }
1531 }
1532
1534}
1535
1536PetscErrorCode DMMoFEMGetFieldIS(DM dm, RowColData rc, const char field_name[],
1537 IS *is) {
1538 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1540 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1542 ->isCreateProblemFieldAndRank(dm_field->problemPtr->getName(), rc,
1543 field_name, 0, 1000, is);
1545}
1546
1547PetscErrorCode DMMoFEMSetVerbosity(DM dm, const int verb) {
1548 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1550 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1551 dm_field->verbosity = verb;
1553}
1554
1556 boost::shared_ptr<BlockStructure> data) {
1557 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1559 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1560 dm_field->blocMatDataPtr = data;
1562}
1563
1565 boost::shared_ptr<BlockStructure> &data) {
1566 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1568 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1569 data = dm_field->blocMatDataPtr;
1571}
1572
1574 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1576 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1577 auto mat_data = createBlockMat(dm, dm_field->blocMatDataPtr);
1578 *mat = mat_data.first;
1579 CHKERR PetscObjectReference((PetscObject)(*mat));
1581}
1582
1583template <>
1585 boost::shared_ptr<NestSchurData> data) {
1586 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1588 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1589 dm_field->nestedSchurDataPtr = data;
1590 if (data)
1591 dm_field->blocMatDataPtr = get<2>(*data);
1592 else
1593 dm_field->blocMatDataPtr.reset();
1595}
1596
1598 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1600 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1601 auto mat_data = createSchurNestedMatrix(dm_field->nestedSchurDataPtr);
1602 *mat = mat_data.first;
1603 CHKERR PetscObjectReference((PetscObject)(*mat));
1605}
1606
1608 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
1610 DMCtxImpl *dm_field = static_cast<DMCtxImpl *>(dm->data);
1611 auto matrix_mng = dm_field->mField_ptr->getInterface<MatrixManager>();
1613 dm_field->problemName, mat);
1615}
1616
1617} // namespace MoFEM
MPI_Comm comm
Implementation of DM context. You should not use it directly.
Discrete manager interface for MoFEM.
RowColData
RowColData.
@ COL
@ ROW
@ MF_EXIST
@ MF_EXCL
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_INVALID_DATA
Definition definitions.h:36
@ 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.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode DMGlobalToLocalBegin_MoFEM(DM dm, Vec, InsertMode, Vec)
Definition DMMoFEM.cpp:1421
PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set ghosted vector values on all existing mesh entities
Definition DMMoFEM.cpp:554
PetscErrorCode DMGlobalToLocalEnd_MoFEM(DM dm, Vec, InsertMode, Vec)
Definition DMMoFEM.cpp:1429
PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned)
Definition DMMoFEM.cpp:1142
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition DMMoFEM.cpp:244
PetscErrorCode DMMoFEMGetIsPartitioned(DM dm, PetscBool *is_partitioned)
Definition DMMoFEM.cpp:1153
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:517
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:737
PetscErrorCode DMMoFEMGetProblemFiniteElementLayout(DM dm, std::string fe_name, PetscLayout *layout)
Get finite elements layout in the problem.
Definition DMMoFEM.cpp:496
PetscErrorCode DMCreateLocalVector_MoFEM(DM dm, Vec *l)
DMShellSetCreateLocalVector.
Definition DMMoFEM.cpp:1207
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition DMMoFEM.cpp:479
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:819
PetscErrorCode DMDestroy_MoFEM(DM dm)
Destroys dm with MoFEM data structure.
Definition DMMoFEM.cpp:105
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
Definition DMMoFEM.cpp:143
PetscErrorCode DMoFEMPostProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
Definition DMMoFEM.cpp:575
PetscErrorCode DMMoFEMAddColCompositeProblem(DM dm, const char prb_name[])
Add problem to composite DM on col.
Definition DMMoFEM.cpp:411
PetscErrorCode DMLocalToGlobalBegin_MoFEM(DM, Vec, InsertMode, Vec)
Definition DMMoFEM.cpp:1457
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition DMMoFEM.cpp:451
PetscErrorCode DMCreate_MoFEM(DM dm)
Create dm data structure with MoFEM data structure.
Definition DMMoFEM.cpp:71
PetscErrorCode DMMoFEMSetSnesCtx(DM dm, boost::shared_ptr< MoFEM::SnesCtx > snes_ctx)
Set MoFEM::SnesCtx data structure.
Definition DMMoFEM.cpp:1130
PetscErrorCode DMMoFEMSetKspCtx(DM dm, boost::shared_ptr< MoFEM::KspCtx > ksp_ctx)
set MoFEM::KspCtx data structure
Definition DMMoFEM.cpp:1104
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
Definition DMMoFEM.cpp:267
PetscErrorCode DMMoFEMGetIsSubDM(DM dm, PetscBool *is_sub_dm)
Definition DMMoFEM.cpp:351
PetscErrorCode DMMoFEMAddRowCompositeProblem(DM dm, const char prb_name[])
Add problem to composite DM on row.
Definition DMMoFEM.cpp:393
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:778
PetscErrorCode DMCreateMatrix_MoFEM(DM dm, Mat *M)
Definition DMMoFEM.cpp:1217
PetscErrorCode DMSetFromOptions_MoFEM(DM dm)
Definition DMMoFEM.cpp:1305
PetscErrorCode DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx)
get MoFEM::TsCtx data structure
Definition DMMoFEM.cpp:1161
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:543
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
PetscErrorCode DMMoFEMGetKspCtx(DM dm, MoFEM::KspCtx **ksp_ctx)
get MoFEM::KspCtx data structure
Definition DMMoFEM.cpp:1087
PetscErrorCode DMMoFEMGetSquareProblem(DM dm, PetscBool *square_problem)
get squared problem
Definition DMMoFEM.cpp:509
PetscErrorCode DMoFEMLoopDofs(DM dm, const char field_name[], MoFEM::DofMethod *method)
execute method for dofs on field in problem
Definition DMMoFEM.cpp:624
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:656
PetscErrorCode DMMoFEMResolveSharedFiniteElements(DM dm, std::string fe_name)
Resolve shared entities.
Definition DMMoFEM.cpp:487
PetscErrorCode DMMoFEMSetTsCtx(DM dm, boost::shared_ptr< MoFEM::TsCtx > ts_ctx)
Set MoFEM::TsCtx data structure.
Definition DMMoFEM.cpp:1178
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:605
PetscErrorCode DMMoFEMGetFieldIS(DM dm, RowColData rc, const char field_name[], IS *is)
get field is in the problem
Definition DMMoFEM.cpp:1536
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:872
MoFEMErrorCode DMMoFEMCreateBlockMat(DM dm, Mat *mat)
Create block matrix.
Definition DMMoFEM.cpp:1573
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
Definition DMMoFEM.cpp:439
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
Definition DMMoFEM.cpp:309
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:1036
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:994
PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
Definition DMMoFEM.cpp:1186
PetscErrorCode DMMoFEMGetSnesCtx(DM dm, MoFEM::SnesCtx **snes_ctx)
get MoFEM::SnesCtx data structure
Definition DMMoFEM.cpp:1113
PetscErrorCode DMMoFEMGetIsCompDM(DM dm, PetscBool *is_comp_dm)
Get if this DM is composite DM.
Definition DMMoFEM.cpp:431
PetscErrorCode DMSubDMSetUp_MoFEM(DM subdm)
Definition DMMoFEM.cpp:1374
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:697
PetscErrorCode DMCreateFieldIS_MoFEM(DM dm, PetscInt *numFields, char ***fieldNames, IS **fields)
Definition DMMoFEM.cpp:1491
PetscErrorCode DMMoFEMUnSetElement(DM dm, std::string fe_name)
unset element from dm
Definition DMMoFEM.cpp:534
PetscErrorCode DMSetUp_MoFEM(DM dm)
Definition DMMoFEM.cpp:1327
PetscErrorCode DMLocalToGlobalEnd_MoFEM(DM, Vec, InsertMode, Vec)
Definition DMMoFEM.cpp:1486
PetscErrorCode DMoFEMLoopFiniteElementsUpAndLowRank(DM dm, const char fe_name[], MoFEM::FEMethod *method, int low_rank, int up_rank, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition DMMoFEM.cpp:586
PetscErrorCode DMoFEMPreProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
Definition DMMoFEM.cpp:565
PetscErrorCode DMSetOperators_MoFEM(DM dm)
Set operators for MoFEM dm.
Definition DMMoFEM.cpp:49
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
virtual const Field_multiIndex * get_fields() const =0
Get the fields object.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
virtual MoFEMErrorCode problem_basic_method_postProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MoFEMErrorCode loop_finite_elements(const std::string problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
MoFEMErrorCode buildProblemOnDistributedMesh(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures, assuming that mesh is distributed (collective)
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode buildComposedProblem(const std::string out_name, const std::vector< std::string > add_row_problems, const std::vector< std::string > add_col_problems, const bool square_matrix=true, int verb=1)
build composite problem
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
MoFEMErrorCode buildSubProblem(const std::string out_name, const std::vector< std::string > &fields_row, const std::vector< std::string > &fields_col, const std::string main_problem, const bool square_matrix=true, const map< std::string, boost::shared_ptr< Range > > *entityMapRow=nullptr, const map< std::string, boost::shared_ptr< Range > > *entityMapCol=nullptr, int verb=VERBOSE)
build sub problem
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
MoFEMErrorCode partitionGhostDofsOnDistributedMesh(const std::string name, int verb=VERBOSE)
determine ghost nodes on distributed meshes
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
virtual MoFEMErrorCode modify_problem_unset_finite_element(const std::string name_problem, const std::string &fe_name)=0
unset finite element from problem, this remove entities assigned to finite element to a particular pr...
virtual MoFEMErrorCode delete_problem(const std::string name)=0
Delete problem.
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
virtual bool check_problem(const std::string name)=0
check if problem exist
virtual MoFEMErrorCode modify_problem_mask_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
set dof mask ref level for problem
virtual MoFEMErrorCode modify_problem_add_finite_element(const std::string name_problem, const std::string &fe_name)=0
add finite element to problem, this add entities assigned to finite element to a particular problem
MoFEM::TsCtx * ts_ctx
FTensor::Index< 'l', 3 > l
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, 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 Monitor To TS solver.
Definition DMMoFEM.cpp:1075
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:169
PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
Definition TsCtx.cpp:263
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:901
PetscErrorCode SnesMat(SNES snes, Vec x, Mat A, Mat B, void *ctx)
This is MoFEM implementation for the left hand side (tangent matrix) evaluation in SNES solver.
Definition SnesCtx.cpp:491
PetscErrorCode DMMoFEMSetDestroyProblem(DM dm, PetscBool destroy_problem)
Definition DMMoFEM.cpp:463
MoFEMErrorCode DMMoFEMCreateHybridL2Mat(DM dm, SmartPetscObj< Mat > &mat)
Create matrix for hybridised system.
Definition DMMoFEM.cpp:1607
PetscErrorCode DMMoFEMGetDestroyProblem(DM dm, PetscBool *destroy_problem)
Definition DMMoFEM.cpp:471
MoFEMErrorCode DMMoFEMGetBlocMatData(DM dm, boost::shared_ptr< BlockStructure > &)
Get data for block mat.
Definition DMMoFEM.cpp:1564
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:620
PetscErrorCode TsSetRHSFunction(TS ts, PetscReal t, Vec u, Vec F, void *ctx)
TS solver function.
Definition TsCtx.cpp:327
std::pair< SmartPetscObj< Mat >, boost::shared_ptr< NestSchurData > > createSchurNestedMatrix(boost::shared_ptr< NestSchurData > schur_net_data_ptr)
Create a Mat Diag Blocks object.
Definition Schur.cpp:4163
PetscErrorCode SnesRhs(SNES snes, Vec x, Vec f, void *ctx)
This is MoFEM implementation for the right hand side (residual vector) evaluation in SNES solver.
Definition SnesCtx.cpp:227
PetscErrorCode DMMoFEMGetSubRowIS(DM dm, IS *is)
get sub problem is
Definition DMMoFEM.cpp:359
PetscErrorCode DMMoFEMClearDMCtx(DM dm)
Clear solver and Schur data owned by a MoFEM DM context.
Definition DMMoFEM.cpp:79
MoFEMErrorCode DMMoFEMCreateNestSchurMat(DM dm, Mat *mat)
Create nest schur matrix.
Definition DMMoFEM.cpp:1597
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 DMMoFEMGetSubColIS(DM dm, IS *is)
get sub problem is
Definition DMMoFEM.cpp:376
PetscErrorCode KspRhs(KSP ksp, Vec f, void *ctx)
Run over elements in the lists.
Definition KspCtx.cpp:147
MoFEMErrorCode DMMoFEMSetBlocMatData(DM dm, boost::shared_ptr< BlockStructure >)
Set data for block mat.
Definition DMMoFEM.cpp:1555
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:519
PetscErrorCode KspMat(KSP ksp, Mat A, Mat B, void *ctx)
Run over elements in the list.
Definition KspCtx.cpp:211
PetscErrorCode TsSetRHSJacobian(TS ts, PetscReal t, Vec u, Mat A, Mat B, void *ctx)
TS solver function.
Definition TsCtx.cpp:430
MoFEMErrorCode DMMoFEMSetNestSchurData(DM dm, boost::shared_ptr< NestSchurData >)
Definition DMMoFEM.cpp:1584
PetscErrorCode DMMoFEMTSSetRHSJacobian(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 jacobian
Definition DMMoFEM.cpp:941
PetscErrorCode DMMoFEMSetVerbosity(DM dm, const int verb)
Set verbosity level.
Definition DMMoFEM.cpp:1547
PetscErrorCode DMMoFEMSwapDMCtx(DM dm, DM dm_swap)
Swap internal data structure.
Definition DMMoFEM.cpp:225
PetscErrorCode DMMoFEMDuplicateDMCtx(DM dm, DM dm_duplicate)
Duplicate internal data structure.
Definition DMMoFEM.cpp:209
SchurShellMatData createBlockMat(DM dm, boost::shared_ptr< BlockStructure > data)
Create a Schur Mat object.
Definition Schur.cpp:3072
boost::weak_ptr< CacheTuple > CacheTupleWeakPtr
constexpr auto field_name
constexpr double g
Data structure to exchange data between MoFEM and User Loop Methods.
Managing BitRefLevels.
virtual MoFEMErrorCode problem_basic_method_preProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MPI_Comm & get_comm() const =0
PetscBool isSquareMatrix
true if rows equals to cols
Definition DMCtxImpl.hpp:37
std::vector< std::string > rowCompPrb
Definition DMCtxImpl.hpp:30
boost::shared_ptr< NestSchurData > nestedSchurDataPtr
Definition DMCtxImpl.hpp:49
PetscBool destroyProblem
If true destroy problem with DM.
Definition DMCtxImpl.hpp:38
const Problem * problemMainOfSubPtr
pointer to main problem to sub-problem
Definition DMCtxImpl.hpp:27
std::string problemName
Problem name.
Definition DMCtxImpl.hpp:45
PetscBool isSubDM
Definition DMCtxImpl.hpp:24
PetscBool isPartitioned
true if read mesh is on parts
Definition DMCtxImpl.hpp:36
std::map< std::string, boost::shared_ptr< Range > > mapTypeCol
Definition DMCtxImpl.hpp:33
const Problem * problemPtr
pointer to problem data structure
Definition DMCtxImpl.hpp:44
std::map< std::string, boost::shared_ptr< Range > > mapTypeRow
Definition DMCtxImpl.hpp:32
std::vector< std::string > colSubFields
Definition DMCtxImpl.hpp:26
PetscBool isCompDM
Definition DMCtxImpl.hpp:29
boost::shared_ptr< BlockStructure > blocMatDataPtr
Definition DMCtxImpl.hpp:48
Interface * mField_ptr
MoFEM interface.
Definition DMCtxImpl.hpp:41
int verbosity
verbosity
Definition DMCtxImpl.hpp:20
std::vector< std::string > rowSubFields
Definition DMCtxImpl.hpp:25
PetscBool isProblemBuild
True if problem is build.
Definition DMCtxImpl.hpp:39
std::vector< std::string > colCompPrb
Definition DMCtxImpl.hpp:31
PETSc Discrete Manager data structure.
Definition DMMoFEM.hpp:1163
boost::shared_ptr< SnesCtx > snesCtx
data structure SNES
Definition DMMoFEM.hpp:1171
boost::shared_ptr< TsCtx > tsCtx
data structure for TS solver
Definition DMMoFEM.hpp:1172
boost::shared_ptr< KspCtx > kspCtx
data structure KSP
Definition DMMoFEM.hpp:1170
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition DMMoFEM.cpp:19
Deprecated interface functions.
Data structure for user loop methods on degrees of freedom (DOFs)
Structure for user loop methods on finite elements.
Section manager is used to create indexes and sections.
Definition ISManager.hpp:23
Interface for linear (KSP) solver.
Definition KspCtx.hpp:14
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
static bool checkIfChannelExist(const std::string channel)
Check if channel exist.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
Matrix manager is used to build and partition problems.
MoFEMErrorCode createHybridL2MPIAIJ(const std::string problem_name, SmartPetscObj< Mat > &aij_ptr, int verb=QUIET)
Create a Hybrid MPIAij object.
keeps basic data about problem
DofIdx getNbLocalDofsRow() const
MoFEMErrorCode getNumberOfElementsByNameAndPart(MPI_Comm comm, const std::string name, PetscLayout *layout) const
Get number of finite elements by name on processors.
BitRefLevel getBitRefLevel() const
BitRefLevel getBitRefLevelMask() const
boost::shared_ptr< SubProblemData > & getSubData() const
Get main problem of sub-problem is.
DofIdx getNbGhostDofsRow() const
Problem manager is used to build and partition problems.
intrusive_ptr for managing petsc objects
Interface for nonlinear (SNES) solver.
Definition SnesCtx.hpp:15
Interface for Time Stepping (TS) solver.
Definition TsCtx.hpp:17
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.