23 const bool surface_case =
24 variant ==
"surface" || variant ==
"folded" || variant ==
"roundoff";
27 {-1, 0, 0}, {1, 0, 0}, {0, 1, 0}, {.1, .25, .4}, {.1, .25, -.4}};
28 if (variant ==
"nonconvex") {
29 mesh.points[3] = {3, 3, 1};
30 mesh.points[4] = {3, 3, -1};
32 mesh.vertexIds = {1, 2, 3, 4, 5};
33 mesh.cells = {{0, 1, 2, 3}, {0, 1, 2, 4}};
35 mesh.points = {{0, 0, 0}, {2, 0, 0}, {1.5, 1, 0}, {0, 1, 0}, {.5, .4, 1}};
36 mesh.cells = {{0, 1, 3, 4}, {1, 2, 3, 4}};
38 if (variant ==
"folded")
39 mesh.points[2][2] = -.02;
40 if (variant ==
"roundoff")
41 mesh.points[2][2] = -3.1803435954086316e-17;
42 if (variant ==
"edge") {
43 mesh.points[3][2] = 1.;
44 mesh.points[4][2] = -1.;
45 mesh.cells = {{0, 1, 3, 4}, {1, 2, 3, 4}, {2, 0, 3, 4}};
47 if (variant ==
"internal") {
48 mesh.points = {{0, 0, 0}, {2, 0, 0}, {1.5, 1, 0},
49 {0, 1, 0}, {.5, .4, 2}, {.5, .4, -2}};
50 mesh.vertexIds = {1, 2, 3, 4, 5, 6};
51 mesh.cells = {{0, 1, 3, 4}, {1, 2, 3, 4}, {0, 1, 3, 5}, {1, 2, 3, 5}};
60 const Range &members) {
63 const auto set = sets->getCubitMeshsetPtr(
id,
type)->getMeshset();
64 CHKERR mb.add_entities(set, members);
65 const int value =
id + 100;
67 CHKERR mb.tag_get_handle(
"RECONSTRUCTION_METADATA", 1, MB_TYPE_INTEGER,
tag,
68 MB_TAG_SPARSE | MB_TAG_CREAT);
77 auto face = [&](std::array<int, 3> corners,
Range &
result) {
79 std::array<EntityHandle, 3> conn;
80 for (
int n = 0;
n != 3; ++
n)
83 moab::Interface::INTERSECT);
84 CHKERR require(
result.size() == 1,
"Missing fixture face");
89 CHKERR face({1, 2, 4}, side);
90 if (variant ==
"internal") {
94 CHKERR face({1, 2, 5}, side);
98 CHKERR face({1, 2, 3}, other);
104 const EntityHandle endpoints[] = {
vertices[variant ==
"edge" ? 3 : 0],
105 vertices[variant ==
"edge" ? 4 : 1]};
106 CHKERR mb.get_adjacencies(endpoints, 2, 1,
false, curve,
107 moab::Interface::INTERSECT);
111 const auto set = sets->getCubitMeshsetPtr(30,
SIDESET)->getMeshset();
112 EntityHandle reverse;
113 CHKERR mb.create_meshset(MESHSET_SET, reverse);
114 CHKERR mb.add_entities(reverse, side);
115 CHKERR mb.remove_entities(set, side);
116 CHKERR mb.add_entities(set, &reverse, 1);
118 const int value = -1;
119 CHKERR mb.tag_get_handle(
"NEUSET_SENSE", 1, MB_TYPE_INTEGER, sense,
120 MB_TAG_SPARSE | MB_TAG_CREAT);
121 CHKERR mb.tag_set_data(sense, &reverse, 1, &value);
123 const EntityHandle *conn;
126 CHKERR mb.tag_get_handle(
"RECONSTRUCTION_SIDE_ORDER", 3, MB_TYPE_HANDLE,
127 orientation, MB_TAG_SPARSE | MB_TAG_CREAT);
128 for (
auto side_entity : side) {
129 CHKERR mb.get_connectivity(side_entity, conn, count,
true);
130 CHKERR mb.tag_set_data(orientation, &side_entity, 1, conn);
133 if (variant ==
"crack" || variant ==
"internal") {
135 CHKERR face(variant ==
"internal" ? std::array<int, 3>{0, 1, 3}
136 : std::array<int, 3>{0, 1, 2},
138 if (variant ==
"internal") {
140 CHKERR face({1, 2, 3}, other);
145 if (variant ==
"missing") {
147 const auto vertex =
vertices.back();
148 CHKERR mb.tag_set_data(
mb.globalId_tag(), &vertex, 1, &zero);
150 if (variant ==
"duplicate") {
151 const int duplicate = 1;
152 const auto vertex =
vertices.back();
153 CHKERR mb.tag_set_data(
mb.globalId_tag(), &vertex, 1, &duplicate);
156 CHKERR mb.tag_get_handle(
"RECONSTRUCTION_ORIGINAL_ID", 1, MB_TYPE_INTEGER,
157 original_id, MB_TAG_SPARSE | MB_TAG_CREAT);
160 CHKERR mb.tag_get_data(
mb.globalId_tag(), &vertex, 1, &
id);
161 CHKERR mb.tag_set_data(original_id, &vertex, 1, &
id);
163 if (variant ==
"raw")
168 ReadUtilIface *reader;
170 EntityHandle unrelated;
171 std::vector<double *> x;
172 CHKERR reader->get_node_coords(3, 1, 0, unrelated, x);
176 CHKERR mb.tag_set_data(
mb.globalId_tag(), &unrelated, 1, &
id);
179 if (variant ==
"quadratic") {
180 EntityHandle meshset;
181 CHKERR mb.create_meshset(MESHSET_SET, meshset);
183 CHKERR mb.convert_entities(meshset,
true,
false,
false);
184 CHKERR mb.delete_entities(&meshset, 1);
185 for (
auto cell :
cells) {
186 CHKERR mb.get_connectivity(cell, conn, count,
false);
187 CHKERR require(count == 10,
"Expected ten-node fixture tetrahedra");
191 mid_nodes = subtract(mid_nodes,
vertices);
192 for (
auto node : mid_nodes) {
194 CHKERR mb.get_coords(&node, 1, xyz);
196 CHKERR mb.set_coords(&node, 1, xyz);
199 CHKERR mb.write_file((variant +
".h5m").c_str(),
"MOAB");
204 const std::string &fixture_case) {
206 const bool surface_patch = fixture_case ==
"surface" ||
207 fixture_case ==
"folded" ||
208 fixture_case ==
"roundoff";
209 const bool internal_sheet = fixture_case ==
"internal";
210 const bool triangular_crack = fixture_case ==
"crack";
211 const int expected_cells =
212 internal_sheet ? 4 : (surface_patch || triangular_crack ? 2 : 3);
227 CHKERR mb.get_entities_by_handle(0, all);
228 all = subtract(all, all.subset_by_type(MBENTITYSET));
229 CHKERR require((output_bit == 0 ||
source.empty()) && unrelated.empty() &&
231 output.num_of_type(MBTET) == expected_cells,
232 "Saved mesh contains entities outside the output level");
234 CHKERR mb.get_connectivity(subtract(output, output.subset_by_type(MBVERTEX)),
237 "Output omitted attached higher-order nodes");
241 std::vector<std::array<double, 3>> original{
242 {-1, 0, 0}, {1, 0, 0}, {0, 1, 0}, {.1, .25, .4}, {.1, .25, -.4}};
244 original = {{0, 0, 0}, {2, 0, 0}, {1.5, 1, 0}, {0, 1, 0}, {.5, .4, 1}};
245 if (fixture_case ==
"folded")
246 original[2][2] = -.02;
247 if (fixture_case ==
"roundoff")
248 original[2][2] = -3.1803435954086316e-17;
250 original = {{0, 0, 0}, {2, 0, 0}, {1.5, 1, 0},
251 {0, 1, 0}, {.5, .4, 2}, {.5, .4, -2}};
253 "Output contains missing or unrelated vertices");
256 CHKERR mb.tag_get_handle(
"RECONSTRUCTION_ORIGINAL_ID", original_id);
258 std::array<double, 3> x;
260 CHKERR mb.get_coords(&vertex, 1, x.data());
261 CHKERR mb.tag_get_data(
mb.globalId_tag(), &vertex, 1, &
id);
262 CHKERR require(x == original[
n++] &&
id > 0 && ids.insert(
id).second,
263 "Source coordinates or vertex IDs changed");
265 CHKERR mb.tag_get_data(original_id, &vertex, 1, &previous_id);
267 previous_id > 0 ?
id == previous_id : id == 101,
268 "Valid IDs were renumbered or missing IDs were not assigned");
270 for (
auto cell : output.subset_by_type(MBTET)) {
271 const EntityHandle *conn;
273 std::array<std::array<double, 3>, 4> x;
274 CHKERR mb.get_connectivity(cell, conn, count,
true);
275 CHKERR require(count == 4,
"Invalid reconstructed tetrahedron");
276 CHKERR mb.get_coords(conn, 4, x[0].data());
277 for (
int i = 1;
i != 4; ++
i)
278 for (
int d = 0;
d != 3; ++
d)
280 const double determinant =
281 x[1][0] * (x[2][1] * x[3][2] - x[2][2] * x[3][1]) -
282 x[1][1] * (x[2][0] * x[3][2] - x[2][2] * x[3][0]) +
283 x[1][2] * (x[2][0] * x[3][1] - x[2][1] * x[3][0]);
284 CHKERR require(determinant > 0,
"Nonpositive reconstructed tetrahedron");
286 for (
auto entity : output) {
287 const auto type =
mb.type_from_handle(entity);
288 if (
type == MBEDGE ||
type == MBTRI) {
289 const EntityHandle *conn;
291 CHKERR mb.get_connectivity(entity, conn, count,
true);
292 CHKERR require(count == (
type == MBEDGE ? 2 : 3),
293 "Invalid output edge or face");
297 CHKERR mb.tag_get_data(bits->get_th_RefParentHandle(), &entity, 1, &
parent);
298 CHKERR mb.tag_get_data(bits->get_th_RefBitLevel(), &entity, 1, &
bit);
300 "Output retained ancestry or another bit level");
303 CHKERR mb.tag_get_handle(
"RECONSTRUCTION_METADATA", metadata);
306 CHKERR mb.tag_get_handle(
"NAME", name_tag);
307 CHKERR mb.tag_get_bytes(name_tag, name_bytes);
308 std::map<int, std::string> expected_names{{11,
"MATERIAL"}, {12,
"OVERLAP"},
309 {20,
"BOUNDARY"}, {21,
"CURVE"},
310 {30,
"LOAD"}, {40,
"FIXED"}};
311 if (internal_sheet || triangular_crack)
312 expected_names.emplace(50,
"CRACK");
313 for (
auto it = sets->getBegin();
it != sets->getEnd(); ++
it) {
314 const int id =
it->getMeshsetId();
315 const auto set =
it->getMeshset();
317 CHKERR mb.tag_get_data(metadata, &set, 1, &value);
318 CHKERR require(value ==
id + 100,
"Meshset metadata changed");
321 std::vector<char>
name(name_bytes + 1, 0);
323 CHKERR require(std::string(
name.data()) == expected_names.at(
id),
324 "Meshset name changed");
326 CHKERR mb.get_entities_by_handle(set, members,
true);
328 subtract(subtract(members, members.subset_by_type(MBENTITYSET)), output)
330 "Meshset contains entities outside the output mesh");
331 members = intersect(members, output);
332 if (
id == 11 ||
id == 12)
333 CHKERR require(members.num_of_type(MBTET) == expected_cells,
334 "Volume/overlapping meshset lost reconstructed cells");
335 else if (
id == 20 ||
id == 30)
336 CHKERR require(members.num_of_type(MBTRI) == (surface_patch ? 2 : 1) &&
337 members.num_of_type(MBTET) == 0,
338 "Surface classification changed");
340 CHKERR require(members.num_of_type(MBEDGE) == 1 &&
341 members.num_of_type(MBTRI) == 0 &&
342 members.num_of_type(MBTET) == 0,
343 "Standalone curve membership changed");
345 CHKERR require(members.num_of_type(MBTRI) == (triangular_crack ? 1 : 2) &&
346 members.num_of_type(MBTET) == 0,
347 "Internal crack meshset membership changed");
350 "Explicit nodeset membership changed");
352 const auto material = sets->getCubitMeshsetPtr(11,
BLOCKSET);
353 std::vector<double> attributes;
354 CHKERR material->getAttributes(attributes);
355 CHKERR require(material->getName() ==
"MATERIAL" &&
356 attributes == std::vector<double>{3.25, 7.},
357 "Meshset names or material attributes changed");
360 sets->getCubitMeshsetPtr(30,
SIDESET)->getMeshset(), MBTRI, side,
true);
363 CHKERR mb.tag_get_handle(
"RECONSTRUCTION_SIDE_ORDER",
order);
364 const auto active_side = intersect(side, output);
365 auto retained_diagonal = [&](EntityHandle face) {
366 const EntityHandle *conn;
369 "Read reconstructed face");
370 std::array<EntityHandle, 3>
key{conn[0], conn[1], conn[2]};
371 std::sort(
key.begin(),
key.end());
379 std::none_of(active_side.begin(), active_side.end(), retained_diagonal),
380 "Fixture did not change the preserved surface triangulation");
382 CHKERR mb.get_connectivity(active_side, skin_vertices,
true);
383 CHKERR require(skin_vertices.size() == 4,
384 "Surface reconstruction changed the preserved node set");
385 const auto set = sets->getCubitMeshsetPtr(30,
SIDESET)->getMeshset();
386 Range nested, direct, members;
387 CHKERR mb.get_entities_by_type(set, MBENTITYSET, nested,
false);
388 CHKERR mb.get_entities_by_type(set, MBTRI, direct,
false);
389 CHKERR require(nested.size() == 1 && direct.empty(),
390 "Sideset hierarchy was flattened into forward membership");
391 const auto reverse = nested.front();
394 CHKERR mb.tag_get_handle(
"NEUSET_SENSE", sense);
395 CHKERR mb.tag_get_data(sense, &reverse, 1, &value);
396 CHKERR mb.get_entities_by_type(reverse, MBTRI, members);
397 CHKERR require(value == -1 && intersect(members, output) == active_side,
398 "Reverse sideset descendants or sense were lost");
400 auto normal = [](moab::Interface &
mesh,
const EntityHandle *nodes,
401 std::array<double, 3> &
n) {
403 std::array<std::array<double, 3>, 3> x;
404 CHKERR mesh.get_coords(nodes, 3, x[0].data());
405 for (
int d = 0;
d != 3; ++
d) {
409 for (
int d = 0;
d != 3; ++
d)
410 n[
d] = x[1][(
d + 1) % 3] * x[2][(
d + 2) % 3] -
411 x[1][(
d + 2) % 3] * x[2][(
d + 1) % 3];
414 std::array<double, 3> source_normal;
416 moab::Core reference;
417 CHKERR reference.load_file((fixture_case +
".h5m").c_str());
419 Range original_sides;
420 CHKERR reference.tag_get_handle(
"RECONSTRUCTION_SIDE_ORDER",
422 CHKERR reference.get_entities_by_type_and_tag(0, MBTRI, &reference_order,
423 nullptr, 1, original_sides);
424 std::array<EntityHandle, 3> nodes;
425 const auto face = original_sides.front();
426 CHKERR reference.tag_get_data(reference_order, &face, 1, nodes.data());
427 CHKERR normal(reference, nodes.data(), source_normal);
429 for (
auto face : active_side) {
430 std::array<EntityHandle, 3> expected;
431 const EntityHandle *conn;
433 CHKERR mb.get_connectivity(face, conn, count,
true);
434 if (!surface_patch) {
436 CHKERR require(count == 3 &&
437 std::equal(expected.begin(), expected.end(), conn),
438 "Sideset face orientation changed");
440 std::array<double, 3>
a;
443 std::inner_product(
a.begin(),
a.end(), source_normal.begin(), 0.) > 0,
444 "Reconstructed sideset has the wrong orientation");
447 if (internal_sheet) {
450 sets->getCubitMeshsetPtr(50,
BLOCKSET)->getMeshset(), MBTRI,
faces);
451 new_faces = intersect(
faces, output);
452 CHKERR mb.get_connectivity(new_faces, new_nodes,
true);
454 new_faces.size() == 2 && new_nodes.size() == 4 &&
455 std::none_of(new_faces.begin(), new_faces.end(),
456 retained_diagonal) &&
458 "Internal sheet did not preserve its nodes through a diagonal flip");
459 for (
auto face : new_faces) {
462 CHKERR require(intersect(
cells, output).num_of_type(MBTET) == 2,
463 "Reconstructed crack is not an internal surface");
466 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Verified reconstructed checkpoint";
477 char stage[32] =
"prepare", output[PETSC_MAX_PATH_LEN] =
"reconstructed.h5m";
478 PetscInt output_bit = 0;
479 char fixture_case[32] =
"valid";
481 sizeof(fixture_case),
nullptr);
483 sizeof(stage),
nullptr);
485 sizeof(output),
nullptr);
489 if (std::string(stage) ==
"prepare") {
490 for (
const auto &
name : {
"valid",
509 "constrained_surface",
510 "constrained_internal",
512 "constrained_edge"}) {
513 const auto file = std::string(
name) +
"_out.h5m";
514 std::filesystem::remove(file);
515 std::filesystem::remove(file +
".tmp.h5m");
517 for (
const auto &variant :
518 {
"valid",
"missing",
"raw",
"surface",
"internal",
"folded",
519 "roundoff",
"quadratic",
"crack",
"edge",
"materials",
"nonconvex",
522 }
else if (std::string(stage) ==
"check") {
523 CHKERR check(output, output_bit, fixture_case);
524 }
else if (std::string(stage) ==
"failures") {
525 for (
const auto &
name :
526 {
"crack",
"edge",
"materials",
"nonconvex",
"duplicate",
"occupied",
527 "invalid_bit",
"angle",
"invalid_angle",
"constrained_edge"})
528 CHKERR require(!std::filesystem::exists(std::string(
name) +
"_out.h5m"),
529 "Rejected input published an output file");
537int main(
int argc,
char *argv[]) {
539 "Serial reconstruction fixture/checkpoint checks\n");
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
std::vector< int > source
std::vector< int > vertices
std::vector< int > parent
std::vector< Cell > cells
std::vector< double > empty
One value per component.
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_ATOM_TEST_INVALID
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
FTensor::Index< 'i', SPACE_DIM > i
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< 32 > CubitBCType
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
implementation of Data Operators for Forces and Sources
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
MoFEMErrorCode run(MoFEM::Interface &m_field)
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
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.
Interface for managing meshsets containing materials and boundary conditions.
std::vector< std::array< double, 3 > > points
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.