This is cleaner than returning a boolean and modifying an input argument.
*
* @p face1 and @p face2 are considered equal, if a one to one matching
* between its vertices can be achieved via an orthogonal equality relation.
+ * If no such relation exists then the returned std::optional object is empty
+ * (i.e., has_value() will return `false`).
*
* Here, two vertices <tt>v_1</tt> and <tt>v_2</tt> are considered equal, if
* $M\cdot v_1 + offset - v_2$ is parallel to the unit vector in unit
* spacedim x spacedim matrix, $M$ is set to @p matrix, otherwise $M$ is the
* identity matrix.
*
- * If the matching was successful, the _relative_ orientation of @p face1
- * with respect to @p face2 is returned in the bitset @p orientation, where
+ * If the matching was successful, the _relative_ orientation of @p face1 with
+ * respect to @p face2 is returned a std::optional<std::bitset<3>> object
+ * orientation in which
* @code
- * orientation[0] -> face_orientation
- * orientation[1] -> face_flip
- * orientation[2] -> face_rotation
+ * orientation.value()[0] = face_orientation
+ * orientation.value()[1] = face_flip
+ * orientation.value()[2] = face_rotation
* @endcode
*
* In 2d <tt>face_orientation</tt> is always <tt>true</tt>,
* article.
*/
template <typename FaceIterator>
- bool
+ std::optional<std::bitset<3>>
orthogonal_equality(
- std::bitset<3> &orientation,
const FaceIterator &face1,
const FaceIterator &face2,
const unsigned int direction,
#include <list>
#include <map>
#include <numeric>
+#include <optional>
#include <set>
#include <vector>
unsigned int n_matches = 0;
// Match with a complexity of O(n^2). This could be improved...
- std::bitset<3> orientation;
using PairIterator =
typename std::set<std::pair<CellIterator, unsigned int>>::const_iterator;
for (PairIterator it1 = pairs1.begin(); it1 != pairs1.end(); ++it1)
const CellIterator cell2 = it2->first;
const unsigned int face_idx1 = it1->second;
const unsigned int face_idx2 = it2->second;
- if (GridTools::orthogonal_equality(orientation,
- cell1->face(face_idx1),
- cell2->face(face_idx2),
- direction,
- offset,
- matrix))
+ if (const std::optional<std::bitset<3>> orientation =
+ GridTools::orthogonal_equality(cell1->face(face_idx1),
+ cell2->face(face_idx2),
+ direction,
+ offset,
+ matrix))
{
// We have a match, so insert the matching pairs and
// remove the matched cell in pairs2 to speed up the
// matching:
const PeriodicFacePair<CellIterator> matched_face = {
- {cell1, cell2}, {face_idx1, face_idx2}, orientation, matrix};
+ {cell1, cell2},
+ {face_idx1, face_idx2},
+ orientation.value(),
+ matrix};
matched_pairs.push_back(matched_face);
pairs2.erase(it2);
++n_matches;
template <typename FaceIterator>
- inline bool
+ std::optional<std::bitset<3>>
orthogonal_equality(
- std::bitset<3> &orientation,
const FaceIterator &face1,
const FaceIterator &face2,
const unsigned int direction,
}
// And finally, a lookup to determine the ordering bitmask:
- if (face2_vertices.empty())
- orientation = OrientationLookupTable<dim>::lookup(matching);
-
- return face2_vertices.empty();
-
+ return face2_vertices.empty() ?
+ std::make_optional(OrientationLookupTable<dim>::lookup(matching)) :
+ std::nullopt;
}
-
-
-
} // namespace GridTools
namespace GridTools
\{
- template bool
+ template std::optional<std::bitset<3>>
orthogonal_equality<X::active_face_iterator>(
- std::bitset<3> &,
const X::active_face_iterator &,
const X::active_face_iterator &,
const unsigned int,
const Tensor<1, deal_II_space_dimension> &,
const FullMatrix<double> &);
- template bool
+ template std::optional<std::bitset<3>>
orthogonal_equality<X::face_iterator>(
- std::bitset<3> &,
const X::face_iterator &,
const X::face_iterator &,
const unsigned int,
deallog << std::endl;
- std::bitset<3> orientation;
- if (not GridTools::orthogonal_equality(orientation,
- face_1,
- face_2,
- dim == 2 ? 1 : 2,
- dealii::Tensor<1, spacedim>()))
- std::cerr << " not match! oh noze!! " << std::endl;
- deallog << "Orientation: " << orientation[0] << orientation[1]
- << orientation[2] << std::endl;
-
-
- DoFTools::make_periodicity_constraints(face_1,
- face_2,
- constraint_matrix,
- velocity_mask,
- orientation[0],
- orientation[1],
- orientation[2]);
+ const auto orientation = GridTools::orthogonal_equality(
+ face_1, face_2, dim == 2 ? 1 : 2, dealii::Tensor<1, spacedim>());
+ AssertThrow(orientation, ExcMessage(" not match! oh noze!! "));
+ const auto o = *orientation;
+ deallog << "Orientation: " << o[0] << o[1] << o[2] << std::endl;
+
+ DoFTools::make_periodicity_constraints(
+ face_1, face_2, constraint_matrix, velocity_mask, o[0], o[1], o[2]);
deallog << "Matching:" << std::endl;
constraint_matrix.print(deallog.get_file_stream());
constraint_matrix.close();
face_1,
constraint_matrix_reverse,
velocity_mask,
- orientation[0],
- orientation[0] ?
- orientation[1] ^ orientation[2] :
- orientation[1],
- orientation[2]);
+ o[0],
+ o[0] ? o[1] ^ o[2] : o[1],
+ o[2]);
deallog << "Reverse Matching:" << std::endl;
constraint_matrix_reverse.print(deallog.get_file_stream());
constraint_matrix_reverse.close();
deallog << std::endl;
- std::bitset<3> orientation;
- if (not GridTools::orthogonal_equality(orientation,
- face_1,
- face_2,
- dim == 2 ? 1 : 2,
- dealii::Tensor<1, spacedim>()))
- std::cerr << " not match! oh noze!! " << std::endl;
- deallog << "Orientation: " << orientation[0] << orientation[1]
- << orientation[2] << std::endl;
-
-
- DoFTools::make_periodicity_constraints(face_1,
- face_2,
- constraint_matrix,
- velocity_mask,
- orientation[0],
- orientation[1],
- orientation[2]);
+ const auto orientation = GridTools::orthogonal_equality(
+ face_1, face_2, dim == 2 ? 1 : 2, dealii::Tensor<1, spacedim>());
+ AssertThrow(orientation, ExcMessage(" not match! oh noze!! "));
+ const auto o = *orientation;
+ deallog << "Orientation: " << o[0] << o[1] << o[2] << std::endl;
+
+ DoFTools::make_periodicity_constraints(
+ face_1, face_2, constraint_matrix, velocity_mask, o[0], o[1], o[2]);
deallog << "Matching:" << std::endl;
constraint_matrix.print(deallog.get_file_stream());
constraint_matrix.close();
face_1,
constraint_matrix_reverse,
velocity_mask,
- orientation[0],
- orientation[0] ?
- orientation[1] ^ orientation[2] :
- orientation[1],
- orientation[2]);
+ o[0],
+ o[0] ? o[1] ^ o[2] : o[1],
+ o[2]);
deallog << "Reverse Matching:" << std::endl;
constraint_matrix_reverse.print(deallog.get_file_stream());
constraint_matrix_reverse.close();