From 3c6d75dbfc0aaa61ed769c22136c0ee6fa334849 Mon Sep 17 00:00:00 2001 From: David Wells Date: Tue, 10 Jan 2023 12:25:23 -0500 Subject: [PATCH] Use TriaObjectsOrientations in connectivity.h. --- include/deal.II/grid/connectivity.h | 43 ++++++++++++++--------------- source/grid/tria.cc | 25 +++++++++++------ 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/include/deal.II/grid/connectivity.h b/include/deal.II/grid/connectivity.h index dbbdbe201f..3be9d0ebc2 100644 --- a/include/deal.II/grid/connectivity.h +++ b/include/deal.II/grid/connectivity.h @@ -23,6 +23,7 @@ #include #include +#include DEAL_II_NAMESPACE_OPEN @@ -827,7 +828,7 @@ namespace internal , cell_types(cell_types) {} - inline std::vector & + inline TriaObjectsOrientations & entity_orientations(const unsigned int structdim) { if (structdim == 1) @@ -838,7 +839,7 @@ namespace internal return quad_orientation; } - inline const std::vector & + inline const TriaObjectsOrientations & entity_orientations(const unsigned int structdim) const { if (structdim == 1) @@ -919,12 +920,12 @@ namespace internal CRS line_vertices; - std::vector line_orientation; + TriaObjectsOrientations line_orientation; CRS quad_vertices; CRS quad_lines; - std::vector quad_orientation; + TriaObjectsOrientations quad_orientation; CRS cell_entities; CRS neighbors; @@ -1003,7 +1004,7 @@ namespace internal const CRS & crs, CRS & crs_d, // result CRS & crs_0, // result - std::vector & orientations, // result + TriaObjectsOrientations & orientations, // result const FU & second_key_function) { const bool compatibility_mode = true; @@ -1094,7 +1095,7 @@ namespace internal } col_d.resize(keys.size()); - orientations.resize(keys.size()); + orientations.reinit(keys.size()); // step 2: sort according to key so that entities with same key can be // merged @@ -1147,7 +1148,7 @@ namespace internal if (ref_key != std::get<0>(keys[i])) { - // new key + // new key: default orientation is correct counter++; ref_key = std::get<0>(keys[i]); ref_indices = ad_entity_vertices[offset_i]; @@ -1156,18 +1157,17 @@ namespace internal for (const auto j : ad_entity_vertices[offset_i]) if (j != 0) col_0.push_back(j - offset); - - // take its orientation as default - col_d[offset_i] = counter; - orientations[offset_i] = 1; } else { - col_d[offset_i] = counter; - orientations[offset_i] = + // previously seen key: set orientation relative to the first + // occurrence + orientations.set_raw_orientation( + offset_i, ad_entity_types[offset_i].compute_orientation( - ad_entity_vertices[offset_i], ref_indices); + ad_entity_vertices[offset_i], ref_indices)); } + col_d[offset_i] = counter; } ptr_0.push_back(col_0.size()); } @@ -1186,7 +1186,7 @@ namespace internal const CRS & crs, CRS & crs_d, CRS & crs_0, - std::vector & orientations, + TriaObjectsOrientations & orientations, const FU & second_key_function) { std::size_t key_length = 0; @@ -1249,14 +1249,13 @@ namespace internal const CRS & con_lv, const CRS & con_cq, const CRS & con_qv, - const std::vector & ori_cq, + const TriaObjectsOrientations & ori_cq, CRS & con_ql, // result - std::vector & ori_ql, // result + TriaObjectsOrientations & ori_ql, // result std::vector & quad_t_id // result ) { // reset output - ori_ql = {}; con_ql.ptr = {}; con_ql.col = {}; @@ -1289,7 +1288,7 @@ namespace internal // allocate memory con_ql.col.resize(con_ql.ptr.back()); - ori_ql.resize(con_ql.ptr.back()); + ori_ql.reinit(con_ql.ptr.back()); // loop over cells for (unsigned int c = 0; c < con_cq.ptr.size() - 1; ++c) @@ -1306,7 +1305,7 @@ namespace internal const unsigned int f = con_cq.col[f_]; // only faces with default orientation have to do something - if (ori_cq[f_] != 1) + if (ori_cq.get_raw_orientation(f_) != 1u) continue; // determine entity type of face @@ -1338,7 +1337,7 @@ namespace internal } // ... comparison gives orientation - ori_ql[con_ql.ptr[f] + l] = (same ? 1 : 0); + ori_ql.set_raw_orientation(con_ql.ptr[f] + l, same ? 1u : 0u); } } } @@ -1370,7 +1369,7 @@ namespace internal if (dim == 2 || dim == 3) // build lines { - std::vector dummy; + TriaObjectsOrientations dummy; build_entity(1, cell_t, diff --git a/source/grid/tria.cc b/source/grid/tria.cc index 7fa1766667..e61a77c8f6 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -2347,7 +2347,8 @@ namespace internal // set line orientations const unsigned char raw_orientation = - connectivity.entity_orientations(1)[k]; + connectivity.entity_orientations(1).get_raw_orientation( + k); // it doesn't make sense to set any flags except // orientation for a line Assert(raw_orientation == 0u || raw_orientation == 1u, @@ -2370,12 +2371,19 @@ namespace internal // in 2D optional: since in in pure QUAD meshes same line // orientations can be guaranteed - const bool orientation_needed = - dim == 3 || - (dim == 2 && - std::any_of(connectivity.entity_orientations(1).begin(), - connectivity.entity_orientations(1).end(), - [](const auto &i) { return i == 0; })); + bool orientation_needed = false; + if (dim == 3) + orientation_needed = true; + else if (dim == 2) + { + const auto &orientations = connectivity.entity_orientations(1); + for (unsigned int i = 0; i < orientations.n_objects(); ++i) + if (orientations.get_raw_orientation(i) != 1u) + { + orientation_needed = true; + break; + } + } // allocate memory reserve_space_(cells_0, n_cell); @@ -2412,7 +2420,8 @@ namespace internal { level.face_orientations.set_raw_orientation( cell * GeometryInfo::faces_per_cell + j, - connectivity.entity_orientations(dim - 1)[i]); + connectivity.entity_orientations(dim - 1) + .get_raw_orientation(i)); } } } -- 2.39.5