v0.14.0
create_mwls_stress_mesh.cpp
Go to the documentation of this file.
1 /* This file is part of MoFEM.
2  * MoFEM is free software: you can redistribute it and/or modify it under
3  * the terms of the GNU Lesser General Public License as published by the
4  * Free Software Foundation, either version 3 of the License, or (at your
5  * option) any later version.
6  *
7  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
8  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  * License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
14 
15 #include <MoFEM.hpp>
16 using namespace MoFEM;
17 
18 static char help[] = "Create mesh for MWLS approximation for internal stresses and density"
19  "\n\n";
20 
21 int main(int argc, char *argv[]) {
22  MoFEM::Core::Initialize(&argc, &argv, PETSC_NULL, help);
23 
24  try {
25 
26  PetscBool flg = PETSC_TRUE;
27  char mesh_file_name[255];
28  CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
29  255, &flg);
30 
31  moab::Core mb_instance;
32  moab::Interface &moab = mb_instance;
33 
34  const char *option;
35  option = "";
36  CHKERR moab.load_file(mesh_file_name, 0, option);
37 
38  std::string mwls_stress_tag_name = "MED_SIGP";
39  std::string mwls_rho_tag_name = "RHO_CELL";
40  Tag th, th_rho;
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);
46 
47  Range three_dimensional_entities;
48  CHKERR moab.get_entities_by_dimension(0, 3, three_dimensional_entities,
49  true);
50  MatrixDouble coords;
51  for (auto ent : three_dimensional_entities) {
52  const EntityHandle *conn;
53  int num_nodes;
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));
62  t_center(i) = 0;
63  for (int rr = 0; rr != coords.size1(); ++rr) {
64  t_center(i) += t_coords(i);
65  ++t_coords;
66  }
67  t_center(i) /= coords.size1();
68  return t_center;
69  };
70  auto t_centre = get_centroid(coords);
71 
72  auto get_stress = [](auto t_center) {
73  VectorDouble voight_stress(9);
74  voight_stress(0) = 0.5*t_center(1); //t_center(0) * t_center(0) * t_center(0);
75  voight_stress(1) = 0.5*t_center(1); //t_center(1) * t_center(1) * t_center(1);
76  voight_stress(2) = 0.5*t_center(1); //t_center(2) * t_center(2) + t_center(2);
77  voight_stress(3) = 0; //(t_center(0) * t_center(1)) * t_center(2);
78  voight_stress(4) = 0; //(t_center(0) * t_center(2)) * t_center(1);
79  voight_stress(5) = 0; //(t_center(1) * t_center(2)) * t_center(0);
80  voight_stress(6) = 0; // dummy only used to make tag visable on ParaView
81  voight_stress(7) = 0; // dummy only used to make tag visable on ParaView
82  voight_stress(8) = 0; // dummy only used to make tag visable on ParaView
83  return voight_stress;
84  };
85 
86  auto get_density = [](auto t_center) {
87  double density = 0.;
88  density = 1 + t_center(0) * 2;
89  return density;
90  };
91 
92  auto voight_stress = get_stress(t_centre);
93  double density = get_density(t_centre);
94 
95  CHKERR moab.tag_set_data(th, &ent, 1, &*voight_stress.data().begin());
96  CHKERR moab.tag_set_data(th_rho, &ent, 1, &density);
97  }
98 
99  EntityHandle meshset = 0;
100  CHKERR moab.write_file("out_for_mwls.h5m", "MOAB", "", &meshset, 1);
101  }
102  CATCH_ERRORS;
103 
105  return 0;
106 }
FTensor::Tensor1
Definition: Tensor1_value.hpp:8
EntityHandle
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
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
main
int main(int argc, char *argv[])
Definition: create_mwls_stress_mesh.cpp:21
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FTensor::Index< 'i', 3 >
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:22
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
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
help
static char help[]
Definition: create_mwls_stress_mesh.cpp:18
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68