From dbac0de625aa720edf40aabee1d93915fc4d7280 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Thu, 5 Dec 2013 12:20:32 +0000 Subject: [PATCH] Changed the signature of collect_periodic_faces to return the result via a reference and not as return value git-svn-id: https://svn.dealii.org/trunk@31900 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/grid/grid_tools.h | 6 ++- deal.II/source/dofs/dof_tools_constraints.cc | 18 +++---- deal.II/source/grid/grid_tools.cc | 55 +++++++++++--------- deal.II/source/grid/grid_tools.inst.in | 30 +++++------ 4 files changed, 56 insertions(+), 53 deletions(-) diff --git a/deal.II/include/deal.II/grid/grid_tools.h b/deal.II/include/deal.II/grid/grid_tools.h index 29cefdfe52..aca9b0b885 100644 --- a/deal.II/include/deal.II/grid/grid_tools.h +++ b/deal.II/include/deal.II/grid/grid_tools.h @@ -1096,12 +1096,13 @@ namespace GridTools * @author Daniel Arndt, Matthias Maier, 2013 */ template - std::vector > + void collect_periodic_faces (const CONTAINER &container, const types::boundary_id b_id1, const types::boundary_id b_id2, const int direction, + std::vector > &matched_pairs, const dealii::Tensor<1,CONTAINER::space_dimension> &offset = dealii::Tensor<1,CONTAINER::space_dimension>()); @@ -1125,11 +1126,12 @@ namespace GridTools * @author Daniel Arndt, Matthias Maier, 2013 */ template - std::vector > + void collect_periodic_faces (const CONTAINER &container, const types::boundary_id b_id, const int direction, + std::vector > &matched_pairs, const dealii::Tensor<1,CONTAINER::space_dimension> &offset = dealii::Tensor<1,CONTAINER::space_dimension>()); diff --git a/deal.II/source/dofs/dof_tools_constraints.cc b/deal.II/source/dofs/dof_tools_constraints.cc index 4ef7047725..b2b3aeb36c 100644 --- a/deal.II/source/dofs/dof_tools_constraints.cc +++ b/deal.II/source/dofs/dof_tools_constraints.cc @@ -2030,13 +2030,12 @@ namespace DoFTools ExcMessage ("The boundary indicators b_id1 and b_id2 must be" "different to denote different boundaries.")); - typedef std::vector > FaceVector; + std::vector > matched_faces; // Collect matching periodic cells on the coarsest level: - FaceVector matched_faces = - GridTools::collect_periodic_faces(dof_handler, b_id1, b_id2, - direction, offset); + GridTools::collect_periodic_faces(dof_handler, b_id1, b_id2, direction, + matched_faces, offset); make_periodicity_constraints (matched_faces, constraint_matrix, component_mask); @@ -2081,13 +2080,12 @@ namespace DoFTools Assert(dim == space_dim, ExcNotImplemented()); - typedef std::vector > FaceVector; + std::vector > matched_faces; // Collect matching periodic cells on the coarsest level: - const FaceVector matched_faces = - GridTools::collect_periodic_faces(dof_handler, b_id, - direction, offset); + GridTools::collect_periodic_faces(dof_handler, b_id, direction, + matched_faces, offset); make_periodicity_constraints (matched_faces, constraint_matrix, component_mask); diff --git a/deal.II/source/grid/grid_tools.cc b/deal.II/source/grid/grid_tools.cc index fef813ec37..445b2694cc 100644 --- a/deal.II/source/grid/grid_tools.cc +++ b/deal.II/source/grid/grid_tools.cc @@ -2368,11 +2368,12 @@ next_cell: * Internally used in collect_periodic_faces */ template - std::vector > + void match_periodic_face_pairs (std::set > &pairs1, std::set::type, unsigned int> > &pairs2, const int direction, + std::vector > & matched_pairs, const dealii::Tensor<1,CellIterator::AccessorType::space_dimension> &offset) { static const int space_dim = CellIterator::AccessorType::space_dimension; @@ -2382,7 +2383,7 @@ next_cell: Assert (pairs1.size() == pairs2.size(), ExcMessage ("Unmatched faces on periodic boundaries")); - typename std::vector > matched_faces; + unsigned int n_matches = 0; // Match with a complexity of O(n^2). This could be improved... std::bitset<3> orientation; @@ -2406,28 +2407,29 @@ next_cell: // matching: const PeriodicFacePair matched_face = {{cell1, cell2},{face_idx1, face_idx2}, orientation}; - matched_faces.push_back(matched_face); + matched_pairs.push_back(matched_face); pairs2.erase(it2); + ++n_matches; break; } } } - AssertThrow (matched_faces.size() == pairs1.size() && pairs2.size() == 0, + //Assure that all faces are matched + AssertThrow (n_matches == pairs1.size() && pairs2.size() == 0, ExcMessage ("Unmatched faces on periodic boundaries")); - - return matched_faces; } template - std::vector > + void collect_periodic_faces - (const CONTAINER &container, + (const CONTAINER &container, const types::boundary_id b_id1, const types::boundary_id b_id2, const int direction, + std::vector > & matched_pairs, const dealii::Tensor<1,CONTAINER::space_dimension> &offset) { static const int dim = CONTAINER::dimension; @@ -2467,17 +2469,19 @@ next_cell: ExcMessage ("Unmatched faces on periodic boundaries")); // and call match_periodic_face_pairs that does the actual matching: - return match_periodic_face_pairs(pairs1, pairs2, direction, offset); + match_periodic_face_pairs(pairs1, pairs2, direction, matched_pairs, offset); } template - std::vector > - collect_periodic_faces (const CONTAINER &container, - const types::boundary_id b_id, - const int direction, - const dealii::Tensor<1,CONTAINER::space_dimension> &offset) + void + collect_periodic_faces + (const CONTAINER &container, + const types::boundary_id b_id, + const int direction, + std::vector > & matched_pairs, + const dealii::Tensor<1,CONTAINER::space_dimension> &offset) { static const int dim = CONTAINER::dimension; static const int space_dim = CONTAINER::space_dimension; @@ -2517,26 +2521,25 @@ next_cell: Assert (pairs1.size() == pairs2.size(), ExcMessage ("Unmatched faces on periodic boundaries")); - // and call match_periodic_face_pairs that does the actual matching: - - typedef std::vector > - FaceVector; - FaceVector matching = match_periodic_face_pairs(pairs1, pairs2, - direction, offset); +#ifdef DEBUG + const unsigned int size_old = matched_pairs.size(); +#endif + + // and call match_periodic_face_pairs that does the actual matching: + match_periodic_face_pairs(pairs1, pairs2, direction, matched_pairs, offset); #ifdef DEBUG - for (typename FaceVector::iterator pairing = matching.begin(); - pairing != matching.end(); ++pairing) + //check for standard orientation + const unsigned int size_new = matched_pairs.size(); + for (unsigned int i = size_old; i < size_new; ++i) { - Assert(pairing->orientation == 1, + Assert(matched_pairs[i].orientation == 1, ExcMessage("Found a face match with non standard orientation. " "This function is only suitable for meshes with cells " "in default orientation")); } -#endif - - return matching; +#endif } diff --git a/deal.II/source/grid/grid_tools.inst.in b/deal.II/source/grid/grid_tools.inst.in index 6e827d7111..8089c7dad6 100644 --- a/deal.II/source/grid/grid_tools.inst.in +++ b/deal.II/source/grid/grid_tools.inst.in @@ -311,21 +311,19 @@ for (X : TRIANGULATION_AND_DOFHANDLERS; deal_II_dimension : DIMENSIONS ; deal_II #if deal_II_dimension >= 2 template - std::vector > - collect_periodic_faces - (const X &, - const types::boundary_id, - const types::boundary_id, - const int, - const Tensor<1,X::space_dimension> &); + void collect_periodic_faces (const X &, + const types::boundary_id, + const types::boundary_id, + const int, + std::vector > &, + const Tensor<1,X::space_dimension> &); template - std::vector > - collect_periodic_faces - (const X &, - const types::boundary_id, - const int, - const Tensor<1,X::space_dimension> &); + void collect_periodic_faces (const X &, + const types::boundary_id, + const int, + std::vector > &, + const Tensor<1,X::space_dimension> &); #endif @@ -341,20 +339,22 @@ for (deal_II_dimension : DIMENSIONS ; deal_II_space_dimension : SPACE_DIMENSIONS namespace GridTools \{ template - std::vector::cell_iterator> > + void collect_periodic_faces > (const parallel::distributed::Triangulation &, const types::boundary_id, const types::boundary_id, const int, + std::vector::cell_iterator> > &, const Tensor<1,parallel::distributed::Triangulation::space_dimension> &); template - std::vector::cell_iterator> > + void collect_periodic_faces > (const parallel::distributed::Triangulation &, const types::boundary_id, const int, + std::vector::cell_iterator> > &, const Tensor<1,parallel::distributed::Triangulation::space_dimension> &); \} -- 2.39.5