45int main(
int argc,
char *argv[]) {
50 moab::Core mb_instance;
51 moab::Interface &moab = mb_instance;
57 char mesh_file[255] =
"mesh.h5m";
58 char output_file[255] =
"out.h5m";
59 char tag_name[255] =
"INTERNAL_STRESS";
63 PetscBool use_voigt_notation = PETSC_FALSE;
65 PetscOptionsBegin(m_field.
get_comm(),
"",
"save thermal stress test",
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,
82 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
84 boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD,
false);
86 pcomm =
new ParallelComm(&moab, moab_comm_wrap->get_comm());
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());
94 CHKERR pcomm->get_part_entities(src_elems, 3);
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);
103 std::vector<double> spos;
104 spos.resize(3 * src_elems.size());
105 CHKERR moab.get_coords(src_elems, &spos[0]);
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;
134 mat_D_ptr.resize(6, 6,
false);
143 if (use_voigt_notation) {
151 bool tets_only =
true;
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);
167 CHKERR moab.tag_set_data(data_tag, src_elems, &data[0]);
171 std::vector<double> data_integ(tag_len, 0.0);
172 for (
auto &tet : src_elems) {
174 std::vector<double> tet_data(tag_len, 0.0);
175 CHKERR moab.tag_get_data(data_tag, &tet, 1, &tet_data[0]);
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]);
184 for (
int itag = 0; itag < tag_len; itag++) {
185 data_integ[itag] += tet_data[itag] * vol;
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,
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() +
" ";
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);
206 if (use_voigt_notation) {
207 non_zero_inds = {0, 1, 2};
208 zero_inds = {3, 4, 5, 6, 7, 8};
210 non_zero_inds = {0, 4, 8};
211 zero_inds = {1, 2, 3, 5, 6, 7};
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 <
218 bool zero_check = all_of(begin(zero_inds), end(zero_inds), [&](
int i) {
219 return abs(global_data_integ[
i]) < 1e-12;
221 if (!non_zero_check || !zero_check) {
223 "Wrong value of the integrated stress");
227 <<
"Mesh has non-tetrahedral elements, skipping the test based on "
228 "integrating the stress in the volume";
231 CHKERR moab.write_file(output_file,
"MOAB",
"PARALLEL=WRITE_PART");