#include <deal.II/grid/tria_accessor.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/fe/mapping_q1.h>
+#include <deal.II/base/std_cxx1x/tuple.h>
#include <bitset>
#include <list>
const int direction,
const dealii::Tensor<1,DH::space_dimension> &offset);
+ /**
+ * Add periodicity information to the @p periodicity_vector for the
+ * boundaries with boundary id @p b_id1 and @p b_id2 in cartesian
+ * direction @p direction.
+ *
+ * This function tries to match all faces belonging to the first
+ * boundary with faces belonging to the second boundary
+ * by comparing the center of the cell faces. To find the correct
+ * corresponding faces, the direction argument indicates in which
+ * cartesian direction periodicity should be set.
+ * ((0,1,2) -> (x,y,z)-direction)
+ *
+ * The output of this function can be used in
+ * parallel::distributed::Triangulation::add_periodicity
+ */
+ template<typename DH>
+ void
+ identify_periodic_face_pairs
+ (const DH &dof_handler,
+ const types::boundary_id b_id1,
+ const types::boundary_id b_id2,
+ const unsigned int direction,
+ std::vector<std_cxx1x::tuple<typename DH::cell_iterator, unsigned int,
+ typename DH::cell_iterator, unsigned int> >
+ &periodicity_vector);
/**
#include <deal.II/base/std_cxx1x/array.h>
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/grid/tria.h>
+#include <deal.II/distributed/tria.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/tria_boundary.h>
}
+ template<typename DH>
+ void
+ identify_periodic_face_pairs
+ (const DH &dof_handler,
+ const types::boundary_id b_id1,
+ const types::boundary_id b_id2,
+ const unsigned int direction,
+ std::vector<std_cxx1x::tuple<typename DH::cell_iterator, unsigned int,
+ typename DH::cell_iterator, unsigned int> >
+ &periodicity_vector)
+ {
+ static const unsigned int dim = DH::dimension;
+ static const unsigned int spacedim = DH::space_dimension;
+
+ Assert (0<=direction && direction<spacedim,
+ ExcIndexRange(direction, 0, spacedim));
+
+ Assert (b_id1 != b_id2,
+ ExcMessage ("The boundary indicators b_id1 and b_id2 must be"
+ "different to denote different boundaries."));
+
+ typename std::map<std::pair<typename DH::cell_iterator,
+ unsigned int>,
+ Point<spacedim> > face_locations;
+
+ // Collect faces with boundary_indicator b_id1
+ typename DH::cell_iterator cell = dof_handler.begin();
+ typename DH::cell_iterator endc = dof_handler.end();
+ for (; cell != endc; ++cell)
+ for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; ++f)
+ if(cell->face(f)->boundary_indicator() == b_id1)
+ {
+ Point<spacedim> face_center (cell->face(f)->center());
+ face_center(direction)=0.;
+ const std::pair<typename DH::cell_iterator, unsigned int>
+ cell_face_pair = std::make_pair(cell, f);
+ face_locations[cell_face_pair]=face_center;
+ }
+
+ // Match faces with boundary_indicator b_id2 to the ones in
+ //face_locations
+ cell = dof_handler.begin();
+ for (; cell != endc; ++cell)
+ for(unsigned int f=0;f<GeometryInfo<dim>::faces_per_cell;++f)
+ if(cell->face(f)->boundary_indicator() == b_id2)
+ {
+ typename std::map<std::pair<typename DH::cell_iterator,
+ unsigned int>,
+ Point<spacedim> >::const_iterator p
+ = face_locations.begin();
+
+ Point<spacedim> center2 (cell->face(f)->center());
+ center2(direction)=0.;
+
+ for (; p != face_locations.end(); ++p)
+ {
+ if (center2.distance(p->second) < 1e-4*cell->face(f)->diameter())
+ {
+ const std_cxx1x::tuple<typename DH::cell_iterator, unsigned int,
+ typename DH::cell_iterator, unsigned int>
+ periodic_tuple
+ = std::make_tuple(p->first.first,
+ p->first.second,
+ cell,
+ f);
+
+ periodicity_vector.push_back(periodic_tuple);
+
+ face_locations.erase(p);
+ break;
+ }
+ Assert (p != face_locations.end(),
+ ExcMessage ("No corresponding face was found!"));
+ }
+ }
+
+ Assert (face_locations.size() == 0,
+ ExcMessage ("There are unmatched faces!"));
+ }
+
} /* namespace GridTools */
int,
const Tensor<1,deal_II_space_dimension> &);
+ template
+ void
+ identify_periodic_face_pairs
+ (const X &,
+ const types::boundary_id,
+ const types::boundary_id,
+ const unsigned int,
+ std::vector<std_cxx1x::tuple<typename X::cell_iterator, unsigned int,
+ typename X::cell_iterator, unsigned int> > &);
+
#endif
\}
#endif
}
+for (deal_II_dimension : DIMENSIONS ; deal_II_space_dimension : SPACE_DIMENSIONS)
+{
+#if deal_II_dimension <= deal_II_space_dimension
+ #if deal_II_dimension >= 2
+ namespace GridTools \{
+ template
+ void
+ identify_periodic_face_pairs
+ (const parallel::distributed::Triangulation<deal_II_dimension, deal_II_space_dimension> &,
+ const types::boundary_id,
+ const types::boundary_id,
+ const unsigned int,
+ std::vector<std_cxx1x::tuple<typename parallel::distributed::Triangulation<deal_II_dimension, deal_II_space_dimension>::cell_iterator,
+ unsigned int,
+ typename parallel::distributed::Triangulation<deal_II_dimension, deal_II_space_dimension>::cell_iterator,
+ unsigned int> > &);
+ \}
+ #endif
+#endif
+}
+
+