v0.16.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
MyPostProc Struct Reference
Inheritance diagram for MyPostProc:
[legend]
Collaboration diagram for MyPostProc:
[legend]

Public Member Functions

MoFEMErrorCode generateReferenceElementMesh ()
 
MoFEMErrorCode setGaussPts (int order)
 
MoFEMErrorCode preProcess ()
 
MoFEMErrorCode postProcess ()
 

Protected Attributes

ublas::matrix< int > refEleMap
 
MatrixDouble shapeFunctions
 

Detailed Description

Examples
mofem/tutorials/fun-2_plot_base/plot_base.cpp.

Definition at line 34 of file plot_base.cpp.

Member Function Documentation

◆ generateReferenceElementMesh()

MoFEMErrorCode MyPostProc::generateReferenceElementMesh ( )
Examples
mofem/tutorials/fun-2_plot_base/plot_base.cpp.

Definition at line 426 of file plot_base.cpp.

426 {
428 moab::Core core_ref;
429 moab::Interface &moab_ref = core_ref;
430
431 char ref_mesh_file_name[255];
432
433 if (SPACE_DIM == 2)
434 strcpy(ref_mesh_file_name, "ref_mesh2d.h5m");
435 else if (SPACE_DIM == 3)
436 strcpy(ref_mesh_file_name, "ref_mesh3d.h5m");
437 else
438 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
439 "Dimension not implemented");
440
441 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-ref_file", ref_mesh_file_name,
442 255, PETSC_NULLPTR);
443 CHKERR moab_ref.load_file(ref_mesh_file_name, 0, "");
444
445 // Get elements
446 Range elems;
447 CHKERR moab_ref.get_entities_by_dimension(0, SPACE_DIM, elems);
448
449 // Add mid-nodes on edges
450 EntityHandle meshset;
451 CHKERR moab_ref.create_meshset(MESHSET_SET, meshset);
452 CHKERR moab_ref.add_entities(meshset, elems);
453 CHKERR moab_ref.convert_entities(meshset, true, false, false);
454 CHKERR moab_ref.delete_entities(&meshset, 1);
455
456 // Get nodes on the mesh
457 Range elem_nodes;
458 CHKERR moab_ref.get_connectivity(elems, elem_nodes, false);
459
460 // Map node entity and Gauss pint number
461 std::map<EntityHandle, int> nodes_pts_map;
462
463 // Set gauss points coordinates from the reference mesh
464 gaussPts.resize(SPACE_DIM + 1, elem_nodes.size(), false);
465 gaussPts.clear();
466 Range::iterator nit = elem_nodes.begin();
467 for (int gg = 0; nit != elem_nodes.end(); nit++, gg++) {
468 double coords[3];
469 CHKERR moab_ref.get_coords(&*nit, 1, coords);
470 for (auto d : {0, 1, 2})
471 gaussPts(d, gg) = coords[d];
472 nodes_pts_map[*nit] = gg;
473 }
474
475 if (SPACE_DIM == 2) {
476 // Set size of adjacency matrix (note ho order nodes 3 nodes and 3 nodes on
477 // edges)
478 refEleMap.resize(elems.size(), 3 + 3);
479 } else if (SPACE_DIM == 3) {
480 refEleMap.resize(elems.size(), 4 + 6);
481 }
482
483 // Set adjacency matrix
484 Range::iterator tit = elems.begin();
485 for (int tt = 0; tit != elems.end(); ++tit, ++tt) {
486 const EntityHandle *conn;
487 int num_nodes;
488 CHKERR moab_ref.get_connectivity(*tit, conn, num_nodes, false);
489 for (int nn = 0; nn != num_nodes; ++nn) {
490 refEleMap(tt, nn) = nodes_pts_map[conn[nn]];
491 }
492 }
493
495}
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ 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.
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
constexpr int SPACE_DIM
Definition plot_base.cpp:26
ublas::matrix< int > refEleMap
Definition plot_base.cpp:44

◆ postProcess()

MoFEMErrorCode MyPostProc::postProcess ( )
Examples
mofem/tutorials/fun-2_plot_base/plot_base.cpp.

Definition at line 650 of file plot_base.cpp.

650 {
652
653 auto resolve_shared_ents = [&]() {
655
656 ParallelComm *pcomm_post_proc_mesh =
657 ParallelComm::get_pcomm(&(getPostProcMesh()), MYPCOMM_INDEX);
658 if (pcomm_post_proc_mesh == NULL) {
659 // wrapRefMeshComm =
660 // boost::make_shared<WrapMPIComm>(T::mField.get_comm(), false);
661 pcomm_post_proc_mesh = new ParallelComm(
662 &(getPostProcMesh()),
663 PETSC_COMM_WORLD /*(T::wrapRefMeshComm)->get_comm()*/);
664 }
665
666 CHKERR pcomm_post_proc_mesh->resolve_shared_ents(0);
667
669 };
670
671 CHKERR resolve_shared_ents();
672
674}
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MYPCOMM_INDEX
default communicator number PCOMM
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...

