v0.14.0
vtk_cgg_base.cpp
Go to the documentation of this file.
1 
2 #include <MoFEM.hpp>
3 #include <h1_hdiv_hcurl_l2.h>
4 using namespace MoFEM;
6 
7 using namespace FTensor;
8 
9 MoFEMErrorCode VTK_cgg_bubble_base_MBTET(const string file_name) {
11 
12  double base_coords[] = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1};
13 
14  moab::Core core_ref;
15  moab::Interface &moab_ref = core_ref;
16 
17  EntityHandle nodes[4];
18  for (int nn = 0; nn < 4; nn++) {
19  CHKERR moab_ref.create_vertex(&base_coords[3 * nn], nodes[nn]);
20  }
21  EntityHandle tet;
22  CHKERR moab_ref.create_element(MBTET, nodes, 4, tet);
23 
24  MoFEM::Core m_core_ref(moab_ref, PETSC_COMM_SELF, -2);
25  MoFEM::Interface &m_field_ref = m_core_ref;
26 
27  CHKERR m_field_ref.getInterface<BitRefManager>()->setBitRefLevelByDim(
28  0, 3, BitRefLevel().set(0));
29 
30  const int max_level = 4;
31  for (int ll = 0; ll != max_level; ll++) {
32  Range edges;
33  CHKERR m_field_ref.getInterface<BitRefManager>()
34  ->getEntitiesByTypeAndRefLevel(BitRefLevel().set(ll),
35  BitRefLevel().set(), MBEDGE, edges);
36  Range tets;
37  CHKERR m_field_ref.getInterface<BitRefManager>()
38  ->getEntitiesByTypeAndRefLevel(BitRefLevel().set(ll),
39  BitRefLevel(ll).set(), MBTET, tets);
40  // refine mesh
41  MeshRefinement *m_ref;
42  CHKERR m_field_ref.getInterface(m_ref);
43  CHKERR m_ref->addVerticesInTheMiddleOfEdges(edges,
44  BitRefLevel().set(ll + 1));
45  CHKERR m_ref->refineTets(tets, BitRefLevel().set(ll + 1));
46  }
47 
48  Range tets;
49  CHKERR m_field_ref.getInterface<BitRefManager>()
50  ->getEntitiesByTypeAndRefLevel(BitRefLevel().set(max_level),
51  BitRefLevel().set(max_level), MBTET, tets);
52 
53  // Use 10 node tets to print base
54  if (1) {
55  EntityHandle meshset;
56  CHKERR moab_ref.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER, meshset);
57  CHKERR moab_ref.add_entities(meshset, tets);
58  CHKERR moab_ref.convert_entities(meshset, true, false, false);
59  CHKERR moab_ref.delete_entities(&meshset, 1);
60  }
61 
62  Range elem_nodes;
63  CHKERR moab_ref.get_connectivity(tets, elem_nodes, false);
64 
65  const int nb_gauss_pts = elem_nodes.size();
66  MatrixDouble gauss_pts(nb_gauss_pts, 4);
67  gauss_pts.clear();
68  Range::iterator nit = elem_nodes.begin();
69  for (int gg = 0; nit != elem_nodes.end(); nit++, gg++) {
70  CHKERR moab_ref.get_coords(&*nit, 1, &gauss_pts(gg, 0));
71  }
72  gauss_pts = trans(gauss_pts);
73 
74  MatrixDouble shape_fun;
75  shape_fun.resize(nb_gauss_pts, 4);
76  CHKERR ShapeMBTET(&*shape_fun.data().begin(), &gauss_pts(0, 0),
77  &gauss_pts(1, 0), &gauss_pts(2, 0), nb_gauss_pts);
78  double diff_shape_fun[12];
79  CHKERR ShapeDiffMBTET(diff_shape_fun);
80 
81  int p = 3;
82  MatrixDouble phi(nb_gauss_pts, 9 * NBVOLUMETET_CCG_BUBBLE(p));
83  Tensor2<PackPtr<double *, 9>, 3, 3> t_phi(&phi(0, 0), &phi(0, 1), &phi(0, 2),
84 
85  &phi(0, 3), &phi(0, 4), &phi(0, 5),
86 
87  &phi(0, 6), &phi(0, 7), &phi(0, 8));
88 
90  p, &shape_fun(0, 0), diff_shape_fun, t_phi, nb_gauss_pts);
91 
92  for (int ll = 0; ll != NBVOLUMETET_CCG_BUBBLE(p); ++ll) {
93 
94  auto get_tag = [&](int d) {
95  double def_val[] = {0, 0, 0};
96  std::string tag_name = "B_" + boost::lexical_cast<std::string>(ll) +
97  "_D" + boost::lexical_cast<std::string>(d);
98  Tag th;
99  CHKERR moab_ref.tag_get_handle(tag_name.c_str(), 3, MB_TYPE_DOUBLE, th,
100  MB_TAG_CREAT | MB_TAG_SPARSE, def_val);
101  return th;
102  };
103  Tag th0 = get_tag(0);
104  Tag th1 = get_tag(1);
105  Tag th2 = get_tag(2);
106 
107  int gg = 0;
108  for (Range::iterator nit = elem_nodes.begin(); nit != elem_nodes.end();
109  nit++, gg++) {
110 
111  auto save_tag = [&](Tag th, const int d, int idx) {
113  double data[] = {phi(gg, idx + 3 * d + 0), phi(gg, idx + 3 * d + 1),
114  phi(gg, idx + 3 * d + 2)};
115  CHKERR moab_ref.tag_set_data(th, &*nit, 1, data);
117  };
118  const int idx = 9 * ll;
119  CHKERR save_tag(th0, 0, idx);
120  CHKERR save_tag(th1, 1, idx);
121  CHKERR save_tag(th2, 2, idx);
122 
123  }
124  }
125 
126  EntityHandle meshset;
127  CHKERR moab_ref.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER, meshset);
128  CHKERR moab_ref.add_entities(meshset, tets);
129  CHKERR moab_ref.write_file(file_name.c_str(), "VTK", "", &meshset, 1);
130 
132 }
133 
134 static char help[] = "...\n\n";
135 
136 int main(int argc, char *argv[]) {
137 
138  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
139 
140  try {
141  CHKERR VTK_cgg_bubble_base_MBTET("out_vtk_cgg_bubble_base_on_tet.vtk");
142  }
143  CATCH_ERRORS;
144 
146 
147  return 0;
148 }
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
sdf_hertz.d
float d
Definition: sdf_hertz.py:5
EntityHandle
phi
static double phi
Definition: poisson_2d_dis_galerkin.cpp:29
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::th
Tag th
Definition: Projection10NodeCoordsOnField.cpp:122
MoFEM.hpp
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
FTensor::Tensor2
Definition: Tensor2_value.hpp:16
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
main
int main(int argc, char *argv[])
Definition: vtk_cgg_base.cpp:136
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
help
static char help[]
Definition: vtk_cgg_base.cpp:134
MoFEM::MeshRefinement
Mesh refinement interface.
Definition: MeshRefinement.hpp:26
EshelbianPlasticity::CGG_BubbleBase_MBTET
MoFEMErrorCode CGG_BubbleBase_MBTET(const int p, const double *N, const double *diffN, FTensor::Tensor2< FTensor::PackPtr< double *, 9 >, 3, 3 > &phi, const int gdim)
Calculate CGGT tonsorial bubble base.
Definition: CGGTonsorialBubbleBase.cpp:20
Range
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
CGGTonsorialBubbleBase.hpp
Implementation of tonsorial bubble base div(v) = 0.
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
NBVOLUMETET_CCG_BUBBLE
#define NBVOLUMETET_CCG_BUBBLE(P)
Bubble function for CGG H div space.
Definition: CGGTonsorialBubbleBase.hpp:19
h1_hdiv_hcurl_l2.h
Functions to approximate hierarchical spaces.
ShapeDiffMBTET
PetscErrorCode ShapeDiffMBTET(double *diffN)
calculate derivatives of shape functions
Definition: fem_tools.c:319
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
ShapeMBTET
PetscErrorCode ShapeMBTET(double *N, const double *G_X, const double *G_Y, const double *G_Z, int DIM)
calculate shape functions
Definition: fem_tools.c:306
VTK_cgg_bubble_base_MBTET
MoFEMErrorCode VTK_cgg_bubble_base_MBTET(const string file_name)
Definition: vtk_cgg_base.cpp:9