10 using namespace MoFEM;
12 static char help[] =
"...\n\n";
77 CHKERR setIntegrationRules();
79 CHKERR boundaryCondition();
92 PetscBool load_file = PETSC_FALSE;
96 if (load_file == PETSC_FALSE) {
98 auto &moab = mField.get_moab();
103 double tet_coords[] = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1};
105 for (
int nn = 0; nn < 4; nn++) {
106 CHKERR moab.create_vertex(&tet_coords[3 * nn], nodes[nn]);
109 CHKERR moab.create_element(MBTET, nodes, 4, tet);
111 for (
auto d : {1, 2})
112 CHKERR moab.get_adjacencies(&tet, 1,
d,
true, adj);
118 double tri_coords[] = {0, 0, 0, 1, 0, 0, 0, 1, 0};
120 for (
int nn = 0; nn < 3; nn++) {
121 CHKERR moab.create_vertex(&tri_coords[3 * nn], nodes[nn]);
124 CHKERR moab.create_element(MBTRI, nodes, 3, tri);
126 CHKERR moab.get_adjacencies(&tri, 1, 1,
true, adj);
129 CHKERR mField.rebuild_database();
130 CHKERR mField.getInterface(simpleInterface);
135 0,
SPACE_DIM, simpleInterface->getBitRefLevel());
139 CHKERR mField.getInterface(simpleInterface);
140 CHKERR simpleInterface->getOptions();
141 CHKERR simpleInterface->loadFile();
154 enum bases { AINSWORTH, AINSWORTH_LOBATTO, DEMKOWICZ, BERNSTEIN, LASBASETOP };
155 const char *list_bases[] = {
"ainsworth",
"ainsworth_lobatto",
"demkowicz",
159 PetscInt choice_base_value = AINSWORTH;
161 &choice_base_value, &flg);
162 if (flg != PETSC_TRUE)
165 if (choice_base_value == AINSWORTH)
167 if (choice_base_value == AINSWORTH_LOBATTO)
169 else if (choice_base_value == DEMKOWICZ)
171 else if (choice_base_value == BERNSTEIN)
174 const char *list_continuity[] = {
"continuous",
"discontinuous"};
175 PetscInt choice_continuity_value =
CONTINUOUS;
187 enum spaces { H1SPACE, L2SPACE, HCURLSPACE, HDIVSPACE, LASBASETSPACE };
188 const char *list_spaces[] = {
"h1",
"l2",
"hcurl",
"hdiv"};
189 PetscInt choice_space_value = H1SPACE;
191 LASBASETSPACE, &choice_space_value, &flg);
192 if (flg != PETSC_TRUE)
195 if (choice_space_value == H1SPACE)
197 else if (choice_space_value == L2SPACE)
199 else if (choice_space_value == HCURLSPACE)
201 else if (choice_space_value == HDIVSPACE)
211 CHKERR simpleInterface->addDomainField(
"U", space, base, 1);
213 CHKERR simpleInterface->addDomainBrokenField(
"U", space, base, 1);
218 CHKERR simpleInterface->setUp();
220 auto bc_mng = mField.getInterface<
BcManager>();
221 CHKERR bc_mng->removeSideDOFs(simpleInterface->getProblemName(),
"ZERO_FLUX",
257 auto post_proc_fe = boost::make_shared<MyPostProc>(mField);
258 post_proc_fe->generateReferenceElementMesh();
262 if (space ==
HCURL) {
263 auto jac_ptr = boost::make_shared<MatrixDouble>();
264 post_proc_fe->getOpPtrVector().push_back(
267 post_proc_fe->getOpPtrVector().push_back(
280 auto u_ptr = boost::make_shared<VectorDouble>();
281 post_proc_fe->getOpPtrVector().push_back(
283 post_proc_fe->getOpPtrVector().push_back(
287 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
308 post_proc_fe->getOpPtrVector(), {space});
309 auto u_ptr = boost::make_shared<MatrixDouble>();
310 post_proc_fe->getOpPtrVector().push_back(
313 post_proc_fe->getOpPtrVector().push_back(
317 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
335 auto scale_tag_val = [&]() {
337 auto &post_proc_mesh = post_proc_fe->getPostProcMesh();
339 CHKERR post_proc_mesh.get_entities_by_type(0, MBVERTEX, nodes);
341 CHKERR post_proc_mesh.tag_get_handle(
"U",
th);
343 CHKERR post_proc_mesh.tag_get_length(
th, length);
344 std::vector<double> data(nodes.size() * length);
345 CHKERR post_proc_mesh.tag_get_data(
th, nodes, &*data.begin());
347 for (
int i = 0;
i != nodes.size(); ++
i) {
349 for (
int d = 0;
d != length; ++
d)
350 v += pow(data[length *
i +
d], 2);
352 max_v = std::max(max_v,
v);
356 CHKERR post_proc_mesh.tag_set_data(
th, nodes, &*data.begin());
360 auto prb_ptr = mField.get_problem(simpleInterface->getProblemName());
363 auto dofs_ptr = prb_ptr->getNumeredRowDofsPtr();
365 for (
auto dof_ptr : (*dofs_ptr)) {
366 MOFEM_LOG(
"PLOTBASE", Sev::verbose) << *dof_ptr;
367 auto &val =
const_cast<double &
>(dof_ptr->getFieldData());
371 CHKERR post_proc_fe->writeFile(
372 "out_base_dof_" + boost::lexical_cast<std::string>(nb) +
".h5m");
373 CHKERR post_proc_fe->getPostProcMesh().delete_mesh();
386 int main(
int argc,
char *argv[]) {
394 DMType dm_name =
"DMMOFEM";
399 auto core_log = logging::core::get();
401 LogManager::createSink(LogManager::getStrmWorld(),
"PLOTBASE"));
402 LogManager::setLog(
"PLOTBASE");
432 char ref_mesh_file_name[255];
435 strcpy(ref_mesh_file_name,
"ref_mesh2d.h5m");
437 strcpy(ref_mesh_file_name,
"ref_mesh3d.h5m");
440 "Dimension not implemented");
444 CHKERR moab_ref.load_file(ref_mesh_file_name, 0,
"");
452 CHKERR moab_ref.create_meshset(MESHSET_SET, meshset);
453 CHKERR moab_ref.add_entities(meshset, elems);
454 CHKERR moab_ref.convert_entities(meshset,
true,
false,
false);
455 CHKERR moab_ref.delete_entities(&meshset, 1);
459 CHKERR moab_ref.get_connectivity(elems, elem_nodes,
false);
462 std::map<EntityHandle, int> nodes_pts_map;
465 gaussPts.resize(
SPACE_DIM + 1, elem_nodes.size(),
false);
467 Range::iterator nit = elem_nodes.begin();
468 for (
int gg = 0; nit != elem_nodes.end(); nit++, gg++) {
470 CHKERR moab_ref.get_coords(&*nit, 1, coords);
471 for (
auto d : {0, 1, 2})
472 gaussPts(
d, gg) = coords[
d];
473 nodes_pts_map[*nit] = gg;
485 Range::iterator tit = elems.begin();
486 for (
int tt = 0; tit != elems.end(); ++tit, ++tt) {
489 CHKERR moab_ref.get_connectivity(*tit, conn, num_nodes,
false);
490 for (
int nn = 0; nn != num_nodes; ++nn) {
491 refEleMap(tt, nn) = nodes_pts_map[conn[nn]];
501 const int num_nodes = gaussPts.size2();
505 switch (numeredEntFiniteElementPtr->getEntType()) {
509 &gaussPts(0, 0), &gaussPts(1, 0), num_nodes);
513 for (
int gg = 0; gg != num_nodes; gg++) {
514 double ksi = gaussPts(0, gg);
515 double eta = gaussPts(1, gg);
525 &gaussPts(0, 0), &gaussPts(1, 0),
526 &gaussPts(2, 0), num_nodes);
530 for (
int gg = 0; gg != num_nodes; gg++) {
531 double ksi = gaussPts(0, gg);
532 double eta = gaussPts(1, gg);
533 double zeta = gaussPts(2, gg);
546 "Not implemented element type");
552 ReadUtilIface *iface;
553 CHKERR getPostProcMesh().query_interface(iface);
555 std::vector<double *> arrays;
560 CHKERR iface->get_node_coords(3, num_nodes, 0, startv, arrays);
562 mapGaussPts.resize(gaussPts.size2());
563 for (
int gg = 0; gg != num_nodes; ++gg)
564 mapGaussPts[gg] = startv + gg;
567 int def_in_the_loop = -1;
568 CHKERR getPostProcMesh().tag_get_handle(
"NB_IN_THE_LOOP", 1, MB_TYPE_INTEGER,
569 th, MB_TAG_CREAT | MB_TAG_SPARSE,
575 const int num_nodes_on_ele =
refEleMap.size2();
582 CHKERR iface->get_element_connect(num_el, num_nodes_on_ele, MBTRI, 0,
585 CHKERR iface->get_element_connect(num_el, num_nodes_on_ele, MBTET, 0,
589 "Dimension not implemented");
593 for (
unsigned int tt = 0; tt !=
refEleMap.size1(); ++tt) {
594 for (
int nn = 0; nn != num_nodes_on_ele; ++nn)
595 conn[num_nodes_on_ele * tt + nn] = mapGaussPts[
refEleMap(tt, nn)];
600 CHKERR iface->update_adjacencies(starte, num_el, num_nodes_on_ele, conn);
602 auto physical_elements =
Range(starte, starte + num_el - 1);
603 CHKERR getPostProcMesh().tag_clear_data(
th, physical_elements, &(nInTheLoop));
605 EntityHandle fe_ent = numeredEntFiniteElementPtr->getEnt();
609 mField.get_moab().get_connectivity(fe_ent, conn, fe_num_nodes,
true);
610 coords.resize(3 * fe_num_nodes,
false);
611 CHKERR mField.get_moab().get_coords(conn, fe_num_nodes, &coords[0]);
620 arrays[0], arrays[1], arrays[2]);
621 const double *t_coords_ele_x = &coords[0];
622 const double *t_coords_ele_y = &coords[1];
623 const double *t_coords_ele_z = &coords[2];
624 for (
int gg = 0; gg != num_nodes; ++gg) {
626 t_coords_ele_x, t_coords_ele_y, t_coords_ele_z);
628 for (
int nn = 0; nn != fe_num_nodes; ++nn) {
629 t_coords(
i) += t_n * t_ele_coords(
i);
630 for (
auto ii : {0, 1, 2})
631 if (std::abs(t_coords(ii)) < std::numeric_limits<float>::epsilon())
644 ParallelComm *pcomm_post_proc_mesh =
646 if (pcomm_post_proc_mesh != NULL)
647 delete pcomm_post_proc_mesh;
654 auto resolve_shared_ents = [&]() {
657 ParallelComm *pcomm_post_proc_mesh =
658 ParallelComm::get_pcomm(&(getPostProcMesh()),
MYPCOMM_INDEX);
659 if (pcomm_post_proc_mesh == NULL) {
662 pcomm_post_proc_mesh =
new ParallelComm(
663 &(getPostProcMesh()),
667 CHKERR pcomm_post_proc_mesh->resolve_shared_ents(0);
672 CHKERR resolve_shared_ents();