45 {
47
48 try {
49
50 moab::Core mb_instance;
51 moab::Interface &moab = mb_instance;
52
53
56
57 char mesh_file[255] = "mesh.h5m";
58 char output_file[255] = "out.h5m";
59 char tag_name[255] = "INTERNAL_STRESS";
60
61 int tag_len = 9;
62
63 PetscBool use_voigt_notation = PETSC_FALSE;
64
65 PetscOptionsBegin(m_field.
get_comm(),
"",
"save thermal stress test",
66 "none");
67 CHKERR PetscOptionsString(
"-file_name",
" mesh file name",
"",
"mesh.h5m",
68 mesh_file, 255, PETSC_NULLPTR);
69 CHKERR PetscOptionsString(
"-output_file",
"output file name",
"",
"out.h5m",
70 output_file, 255, PETSC_NULLPTR);
71 CHKERR PetscOptionsString(
"-tag_name",
"Stress tag name",
"",
72 "INTERNAL_STRESS", tag_name, 255, PETSC_NULLPTR);
73 CHKERR PetscOptionsBool(
"-voigt_notation",
"use voigt notation",
"",
74 use_voigt_notation, &use_voigt_notation,
75 PETSC_NULLPTR);
76
77 PetscOptionsEnd();
78
81
82 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
83 auto moab_comm_wrap =
84 boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD, false);
85 if (pcomm == NULL)
86 pcomm = new ParallelComm(&moab, moab_comm_wrap->get_comm());
87
88 const std::string options = "PARALLEL=READ_PART;"
89 "PARALLEL_RESOLVE_SHARED_ENTS;"
90 "PARTITION=PARALLEL_PARTITION;";
91 CHKERR moab.load_file(mesh_file, 0, options.c_str());
92
94 CHKERR pcomm->get_part_entities(src_elems, 3);
95
97 double def_val[9];
98 bzero(def_val, 9 * sizeof(double));
99 CHKERR moab.tag_get_handle(tag_name, tag_len, MB_TYPE_DOUBLE, data_tag,
100 MB_TAG_CREAT | MB_TAG_DENSE, &def_val);
101
102
103 std::vector<double> spos;
104 spos.resize(3 * src_elems.size());
105 CHKERR moab.get_coords(src_elems, &spos[0]);
106
109
110
111
112 auto temperature = [](double z) -> double {
113 return (z < -1) ? (120.0 / -9.0) * (z + 10) + 250
114 : (z <= 2) ? (50.0 / -3.0) * (z + 1) + 130
115 : (170.0 / 8.0) * (z - 2) + 80;
116 };
117
118
121 double alpha = 1e-5;
122 double temp_0 = 250;
123
126
131
132
134 mat_D_ptr.resize(6, 6, false);
140
143 if (use_voigt_notation) {
145 } else {
147 }
148
150
151 bool tets_only = true;
152
153
154 int ielem = 0;
155 for (auto sit = src_elems.begin(); sit != src_elems.end(); sit++) {
156 double z = spos[3 * ielem + 2];
157 double temp = temperature(z);
159 t_data(
L) = t_L(
i,
j,
L) * t_stress(
i,
j);
160 ++t_data;
161 ++ielem;
163 tets_only = false;
164 }
165 }
166
167 CHKERR moab.tag_set_data(data_tag, src_elems, &data[0]);
168
169
170 if (tets_only) {
171 std::vector<double> data_integ(tag_len, 0.0);
172 for (auto &tet : src_elems) {
173
174 std::vector<double> tet_data(tag_len, 0.0);
175 CHKERR moab.tag_get_data(data_tag, &tet, 1, &tet_data[0]);
176
178 int vert_num;
179 CHKERR moab.get_connectivity(tet, vert_conn, vert_num,
true);
180 std::vector<double> vpos(3 * vert_num);
181 CHKERR moab.get_coords(vert_conn, vert_num, &vpos[0]);
183
184 for (int itag = 0; itag < tag_len; itag++) {
185 data_integ[itag] += tet_data[itag] * vol;
186 }
187 }
188
189 std::vector<double> global_data_integ(tag_len, 0.0);
190 MPI_Allreduce(&data_integ[0], &global_data_integ[0], tag_len, MPI_DOUBLE,
192
193 std::string
temp =
"Integrated stress for sslv116 test: ";
194 for (
int i = 0;
i < 9; ++
i) {
195 std::stringstream ss;
196 ss << std::scientific << std::setprecision(3) << global_data_integ[
i];
197 temp += ss.str() +
" ";
198 }
200
201 double non_zero_val = 1.655e12;
202 double non_zero_tol = 2e-3;
203 std::vector<int> non_zero_inds(3);
204 std::vector<int> zero_inds(6);
205
206 if (use_voigt_notation) {
207 non_zero_inds = {0, 1, 2};
208 zero_inds = {3, 4, 5, 6, 7, 8};
209 } else {
210 non_zero_inds = {0, 4, 8};
211 zero_inds = {1, 2, 3, 5, 6, 7};
212 }
213 bool non_zero_check =
214 all_of(begin(non_zero_inds), end(non_zero_inds), [&](
int i) {
215 return abs(global_data_integ[
i] - non_zero_val) / non_zero_val <
216 non_zero_tol;
217 });
218 bool zero_check = all_of(begin(zero_inds), end(zero_inds), [&](
int i) {
219 return abs(global_data_integ[
i]) < 1e-12;
220 });
221 if (!non_zero_check || !zero_check) {
223 "Wrong value of the integrated stress");
224 }
225 } else {
227 << "Mesh has non-tetrahedral elements, skipping the test based on "
228 "integrating the stress in the volume";
229 }
230
231 CHKERR moab.write_file(output_file,
"MOAB",
"PARALLEL=WRITE_PART");
232 }
234
236
237 return 0;
238}
Kronecker Delta class symmetric.
#define CATCH_ERRORS
Catch errors.
#define MYPCOMM_INDEX
default communicator number PCOMM
@ MOFEM_ATOM_TEST_INVALID
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
auto type_from_handle(const EntityHandle h)
get type from entity handle
static auto getFTensor4DdgFromPtr(T *ptr)
auto getFTensor1FromArray(VectorDouble &data)
Get FTensor1 from array.
double young_modulus
Young modulus.
double poisson_ratio
Poisson ratio.
void temp(int x, int y=10)
virtual MPI_Comm & get_comm() const =0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.