v0.14.0
Loading...
Searching...
No Matches
vtk_cgg_base.cpp
Go to the documentation of this file.
1
2#include <MoFEM.hpp>
3#include <h1_hdiv_hcurl_l2.h>
4using namespace MoFEM;
6
7using namespace FTensor;
8
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);
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
134static char help[] = "...\n\n";
135
136int 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 }
144
146
147 return 0;
148}
Implementation of tonsorial bubble base div(v) = 0.
#define NBVOLUMETET_CCG_BUBBLE(P)
Bubble function for CGG H div space.
int main()
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
PetscErrorCode ShapeDiffMBTET(double *diffN)
calculate derivatives of shape functions
Definition fem_tools.c:319
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
Functions to approximate hierarchical spaces.
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.
Tensors class implemented by Walter Landry.
Definition FTensor.hpp:51
const Tensor1_Expr< const dTensor0< T, Dim, i >, typename promote< T, double >::V, Dim, i > d(const Tensor0< T * > &a, const Index< i, Dim > index, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition dTensor0.hpp:27
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
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
static double phi
Managing BitRefLevels.
Core (interface) class.
Definition Core.hpp:82
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
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:112
Deprecated interface functions.
Mesh refinement interface.
MoFEMErrorCode refineTets(const EntityHandle meshset, const BitRefLevel &bit, int verb=QUIET, const bool debug=false)
refine TET in the meshset
MoFEMErrorCode addVerticesInTheMiddleOfEdges(const EntityHandle meshset, const BitRefLevel &bit, const bool recursive=false, int verb=QUIET, EntityHandle start_v=0)
make vertices in the middle of edges in meshset and add them to refinement levels defined by bit
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
static char help[]
MoFEMErrorCode VTK_cgg_bubble_base_MBTET(const string file_name)