◆ preProcess()

MoFEMErrorCode MyPostProc::preProcess ( )
Examples
mofem/tutorials/fun-2_plot_base/plot_base.cpp.

Definition at line 641 of file plot_base.cpp.

641 {
643 ParallelComm *pcomm_post_proc_mesh =
644 ParallelComm::get_pcomm(coreMeshPtr.get(), MYPCOMM_INDEX);
645 if (pcomm_post_proc_mesh != NULL)
646 delete pcomm_post_proc_mesh;
648};

◆ setGaussPts()

MoFEMErrorCode MyPostProc::setGaussPts ( int  order)

pointers to memory allocated by MoAB for storing X, Y, and Z coordinates

Examples
mofem/tutorials/fun-2_plot_base/plot_base.cpp.

Definition at line 497 of file plot_base.cpp.

497 {
499
500 const int num_nodes = gaussPts.size2();
501
502 // Calculate shape functions
503
504 switch (numeredEntFiniteElementPtr->getEntType()) {
505 case MBTRI:
506 shapeFunctions.resize(num_nodes, 3);
508 &gaussPts(0, 0), &gaussPts(1, 0), num_nodes);
509 break;
510 case MBQUAD: {
511 shapeFunctions.resize(num_nodes, 4);
512 for (int gg = 0; gg != num_nodes; gg++) {
513 double ksi = gaussPts(0, gg);
514 double eta = gaussPts(1, gg);
515 shapeFunctions(gg, 0) = N_MBQUAD0(ksi, eta);
516 shapeFunctions(gg, 1) = N_MBQUAD1(ksi, eta);
517 shapeFunctions(gg, 2) = N_MBQUAD2(ksi, eta);
518 shapeFunctions(gg, 3) = N_MBQUAD3(ksi, eta);
519 }
520 } break;
521 case MBTET: {
522 shapeFunctions.resize(num_nodes, 8);
524 &gaussPts(0, 0), &gaussPts(1, 0),
525 &gaussPts(2, 0), num_nodes);
526 } break;
527 case MBHEX: {
528 shapeFunctions.resize(num_nodes, 8);
529 for (int gg = 0; gg != num_nodes; gg++) {
530 double ksi = gaussPts(0, gg);
531 double eta = gaussPts(1, gg);
532 double zeta = gaussPts(2, gg);
533 shapeFunctions(gg, 0) = N_MBHEX0(ksi, eta, zeta);
534 shapeFunctions(gg, 1) = N_MBHEX1(ksi, eta, zeta);
535 shapeFunctions(gg, 2) = N_MBHEX2(ksi, eta, zeta);
536 shapeFunctions(gg, 3) = N_MBHEX3(ksi, eta, zeta);
537 shapeFunctions(gg, 4) = N_MBHEX4(ksi, eta, zeta);
538 shapeFunctions(gg, 5) = N_MBHEX5(ksi, eta, zeta);
539 shapeFunctions(gg, 6) = N_MBHEX6(ksi, eta, zeta);
540 shapeFunctions(gg, 7) = N_MBHEX7(ksi, eta, zeta);
541 }
542 } break;
543 default:
544 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
545 "Not implemented element type");
546 }
547
548 // Create physical nodes
549
550 // MoAB interface allowing for creating nodes and elements in the bulk
551 ReadUtilIface *iface;
552 CHKERR getPostProcMesh().query_interface(iface);
553
554 std::vector<double *> arrays; /// pointers to memory allocated by MoAB for
555 /// storing X, Y, and Z coordinates
556 EntityHandle startv; // Starting handle for vertex
557 // Allocate memory for num_nodes, and return starting handle, and access to
558 // memort.
559 CHKERR iface->get_node_coords(3, num_nodes, 0, startv, arrays);
560
561 mapGaussPts.resize(gaussPts.size2());
562 for (int gg = 0; gg != num_nodes; ++gg)
563 mapGaussPts[gg] = startv + gg;
564
565 Tag th;
566 int def_in_the_loop = -1;
567 CHKERR getPostProcMesh().tag_get_handle("NB_IN_THE_LOOP", 1, MB_TYPE_INTEGER,
568 th, MB_TAG_CREAT | MB_TAG_SPARSE,
569 &def_in_the_loop);
570
571 // Create physical elements
572
573 const int num_el = refEleMap.size1();
574 const int num_nodes_on_ele = refEleMap.size2();
575
576 EntityHandle starte; // Starting handle to first created element
577 EntityHandle *conn; // Access to MOAB memory with connectivity of elements
578
579 // Create tris/tets in the bulk in MoAB database
580 if (SPACE_DIM == 2)
581 CHKERR iface->get_element_connect(num_el, num_nodes_on_ele, MBTRI, 0,
582 starte, conn);
583 else if (SPACE_DIM == 3)
584 CHKERR iface->get_element_connect(num_el, num_nodes_on_ele, MBTET, 0,
585 starte, conn);
586 else
587 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
588 "Dimension not implemented");
589
590 // At this point elements (memory for elements) is allocated, at code bellow
591 // actual connectivity of elements is set.
592 for (unsigned int tt = 0; tt != refEleMap.size1(); ++tt) {
593 for (int nn = 0; nn != num_nodes_on_ele; ++nn)
594 conn[num_nodes_on_ele * tt + nn] = mapGaussPts[refEleMap(tt, nn)];
595 }
596
597 // Finalise elements creation. At that point MOAB updates adjacency tables,
598 // and elements are ready to use.
599 CHKERR iface->update_adjacencies(starte, num_el, num_nodes_on_ele, conn);
600
601 auto physical_elements = Range(starte, starte + num_el - 1);
602 CHKERR getPostProcMesh().tag_clear_data(th, physical_elements, &(nInTheLoop));
603
604 EntityHandle fe_ent = numeredEntFiniteElementPtr->getEnt();
605 int fe_num_nodes;
606 {
607 const EntityHandle *conn;
608 mField.get_moab().get_connectivity(fe_ent, conn, fe_num_nodes, true);
609 coords.resize(3 * fe_num_nodes, false);
610 CHKERR mField.get_moab().get_coords(conn, fe_num_nodes, &coords[0]);
611 }
612
613 // Set physical coordinates to physical nodes
614 FTensor::Index<'i', 3> i;
616 &*shapeFunctions.data().begin());
617
619 arrays[0], arrays[1], arrays[2]);
620 const double *t_coords_ele_x = &coords[0];
621 const double *t_coords_ele_y = &coords[1];
622 const double *t_coords_ele_z = &coords[2];
623 for (int gg = 0; gg != num_nodes; ++gg) {
625 t_coords_ele_x, t_coords_ele_y, t_coords_ele_z);
626 t_coords(i) = 0;
627 for (int nn = 0; nn != fe_num_nodes; ++nn) {
628 t_coords(i) += t_n * t_ele_coords(i);
629 for (auto ii : {0, 1, 2})
630 if (std::abs(t_coords(ii)) < std::numeric_limits<float>::epsilon())
631 t_coords(ii) = 0;
632 ++t_ele_coords;
633 ++t_n;
634 }
635 ++t_coords;
636 }
637
639}
#define N_MBQUAD3(x, y)
quad shape function
Definition fem_tools.h:60
#define N_MBHEX7(x, y, z)
Definition fem_tools.h:78
#define N_MBHEX3(x, y, z)
Definition fem_tools.h:74
#define N_MBHEX5(x, y, z)
Definition fem_tools.h:76
#define N_MBHEX4(x, y, z)
Definition fem_tools.h:75
#define N_MBHEX0(x, y, z)
Definition fem_tools.h:71
#define N_MBHEX6(x, y, z)
Definition fem_tools.h:77
#define N_MBHEX2(x, y, z)
Definition fem_tools.h:73
#define N_MBQUAD0(x, y)
quad shape function
Definition fem_tools.h:57
#define N_MBHEX1(x, y, z)
Definition fem_tools.h:72
#define N_MBQUAD2(x, y)
quad shape function
Definition fem_tools.h:59
#define N_MBQUAD1(x, y)
quad shape function
Definition fem_tools.h:58
double eta
FTensor::Index< 'i', SPACE_DIM > i
static MoFEMErrorCode shapeFunMBTET(double *shape, const double *ksi, const double *eta, const double *zeta, const double nb)
Calculate shape functions on tetrahedron.
Definition Tools.hpp:767
static MoFEMErrorCode shapeFunMBTRI(double *shape, const double *ksi, const double *eta, const int nb)
Calculate shape functions on triangle.
Definition Tools.hpp:730
MatrixDouble shapeFunctions
Definition plot_base.cpp:45
double zeta
Viscous hardening.
Definition plastic.cpp:131

Member Data Documentation

◆ refEleMap

ublas::matrix<int> MyPostProc::refEleMap
protected
Examples
mofem/tutorials/fun-2_plot_base/plot_base.cpp.

Definition at line 44 of file plot_base.cpp.

◆ shapeFunctions

MatrixDouble MyPostProc::shapeFunctions
protected
Examples
mofem/tutorials/fun-2_plot_base/plot_base.cpp.

Definition at line 45 of file plot_base.cpp.


The documentation for this struct was generated from the following file: