16 using namespace MoFEM;
18 static char help[] =
"Create mesh for MWLS approximation for internal stresses and density"
21 int main(
int argc,
char *argv[]) {
26 PetscBool flg = PETSC_TRUE;
38 std::string mwls_stress_tag_name =
"MED_SIGP";
39 std::string mwls_rho_tag_name =
"RHO_CELL";
41 double def[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0};
42 CHKERR moab.tag_get_handle(mwls_stress_tag_name.c_str(), 9, MB_TYPE_DOUBLE,
43 th, MB_TAG_CREAT | MB_TAG_SPARSE, def);
44 CHKERR moab.tag_get_handle(mwls_rho_tag_name.c_str(), 1, MB_TYPE_DOUBLE,
45 th_rho, MB_TAG_CREAT | MB_TAG_SPARSE, def);
47 Range three_dimensional_entities;
48 CHKERR moab.get_entities_by_dimension(0, 3, three_dimensional_entities,
51 for (
auto ent : three_dimensional_entities) {
54 CHKERR moab.get_connectivity(ent, conn, num_nodes,
true);
55 coords.resize(num_nodes, 3,
false);
56 CHKERR moab.get_coords(conn, num_nodes, &*coords.data().begin());
57 auto get_centroid = [](
auto &coords) {
59 &coords(0, 0), &coords(0, 1), &coords(0, 2));
63 for (
int rr = 0; rr != coords.size1(); ++rr) {
64 t_center(
i) += t_coords(
i);
67 t_center(
i) /= coords.size1();
70 auto t_centre = get_centroid(coords);
72 auto get_stress = [](
auto t_center) {
74 voight_stress(0) = 0.5*t_center(1);
75 voight_stress(1) = 0.5*t_center(1);
76 voight_stress(2) = 0.5*t_center(1);
86 auto get_density = [](
auto t_center) {
88 density = 1 + t_center(0) * 2;
92 auto voight_stress = get_stress(t_centre);
93 double density = get_density(t_centre);
95 CHKERR moab.tag_set_data(
th, &ent, 1, &*voight_stress.data().begin());
96 CHKERR moab.tag_set_data(th_rho, &ent, 1, &density);
100 CHKERR moab.write_file(
"out_for_mwls.h5m",
"MOAB",
"", &meshset, 1);