v0.15.5
Loading...
Searching...
No Matches
Simple.cpp
Go to the documentation of this file.
1/** \file Simple.cpp
2 * \brief Implementation of simple interface
3 * \ingroup mofem_simple_interface
4 */
5
6namespace MoFEM {
7
8MoFEMErrorCode Simple::query_interface(boost::typeindex::type_index type_index,
9 UnknownInterface **iface) const {
10 *iface = const_cast<Simple *>(this);
11 return 0;
12}
13
14template <int DIM>
16 static_assert(DIM == 2 || DIM == 3, "not implemented");
18}
19
20template <>
21MoFEMErrorCode Simple::setSkeletonAdjacency<2>(std::string fe_name) {
22 Interface &m_field = cOre;
24
26 boost::make_shared<ParentFiniteElementAdjacencyFunctionSkeleton<1>>(
29 fe_name, MBEDGE, *parentAdjSkeletonFunctionDim1);
30
32}
33
34template <>
35MoFEMErrorCode Simple::setSkeletonAdjacency<3>(std::string fe_name) {
36 Interface &m_field = cOre;
38
40 boost::make_shared<ParentFiniteElementAdjacencyFunctionSkeleton<2>>(
42
44 fe_name, MBTRI, *parentAdjSkeletonFunctionDim2);
46 fe_name, MBQUAD, *parentAdjSkeletonFunctionDim2);
47
49}
50
51template <>
54
55 switch (getDim()) {
56 case 1:
57 THROW_MESSAGE("Not implemented");
58 case 2:
59 return setSkeletonAdjacency<2>(fe_name);
60 case 3:
61 return setSkeletonAdjacency<3>(fe_name);
62 default:
63 THROW_MESSAGE("Not implemented");
64 }
66}
68 static_assert(DIM == 2 || DIM == 3, "not implemented");
70}
71
72template <> MoFEMErrorCode Simple::setParentAdjacency<3>() {
73 Interface &m_field = cOre;
75
77 boost::make_shared<ParentFiniteElementAdjacencyFunction<3>>(
80 boost::make_shared<ParentFiniteElementAdjacencyFunction<2>>(
82
87 if (addBoundaryFE || !boundaryFields.empty()) {
92 }
93 if (addSkeletonFE || !skeletonFields.empty()) {
98 }
99
101}
102
103template <> MoFEMErrorCode Simple::setParentAdjacency<2>() {
104 Interface &m_field = cOre;
106
108 boost::make_shared<ParentFiniteElementAdjacencyFunction<2>>(
111 boost::make_shared<ParentFiniteElementAdjacencyFunction<1>>(
113
118 if (addBoundaryFE || !boundaryFields.empty())
121 if (addSkeletonFE || !skeletonFields.empty())
124
126}
127
130 switch (getDim()) {
131 case 1:
132 THROW_MESSAGE("Not implemented");
133 case 2:
134 return setParentAdjacency<2>();
135 case 3:
136 return setParentAdjacency<3>();
137 default:
138 THROW_MESSAGE("Not implemented");
139 }
141}
142
143MoFEMErrorCode Simple::setSkeletonAdjacency(int dim, std::string fe_name) {
145 if (dim == -1)
146 dim = getDim();
147
148 if (fe_name.empty())
149 fe_name = skeletonFE;
150
151 switch (dim) {
152 case 2:
153 return setSkeletonAdjacency<2>(fe_name);
154 case 3:
155 return setSkeletonAdjacency<3>(fe_name);
156 default:
157 SETERRQ(PETSC_COMM_WORLD, MOFEM_NOT_IMPLEMENTED, "Not implemented");
158 }
160}
161
163 : cOre(const_cast<Core &>(core)), bitLevel(BitRefLevel().set(0)),
164 bitLevelMask(BitRefLevel().set()), meshSet(0), boundaryMeshset(0),
165 skeletonMeshset(0), nameOfProblem("SimpleProblem"), domainFE("dFE"),
166 boundaryFE("bFE"), skeletonFE("sFE"), dIm(-1), addSkeletonFE(false),
167 addBoundaryFE(false), addParentAdjacencies(false),
168 bitAdjParent(BitRefLevel().set()), bitAdjParentMask(BitRefLevel().set()),
169 bitAdjEnt(BitRefLevel().set()), bitAdjEntMask(BitRefLevel().set()) {
170 PetscLogEventRegister("SimpSetUp", 0, &MOFEM_EVENT_SimpleSetUP);
171 PetscLogEventRegister("SimpLoadMesh", 0, &MOFEM_EVENT_SimpleLoadMesh);
172 PetscLogEventRegister("SimpBuildFields", 0, &MOFEM_EVENT_SimpleBuildFields);
173 PetscLogEventRegister("SimpBuildFEs", 0,
175 PetscLogEventRegister("SimpSetUp", 0, &MOFEM_EVENT_SimpleBuildProblem);
176 PetscLogEventRegister("SimpKSPSolve", 0, &MOFEM_EVENT_SimpleKSPSolve);
177 strcpy(meshFileName, "mesh.h5m");
178}
179
181 PetscBool flg = PETSC_TRUE;
183 PetscOptionsBegin(PETSC_COMM_WORLD, "", "Simple interface options",
184 "none");
185 ierr = PetscOptionsString("-file_name", "file name", "", "mesh.h5m",
186 meshFileName, 255, &flg);
187 PetscOptionsEnd();
189}
190
191MoFEMErrorCode Simple::loadFile(const std::string options,
192 const std::string mesh_file_name,
193 LoadFileFunc loadFunc) {
194 Interface &m_field = cOre;
196 PetscLogEventBegin(MOFEM_EVENT_SimpleLoadMesh, 0, 0, 0, 0);
197
198 if (!mesh_file_name.empty())
199 strcpy(meshFileName, mesh_file_name.c_str());
200
201 // Invoke the boost function, passing in required arguments
202 CHKERR loadFunc(m_field, meshFileName, options.c_str());
203 CHKERR m_field.rebuild_database();
204
205 // determine problem dimension
206 if (dIm == -1) {
207 int nb_ents_3d;
208 CHKERR m_field.get_moab().get_number_entities_by_dimension(
209 meshSet, 3, nb_ents_3d, true);
210 if (nb_ents_3d > 0) {
211 dIm = 3;
212 } else {
213 int nb_ents_2d;
214 CHKERR m_field.get_moab().get_number_entities_by_dimension(
215 meshSet, 2, nb_ents_2d, true);
216 if (nb_ents_2d > 0) {
217 dIm = 2;
218 } else {
219 dIm = 1;
220 }
221 }
222 }
223
224 if (!boundaryMeshset)
226 if (!skeletonMeshset)
228 if (addSkeletonFE)
230
231 if (bitLevel.any()) {
232 Range ents;
233 CHKERR m_field.get_moab().get_entities_by_dimension(meshSet, dIm, ents,
234 true);
235 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevel(ents, bitLevel,
236 false);
237 } else {
238 MOFEM_LOG("WORLD", Sev::warning) << "BitRefLevel is none and not set";
239 CHKERR m_field.getInterface<BitRefManager>()->addToDatabaseBitRefLevelByDim(
240 dIm, BitRefLevel().set(), BitRefLevel().set());
241 }
242
243 PetscLogEventEnd(MOFEM_EVENT_SimpleLoadMesh, 0, 0, 0, 0);
245}
246
247MoFEMErrorCode Simple::loadFile(const std::string mesh_file_name) {
249 Interface &m_field = cOre;
250 if (m_field.get_comm_size() == 1)
252 else
253 CHKERR loadFile("PARALLEL=READ_PART;"
254 "PARALLEL_RESOLVE_SHARED_ENTS;"
255 "PARTITION=PARALLEL_PARTITION;",
258}
259
261Simple::addDomainField(const std::string name, const FieldSpace space,
262 const FieldApproximationBase base,
263 const FieldCoefficientsNumber nb_of_coefficients,
264 const TagType tag_type, const enum MoFEMTypes bh,
265 int verb) {
266
267 Interface &m_field = cOre;
269 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
270 verb);
271 domainFields.push_back(name);
272 if (space == NOFIELD)
273 SETERRQ(
274 PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
275 "NOFIELD space for boundary field not implemented in Simple interface");
276
277
279}
280
282Simple::addDomainBrokenField(const std::string name, const FieldSpace space,
283 const FieldApproximationBase base,
284 const FieldCoefficientsNumber nb_of_coefficients,
285 const TagType tag_type, const enum MoFEMTypes bh,
286 int verb) {
287
288 Interface &m_field = cOre;
290
291 auto get_side_map_hcurl = [&]() {
292 return std::vector<
293
294 std::pair<EntityType,
296
297 >>{
298
299 {MBTRI,
300 [&](BaseFunction::DofsSideMap &dofs_side_map) -> MoFEMErrorCode {
302 dofs_side_map);
303 }}
304
305 };
306 };
307
308 auto get_side_map_hdiv = [&]() {
309 return std::vector<
310
311 std::pair<EntityType,
313
314 >>{
315
316 {MBTET,
317 [&](BaseFunction::DofsSideMap &dofs_side_map) -> MoFEMErrorCode {
319 dofs_side_map);
320 }}
321
322 };
323 };
324
325 auto get_side_map = [&](auto space) {
326 switch (space) {
327 case HCURL:
328 return get_side_map_hcurl();
329 case HDIV:
330 return get_side_map_hdiv();
331 default:
332 MOFEM_LOG_CHANNEL("WORLD");
333 MOFEM_LOG("WORLD", Sev::warning)
334 << "Side dof map for broken space <" << space << "> not implemented";
335 }
336 return std::vector<
337
338 std::pair<EntityType,
340
341 >>{};
342 };
343
344 CHKERR m_field.add_broken_field(name, space, base, nb_of_coefficients,
345 get_side_map(space), tag_type, bh, verb);
346 domainFields.push_back(name);
347 if (space == NOFIELD)
348 SETERRQ(
349 PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
350 "NOFIELD space for boundary field not implemented in Simple interface");
352}
353
355Simple::addBoundaryField(const std::string name, const FieldSpace space,
356 const FieldApproximationBase base,
357 const FieldCoefficientsNumber nb_of_coefficients,
358 const TagType tag_type, const enum MoFEMTypes bh,
359 int verb) {
360 Interface &m_field = cOre;
362 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
363 verb);
364 boundaryFields.push_back(name);
365 if (space == NOFIELD)
366 SETERRQ(
367 PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
368 "NOFIELD space for boundary field not implemented in Simple interface");
370}
371
373Simple::addSkeletonField(const std::string name, const FieldSpace space,
374 const FieldApproximationBase base,
375 const FieldCoefficientsNumber nb_of_coefficients,
376 const TagType tag_type, const enum MoFEMTypes bh,
377 int verb) {
378
379 Interface &m_field = cOre;
381 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
382 verb);
383 skeletonFields.push_back(name);
384 if (space == NOFIELD)
385 SETERRQ(
386 PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
387 "NOFIELD space for boundary field not implemented in Simple interface");
388
390}
391
393Simple::addDataField(const std::string name, const FieldSpace space,
394 const FieldApproximationBase base,
395 const FieldCoefficientsNumber nb_of_coefficients,
396 const TagType tag_type, const enum MoFEMTypes bh,
397 int verb) {
398
399 Interface &m_field = cOre;
401 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
402 verb);
403 if (space == NOFIELD)
404 noFieldDataFields.push_back(name);
405 else
406 dataFields.push_back(name);
408}
409
411Simple::addMeshsetField(const std::string name, const FieldSpace space,
412 const FieldApproximationBase base,
413 const FieldCoefficientsNumber nb_of_coefficients,
414 const TagType tag_type, const enum MoFEMTypes bh,
415 int verb) {
416
417 Interface &m_field = cOre;
419 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
420 verb);
421 if (space != NOFIELD) {
422 meshsetFields.push_back(name);
423 } else {
424 noFieldFields.push_back(name);
425 }
427}
428
431
432 auto remove_field_from_list = [&](auto &vec) {
433 auto it = std::find(vec.begin(), vec.end(), name);
434 if (it != vec.end())
435 vec.erase(it);
436 };
437
438 remove_field_from_list(domainFields);
439
441}
442
445
446 auto remove_field_from_list = [&](auto &vec) {
447 auto it = std::find(vec.begin(), vec.end(), name);
448 if (it != vec.end())
449 vec.erase(it);
450 };
451
452 remove_field_from_list(boundaryFields);
453
455}
456
459
460 auto remove_field_from_list = [&](auto &vec) {
461 auto it = std::find(vec.begin(), vec.end(), name);
462 if (it != vec.end())
463 vec.erase(it);
464 };
465
466 remove_field_from_list(skeletonFields);
467
469}
470
472 Interface &m_field = cOre;
474
475 auto clear_rows_and_cols = [&](auto &fe_name) {
477 auto fe_ptr = m_field.get_finite_elements();
478 auto &fe_by_name = const_cast<FiniteElement_multiIndex *>(fe_ptr)
479 ->get<FiniteElement_name_mi_tag>();
480 auto it_fe = fe_by_name.find(fe_name);
481 if (it_fe != fe_by_name.end()) {
482
483 if (!fe_by_name.modify(it_fe, FiniteElement_row_change_bit_reset()))
484 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
485 "modification unsuccessful");
486
487 if (!fe_by_name.modify(it_fe, FiniteElement_col_change_bit_reset()))
488 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
489 "modification unsuccessful");
490 }
492 };
493 CHKERR clear_rows_and_cols(domainFE);
494 CHKERR clear_rows_and_cols(boundaryFE);
495 CHKERR clear_rows_and_cols(skeletonFE);
496
497 // Define finite elements
499
500 auto add_fields = [&](auto &fe_name, auto &fields) {
502 for (auto &field : fields) {
503 CHKERR m_field.modify_finite_element_add_field_row(fe_name, field);
504 CHKERR m_field.modify_finite_element_add_field_col(fe_name, field);
505 CHKERR m_field.modify_finite_element_add_field_data(fe_name, field);
506 }
508 };
509
510 auto add_data_fields = [&](auto &fe_name, auto &fields) {
512 for (auto &field : fields)
513 CHKERR m_field.modify_finite_element_add_field_data(fe_name, field);
515 };
516
517 CHKERR add_fields(domainFE, domainFields);
518 CHKERR add_data_fields(domainFE, dataFields);
519 CHKERR add_fields(domainFE, noFieldFields);
520 CHKERR add_data_fields(domainFE, noFieldDataFields);
521
522 if (addBoundaryFE || !boundaryFields.empty()) {
524 CHKERR add_fields(boundaryFE, domainFields);
525 if (!boundaryFields.empty())
526 CHKERR add_fields(boundaryFE, boundaryFields);
527 CHKERR add_data_fields(boundaryFE, dataFields);
528 CHKERR add_data_fields(boundaryFE, noFieldDataFields);
529 CHKERR add_fields(boundaryFE, noFieldFields);
530 }
531 if (addSkeletonFE || !skeletonFields.empty()) {
533 CHKERR add_fields(skeletonFE, domainFields);
534 if (!skeletonFields.empty())
535 CHKERR add_fields(skeletonFE, skeletonFields);
536 CHKERR add_data_fields(skeletonFE, dataFields);
537 CHKERR add_data_fields(skeletonFE, noFieldDataFields);
538 CHKERR add_fields(skeletonFE, noFieldFields);
539 }
540
541 if (noFieldFields.size() || meshsetFields.size()) {
543 CHKERR add_fields(meshsetFE, meshsetFields);
544 CHKERR add_fields(meshsetFE, noFieldFields);
545 CHKERR add_data_fields(meshsetFE, noFieldDataFields);
546 }
547
549}
550
551MoFEMErrorCode Simple::defineProblem(const PetscBool is_partitioned) {
552 Interface &m_field = cOre;
554 // Create dm instance
555 dM = createDM(m_field.get_comm(), "DMMOFEM");
556 // set dm data structure which created mofem data structures
559 CHKERR DMSetFromOptions(dM);
561 if (addBoundaryFE || !boundaryFields.empty()) {
563 }
564 if (addSkeletonFE || !skeletonFields.empty()) {
566 }
567 if (noFieldFields.size() || meshsetFields.size()) {
569 }
571 CHKERR DMMoFEMSetIsPartitioned(dM, is_partitioned);
573}
574
576 const int order, const Range *ents) {
578 fieldsOrder.emplace_back(field_name, order,
579 ents == NULL ? Range() : Range(*ents),
580 ents == NULL ? false : true);
582}
583
585 Interface &m_field = cOre;
587 PetscLogEventBegin(MOFEM_EVENT_SimpleBuildFields, 0, 0, 0, 0);
588
589 auto comm_interface_ptr = m_field.getInterface<CommInterface>();
590
591 // Add entities to the fields
592 auto add_ents_to_field = [&](auto meshset, auto dim, auto &fields) {
594 for (auto &field : fields) {
595 CHKERR m_field.add_ents_to_field_by_dim(meshset, dim, field);
596 CHKERR comm_interface_ptr->synchroniseFieldEntities(field, 0);
597 }
599 };
600
601 CHKERR add_ents_to_field(meshSet, dIm, domainFields);
602 CHKERR add_ents_to_field(meshSet, dIm, dataFields);
603 CHKERR add_ents_to_field(boundaryMeshset, dIm - 1, boundaryFields);
604 CHKERR add_ents_to_field(skeletonMeshset, dIm - 1, skeletonFields);
605
606 std::set<std::string> nofield_fields;
607 for (auto &f : noFieldFields)
608 nofield_fields.insert(f);
609 for (auto &f : noFieldDataFields)
610 nofield_fields.insert(f);
611
612 // Set order
613
614 auto get_field_ptr = [&](auto &f) { return m_field.get_field_structure(f); };
615 for (auto &t : fieldsOrder) {
616 const auto f = std::get<0>(t);
617 const auto order = std::get<1>(t);
618
619 MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "Simple")
620 << "Set order to field " << f << " order " << order;
621 MOFEM_LOG_CHANNEL("SYNC");
622 if (std::get<3>(t)) {
623 MOFEM_TAG_AND_LOG("SYNC", Sev::verbose, "Simple")
624 << "To ents: " << std::endl
625 << std::get<2>(t) << std::endl;
626 }
627 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
628
629 if (std::get<3>(t)) {
630
631 CHKERR m_field.set_field_order(std::get<2>(t), f, order);
632
633 } else {
634 auto f_ptr = get_field_ptr(f);
635
636 if (f_ptr->getSpace() == H1) {
637 if (f_ptr->getApproxBase() == AINSWORTH_BERNSTEIN_BEZIER_BASE) {
638 CHKERR m_field.set_field_order(meshSet, MBVERTEX, f, order);
639 } else {
640 CHKERR m_field.set_field_order(meshSet, MBVERTEX, f, 1);
641 }
642 }
643
644 for (auto d = 1; d <= dIm; ++d) {
645 for (EntityType t = CN::TypeDimensionMap[d].first;
646 t <= CN::TypeDimensionMap[d].second; ++t) {
647 CHKERR m_field.set_field_order(meshSet, t, f, order);
648 }
649 }
650 }
651 }
652 MOFEM_LOG_CHANNEL("WORLD");
653 // Build fields
654 CHKERR m_field.build_fields();
655 PetscLogEventEnd(MOFEM_EVENT_SimpleBuildFields, 0, 0, 0, 0);
657}
658
660 Interface &m_field = cOre;
662 PetscLogEventBegin(MOFEM_EVENT_SimpleBuildFiniteElements, 0, 0, 0, 0);
663 // Add finite elements
665 true);
667 if (addBoundaryFE || boundaryFields.size()) {
669 boundaryFE, true);
671 }
672 if (addSkeletonFE || skeletonFields.size()) {
674 skeletonFE, true);
676 }
677
678 if (noFieldFields.size() || meshsetFields.size()) {
679
680 auto create_meshset = [&]() {
681 EntityHandle meshset;
682 auto create = [&]() {
684 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, meshset);
685 {
686 ParallelComm *pcomm =
687 ParallelComm::get_pcomm(&m_field.get_moab(), MYPCOMM_INDEX);
688 Tag part_tag = pcomm->part_tag();
689 int rank = pcomm->rank();
690 CHKERR m_field.get_moab().tag_set_data(part_tag, &meshset, 1,
691 &rank);
692 CHKERR m_field.getInterface<BitRefManager>()->setBitLevelToMeshset(
693 meshset, BitRefLevel().set());
694 }
696 };
697 CHK_THROW_MESSAGE(create(), "Failed to create meshset");
698 return meshset;
699 };
700
701 auto fe_meshset = create_meshset();
703 meshsetFE, false);
704 // Add entities to the meshset, that will make DOFs on those entities
705 // accessible on meshset finite element
706 for (auto ents : meshsetFiniteElementEntities) {
707 CHKERR m_field.get_moab().add_entities(fe_meshset, ents);
708 }
710
711 }
712
713 for (std::vector<std::string>::iterator fit = otherFEs.begin();
714 fit != otherFEs.end(); ++fit) {
715 CHKERR m_field.build_finite_elements(*fit);
716 }
717 PetscLogEventEnd(MOFEM_EVENT_SimpleBuildFiniteElements, 0, 0, 0, 0);
719}
720
722 Interface &m_field = cOre;
724 PetscLogEventBegin(MOFEM_EVENT_SimpleBuildProblem, 0, 0, 0, 0);
726 // Set problem by the DOFs on the fields rather that by adding DOFs on the
727 // elements
728 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_TRUE;
730 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_FALSE;
731 PetscLogEventEnd(MOFEM_EVENT_SimpleBuildProblem, 0, 0, 0, 0);
733}
734
735MoFEMErrorCode Simple::setUp(const PetscBool is_partitioned) {
737
738 PetscLogEventBegin(MOFEM_EVENT_SimpleSetUP, 0, 0, 0, 0);
739
741
742 if (addSkeletonFE || !skeletonFields.empty()) {
744 if (addBoundaryFE || !boundaryFields.empty()) {
746 }
747 }
748
751
752 CHKERR defineProblem(is_partitioned);
756
757 PetscLogEventEnd(MOFEM_EVENT_SimpleSetUP, 0, 0, 0, 0);
759}
760
762 Interface &m_field = cOre;
764 PetscLogEventBegin(MOFEM_EVENT_SimpleBuildProblem, 0, 0, 0, 0);
765
766 if (!only_dm) {
769 if (addSkeletonFE || !skeletonFields.empty()) {
771 if (addBoundaryFE || !boundaryFields.empty()) {
773 }
774 }
778 }
779
781
782 const Problem *problem_ptr;
783 CHKERR DMMoFEMGetProblemPtr(dM, &problem_ptr);
784 const auto problem_name = problem_ptr->getName();
785 CHKERR m_field.modify_problem_ref_level_set_bit(problem_name, bitLevel);
788
789 // Set problem by the DOFs on the fields rather that by adding DOFs on the
790 // elements
791 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_TRUE;
793 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_FALSE;
794
795 PetscLogEventEnd(MOFEM_EVENT_SimpleBuildProblem, 0, 0, 0, 0);
797}
798
801 CHKERR PetscObjectReference(getPetscObject(dM.get()));
802 *dm = dM.get();
804}
805
806/**
807 * @brief Delete dm
808 *
809 * @return MoFEMErrorCode
810 */
816
817/**
818 * @brief Delete finite elements
819 *
820 * @return MoFEMErrorCode
821 */
823 Interface &m_field = cOre;
825 for (auto fe : {domainFE, boundaryFE, skeletonFE}) {
826 if (m_field.check_finite_element(fe)) {
827 CHKERR m_field.delete_finite_element(fe);
828 }
829 }
831}
832
834Simple::addFieldToEmptyFieldBlocks(const std::string row_field,
835 const std::string col_field) const {
836 Interface &m_field = cOre;
839 getProblemName(), row_field, col_field);
841}
842
844 Interface &m_field = cOre;
846 ParallelComm *pcomm =
847 ParallelComm::get_pcomm(&m_field.get_moab(), MYPCOMM_INDEX);
848
849 auto get_skin = [&](auto meshset) {
850 // filter not owned entities, those are not on boundary
851
852 Range domain_ents;
853 CHKERR m_field.get_moab().get_entities_by_dimension(meshset, dIm,
854 domain_ents, true);
855 CHKERR pcomm->filter_pstatus(domain_ents,
856 PSTATUS_SHARED | PSTATUS_MULTISHARED,
857 PSTATUS_NOT, -1, nullptr);
858
859 Skinner skin(&m_field.get_moab());
860 Range domain_skin;
861 CHKERR skin.find_skin(0, domain_ents, false, domain_skin);
862 CHKERR pcomm->filter_pstatus(domain_skin,
863 PSTATUS_SHARED | PSTATUS_MULTISHARED,
864 PSTATUS_NOT, -1, nullptr);
865 return domain_skin;
866 };
867
868 auto create_boundary_meshset = [&](auto &&domain_skin) {
870 // create boundary meshset
871 if (boundaryMeshset != 0) {
873 }
874 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, boundaryMeshset);
875 CHKERR m_field.get_moab().add_entities(boundaryMeshset, domain_skin);
876 for (int dd = 0; dd != dIm - 1; dd++) {
877 Range adj;
878 CHKERR m_field.get_moab().get_adjacencies(domain_skin, dd, false, adj,
879 moab::Interface::UNION);
880 CHKERR m_field.get_moab().add_entities(boundaryMeshset, adj);
881 }
883 };
884
885 CHKERR create_boundary_meshset(get_skin(meshSet));
886
888}
889
891 Interface &m_field = cOre;
893
894 ParallelComm *pcomm =
895 ParallelComm::get_pcomm(&m_field.get_moab(), MYPCOMM_INDEX);
896
897 auto create_skeleton_meshset = [&](auto meshset) {
899 // create boundary meshset
900 if (skeletonMeshset != 0) {
902 }
903 Range boundary_ents, skeleton_ents;
904 CHKERR m_field.get_moab().get_entities_by_dimension(boundaryMeshset,
905 dIm - 1, boundary_ents);
906 Range domain_ents;
907 CHKERR m_field.get_moab().get_entities_by_dimension(meshset, dIm,
908 domain_ents, true);
909 CHKERR m_field.get_moab().get_adjacencies(
910 domain_ents, dIm - 1, true, skeleton_ents, moab::Interface::UNION);
911 skeleton_ents = subtract(skeleton_ents, boundary_ents);
912 CHKERR pcomm->filter_pstatus(skeleton_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT,
913 -1, nullptr);
914 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, skeletonMeshset);
915 CHKERR m_field.get_moab().add_entities(skeletonMeshset, skeleton_ents);
917 };
918
919 CHKERR create_skeleton_meshset(meshSet);
920
922}
923
925 Interface &m_field = cOre;
927 MOFEM_LOG("WORLD", Sev::verbose) << "Exchange ghost cells";
928
929 ParallelComm *pcomm =
930 ParallelComm::get_pcomm(&m_field.get_moab(), MYPCOMM_INDEX);
931 if (pcomm == NULL)
932 pcomm = new ParallelComm(&m_field.get_moab(), m_field.get_comm());
933
934 CHKERR pcomm->exchange_ghost_cells(getDim(), getDim() - 1, 1,
935 3 /**get all adjacent ghosted entities */,
936 true, true, meshSet ? &meshSet : nullptr);
937
938 Range shared;
939 CHKERR m_field.get_moab().get_entities_by_dimension(0, dIm, shared);
940 for (auto d = dIm - 1; d >= 0; --d) {
941 CHKERR m_field.get_moab().get_adjacencies(shared, d, false, shared,
942 moab::Interface::UNION);
943 }
944 CHKERR pcomm->filter_pstatus(shared, PSTATUS_SHARED | PSTATUS_MULTISHARED,
945 PSTATUS_OR, -1, &shared);
946 Tag part_tag = pcomm->part_tag();
947 CHKERR pcomm->exchange_tags(part_tag, shared);
948 CHKERR m_field.getInterface<CommInterface>()->resolveParentEntities(shared,
949 VERBOSE);
950
952}
953
954} // namespace MoFEM
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
@ VERBOSE
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
@ MF_ZERO
FieldApproximationBase
approximation base
Definition definitions.h:58
@ AINSWORTH_BERNSTEIN_BEZIER_BASE
Definition definitions.h:64
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
FieldSpace
approximation spaces
Definition definitions.h:82
@ NOFIELD
scalar or vector of scalars describe (no true field)
Definition definitions.h:84
@ H1
continuous field
Definition definitions.h:85
@ HCURL
field with continuous tangents
Definition definitions.h:86
@ HDIV
field with continuous normal traction
Definition definitions.h:87
#define MYPCOMM_INDEX
default communicator number PCOMM
@ DISCONTINUOUS
Broken continuity (No effect on L2 space)
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ 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 ...
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
constexpr int order
PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned)
Definition DMMoFEM.cpp:1113
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:488
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:114
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
Definition DMMoFEM.cpp:422
PetscErrorCode DMSetUp_MoFEM(DM dm)
Definition DMMoFEM.cpp:1297
multi_index_container< boost::shared_ptr< FiniteElement >, indexed_by< hashed_unique< tag< FiniteElement_Meshset_mi_tag >, member< FiniteElement, EntityHandle, &FiniteElement::meshset > >, hashed_unique< tag< BitFEId_mi_tag >, const_mem_fun< FiniteElement, BitFEId, &FiniteElement::getId >, HashBit< BitFEId >, EqBit< BitFEId > >, ordered_unique< tag< FiniteElement_name_mi_tag >, const_mem_fun< FiniteElement, boost::string_ref, &FiniteElement::getNameRef > > > > FiniteElement_multiIndex
MultiIndex for entities for FiniteElement.
virtual const FiniteElement_multiIndex * get_finite_elements() const =0
Get the finite elements object.
virtual MoFEMErrorCode add_ents_to_finite_element_by_dim(const EntityHandle entities, const int dim, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode modify_finite_element_adjacency_table(const std::string &fe_name, const EntityType type, ElementAdjacencyFunct function)=0
modify finite element table, only for advanced user
virtual MoFEMErrorCode add_ents_to_finite_element_by_MESHSET(const EntityHandle meshset, const std::string &name, const bool recursive=false)=0
add MESHSET element to finite element database given by name
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode add_ents_to_field_by_dim(const Range &ents, const int dim, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
virtual MoFEMErrorCode modify_problem_mask_ref_level_set_bit(const std::string &name_problem, const BitRefLevel &bit)=0
set dof mask ref level for problem
virtual MoFEMErrorCode modify_problem_ref_level_set_bit(const std::string &name_problem, const BitRefLevel &bit)=0
set ref level for problem
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
int FieldCoefficientsNumber
Number of field coefficients.
Definition Types.hpp:27
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
PetscObject getPetscObject(T obj)
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
constexpr double t
plate stiffness
Definition plate.cpp:58
constexpr auto field_name
multi_index_container< DofsSideMapData, indexed_by< ordered_non_unique< tag< TypeSide_mi_tag >, composite_key< DofsSideMapData, member< DofsSideMapData, EntityType, &DofsSideMapData::type >, member< DofsSideMapData, int, &DofsSideMapData::side > > >, ordered_unique< tag< EntDofIdx_mi_tag >, member< DofsSideMapData, int, &DofsSideMapData::dof > > > > DofsSideMap
Map entity stype and side to element/entity dof index.
Managing BitRefLevels.
Managing BitRefLevels.
virtual int get_comm_size() const =0
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode add_broken_field(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const std::vector< std::pair< EntityType, std::function< MoFEMErrorCode(BaseFunction::DofsSideMap &)> > > list_dof_side_map, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
virtual bool check_finite_element(const std::string &name) const =0
Check if finite element is in database.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MoFEMErrorCode add_field(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
virtual MPI_Comm & get_comm() const =0
virtual MoFEMErrorCode delete_finite_element(const std::string name, int verb=DEFAULT_VERBOSITY)=0
Delete finite element from MoFEM database.
virtual MoFEMErrorCode rebuild_database(int verb=DEFAULT_VERBOSITY)=0
Clear database and initialize it once again.
Core (interface) class.
Definition Core.hpp:82
Deprecated interface functions.
keeps basic data about problem
Problem manager is used to build and partition problems.
Simple interface for fast problem set-up.
Definition Simple.hpp:27
boost::shared_ptr< ParentFiniteElementAdjacencyFunction< 2 > > parentAdjFunctionDim2
Definition Simple.hpp:665
EntityHandle boundaryMeshset
meshset with boundary
Definition Simple.hpp:613
MoFEMErrorCode buildProblem()
Build problem.
Definition Simple.cpp:721
MoFEMErrorCode addDomainField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on domain.
Definition Simple.cpp:261
std::vector< std::string > dataFields
Data fields.
Definition Simple.hpp:628
MoFEMErrorCode setParentAdjacency()
Definition Simple.cpp:67
std::list< std::tuple< std::string, int, Range, bool > > fieldsOrder
Definition Simple.hpp:634
std::vector< std::string > domainFields
domain fields
Definition Simple.hpp:625
MoFEMErrorCode defineFiniteElements()
Define finite elements.
Definition Simple.cpp:471
MoFEM::Core & cOre
Definition Simple.hpp:600
BitRefLevel bitAdjEnt
bit ref level for parent
Definition Simple.hpp:622
char meshFileName[255]
mesh file name
Definition Simple.hpp:647
EntityHandle meshSet
domain meshset
Definition Simple.hpp:612
int getDim() const
Get the problem dimension.
Definition Simple.hpp:373
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition Simple.cpp:191
std::vector< std::string > otherFEs
Other finite elements.
Definition Simple.hpp:643
MoFEMErrorCode buildFiniteElements()
Build finite elements.
Definition Simple.cpp:659
MoFEMErrorCode addMeshsetField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add meshset field.
Definition Simple.cpp:411
boost::shared_ptr< ParentFiniteElementAdjacencyFunctionSkeleton< 2 > > parentAdjSkeletonFunctionDim2
Definition Simple.hpp:670
MoFEMErrorCode exchangeGhostCells()
Definition Simple.cpp:924
PetscLogEvent MOFEM_EVENT_SimpleBuildFields
Definition Simple.hpp:607
PetscLogEvent MOFEM_EVENT_SimpleLoadMesh
Definition Simple.hpp:606
MoFEMErrorCode reSetUp(bool only_dm=false)
Rebuild internal MoFEM data structures.
Definition Simple.cpp:761
MoFEMErrorCode addBoundaryField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on boundary.
Definition Simple.cpp:355
std::vector< std::string > noFieldFields
NOFIELD field name.
Definition Simple.hpp:630
std::string meshsetFE
meshset finite element
Definition Simple.hpp:641
bool addSkeletonFE
Add skeleton FE.
Definition Simple.hpp:616
BitRefLevel bitAdjParent
bit ref level for parent
Definition Simple.hpp:620
bool addBoundaryFE
Add boundary FE.
Definition Simple.hpp:617
MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string row_field, const std::string col_field) const
Add empty block to problem.
Definition Simple.cpp:834
std::string skeletonFE
skeleton finite element
Definition Simple.hpp:640
std::vector< std::string > noFieldDataFields
NOFIELD field name.
Definition Simple.hpp:631
std::vector< std::string > meshsetFields
meshset fields
Definition Simple.hpp:629
std::string boundaryFE
boundary finite element
Definition Simple.hpp:639
std::string nameOfProblem
problem name
Definition Simple.hpp:637
boost::shared_ptr< ParentFiniteElementAdjacencyFunction< 3 > > parentAdjFunctionDim3
Definition Simple.hpp:663
MoFEMErrorCode getOptions()
get options
Definition Simple.cpp:180
std::string domainFE
domain finite element
Definition Simple.hpp:638
std::vector< std::string > boundaryFields
boundary fields
Definition Simple.hpp:626
boost::shared_ptr< ParentFiniteElementAdjacencyFunctionSkeleton< 1 > > parentAdjSkeletonFunctionDim1
Definition Simple.hpp:672
MoFEMErrorCode removeSkeletonField(const std::string name)
Remove field from skeleton.
Definition Simple.cpp:457
BitRefLevel bitAdjEntMask
bit ref level for parent parent
Definition Simple.hpp:623
SmartPetscObj< DM > dM
Discrete manager (interface to PETSc/MoFEM functions)
Definition Simple.hpp:651
MoFEMErrorCode removeDomainField(const std::string name)
Remove field from domain.
Definition Simple.cpp:429
MoFEMErrorCode buildFields()
Build fields.
Definition Simple.cpp:584
SmartPetscObj< DM > getDM()
Return smart DM object.
Definition Simple.hpp:363
std::vector< Range > meshsetFiniteElementEntities
Meshset element entities.
Definition Simple.hpp:645
BitRefLevel bitLevel
BitRefLevel of the problem.
Definition Simple.hpp:602
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition Simple.cpp:575
MoFEMErrorCode defineProblem(const PetscBool is_partitioned=PETSC_TRUE)
define problem
Definition Simple.cpp:551
std::vector< std::string > skeletonFields
fields on the skeleton
Definition Simple.hpp:627
MoFEMErrorCode addDataField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add data field.
Definition Simple.cpp:393
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition Simple.cpp:8
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition Simple.cpp:735
boost::function< MoFEMErrorCode(Interface &, const char *, const char *)> LoadFileFunc
Definition Simple.hpp:46
MoFEMErrorCode removeBoundaryField(const std::string name)
Remove field from boundary.
Definition Simple.cpp:443
const std::string getProblemName() const
Get the Problem Name.
Definition Simple.hpp:450
int dIm
dimension of problem
Definition Simple.hpp:648
MoFEMErrorCode setSkeletonAdjacency(int dim=-1, std::string fe_name="")
Set the skeleton adjacency object.
Definition Simple.cpp:143
MoFEMErrorCode deleteDM()
Delete dm.
Definition Simple.cpp:811
PetscLogEvent MOFEM_EVENT_SimpleSetUP
Definition Simple.hpp:605
PetscLogEvent MOFEM_EVENT_SimpleKSPSolve
Definition Simple.hpp:610
MoFEMErrorCode createBoundaryMeshset()
Definition Simple.cpp:843
PetscLogEvent MOFEM_EVENT_SimpleBuildFiniteElements
Definition Simple.hpp:608
BitRefLevel bitLevelMask
BitRefLevel of the problem.
Definition Simple.hpp:603
BitRefLevel bitAdjParentMask
bit ref level for parent parent
Definition Simple.hpp:621
PetscLogEvent MOFEM_EVENT_SimpleBuildProblem
Definition Simple.hpp:609
boost::shared_ptr< ParentFiniteElementAdjacencyFunction< 1 > > parentAdjFunctionDim1
Definition Simple.hpp:667
MoFEMErrorCode deleteFiniteElements()
Delete finite elements.
Definition Simple.cpp:822
Simple(const MoFEM::Core &core)
Definition Simple.cpp:162
EntityHandle skeletonMeshset
skeleton meshset with boundary
Definition Simple.hpp:614
MoFEMErrorCode createSkeletonMeshset()
Definition Simple.cpp:890
bool addParentAdjacencies
If set to true parent adjacencies are build.
Definition Simple.hpp:618
MoFEMErrorCode addDomainBrokenField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add broken field on domain.
Definition Simple.cpp:282
MoFEMErrorCode addSkeletonField(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_ZERO, int verb=-1)
Add field on skeleton.
Definition Simple.cpp:373
static MoFEMErrorCode setDofsSideMap(const FieldSpace space, const FieldContinuity continuity, const FieldApproximationBase base, DofsSideMap &)
Set map of dof to side number.
static MoFEMErrorCode setDofsSideMap(const FieldSpace space, const FieldContinuity continuity, const FieldApproximationBase base, DofsSideMap &)
Set map of dof to side number.
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.