v0.14.0
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 <>
22 Interface &m_field = cOre;
24
26 boost::make_shared<ParentFiniteElementAdjacencyFunctionSkeleton<1>>(
29 fe_name, MBEDGE, *parentAdjSkeletonFunctionDim1);
30
32}
33
34template <>
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
102
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 ierr = PetscOptionsBegin(PETSC_COMM_WORLD, "", "Simple interface options",
184 "none");
185 CHKERRG(ierr);
186 ierr = PetscOptionsString("-file_name", "file name", "", "mesh.h5m",
187 meshFileName, 255, &flg);
188 CHKERRG(ierr);
189 ierr = PetscOptionsEnd();
190 CHKERRG(ierr);
192}
193
194MoFEMErrorCode Simple::loadFile(const std::string options,
195 const std::string mesh_file_name,
196 LoadFileFunc loadFunc) {
197 Interface &m_field = cOre;
199 PetscLogEventBegin(MOFEM_EVENT_SimpleLoadMesh, 0, 0, 0, 0);
200
201 if (!mesh_file_name.empty())
202 strcpy(meshFileName, mesh_file_name.c_str());
203
204 // Invoke the boost function, passing in required arguments
205 CHKERR loadFunc(m_field, meshFileName, options.c_str());
206 CHKERR m_field.rebuild_database();
207
208 // determine problem dimension
209 if (dIm == -1) {
210 int nb_ents_3d;
211 CHKERR m_field.get_moab().get_number_entities_by_dimension(
212 meshSet, 3, nb_ents_3d, true);
213 if (nb_ents_3d > 0) {
214 dIm = 3;
215 } else {
216 int nb_ents_2d;
217 CHKERR m_field.get_moab().get_number_entities_by_dimension(
218 meshSet, 2, nb_ents_2d, true);
219 if (nb_ents_2d > 0) {
220 dIm = 2;
221 } else {
222 dIm = 1;
223 }
224 }
225 }
226
227 if (!boundaryMeshset)
229 if (!skeletonMeshset)
231 if (addSkeletonFE)
233
234 if (bitLevel.any()) {
235 Range ents;
236 CHKERR m_field.get_moab().get_entities_by_dimension(meshSet, dIm, ents,
237 true);
238 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevel(ents, bitLevel,
239 false);
240 } else {
241 MOFEM_LOG("WORLD", Sev::warning) << "BitRefLevel is none and not set";
242 CHKERR m_field.getInterface<BitRefManager>()->addToDatabaseBitRefLevelByDim(
243 dIm, BitRefLevel().set(), BitRefLevel().set());
244 }
245
246 PetscLogEventEnd(MOFEM_EVENT_SimpleLoadMesh, 0, 0, 0, 0);
248}
249
252 Interface &m_field = cOre;
253 if (m_field.get_comm_size() == 1)
255 else
256 CHKERR loadFile("PARALLEL=READ_PART;"
257 "PARALLEL_RESOLVE_SHARED_ENTS;"
258 "PARTITION=PARALLEL_PARTITION;",
261}
262
264Simple::addDomainField(const std::string name, const FieldSpace space,
265 const FieldApproximationBase base,
266 const FieldCoefficientsNumber nb_of_coefficients,
267 const TagType tag_type, const enum MoFEMTypes bh,
268 int verb) {
269
270 Interface &m_field = cOre;
272 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
273 verb);
274 domainFields.push_back(name);
275 if (space == NOFIELD)
276 SETERRQ(
277 PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
278 "NOFIELD space for boundary filed not implemented in Simple interface");
279
280
282}
283
285Simple::addDomainBrokenField(const std::string name, const FieldSpace space,
286 const FieldApproximationBase base,
287 const FieldCoefficientsNumber nb_of_coefficients,
288 const TagType tag_type, const enum MoFEMTypes bh,
289 int verb) {
290
291 Interface &m_field = cOre;
293
294 auto get_side_map_hcurl = [&]() {
295 return std::vector<
296
297 std::pair<EntityType,
299
300 >>{
301
302 {MBTRI,
303 [&](BaseFunction::DofsSideMap &dofs_side_map) -> MoFEMErrorCode {
305 dofs_side_map);
306 }}
307
308 };
309 };
310
311 auto get_side_map_hdiv = [&]() {
312 return std::vector<
313
314 std::pair<EntityType,
316
317 >>{
318
319 {MBTET,
320 [&](BaseFunction::DofsSideMap &dofs_side_map) -> MoFEMErrorCode {
322 dofs_side_map);
323 }}
324
325 };
326 };
327
328 auto get_side_map = [&](auto space) {
329 switch (space) {
330 case HCURL:
331 return get_side_map_hcurl();
332 case HDIV:
333 return get_side_map_hdiv();
334 default:
335 MOFEM_LOG_CHANNEL("WORLD");
336 MOFEM_LOG("WORLD", Sev::warning)
337 << "Side dof map for broken space <" << space << "> not implemented";
338 }
339 return std::vector<
340
341 std::pair<EntityType,
343
344 >>{};
345 };
346
347 CHKERR m_field.add_broken_field(name, space, base, nb_of_coefficients,
348 get_side_map(space), tag_type, bh, verb);
349 domainFields.push_back(name);
350 if (space == NOFIELD)
351 SETERRQ(
352 PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
353 "NOFIELD space for boundary filed not implemented in Simple interface");
355}
356
358Simple::addBoundaryField(const std::string name, const FieldSpace space,
359 const FieldApproximationBase base,
360 const FieldCoefficientsNumber nb_of_coefficients,
361 const TagType tag_type, const enum MoFEMTypes bh,
362 int verb) {
363 Interface &m_field = cOre;
365 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
366 verb);
367 boundaryFields.push_back(name);
368 if (space == NOFIELD)
369 SETERRQ(
370 PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
371 "NOFIELD space for boundary filed not implemented in Simple interface");
373}
374
376Simple::addSkeletonField(const std::string name, const FieldSpace space,
377 const FieldApproximationBase base,
378 const FieldCoefficientsNumber nb_of_coefficients,
379 const TagType tag_type, const enum MoFEMTypes bh,
380 int verb) {
381
382 Interface &m_field = cOre;
384 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
385 verb);
386 skeletonFields.push_back(name);
387 if (space == NOFIELD)
388 SETERRQ(
389 PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
390 "NOFIELD space for boundary filed not implemented in Simple interface");
391
393}
394
396Simple::addDataField(const std::string name, const FieldSpace space,
397 const FieldApproximationBase base,
398 const FieldCoefficientsNumber nb_of_coefficients,
399 const TagType tag_type, const enum MoFEMTypes bh,
400 int verb) {
401
402 Interface &m_field = cOre;
404 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
405 verb);
406 if (space == NOFIELD)
407 noFieldDataFields.push_back(name);
408 else
409 dataFields.push_back(name);
411}
412
414Simple::addMeshsetField(const std::string name, const FieldSpace space,
415 const FieldApproximationBase base,
416 const FieldCoefficientsNumber nb_of_coefficients,
417 const TagType tag_type, const enum MoFEMTypes bh,
418 int verb) {
419
420 Interface &m_field = cOre;
422 CHKERR m_field.add_field(name, space, base, nb_of_coefficients, tag_type, bh,
423 verb);
424 if (space != NOFIELD) {
425 meshsetFields.push_back(name);
426 } else {
427 noFieldFields.push_back(name);
428 }
430}
431
434
435 auto remove_field_from_list = [&](auto &vec) {
436 auto it = std::find(vec.begin(), vec.end(), name);
437 if (it != vec.end())
438 vec.erase(it);
439 };
440
441 remove_field_from_list(domainFields);
442
444}
445
448
449 auto remove_field_from_list = [&](auto &vec) {
450 auto it = std::find(vec.begin(), vec.end(), name);
451 if (it != vec.end())
452 vec.erase(it);
453 };
454
455 remove_field_from_list(boundaryFields);
456
458}
459
462
463 auto remove_field_from_list = [&](auto &vec) {
464 auto it = std::find(vec.begin(), vec.end(), name);
465 if (it != vec.end())
466 vec.erase(it);
467 };
468
469 remove_field_from_list(skeletonFields);
470
472}
473
475 Interface &m_field = cOre;
477
478 auto clear_rows_and_cols = [&](auto &fe_name) {
480 auto fe_ptr = m_field.get_finite_elements();
481 auto &fe_by_name = const_cast<FiniteElement_multiIndex *>(fe_ptr)
482 ->get<FiniteElement_name_mi_tag>();
483 auto it_fe = fe_by_name.find(fe_name);
484 if (it_fe != fe_by_name.end()) {
485
486 if (!fe_by_name.modify(it_fe, FiniteElement_row_change_bit_reset()))
487 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
488 "modification unsuccessful");
489
490 if (!fe_by_name.modify(it_fe, FiniteElement_col_change_bit_reset()))
491 SETERRQ(m_field.get_comm(), MOFEM_OPERATION_UNSUCCESSFUL,
492 "modification unsuccessful");
493 }
495 };
496 CHKERR clear_rows_and_cols(domainFE);
497 CHKERR clear_rows_and_cols(boundaryFE);
498 CHKERR clear_rows_and_cols(skeletonFE);
499
500 // Define finite elements
502
503 auto add_fields = [&](auto &fe_name, auto &fields) {
505 for (auto &field : fields) {
506 CHKERR m_field.modify_finite_element_add_field_row(fe_name, field);
507 CHKERR m_field.modify_finite_element_add_field_col(fe_name, field);
508 CHKERR m_field.modify_finite_element_add_field_data(fe_name, field);
509 }
511 };
512
513 auto add_data_fields = [&](auto &fe_name, auto &fields) {
515 for (auto &field : fields)
516 CHKERR m_field.modify_finite_element_add_field_data(fe_name, field);
518 };
519
520 CHKERR add_fields(domainFE, domainFields);
521 CHKERR add_data_fields(domainFE, dataFields);
522 CHKERR add_fields(domainFE, noFieldFields);
523 CHKERR add_data_fields(domainFE, noFieldDataFields);
524
525 if (addBoundaryFE || !boundaryFields.empty()) {
527 CHKERR add_fields(boundaryFE, domainFields);
528 if (!boundaryFields.empty())
529 CHKERR add_fields(boundaryFE, boundaryFields);
530 CHKERR add_data_fields(boundaryFE, dataFields);
531 CHKERR add_data_fields(boundaryFE, noFieldDataFields);
532 CHKERR add_fields(boundaryFE, noFieldFields);
533 }
534 if (addSkeletonFE || !skeletonFields.empty()) {
536 CHKERR add_fields(skeletonFE, domainFields);
537 if (!skeletonFields.empty())
538 CHKERR add_fields(skeletonFE, skeletonFields);
539 CHKERR add_data_fields(skeletonFE, dataFields);
540 CHKERR add_data_fields(skeletonFE, noFieldDataFields);
541 CHKERR add_fields(skeletonFE, noFieldFields);
542 }
543
544 if (noFieldFields.size() || meshsetFields.size()) {
546
547 auto create_meshset = [&]() {
548 EntityHandle fe_meshset;
549 auto create = [&]() {
551 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, fe_meshset);
552 {
553 EntityHandle meshset;
554 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, meshset);
555 CHKERR m_field.getInterface<BitRefManager>()->setBitLevelToMeshset(
556 meshset, BitRefLevel().set());
557 }
559 };
560 CHK_THROW_MESSAGE(create(), "Failed to create meshset");
561 return fe_meshset;
562 };
563
564 CHKERR m_field.add_ents_to_finite_element_by_MESHSET(create_meshset(),
565 meshsetFE, false);
566
567 CHKERR add_fields(meshsetFE, meshsetFields);
568 CHKERR add_fields(meshsetFE, noFieldFields);
569 CHKERR add_data_fields(meshsetFE, noFieldDataFields);
570 }
571
573}
574
575MoFEMErrorCode Simple::defineProblem(const PetscBool is_partitioned) {
576 Interface &m_field = cOre;
578 // Create dm instance
579 dM = createDM(m_field.get_comm(), "DMMOFEM");
580 // set dm data structure which created mofem data structures
583 CHKERR DMSetFromOptions(dM);
585 if (addBoundaryFE || !boundaryFields.empty()) {
587 }
588 if (addSkeletonFE || !skeletonFields.empty()) {
590 }
591 if (noFieldFields.size() || meshsetFields.size()) {
593 }
595 CHKERR DMMoFEMSetIsPartitioned(dM, is_partitioned);
597}
598
600 const int order, const Range *ents) {
602 fieldsOrder.emplace_back(field_name, order,
603 ents == NULL ? Range() : Range(*ents),
604 ents == NULL ? false : true);
606}
607
609 Interface &m_field = cOre;
611 PetscLogEventBegin(MOFEM_EVENT_SimpleBuildFields, 0, 0, 0, 0);
612
613 auto comm_interface_ptr = m_field.getInterface<CommInterface>();
614 auto bit_ref_ptr = m_field.getInterface<BitRefManager>();
615
616 // Add entities to the fields
617 auto add_ents_to_field = [&](auto meshset, auto dim, auto &fields) {
619 for (auto &field : fields) {
620 CHKERR m_field.add_ents_to_field_by_dim(meshset, dim, field);
621 CHKERR comm_interface_ptr->synchroniseFieldEntities(field, 0);
622 }
624 };
625
626 auto make_no_field_ents = [&](auto &fields) {
628 for (auto &field : fields) {
629 std::array<double, 6> coords = {0, 0, 0, 0, 0, 0};
630 CHKERR m_field.create_vertices_and_add_to_field(field, coords.data(), 1);
631 CHKERR comm_interface_ptr->makeFieldEntitiesMultishared(field, 0);
632 CHKERR bit_ref_ptr->setFieldEntitiesBitRefLevel(field, bitLevel);
633 }
635 };
636
637 CHKERR add_ents_to_field(meshSet, dIm, domainFields);
638 CHKERR add_ents_to_field(meshSet, dIm, dataFields);
639 CHKERR add_ents_to_field(boundaryMeshset, dIm - 1, boundaryFields);
640 CHKERR add_ents_to_field(skeletonMeshset, dIm - 1, skeletonFields);
641
642 std::set<std::string> nofield_fields;
643 for (auto &f : noFieldFields)
644 nofield_fields.insert(f);
645 for (auto &f : noFieldDataFields)
646 nofield_fields.insert(f);
647
648 CHKERR make_no_field_ents(nofield_fields);
649
650 // Set order
651
652 auto get_field_ptr = [&](auto &f) { return m_field.get_field_structure(f); };
653 for (auto &t : fieldsOrder) {
654 const auto f = std::get<0>(t);
655 const auto order = std::get<1>(t);
656
657 MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "Simple")
658 << "Set order to field " << f << " order " << order;
659 MOFEM_LOG_CHANNEL("SYNC");
660 if (std::get<3>(t)) {
661 MOFEM_TAG_AND_LOG("SYNC", Sev::verbose, "Simple")
662 << "To ents: " << std::endl
663 << std::get<2>(t) << std::endl;
664 }
665 MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::verbose);
666
667 if (std::get<3>(t)) {
668
669 CHKERR m_field.set_field_order(std::get<2>(t), f, order);
670
671 } else {
672 auto f_ptr = get_field_ptr(f);
673
674 if (f_ptr->getSpace() == H1) {
675 if (f_ptr->getApproxBase() == AINSWORTH_BERNSTEIN_BEZIER_BASE) {
676 CHKERR m_field.set_field_order(meshSet, MBVERTEX, f, order);
677 } else {
678 CHKERR m_field.set_field_order(meshSet, MBVERTEX, f, 1);
679 }
680 }
681
682 for (auto d = 1; d <= dIm; ++d) {
683 for (EntityType t = CN::TypeDimensionMap[d].first;
684 t <= CN::TypeDimensionMap[d].second; ++t) {
685 CHKERR m_field.set_field_order(meshSet, t, f, order);
686 }
687 }
688 }
689 }
690 MOFEM_LOG_CHANNEL("WORLD");
691 // Build fields
692 CHKERR m_field.build_fields();
693 PetscLogEventEnd(MOFEM_EVENT_SimpleBuildFields, 0, 0, 0, 0);
695}
696
698 Interface &m_field = cOre;
700 PetscLogEventBegin(MOFEM_EVENT_SimpleBuildFiniteElements, 0, 0, 0, 0);
701 // Add finite elements
703 true);
705 if (addBoundaryFE || boundaryFields.size()) {
707 boundaryFE, true);
709 }
710 if (addSkeletonFE || skeletonFields.size()) {
712 skeletonFE, true);
714 }
715
716 if (noFieldFields.size() || meshsetFields.size()) {
717 auto add_fields_ents = [&](auto list) {
719 auto fe_meshset = m_field.get_finite_element_meshset(meshsetFE);
720 for (auto &fe_ents : meshsetFiniteElementEntities) {
721 EntityHandle meshset_entity_fe;
722 CHKERR m_field.get_moab().create_meshset(MESHSET_SET,
723 meshset_entity_fe);
724 CHKERR m_field.getInterface<BitRefManager>()->setBitLevelToMeshset(
725 meshset_entity_fe, BitRefLevel().set());
726 for (auto f : list) {
727 auto field_meshset = m_field.get_field_meshset(f);
728 Range ents;
729 CHKERR m_field.get_moab().get_entities_by_handle(field_meshset, ents,
730 true);
731 CHKERR m_field.get_moab().add_entities(meshset_entity_fe, ents);
732 }
733 CHKERR m_field.get_moab().add_entities(meshset_entity_fe, fe_ents);
734 CHKERR m_field.get_moab().add_entities(fe_meshset, &meshset_entity_fe,
735 1);
736 }
738 };
739 CHKERR add_fields_ents(noFieldFields);
741 }
742
743 for (std::vector<std::string>::iterator fit = otherFEs.begin();
744 fit != otherFEs.end(); ++fit) {
745 CHKERR m_field.build_finite_elements(*fit);
746 }
747 PetscLogEventEnd(MOFEM_EVENT_SimpleBuildFiniteElements, 0, 0, 0, 0);
749}
750
752 Interface &m_field = cOre;
754 PetscLogEventBegin(MOFEM_EVENT_SimpleBuildProblem, 0, 0, 0, 0);
756 // Set problem by the DOFs on the fields rather that by adding DOFs on the
757 // elements
758 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_TRUE;
760 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_FALSE;
761 PetscLogEventEnd(MOFEM_EVENT_SimpleBuildProblem, 0, 0, 0, 0);
763}
764
765MoFEMErrorCode Simple::setUp(const PetscBool is_partitioned) {
767
768 PetscLogEventBegin(MOFEM_EVENT_SimpleSetUP, 0, 0, 0, 0);
769
771
772 if (addSkeletonFE || !skeletonFields.empty()) {
774 if (addBoundaryFE || !boundaryFields.empty()) {
776 }
777 }
778
781
782 CHKERR defineProblem(is_partitioned);
786
787 PetscLogEventEnd(MOFEM_EVENT_SimpleSetUP, 0, 0, 0, 0);
789}
790
792 Interface &m_field = cOre;
794 PetscLogEventBegin(MOFEM_EVENT_SimpleBuildProblem, 0, 0, 0, 0);
795
796 if (!only_dm) {
799 if (addSkeletonFE || !skeletonFields.empty()) {
801 if (addBoundaryFE || !boundaryFields.empty()) {
803 }
804 }
808 }
809
811
812 const Problem *problem_ptr;
813 CHKERR DMMoFEMGetProblemPtr(dM, &problem_ptr);
814 const auto problem_name = problem_ptr->getName();
815 CHKERR m_field.modify_problem_ref_level_set_bit(problem_name, bitLevel);
818
819 // Set problem by the DOFs on the fields rather that by adding DOFs on the
820 // elements
821 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_TRUE;
823 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_FALSE;
824
825 PetscLogEventEnd(MOFEM_EVENT_SimpleBuildProblem, 0, 0, 0, 0);
827}
828
831 CHKERR PetscObjectReference(getPetscObject(dM.get()));
832 *dm = dM.get();
834}
835
836/**
837 * @brief Delete dm
838 *
839 * @return MoFEMErrorCode
840 */
846
847/**
848 * @brief Delete finite elements
849 *
850 * @return MoFEMErrorCode
851 */
853 Interface &m_field = cOre;
855 for (auto fe : {domainFE, boundaryFE, skeletonFE}) {
856 if (m_field.check_finite_element(fe)) {
857 CHKERR m_field.delete_finite_element(fe);
858 }
859 }
861}
862
864Simple::addFieldToEmptyFieldBlocks(const std::string row_field,
865 const std::string col_field) const {
866 Interface &m_field = cOre;
869 getProblemName(), row_field, col_field);
871}
872
874 Interface &m_field = cOre;
876 ParallelComm *pcomm =
877 ParallelComm::get_pcomm(&m_field.get_moab(), MYPCOMM_INDEX);
878
879 auto get_skin = [&](auto meshset) {
880 // filter not owned entities, those are not on boundary
881
882 Range domain_ents;
883 CHKERR m_field.get_moab().get_entities_by_dimension(meshset, dIm,
884 domain_ents, true);
885 CHKERR pcomm->filter_pstatus(domain_ents,
886 PSTATUS_SHARED | PSTATUS_MULTISHARED,
887 PSTATUS_NOT, -1, nullptr);
888
889 Skinner skin(&m_field.get_moab());
890 Range domain_skin;
891 CHKERR skin.find_skin(0, domain_ents, false, domain_skin);
892 CHKERR pcomm->filter_pstatus(domain_skin,
893 PSTATUS_SHARED | PSTATUS_MULTISHARED,
894 PSTATUS_NOT, -1, nullptr);
895 return domain_skin;
896 };
897
898 auto create_boundary_meshset = [&](auto &&domain_skin) {
900 // create boundary meshset
901 if (boundaryMeshset != 0) {
903 }
904 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, boundaryMeshset);
905 CHKERR m_field.get_moab().add_entities(boundaryMeshset, domain_skin);
906 for (int dd = 0; dd != dIm - 1; dd++) {
907 Range adj;
908 CHKERR m_field.get_moab().get_adjacencies(domain_skin, dd, false, adj,
909 moab::Interface::UNION);
910 CHKERR m_field.get_moab().add_entities(boundaryMeshset, adj);
911 }
913 };
914
915 CHKERR create_boundary_meshset(get_skin(meshSet));
916
918}
919
921 Interface &m_field = cOre;
923
924 ParallelComm *pcomm =
925 ParallelComm::get_pcomm(&m_field.get_moab(), MYPCOMM_INDEX);
926
927 auto create_skeleton_meshset = [&](auto meshset) {
929 // create boundary meshset
930 if (skeletonMeshset != 0) {
932 }
933 Range boundary_ents, skeleton_ents;
934 CHKERR m_field.get_moab().get_entities_by_dimension(boundaryMeshset,
935 dIm - 1, boundary_ents);
936 Range domain_ents;
937 CHKERR m_field.get_moab().get_entities_by_dimension(meshset, dIm,
938 domain_ents, true);
939 CHKERR m_field.get_moab().get_adjacencies(
940 domain_ents, dIm - 1, true, skeleton_ents, moab::Interface::UNION);
941 skeleton_ents = subtract(skeleton_ents, boundary_ents);
942 CHKERR pcomm->filter_pstatus(skeleton_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT,
943 -1, nullptr);
944 CHKERR m_field.get_moab().create_meshset(MESHSET_SET, skeletonMeshset);
945 CHKERR m_field.get_moab().add_entities(skeletonMeshset, skeleton_ents);
947 };
948
949 CHKERR create_skeleton_meshset(meshSet);
950
952}
953
955 Interface &m_field = cOre;
957 MOFEM_LOG("WORLD", Sev::verbose) << "Exchange ghost cells";
958
959 ParallelComm *pcomm =
960 ParallelComm::get_pcomm(&m_field.get_moab(), MYPCOMM_INDEX);
961 if (pcomm == NULL)
962 pcomm = new ParallelComm(&m_field.get_moab(), m_field.get_comm());
963
964 CHKERR pcomm->exchange_ghost_cells(getDim(), getDim() - 1, 1,
965 3 /**get all adjacent ghosted entities */,
966 true, true, meshSet ? &meshSet : nullptr);
967
968 Range shared;
969 CHKERR m_field.get_moab().get_entities_by_dimension(0, dIm, shared);
970 for (auto d = dIm - 1; d >= 0; --d) {
971 CHKERR m_field.get_moab().get_adjacencies(shared, d, false, shared,
972 moab::Interface::UNION);
973 }
974 CHKERR pcomm->filter_pstatus(shared, PSTATUS_SHARED | PSTATUS_MULTISHARED,
975 PSTATUS_OR, -1, &shared);
976 Tag part_tag = pcomm->part_tag();
977 CHKERR pcomm->exchange_tags(part_tag, shared);
978 CHKERR m_field.getInterface<CommInterface>()->resolveParentEntities(shared,
979 VERBOSE);
980
982}
983
984} // namespace MoFEM
static auto get_skin(MoFEM::Interface &m_field, Range body_ents)
#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 ...
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ 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:1123
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:497
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:426
PetscErrorCode DMSetUp_MoFEM(DM dm)
Definition DMMoFEM.cpp:1303
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 EntityHandle get_finite_element_meshset(const std::string name) const =0
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
char mesh_file_name[255]
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 EntityHandle get_field_meshset(const std::string name) const =0
get field meshset
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.
virtual MoFEMErrorCode create_vertices_and_add_to_field(const std::string name, const double coords[], int size, int verb=DEFAULT_VERBOSITY)=0
Create a vertices and add to field object.
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:618
EntityHandle boundaryMeshset
meshset with boundary
Definition Simple.hpp:566
MoFEMErrorCode buildProblem()
Build problem.
Definition Simple.cpp:751
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:264
std::vector< std::string > dataFields
Data fields.
Definition Simple.hpp:581
MoFEMErrorCode setParentAdjacency()
Definition Simple.cpp:67
std::list< std::tuple< std::string, int, Range, bool > > fieldsOrder
Definition Simple.hpp:587
std::vector< std::string > domainFields
domain fields
Definition Simple.hpp:578
MoFEMErrorCode defineFiniteElements()
Define finite elements.
Definition Simple.cpp:474
MoFEM::Core & cOre
Definition Simple.hpp:553
BitRefLevel bitAdjEnt
bit ref level for parent
Definition Simple.hpp:575
char meshFileName[255]
mesh file name
Definition Simple.hpp:600
EntityHandle meshSet
domain meshset
Definition Simple.hpp:565
int getDim() const
Get the problem dimension.
Definition Simple.hpp:331
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition Simple.cpp:194
std::vector< std::string > otherFEs
Other finite elements.
Definition Simple.hpp:596
MoFEMErrorCode buildFiniteElements()
Build finite elements.
Definition Simple.cpp:697
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:414
boost::shared_ptr< ParentFiniteElementAdjacencyFunctionSkeleton< 2 > > parentAdjSkeletonFunctionDim2
Definition Simple.hpp:623
MoFEMErrorCode exchangeGhostCells()
Definition Simple.cpp:954
PetscLogEvent MOFEM_EVENT_SimpleBuildFields
Definition Simple.hpp:560
PetscLogEvent MOFEM_EVENT_SimpleLoadMesh
Definition Simple.hpp:559
MoFEMErrorCode reSetUp(bool only_dm=false)
Rebuild internal MoFEM data structures.
Definition Simple.cpp:791
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:358
std::vector< std::string > noFieldFields
NOFIELD field name.
Definition Simple.hpp:583
std::string meshsetFE
meshset finite element
Definition Simple.hpp:594
bool addSkeletonFE
Add skeleton FE.
Definition Simple.hpp:569
BitRefLevel bitAdjParent
bit ref level for parent
Definition Simple.hpp:573
bool addBoundaryFE
Add boundary FE.
Definition Simple.hpp:570
MoFEMErrorCode addFieldToEmptyFieldBlocks(const std::string row_field, const std::string col_field) const
add empty block to problem
Definition Simple.cpp:864
std::string skeletonFE
skeleton finite element
Definition Simple.hpp:593
std::vector< std::string > noFieldDataFields
NOFIELD field name.
Definition Simple.hpp:584
std::vector< std::string > meshsetFields
meshset fields
Definition Simple.hpp:582
std::string boundaryFE
boundary finite element
Definition Simple.hpp:592
std::string nameOfProblem
problem name
Definition Simple.hpp:590
boost::shared_ptr< ParentFiniteElementAdjacencyFunction< 3 > > parentAdjFunctionDim3
Definition Simple.hpp:616
MoFEMErrorCode getOptions()
get options
Definition Simple.cpp:180
std::string domainFE
domain finite element
Definition Simple.hpp:591
std::vector< std::string > boundaryFields
boundary fields
Definition Simple.hpp:579
boost::shared_ptr< ParentFiniteElementAdjacencyFunctionSkeleton< 1 > > parentAdjSkeletonFunctionDim1
Definition Simple.hpp:625
MoFEMErrorCode removeSkeletonField(const std::string name)
Remove field form skeleton.
Definition Simple.cpp:460
BitRefLevel bitAdjEntMask
bit ref level for parent parent
Definition Simple.hpp:576
SmartPetscObj< DM > dM
Discrete manager (interface to PETSc/MoFEM functions)
Definition Simple.hpp:604
MoFEMErrorCode removeDomainField(const std::string name)
Remove field form domain.
Definition Simple.cpp:432
MoFEMErrorCode buildFields()
Build fields.
Definition Simple.cpp:608
SmartPetscObj< DM > getDM()
Return smart DM object.
Definition Simple.hpp:321
std::vector< Range > meshsetFiniteElementEntities
Meshset element entities.
Definition Simple.hpp:598
BitRefLevel bitLevel
BitRefLevel of the problem.
Definition Simple.hpp:555
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition Simple.cpp:599
MoFEMErrorCode defineProblem(const PetscBool is_partitioned=PETSC_TRUE)
define problem
Definition Simple.cpp:575
std::vector< std::string > skeletonFields
fields on the skeleton
Definition Simple.hpp:580
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 field on domain.
Definition Simple.cpp:396
boost::function< MoFEMErrorCode(Interface &, const char *, const char *)> LoadFileFunc
Definition Simple.hpp:43
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:765
MoFEMErrorCode removeBoundaryField(const std::string name)
Remove field form boundary.
Definition Simple.cpp:446
const std::string getProblemName() const
Get the Problem Name.
Definition Simple.hpp:408
int dIm
dimension of problem
Definition Simple.hpp:601
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:841
PetscLogEvent MOFEM_EVENT_SimpleSetUP
Definition Simple.hpp:558
PetscLogEvent MOFEM_EVENT_SimpleKSPSolve
Definition Simple.hpp:563
MoFEMErrorCode createBoundaryMeshset()
Definition Simple.cpp:873
PetscLogEvent MOFEM_EVENT_SimpleBuildFiniteElements
Definition Simple.hpp:561
BitRefLevel bitLevelMask
BitRefLevel of the problem.
Definition Simple.hpp:556
BitRefLevel bitAdjParentMask
bit ref level for parent parent
Definition Simple.hpp:574
PetscLogEvent MOFEM_EVENT_SimpleBuildProblem
Definition Simple.hpp:562
boost::shared_ptr< ParentFiniteElementAdjacencyFunction< 1 > > parentAdjFunctionDim1
Definition Simple.hpp:620
MoFEMErrorCode deleteFiniteElements()
Delete finite elements.
Definition Simple.cpp:852
Simple(const MoFEM::Core &core)
Definition Simple.cpp:162
EntityHandle skeletonMeshset
skeleton meshset with boundary
Definition Simple.hpp:567
MoFEMErrorCode createSkeletonMeshset()
Definition Simple.cpp:920
bool addParentAdjacencies
If set to true parent adjacencies are build.
Definition Simple.hpp:571
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:285
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:376
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.