16 #include <deal.II/base/std_cxx11/array.h> 17 #include <deal.II/base/quadrature_lib.h> 18 #include <deal.II/base/thread_management.h> 19 #include <deal.II/lac/vector.h> 20 #include <deal.II/lac/vector_memory.h> 21 #include <deal.II/lac/filtered_matrix.h> 22 #include <deal.II/lac/precondition.h> 23 #include <deal.II/lac/solver_cg.h> 24 #include <deal.II/lac/sparse_matrix.h> 25 #include <deal.II/lac/dynamic_sparsity_pattern.h> 26 #include <deal.II/lac/constraint_matrix.h> 27 #include <deal.II/lac/sparsity_pattern.h> 28 #include <deal.II/lac/sparsity_tools.h> 29 #include <deal.II/grid/filtered_iterator.h> 30 #include <deal.II/grid/tria.h> 31 #include <deal.II/distributed/tria.h> 32 #include <deal.II/distributed/shared_tria.h> 33 #include <deal.II/distributed/tria_base.h> 34 #include <deal.II/grid/tria_accessor.h> 35 #include <deal.II/grid/tria_iterator.h> 36 #include <deal.II/grid/tria_boundary.h> 37 #include <deal.II/grid/grid_generator.h> 38 #include <deal.II/grid/grid_tools.h> 39 #include <deal.II/dofs/dof_handler.h> 40 #include <deal.II/dofs/dof_accessor.h> 41 #include <deal.II/dofs/dof_tools.h> 42 #include <deal.II/fe/fe_nothing.h> 43 #include <deal.II/fe/mapping_q1.h> 44 #include <deal.II/fe/mapping_q.h> 45 #include <deal.II/fe/fe_values.h> 46 #include <deal.II/hp/mapping_collection.h> 47 #include <deal.II/numerics/matrix_tools.h> 49 #include <boost/random/uniform_real_distribution.hpp> 50 #include <boost/random/mersenne_twister.hpp> 58 DEAL_II_NAMESPACE_OPEN
64 template <
int dim,
int spacedim>
74 #if defined(DEAL_II_WITH_P4EST) && defined(DEBUG) 87 const std::vector<Point<spacedim> > &vertices = tria.
get_vertices ();
88 std::vector<bool> boundary_vertices (vertices.size(),
false);
94 for (; cell!=endc; ++cell)
95 for (
unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
96 if (cell->face(face)->at_boundary ())
97 for (
unsigned int i=0; i<GeometryInfo<dim>::vertices_per_face; ++i)
98 boundary_vertices[cell->face(face)->vertex_index(i)] =
true;
102 double max_distance_sqr = 0;
103 std::vector<bool>::const_iterator pi = boundary_vertices.begin();
104 const unsigned int N = boundary_vertices.size();
105 for (
unsigned int i=0; i<N; ++i, ++pi)
107 std::vector<bool>::const_iterator pj = pi+1;
108 for (
unsigned int j=i+1; j<N; ++j, ++pj)
109 if ((*pi==
true) && (*pj==
true) &&
110 ((vertices[i]-vertices[j]).norm_square() > max_distance_sqr))
111 max_distance_sqr = (vertices[i]-vertices[j]).norm_square();
114 return std::sqrt(max_distance_sqr);
119 template <
int dim,
int spacedim>
125 const unsigned int mapping_degree
131 const QGauss<dim> quadrature_formula (mapping_degree + 1);
132 const unsigned int n_q_points = quadrature_formula.
size();
143 endc = triangulation.
end();
145 double local_volume = 0;
148 for (; cell!=endc; ++cell)
149 if (cell->is_locally_owned())
152 for (
unsigned int q=0; q<n_q_points; ++q)
153 local_volume += fe_values.
JxW(q);
156 double global_volume = 0;
158 #ifdef DEAL_II_WITH_MPI 164 global_volume = local_volume;
166 return global_volume;
172 cell_measure<3>(
const std::vector<Point<3> > &all_vertices,
181 const double x[8] = { all_vertices[vertex_indices[0]](0),
182 all_vertices[vertex_indices[1]](0),
183 all_vertices[vertex_indices[2]](0),
184 all_vertices[vertex_indices[3]](0),
185 all_vertices[vertex_indices[4]](0),
186 all_vertices[vertex_indices[5]](0),
187 all_vertices[vertex_indices[6]](0),
188 all_vertices[vertex_indices[7]](0)
190 const double y[8] = { all_vertices[vertex_indices[0]](1),
191 all_vertices[vertex_indices[1]](1),
192 all_vertices[vertex_indices[2]](1),
193 all_vertices[vertex_indices[3]](1),
194 all_vertices[vertex_indices[4]](1),
195 all_vertices[vertex_indices[5]](1),
196 all_vertices[vertex_indices[6]](1),
197 all_vertices[vertex_indices[7]](1)
199 const double z[8] = { all_vertices[vertex_indices[0]](2),
200 all_vertices[vertex_indices[1]](2),
201 all_vertices[vertex_indices[2]](2),
202 all_vertices[vertex_indices[3]](2),
203 all_vertices[vertex_indices[4]](2),
204 all_vertices[vertex_indices[5]](2),
205 all_vertices[vertex_indices[6]](2),
206 all_vertices[vertex_indices[7]](2)
245 const double t3 = y[3]*x[2];
246 const double t5 = z[1]*x[5];
247 const double t9 = z[3]*x[2];
248 const double t11 = x[1]*y[0];
249 const double t14 = x[4]*y[0];
250 const double t18 = x[5]*y[7];
251 const double t20 = y[1]*x[3];
252 const double t22 = y[5]*x[4];
253 const double t26 = z[7]*x[6];
254 const double t28 = x[0]*y[4];
255 const double t34 = z[3]*x[1]*y[2]+t3*z[1]-t5*y[7]+y[7]*x[4]*z[6]+t9*y[6]-t11*z[4]-t5*y[3]-t14*z[2]+z[1]*x[4]*y[0]-t18*z[3]+t20*z[0]-t22*z[0]-y[0]*x[5]*z[4]-t26*y[3]+t28*z[2]-t9*y[1]-y[1]*x[4]*z[0]-t11*z[5];
256 const double t37 = y[1]*x[0];
257 const double t44 = x[1]*y[5];
258 const double t46 = z[1]*x[0];
259 const double t49 = x[0]*y[2];
260 const double t52 = y[5]*x[7];
261 const double t54 = x[3]*y[7];
262 const double t56 = x[2]*z[0];
263 const double t58 = x[3]*y[2];
264 const double t64 = -x[6]*y[4]*z[2]-t37*z[2]+t18*z[6]-x[3]*y[6]*z[2]+t11*z[2]+t5*y[0]+t44*z[4]-t46*y[4]-t20*z[7]-t49*z[6]-t22*z[1]+t52*z[3]-t54*z[2]-t56*y[4]-t58*z[0]+y[1]*x[2]*z[0]+t9*y[7]+t37*z[4];
265 const double t66 = x[1]*y[7];
266 const double t68 = y[0]*x[6];
267 const double t70 = x[7]*y[6];
268 const double t73 = z[5]*x[4];
269 const double t76 = x[6]*y[7];
270 const double t90 = x[4]*z[0];
271 const double t92 = x[1]*y[3];
272 const double t95 = -t66*z[3]-t68*z[2]-t70*z[2]+t26*y[5]-t73*y[6]-t14*z[6]+t76*z[2]-t3*z[6]+x[6]*y[2]*z[4]-z[3]*x[6]*y[2]+t26*y[4]-t44*z[3]-x[1]*y[2]*z[0]+x[5]*y[6]*z[4]+t54*z[5]+t90*y[2]-t92*z[2]+t46*y[2];
273 const double t102 = x[2]*y[0];
274 const double t107 = y[3]*x[7];
275 const double t114 = x[0]*y[6];
276 const double t125 = y[0]*x[3]*z[2]-z[7]*x[5]*y[6]-x[2]*y[6]*z[4]+t102*z[6]-t52*z[6]+x[2]*y[4]*z[6]-t107*z[5]-t54*z[6]+t58*z[6]-x[7]*y[4]*z[6]+t37*z[5]-t114*z[4]+t102*z[4]-z[1]*x[2]*y[0]+t28*z[6]-y[5]*x[6]*z[4]-z[5]*x[1]*y[4]-t73*y[7];
277 const double t129 = z[0]*x[6];
278 const double t133 = y[1]*x[7];
279 const double t145 = y[1]*x[5];
280 const double t156 = t90*y[6]-t129*y[4]+z[7]*x[2]*y[6]-t133*z[5]+x[5]*y[3]*z[7]-t26*y[2]-t70*z[3]+t46*y[3]+z[5]*x[7]*y[4]+z[7]*x[3]*y[6]-t49*z[4]+t145*z[7]-x[2]*y[7]*z[6]+t70*z[5]+t66*z[5]-z[7]*x[4]*y[6]+t18*z[4]+x[1]*y[4]*z[0];
281 const double t160 = x[5]*y[4];
282 const double t165 = z[1]*x[7];
283 const double t178 = z[1]*x[3];
284 const double t181 = t107*z[6]+t22*z[7]+t76*z[3]+t160*z[1]-x[4]*y[2]*z[6]+t70*z[4]+t165*y[5]+x[7]*y[2]*z[6]-t76*z[5]-t76*z[4]+t133*z[3]-t58*z[1]+y[5]*x[0]*z[4]+t114*z[2]-t3*z[7]+t20*z[2]+t178*y[7]+t129*y[2];
285 const double t207 = t92*z[7]+t22*z[6]+z[3]*x[0]*y[2]-x[0]*y[3]*z[2]-z[3]*x[7]*y[2]-t165*y[3]-t9*y[0]+t58*z[7]+y[3]*x[6]*z[2]+t107*z[2]+t73*y[0]-x[3]*y[5]*z[7]+t3*z[0]-t56*y[6]-z[5]*x[0]*y[4]+t73*y[1]-t160*z[6]+t160*z[0];
286 const double t228 = -t44*z[7]+z[5]*x[6]*y[4]-t52*z[4]-t145*z[4]+t68*z[4]+t92*z[5]-t92*z[0]+t11*z[3]+t44*z[0]+t178*y[5]-t46*y[5]-t178*y[0]-t145*z[0]-t20*z[5]-t37*z[3]-t160*z[7]+t145*z[3]+x[4]*y[6]*z[2];
288 return (t34+t64+t95+t125+t156+t181+t207+t228)/12.;
334 const double x[4] = { all_vertices[vertex_indices[0]](0),
335 all_vertices[vertex_indices[1]](0),
336 all_vertices[vertex_indices[2]](0),
337 all_vertices[vertex_indices[3]](0)
340 const double y[4] = { all_vertices[vertex_indices[0]](1),
341 all_vertices[vertex_indices[1]](1),
342 all_vertices[vertex_indices[2]](1),
343 all_vertices[vertex_indices[3]](1)
346 return (-x[1]*y[0]+x[1]*y[3]+y[0]*x[2]+x[0]*y[1]-x[0]*y[2]-y[1]*x[3]-x[2]*y[3]+x[3]*y[2])/2;
358 Assert(
false, ExcNotImplemented());
364 template <
int dim,
int spacedim>
372 std::vector<bool> vertex_used (vertices.size(),
false);
373 for (
unsigned int c=0; c<cells.size(); ++c)
374 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
375 vertex_used[cells[c].vertices[v]] =
true;
381 std::vector<unsigned int> new_vertex_numbers (vertices.size(), invalid_vertex);
382 unsigned int next_free_number = 0;
383 for (
unsigned int i=0; i<vertices.size(); ++i)
384 if (vertex_used[i] ==
true)
386 new_vertex_numbers[i] = next_free_number;
392 for (
unsigned int c=0; c<cells.size(); ++c)
393 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
394 cells[c].vertices[v] = new_vertex_numbers[cells[c].vertices[v]];
398 for (
unsigned int v=0; v<GeometryInfo<1>::vertices_per_cell; ++v)
402 for (
unsigned int v=0; v<GeometryInfo<2>::vertices_per_cell; ++v)
411 tmp.reserve (std::count(vertex_used.begin(), vertex_used.end(),
true));
412 for (
unsigned int v=0; v<vertices.size(); ++v)
413 if (vertex_used[v] ==
true)
414 tmp.push_back (vertices[v]);
415 swap (vertices, tmp);
420 template <
int dim,
int spacedim>
425 std::vector<unsigned int> &considered_vertices,
431 std::vector<unsigned int> new_vertex_numbers(vertices.size());
432 for (
unsigned int i=0; i<vertices.size(); ++i)
433 new_vertex_numbers[i]=i;
437 if (considered_vertices.size()==0)
438 considered_vertices=new_vertex_numbers;
443 for (
unsigned int i=0; i<considered_vertices.size(); ++i)
445 if (new_vertex_numbers[considered_vertices[i]]!=considered_vertices[i])
456 for (
unsigned int j=i+1; j<considered_vertices.size(); ++j)
459 for (
unsigned int d=0; d<spacedim; ++d)
460 equal &= (fabs(vertices[considered_vertices[j]](d)-vertices[considered_vertices[i]](d))<tol);
463 new_vertex_numbers[considered_vertices[j]]=considered_vertices[i];
478 for (
unsigned int c=0; c<cells.size(); ++c)
479 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
480 cells[c].vertices[v]=new_vertex_numbers[cells[c].vertices[v]];
490 template <
int spacedim>
513 Rotate2d (
const double angle)
519 return Point<2> (std::cos(angle)*p(0) - std::sin(angle) * p(1),
520 std::sin(angle)*p(0) + std::cos(angle) * p(1));
527 template <
int spacedim>
531 Scale (
const double factor)
545 template <
int dim,
int spacedim>
550 transform (Shift<spacedim>(shift_vector), triangulation);
559 transform (Rotate2d(angle), triangulation);
564 template <
int dim,
int spacedim>
569 Assert (scaling_factor>0, ExcScalingFactorNotPositive (scaling_factor));
570 transform (Scale<spacedim>(scaling_factor), triangulation);
582 const std::map<unsigned int,double> &m,
585 const unsigned int n_dofs=S.
n();
599 solver.
solve(SF, u, f, PF);
611 Assert(
false, ExcNotImplemented());
646 std::vector<std::map<unsigned int,double> > m(dim);
647 typename std::map<unsigned int,Point<dim> >::const_iterator map_end=new_points.end();
652 endc=dof_handler.
end();
653 for (; cell!=endc; ++cell)
655 for (
unsigned int face_no=0; face_no<GeometryInfo<dim>::faces_per_cell; ++face_no)
661 for (
unsigned int vertex_no=0;
662 vertex_no<GeometryInfo<dim>::vertices_per_face; ++vertex_no)
664 const unsigned int vertex_index=face->vertex_index(vertex_no);
666 const typename std::map<unsigned int,Point<dim> >::const_iterator map_iter
667 = new_points.find(vertex_index);
669 if (map_iter!=map_end)
670 for (
unsigned int i=0; i<dim; ++i)
671 m[i].insert(std::pair<unsigned int,double> (
672 face->vertex_dof_index(vertex_no, 0), map_iter->second(i)));
680 for (
unsigned int i=0; i<dim; ++i)
681 us[i].reinit (dof_handler.
n_dofs());
685 for (
unsigned int i=0; i<dim; ++i)
693 for (cell=dof_handler.
begin_active(); cell!=endc; ++cell)
694 for (
unsigned int vertex_no=0;
695 vertex_no<GeometryInfo<dim>::vertices_per_cell; ++vertex_no)
698 const unsigned int dof_index=cell->vertex_dof_index(vertex_no, 0);
699 for (
unsigned int i=0; i<dim; ++i)
700 v(i)=us[i](dof_index);
704 template <
int dim,
int spacedim>
705 std::map<unsigned int, Point<spacedim> >
708 std::map<unsigned int, Point<spacedim> > vertex_map;
712 for (; cell!=endc; ++cell)
714 for (
unsigned int i=0; i<GeometryInfo<dim>::faces_per_cell; ++i)
718 if (face->at_boundary())
720 for (
unsigned j = 0; j < GeometryInfo<dim>::vertices_per_face; ++j)
723 const unsigned int vertex_index = face->vertex_index(j);
724 vertex_map[vertex_index] = vertex;
736 template <
int dim,
int spacedim>
740 const bool keep_boundary)
745 Assert (spacedim == dim, ExcNotImplemented());
757 double almost_infinite_length = 0;
759 cell=triangulation.
begin(0); cell!=triangulation.
end(0); ++cell)
760 almost_infinite_length += cell->diameter();
762 std::vector<double> minimal_length (triangulation.
n_vertices(),
763 almost_infinite_length);
766 std::vector<bool> at_boundary (triangulation.
n_vertices(),
false);
769 if (cell->is_locally_owned())
773 for (
unsigned int i=0; i<GeometryInfo<dim>::lines_per_cell; ++i)
775 const typename Triangulation<dim,spacedim>::line_iterator line
778 if (keep_boundary && line->at_boundary())
780 at_boundary[line->vertex_index(0)] =
true;
781 at_boundary[line->vertex_index(1)] =
true;
784 minimal_length[line->vertex_index(0)]
785 = std::min(line->diameter(),
786 minimal_length[line->vertex_index(0)]);
787 minimal_length[line->vertex_index(1)]
788 = std::min(line->diameter(),
789 minimal_length[line->vertex_index(1)]);
795 for (
unsigned int vertex=0; vertex<2; ++vertex)
796 if (cell->at_boundary(vertex) ==
true)
797 at_boundary[cell->vertex_index(vertex)] =
true;
799 minimal_length[cell->vertex_index(0)]
800 = std::min(cell->diameter(),
801 minimal_length[cell->vertex_index(0)]);
802 minimal_length[cell->vertex_index(1)]
803 = std::min(cell->diameter(),
804 minimal_length[cell->vertex_index(1)]);
813 boost::random::mt19937 rng;
814 boost::random::uniform_real_distribution<> uniform_distribution(-1,1);
822 std::vector<bool> vertex_moved (triangulation.
n_vertices(),
false);
827 if (cell->is_locally_owned())
829 for (
unsigned int vertex_no=0; vertex_no<GeometryInfo<dim>::vertices_per_cell;
832 const unsigned global_vertex_no = cell->vertex_index(vertex_no);
837 if ((keep_boundary && at_boundary[global_vertex_no])
838 || vertex_moved[global_vertex_no]
839 || !locally_owned_vertices[global_vertex_no])
844 for (
unsigned int d=0; d<spacedim; ++d)
845 shift_vector(d) = uniform_distribution(rng);
847 shift_vector *= factor * minimal_length[global_vertex_no] /
848 std::sqrt(shift_vector.
square());
851 cell->vertex(vertex_no) += shift_vector;
852 vertex_moved[global_vertex_no] =
true;
856 #ifdef DEAL_II_WITH_P4EST 857 distributed_triangulation
858 ->communicate_locally_moved_vertices(locally_owned_vertices);
860 (void)distributed_triangulation;
861 Assert (
false, ExcInternalError());
871 const unsigned int n_vertices = triangulation.
n_vertices();
872 std::vector<Point<spacedim> > new_vertex_locations (n_vertices);
873 const std::vector<Point<spacedim> > &old_vertex_locations
876 for (
unsigned int vertex=0; vertex<n_vertices; ++vertex)
880 if (keep_boundary && at_boundary[vertex])
881 new_vertex_locations[vertex] = old_vertex_locations[vertex];
886 for (
unsigned int d=0; d<spacedim; ++d)
887 shift_vector(d) = uniform_distribution(rng);
889 shift_vector *= factor * minimal_length[vertex] /
890 std::sqrt(shift_vector.
square());
893 new_vertex_locations[vertex] = old_vertex_locations[vertex] + shift_vector;
900 for (
unsigned int vertex_no=0;
901 vertex_no<GeometryInfo<dim>::vertices_per_cell; ++vertex_no)
902 cell->vertex(vertex_no) = new_vertex_locations[cell->vertex_index(vertex_no)];
917 endc = triangulation.
end();
918 for (; cell!=endc; ++cell)
919 if (!cell->is_artificial())
920 for (
unsigned int face=0;
921 face<GeometryInfo<dim>::faces_per_cell; ++face)
922 if (cell->face(face)->has_children() &&
923 !cell->face(face)->at_boundary())
927 cell->face(face)->child(0)->vertex(1)
928 = (cell->face(face)->vertex(0) +
929 cell->face(face)->vertex(1)) / 2;
932 cell->face(face)->child(0)->vertex(1)
933 = .5*(cell->face(face)->vertex(0)
934 +cell->face(face)->vertex(1));
935 cell->face(face)->child(0)->vertex(2)
936 = .5*(cell->face(face)->vertex(0)
937 +cell->face(face)->vertex(2));
938 cell->face(face)->child(1)->vertex(3)
939 = .5*(cell->face(face)->vertex(1)
940 +cell->face(face)->vertex(3));
941 cell->face(face)->child(2)->vertex(3)
942 = .5*(cell->face(face)->vertex(2)
943 +cell->face(face)->vertex(3));
946 cell->face(face)->child(0)->vertex(3)
947 = .25*(cell->face(face)->vertex(0)
948 +cell->face(face)->vertex(1)
949 +cell->face(face)->vertex(2)
950 +cell->face(face)->vertex(3));
958 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
969 const std::vector< Point<spacedim> > &vertices = tria.
get_vertices();
974 std::vector<bool>::const_iterator first =
975 std::find(used.begin(), used.end(),
true);
979 Assert(first != used.end(), ExcInternalError());
981 unsigned int best_vertex = std::distance(used.begin(), first);
982 double best_dist = (p - vertices[best_vertex]).norm_square();
986 for (
unsigned int j = best_vertex+1; j < vertices.size(); j++)
989 double dist = (p - vertices[j]).norm_square();
990 if (dist < best_dist)
1001 template<
int dim,
template<
int,
int>
class MeshType,
int spacedim>
1003 std::vector<typename MeshType<dim, spacedim>::active_cell_iterator>
1005 std::vector<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type>
1008 const unsigned int vertex)
1013 Assert(vertex < mesh.get_triangulation().n_vertices(),
1014 ExcIndexRange(0,mesh.get_triangulation().n_vertices(),vertex));
1015 Assert(mesh.get_triangulation().get_used_vertices()[vertex],
1016 ExcVertexNotUsed(vertex));
1021 std::set<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type> adjacent_cells;
1023 typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type
1024 cell = mesh.begin_active(),
1060 for (; cell != endc; ++cell)
1062 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; v++)
1063 if (cell->vertex_index(v) == vertex)
1068 adjacent_cells.insert(cell);
1075 for (
unsigned int vface = 0; vface < dim; vface++)
1077 const unsigned int face =
1080 if (!cell->at_boundary(face)
1082 cell->neighbor(face)->active())
1094 adjacent_cells.insert (cell->neighbor(face));
1105 for (
unsigned int e=0; e<GeometryInfo<dim>::lines_per_cell; ++e)
1106 if (cell->line(e)->has_children())
1110 if (cell->line(e)->child(0)->vertex_index(1) == vertex)
1112 adjacent_cells.insert(cell);
1121 Assert (dim <= 3, ExcNotImplemented());
1131 Assert (adjacent_cells.size() > 0, ExcInternalError());
1135 std::vector<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type>
1136 (adjacent_cells.begin(), adjacent_cells.end());
1143 template <
int dim,
template<
int,
int>
class MeshType,
int spacedim>
1144 void find_active_cell_around_point_internal
1145 (
const MeshType<dim,spacedim> &mesh,
1147 std::set<
typename MeshType<dim, spacedim>::active_cell_iterator> &searched_cells,
1148 std::set<
typename MeshType<dim, spacedim>::active_cell_iterator> &adjacent_cells)
1150 std::set<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type> &searched_cells,
1151 std::set<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type> &adjacent_cells)
1155 typedef typename MeshType<dim, spacedim>::active_cell_iterator cell_iterator;
1157 typedef typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type cell_iterator;
1161 searched_cells.insert(adjacent_cells.begin(), adjacent_cells.end());
1165 std::set<cell_iterator> adjacent_cells_new;
1167 typename std::set<cell_iterator>::const_iterator
1168 cell = adjacent_cells.begin(),
1169 endc = adjacent_cells.end();
1170 for (; cell != endc; ++cell)
1172 std::vector<cell_iterator> active_neighbors;
1173 get_active_neighbors<MeshType<dim, spacedim> >(*cell, active_neighbors);
1174 for (
unsigned int i=0; i<active_neighbors.size(); ++i)
1175 if (searched_cells.find(active_neighbors[i]) == searched_cells.end())
1176 adjacent_cells_new.insert(active_neighbors[i]);
1178 adjacent_cells.clear();
1179 adjacent_cells.insert(adjacent_cells_new.begin(), adjacent_cells_new.end());
1180 if (adjacent_cells.size() == 0)
1188 cell_iterator it = mesh.begin_active();
1189 for ( ; it!=mesh.end(); ++it)
1190 if (searched_cells.find(it) == searched_cells.end())
1192 adjacent_cells.insert(it);
1199 template <
int dim,
template<
int,
int>
class MeshType,
int spacedim>
1201 typename MeshType<dim, spacedim>::active_cell_iterator
1203 typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type
1209 find_active_cell_around_point<dim,MeshType,spacedim>
1215 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1217 std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
Point<dim> >
1219 std::pair<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type,
Point<dim> >
1222 const MeshType<dim,spacedim> &mesh,
1225 typedef typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type active_cell_iterator;
1231 double best_distance = 1e-10;
1232 int best_level = -1;
1233 std::pair<active_cell_iterator, Point<dim> > best_cell;
1237 std::vector<active_cell_iterator> adjacent_cells_tmp
1243 Assert(adjacent_cells_tmp.size()>0, ExcInternalError());
1246 std::set<active_cell_iterator> adjacent_cells (adjacent_cells_tmp.begin(),
1247 adjacent_cells_tmp.end());
1248 std::set<active_cell_iterator> searched_cells;
1256 const unsigned int n_active_cells = mesh.get_triangulation().n_active_cells();
1258 unsigned int cells_searched = 0;
1259 while (!found && cells_searched < n_active_cells)
1261 typename std::set<active_cell_iterator>::const_iterator
1262 cell = adjacent_cells.begin(),
1263 endc = adjacent_cells.end();
1264 for (; cell != endc; ++cell)
1278 if ((dist < best_distance)
1280 ((dist == best_distance)
1282 ((*cell)->level() > best_level)))
1285 best_distance = dist;
1286 best_level = (*cell)->level();
1287 best_cell = std::make_pair(*cell, p_cell);
1307 cells_searched += adjacent_cells.size();
1316 if (!found && cells_searched < n_active_cells)
1318 find_active_cell_around_point_internal<dim,MeshType,spacedim>
1319 (mesh, searched_cells, adjacent_cells);
1324 ExcPointNotFound<spacedim>(p));
1331 template <
int dim,
int spacedim>
1332 std::pair<typename hp::DoFHandler<dim,spacedim>::active_cell_iterator,
Point<dim> >
1339 ExcMessage (
"Mapping collection needs to have either size 1 " 1340 "or size equal to the number of elements in " 1341 "the FECollection."));
1345 std::pair<cell_iterator, Point<dim> > best_cell;
1349 if (mapping.
size() == 1)
1359 double best_distance = 1e-10;
1360 int best_level = -1;
1367 std::vector<cell_iterator> adjacent_cells_tmp =
1372 Assert(adjacent_cells_tmp.size()>0, ExcInternalError());
1375 std::set<cell_iterator> adjacent_cells(adjacent_cells_tmp.begin(), adjacent_cells_tmp.end());
1376 std::set<cell_iterator> searched_cells;
1386 unsigned int cells_searched = 0;
1387 while (!found && cells_searched < n_cells)
1389 typename std::set<cell_iterator>::const_iterator
1390 cell = adjacent_cells.begin(),
1391 endc = adjacent_cells.end();
1392 for (; cell != endc; ++cell)
1396 const Point<dim> p_cell = mapping[(*cell)->active_fe_index()].transform_real_to_unit_cell(*cell, p);
1407 if (dist < best_distance ||
1408 (dist == best_distance && (*cell)->level() > best_level))
1411 best_distance = dist;
1412 best_level = (*cell)->level();
1413 best_cell = std::make_pair(*cell, p_cell);
1432 cells_searched += adjacent_cells.size();
1438 if (!found && cells_searched < n_cells)
1440 find_active_cell_around_point_internal<dim,hp::DoFHandler,spacedim>
1441 (mesh, searched_cells, adjacent_cells);
1448 ExcPointNotFound<spacedim>(p));
1457 template<
class MeshType>
1459 contains_locally_owned_cells (
const std::vector<typename MeshType::active_cell_iterator> &cells)
1461 for (
typename std::vector<typename MeshType::active_cell_iterator>::const_iterator
1462 it = cells.begin(); it != cells.end(); ++it)
1464 if ((*it)->is_locally_owned())
1470 template<
class MeshType>
1472 contains_artificial_cells (
const std::vector<typename MeshType::active_cell_iterator> &cells)
1474 for (
typename std::vector<typename MeshType::active_cell_iterator>::const_iterator
1475 it = cells.begin(); it != cells.end(); ++it)
1477 if ((*it)->is_artificial())
1487 template <
class MeshType>
1488 std::vector<typename MeshType::active_cell_iterator>
1490 (
const MeshType &mesh,
1491 const std_cxx11::function<
bool (
const typename MeshType::active_cell_iterator &)> &predicate)
1493 std::vector<typename MeshType::active_cell_iterator> active_halo_layer;
1494 std::vector<bool> locally_active_vertices_on_subdomain (mesh.get_triangulation().n_vertices(),
1500 for (
typename MeshType::active_cell_iterator
1501 cell = mesh.begin_active();
1502 cell != mesh.end(); ++cell)
1503 if (predicate(cell))
1504 for (
unsigned int v=0; v<GeometryInfo<MeshType::dimension>::vertices_per_cell; ++v)
1505 locally_active_vertices_on_subdomain[cell->vertex_index(v)] =
true;
1510 for (
typename MeshType::active_cell_iterator
1511 cell = mesh.begin_active();
1512 cell != mesh.end(); ++cell)
1513 if (!predicate(cell))
1514 for (
unsigned int v=0; v<GeometryInfo<MeshType::dimension>::vertices_per_cell; ++v)
1515 if (locally_active_vertices_on_subdomain[cell->vertex_index(v)] ==
true)
1517 active_halo_layer.push_back(cell);
1521 return active_halo_layer;
1526 template <
class MeshType>
1527 std::vector<typename MeshType::active_cell_iterator>
1530 std_cxx11::function<bool (const typename MeshType::active_cell_iterator &)> predicate
1533 const std::vector<typename MeshType::active_cell_iterator>
1538 Assert(contains_locally_owned_cells<MeshType>(active_halo_layer) ==
false,
1539 ExcMessage(
"Halo layer contains locally owned cells"));
1540 Assert(contains_artificial_cells<MeshType>(active_halo_layer) ==
false,
1541 ExcMessage(
"Halo layer contains artificial cells"));
1543 return active_halo_layer;
1548 template <
int dim,
int spacedim>
1549 std::vector<std::set<typename Triangulation<dim,spacedim>::active_cell_iterator> >
1552 std::vector<std::set<typename Triangulation<dim,spacedim>::active_cell_iterator> >
1555 endc = triangulation.
end();
1556 for (; cell!=endc; ++cell)
1557 for (
unsigned int i=0; i<GeometryInfo<dim>::vertices_per_cell; ++i)
1562 for (; cell!=endc; ++cell)
1564 for (
unsigned int i=0; i<GeometryInfo<dim>::faces_per_cell; ++i)
1566 if ((cell->at_boundary(i)==
false) && (cell->neighbor(i)->active()))
1570 for (
unsigned int j=0; j<GeometryInfo<dim>::vertices_per_face; ++j)
1578 for (
unsigned int i=0; i<GeometryInfo<dim>::lines_per_cell; ++i)
1579 if (cell->line(i)->has_children())
1592 template <
int dim,
int spacedim>
1593 std::map<unsigned int,types::global_vertex_index>
1597 std::map<unsigned int,types::global_vertex_index> local_to_global_vertex_index;
1599 #ifndef DEAL_II_WITH_MPI 1604 (void)triangulation;
1606 "for parallel::distributed::Triangulation " 1607 "objects if you do not have MPI enabled."));
1612 const std::vector<std::set<active_cell_iterator> > vertex_to_cell =
1617 unsigned int max_cellid_size = 0;
1618 std::set<std::pair<types::subdomain_id,types::global_vertex_index> > vertices_added;
1619 std::map<types::subdomain_id,std::set<unsigned int> > vertices_to_recv;
1622 active_cell_iterator cell = triangulation.
begin_active(),
1623 endc = triangulation.
end();
1624 std::set<active_cell_iterator> missing_vert_cells;
1625 std::set<unsigned int> used_vertex_index;
1626 for (; cell!=endc; ++cell)
1628 if (cell->is_locally_owned())
1630 for (
unsigned int i=0; i<GeometryInfo<dim>::vertices_per_cell; ++i)
1632 types::subdomain_id lowest_subdomain_id = cell->subdomain_id();
1633 typename std::set<active_cell_iterator>::iterator
1634 adjacent_cell = vertex_to_cell[cell->vertex_index(i)].begin(),
1635 end_adj_cell = vertex_to_cell[cell->vertex_index(i)].end();
1636 for (; adjacent_cell!=end_adj_cell; ++adjacent_cell)
1637 lowest_subdomain_id = std::min(lowest_subdomain_id,
1638 (*adjacent_cell)->subdomain_id());
1641 if (lowest_subdomain_id==cell->subdomain_id())
1645 if (used_vertex_index.find(cell->vertex_index(i))==used_vertex_index.end())
1648 local_to_global_vertex_index[cell->vertex_index(i)] = next_index++;
1652 adjacent_cell = vertex_to_cell[cell->vertex_index(i)].begin();
1653 std::vector<types::subdomain_id> subdomain_ids;
1654 for (; adjacent_cell!=end_adj_cell; ++adjacent_cell)
1655 if ((*adjacent_cell)->subdomain_id()!=cell->subdomain_id())
1657 std::pair<types::subdomain_id,types::global_vertex_index>
1658 tmp((*adjacent_cell)->subdomain_id(), cell->vertex_index(i));
1659 if (vertices_added.find(tmp)==vertices_added.end())
1661 vertices_to_send[(*adjacent_cell)->subdomain_id()].push_back(
1662 std_cxx11::tuple<types::global_vertex_index,types::global_vertex_index,
1663 std::string> (i,cell->vertex_index(i),
1664 cell->id().to_string()));
1665 if (cell->id().to_string().size() > max_cellid_size)
1666 max_cellid_size = cell->id().to_string().size();
1667 vertices_added.insert(tmp);
1670 used_vertex_index.insert(cell->vertex_index(i));
1676 vertices_to_recv[lowest_subdomain_id].insert(cell->vertex_index(i));
1677 missing_vert_cells.insert(cell);
1684 if (cell->is_ghost())
1686 for (
unsigned int i=0; i<GeometryInfo<dim>::faces_per_cell; ++i)
1688 if (cell->at_boundary(i)==
false)
1690 if (cell->neighbor(i)->active())
1694 if ((adjacent_cell->is_locally_owned()))
1696 types::subdomain_id adj_subdomain_id = adjacent_cell->subdomain_id();
1697 if (cell->subdomain_id()<adj_subdomain_id)
1698 for (
unsigned int j=0; j<GeometryInfo<dim>::vertices_per_face; ++j)
1700 vertices_to_recv[cell->subdomain_id()].insert(cell->face(i)->vertex_index(j));
1701 missing_vert_cells.insert(cell);
1716 std::vector<types::global_vertex_index> indices(n_cpu);
1717 MPI_Allgather(&next_index, 1, DEAL_II_DOF_INDEX_MPI_TYPE, &indices[0],
1718 indices.size(), DEAL_II_DOF_INDEX_MPI_TYPE, triangulation.
get_communicator());
1719 const types::global_vertex_index
shift = std::accumulate(&indices[0],
1722 std::map<unsigned int,types::global_vertex_index>::iterator
1723 global_index_it = local_to_global_vertex_index.begin(),
1724 global_index_end = local_to_global_vertex_index.end();
1725 for (; global_index_it!=global_index_end; ++global_index_it)
1726 global_index_it->second += shift;
1733 std::vector<std::vector<types::global_vertex_index> > vertices_send_buffers(
1734 vertices_to_send.size());
1735 std::vector<MPI_Request> first_requests(vertices_to_send.size());
1739 vert_to_send_it = vertices_to_send.begin(),
1740 vert_to_send_end = vertices_to_send.end();
1741 for (
unsigned int i=0; vert_to_send_it!=vert_to_send_end;
1742 ++vert_to_send_it, ++i)
1744 int destination = vert_to_send_it->first;
1745 const unsigned int n_vertices = vert_to_send_it->second.size();
1746 const int buffer_size = 2*n_vertices;
1747 vertices_send_buffers[i].resize(buffer_size);
1750 for (
unsigned int j=0; j<n_vertices; ++j)
1752 vertices_send_buffers[i][2*j] = std_cxx11::get<0>(vert_to_send_it->second[j]);
1753 vertices_send_buffers[i][2*j+1] =
1754 local_to_global_vertex_index[std_cxx11::get<1>(vert_to_send_it->second[j])];
1758 MPI_Isend(&vertices_send_buffers[i][0],buffer_size,DEAL_II_VERTEX_INDEX_MPI_TYPE,
1763 std::vector<std::vector<types::global_vertex_index> > vertices_recv_buffers(
1764 vertices_to_recv.size());
1765 typename std::map<types::subdomain_id,std::set<unsigned int> >::iterator
1766 vert_to_recv_it = vertices_to_recv.begin(),
1767 vert_to_recv_end = vertices_to_recv.end();
1768 for (
unsigned int i=0; vert_to_recv_it!=vert_to_recv_end; ++vert_to_recv_it, ++i)
1770 int source = vert_to_recv_it->first;
1771 const unsigned int n_vertices = vert_to_recv_it->second.size();
1772 const int buffer_size = 2*n_vertices;
1773 vertices_recv_buffers[i].resize(buffer_size);
1776 MPI_Recv(&vertices_recv_buffers[i][0],buffer_size,DEAL_II_VERTEX_INDEX_MPI_TYPE,
1782 std::vector<std::vector<char> > cellids_send_buffers(vertices_to_send.size());
1783 std::vector<MPI_Request> second_requests(vertices_to_send.size());
1784 vert_to_send_it = vertices_to_send.begin();
1785 for (
unsigned int i=0; vert_to_send_it!=vert_to_send_end;
1786 ++vert_to_send_it, ++i)
1788 int destination = vert_to_send_it->first;
1789 const unsigned int n_vertices = vert_to_send_it->second.size();
1790 const int buffer_size = max_cellid_size*n_vertices;
1791 cellids_send_buffers[i].resize(buffer_size);
1794 unsigned int pos = 0;
1795 for (
unsigned int j=0; j<n_vertices; ++j)
1797 std::string cell_id = std_cxx11::get<2>(vert_to_send_it->second[j]);
1798 for (
unsigned int k=0; k<max_cellid_size; ++k, ++pos)
1800 if (k<cell_id.size())
1801 cellids_send_buffers[i][pos] = cell_id[k];
1805 cellids_send_buffers[i][pos] =
'-';
1810 MPI_Isend(&cellids_send_buffers[i][0], buffer_size, MPI_CHAR,
1815 std::vector<std::vector<char> > cellids_recv_buffers(vertices_to_recv.size());
1816 vert_to_recv_it = vertices_to_recv.begin();
1817 for (
unsigned int i=0; vert_to_recv_it!=vert_to_recv_end; ++vert_to_recv_it, ++i)
1819 int source = vert_to_recv_it->first;
1820 const unsigned int n_vertices = vert_to_recv_it->second.size();
1821 const int buffer_size = max_cellid_size*n_vertices;
1822 cellids_recv_buffers[i].resize(buffer_size);
1825 MPI_Recv(&cellids_recv_buffers[i][0],buffer_size, MPI_CHAR,
1831 vert_to_recv_it = vertices_to_recv.begin();
1832 for (
unsigned int i=0; vert_to_recv_it!=vert_to_recv_end; ++i, ++vert_to_recv_it)
1834 for (
unsigned int j=0; j<vert_to_recv_it->second.size(); ++j)
1836 const unsigned int local_pos_recv = vertices_recv_buffers[i][2*j];
1837 const types::global_vertex_index global_id_recv = vertices_recv_buffers[i][2*j+1];
1838 const std::string cellid_recv(&cellids_recv_buffers[i][max_cellid_size*j],
1839 &cellids_recv_buffers[i][max_cellid_size*(j+1)]);
1841 typename std::set<active_cell_iterator>::iterator
1842 cell_set_it = missing_vert_cells.begin(),
1843 end_cell_set = missing_vert_cells.end();
1844 for (; (found==
false) && (cell_set_it!=end_cell_set); ++cell_set_it)
1846 typename std::set<active_cell_iterator>::iterator
1847 candidate_cell = vertex_to_cell[(*cell_set_it)->vertex_index(i)].begin(),
1848 end_cell = vertex_to_cell[(*cell_set_it)->vertex_index(i)].end();
1849 for (; candidate_cell!=end_cell; ++candidate_cell)
1851 std::string current_cellid = (*candidate_cell)->id().to_string();
1852 current_cellid.resize(max_cellid_size,
'-');
1853 if (current_cellid.compare(cellid_recv)==0)
1855 local_to_global_vertex_index[(*candidate_cell)->vertex_index(local_pos_recv)] =
1867 return local_to_global_vertex_index;
1872 template <
int dim,
int spacedim>
1884 std::map< std::pair<unsigned int,unsigned int>,
unsigned int >
1888 cell != triangulation.
end(); ++cell)
1889 indexmap[std::pair<unsigned int,unsigned int>(cell->level(),cell->index())] = cell->active_cell_index();
1900 cell != triangulation.
end(); ++cell)
1902 const unsigned int index = cell->active_cell_index();
1903 cell_connectivity.
add (index, index);
1904 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
1905 if ((cell->at_boundary(f) ==
false)
1907 (cell->neighbor(f)->has_children() ==
false))
1909 unsigned int other_index = indexmap.find(
1910 std::pair<unsigned int,unsigned int>(cell->neighbor(f)->level(),cell->neighbor(f)->index()))->second;
1911 cell_connectivity.
add (index, other_index);
1912 cell_connectivity.
add (other_index, index);
1919 template <
int dim,
int spacedim>
1931 template <
int dim,
int spacedim>
1936 std::vector<std::vector<unsigned int> > vertex_to_cell(triangulation.
n_vertices());
1940 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
1941 vertex_to_cell[cell->vertex_index(v)].push_back(cell->active_cell_index());
1949 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
1950 for (
unsigned int n=0; n<vertex_to_cell[cell->vertex_index(v)].size(); ++n)
1951 cell_connectivity.
add(cell->active_cell_index(), vertex_to_cell[cell->vertex_index(v)][n]);
1957 template <
int dim,
int spacedim>
1965 ExcMessage (
"Objects of type parallel::distributed::Triangulation " 1966 "are already partitioned implicitly and can not be " 1967 "partitioned again explicitly."));
1968 Assert (n_partitions > 0, ExcInvalidNumberOfPartitions(n_partitions));
1971 if (n_partitions == 1)
1975 cell != triangulation.
end(); ++cell)
1976 cell->set_subdomain_id (0);
1996 template <
int dim,
int spacedim>
2005 ExcMessage (
"Objects of type parallel::distributed::Triangulation " 2006 "are already partitioned implicitly and can not be " 2007 "partitioned again explicitly."));
2008 Assert (n_partitions > 0, ExcInvalidNumberOfPartitions(n_partitions));
2010 ExcMessage (
"Connectivity graph has wrong size"));
2012 ExcMessage (
"Connectivity graph has wrong size"));
2015 if (n_partitions == 1)
2019 cell != triangulation.
end(); ++cell)
2020 cell->set_subdomain_id (0);
2028 std::vector<unsigned int> partition_indices (triangulation.
n_active_cells());
2035 cell != triangulation.
end(); ++cell)
2036 cell->set_subdomain_id (partition_indices[cell->active_cell_index()]);
2041 template <
int dim,
int spacedim>
2044 std::vector<types::subdomain_id> &subdomain)
2047 ExcDimensionMismatch (subdomain.size(),
2050 cell = triangulation.
begin_active(); cell!=triangulation.
end(); ++cell)
2051 subdomain[cell->active_cell_index()] = cell->subdomain_id();
2056 template <
int dim,
int spacedim>
2061 unsigned int count = 0;
2064 cell!=triangulation.
end(); ++cell)
2065 if (cell->subdomain_id() == subdomain)
2073 template <
int dim,
int spacedim>
2089 cell != triangulation.
end(); ++cell)
2090 if (cell->is_artificial()
2092 (cell->is_ghost() &&
2093 (cell->subdomain_id() < tr->locally_owned_subdomain())))
2094 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
2095 locally_owned_vertices[cell->vertex_index(v)] =
false;
2097 return locally_owned_vertices;
2102 template <
typename MeshType>
2103 std::list<std::pair<
typename MeshType::cell_iterator,
2104 typename MeshType::cell_iterator> >
2106 const MeshType &mesh_2)
2109 ExcMessage (
"The two meshes must be represent triangulations that " 2110 "have the same coarse meshes"));
2128 std::list<std::pair<
typename MeshType::cell_iterator,
2129 typename MeshType::cell_iterator> >
2135 typename MeshType::cell_iterator
2136 cell_1 = mesh_1.begin(0),
2137 cell_2 = mesh_2.begin(0);
2138 for (; cell_1 != mesh_1.end(0); ++cell_1, ++cell_2)
2139 cell_list.push_back (std::make_pair (cell_1, cell_2));
2143 typename CellList::iterator cell_pair = cell_list.begin();
2144 while (cell_pair != cell_list.end())
2150 if (cell_pair->first->has_children()
2152 cell_pair->second->has_children())
2154 Assert(cell_pair->first->refinement_case()==
2155 cell_pair->second->refinement_case(), ExcNotImplemented());
2156 for (
unsigned int c=0; c<cell_pair->first->n_children(); ++c)
2157 cell_list.push_back (std::make_pair (cell_pair->first->child(c),
2158 cell_pair->second->child(c)));
2167 const typename CellList::iterator previous_cell_pair = cell_pair;
2170 cell_list.erase (previous_cell_pair);
2182 for (cell_pair = cell_list.begin(); cell_pair != cell_list.end(); ++cell_pair)
2183 Assert (cell_pair->first->active()
2185 cell_pair->second->active()
2187 (cell_pair->first->refinement_case()
2188 != cell_pair->second->refinement_case()),
2189 ExcInternalError());
2194 template <
int dim,
int spacedim>
2208 cell_1 = mesh_1.
begin(0),
2209 cell_2 = mesh_2.
begin(0),
2210 endc = mesh_1.
end(0);
2211 for (; cell_1!=endc; ++cell_1, ++cell_2)
2212 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
2213 if (cell_1->vertex(v) != cell_2->vertex(v))
2225 template <
typename MeshType>
2228 const MeshType &mesh_2)
2231 mesh_2.get_triangulation());
2236 template <
int dim,
int spacedim>
2240 double min_diameter = triangulation.
begin_active()->diameter();
2244 min_diameter = std::min (min_diameter,
2246 return min_diameter;
2251 template <
int dim,
int spacedim>
2255 double max_diameter = triangulation.
begin_active()->diameter();
2259 max_diameter = std::max (max_diameter,
2261 return max_diameter;
2268 namespace FixUpDistortedChildCells
2291 template <
typename Iterator,
int spacedim>
2293 objective_function (
const Iterator &
object,
2296 const unsigned int structdim = Iterator::AccessorType::structure_dimension;
2297 Assert (spacedim == Iterator::AccessorType::dimension,
2298 ExcInternalError());
2304 ExcNotImplemented());
2310 Tensor<spacedim-structdim,spacedim> parent_alternating_forms
2313 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2314 parent_vertices[i] = object->vertex(i);
2317 parent_alternating_forms);
2319 const Tensor<spacedim-structdim,spacedim>
2320 average_parent_alternating_form
2321 = std::accumulate (&parent_alternating_forms[0],
2334 [GeometryInfo<structdim>::vertices_per_cell];
2335 Tensor<spacedim-structdim,spacedim> child_alternating_forms
2337 [GeometryInfo<structdim>::vertices_per_cell];
2339 for (
unsigned int c=0; c<
object->n_children(); ++c)
2340 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2341 child_vertices[c][i] = object->child(c)->vertex(i);
2349 for (
unsigned int c=0; c<
object->n_children(); ++c)
2353 for (
unsigned int c=0; c<
object->n_children(); ++c)
2355 child_alternating_forms[c]);
2367 double objective = 0;
2368 for (
unsigned int c=0; c<
object->n_children(); ++c)
2369 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2370 objective += (child_alternating_forms[c][i] -
2371 average_parent_alternating_form/std::pow(2.,1.*structdim))
2383 template <
typename Iterator>
2385 get_face_midpoint (
const Iterator &
object,
2386 const unsigned int f,
2389 return object->vertex(f);
2399 template <
typename Iterator>
2401 get_face_midpoint (
const Iterator &
object,
2402 const unsigned int f,
2405 return object->line(f)->center();
2415 template <
typename Iterator>
2417 get_face_midpoint (
const Iterator &
object,
2418 const unsigned int f,
2421 return object->face(f)->center();
2449 template <
typename Iterator>
2451 minimal_diameter (
const Iterator &
object)
2454 structdim = Iterator::AccessorType::structure_dimension;
2456 double diameter =
object->diameter();
2457 for (
unsigned int f=0;
2458 f<GeometryInfo<structdim>::faces_per_cell;
2460 for (
unsigned int e=f+1;
2461 e<GeometryInfo<structdim>::faces_per_cell;
2463 diameter = std::min (diameter,
2467 .distance (get_face_midpoint
2487 template <
typename Iterator>
2489 fix_up_object (
const Iterator &
object,
2490 const bool respect_manifold)
2492 const Boundary<Iterator::AccessorType::dimension,
2493 Iterator::AccessorType::space_dimension>
2494 *manifold = (respect_manifold ?
2495 &
object->get_boundary() :
2498 const unsigned int structdim = Iterator::AccessorType::structure_dimension;
2499 const unsigned int spacedim = Iterator::AccessorType::space_dimension;
2510 Assert (object->has_children(), ExcInternalError());
2512 ExcNotImplemented());
2523 unsigned int iteration = 0;
2524 const double diameter = minimal_diameter (
object);
2528 double current_value = objective_function (
object, object_mid_point);
2529 double initial_delta = 0;
2541 const double step_length = diameter / 4 / (iteration + 1);
2548 for (
unsigned int d=0; d<spacedim; ++d)
2550 const double eps = step_length/10;
2555 if (respect_manifold ==
false)
2557 = ((objective_function (
object, object_mid_point + h)
2559 objective_function (
object, object_mid_point - h))
2564 = ((objective_function (
object,
2565 manifold->project_to_surface(
object,
2566 object_mid_point + h))
2568 objective_function (
object,
2569 manifold->project_to_surface(
object,
2570 object_mid_point - h)))
2584 if (gradient.
norm() == 0)
2599 object_mid_point -= std::min(2 * current_value / (gradient*gradient),
2600 step_length / gradient.norm()) *
2603 if (respect_manifold ==
true)
2604 object_mid_point = manifold->project_to_surface(
object,
2609 const double previous_value = current_value;
2610 current_value = objective_function (
object, object_mid_point);
2613 initial_delta = (previous_value - current_value);
2617 if ((iteration >= 1) &&
2618 ((previous_value - current_value < 0)
2620 (std::fabs (previous_value - current_value)
2622 0.001 * initial_delta)))
2627 while (iteration < 20);
2643 double old_min_product, new_min_product;
2647 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2648 parent_vertices[i] = object->vertex(i);
2650 Tensor<spacedim-structdim,spacedim> parent_alternating_forms
2653 parent_alternating_forms);
2659 for (
unsigned int c=0; c<
object->n_children(); ++c)
2660 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2661 child_vertices[c][i] = object->child(c)->vertex(i);
2663 Tensor<spacedim-structdim,spacedim> child_alternating_forms
2667 for (
unsigned int c=0; c<
object->n_children(); ++c)
2669 child_alternating_forms[c]);
2671 old_min_product = child_alternating_forms[0][0] * parent_alternating_forms[0];
2672 for (
unsigned int c=0; c<
object->n_children(); ++c)
2673 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2674 for (
unsigned int j=0; j<GeometryInfo<structdim>::vertices_per_cell; ++j)
2676 std::min<double> (old_min_product,
2677 child_alternating_forms[c][i] *
2678 parent_alternating_forms[j]);
2686 for (
unsigned int c=0; c<
object->n_children(); ++c)
2690 for (
unsigned int c=0; c<
object->n_children(); ++c)
2692 child_alternating_forms[c]);
2694 new_min_product = child_alternating_forms[0][0] * parent_alternating_forms[0];
2695 for (
unsigned int c=0; c<
object->n_children(); ++c)
2696 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2697 for (
unsigned int j=0; j<GeometryInfo<structdim>::vertices_per_cell; ++j)
2699 std::min<double> (new_min_product,
2700 child_alternating_forms[c][i] *
2701 parent_alternating_forms[j]);
2709 if (new_min_product >= old_min_product)
2716 return (std::max (new_min_product, old_min_product) > 0);
2721 void fix_up_faces (const ::Triangulation<1,1>::cell_iterator &,
2734 template <
int structdim,
int spacedim>
2735 void fix_up_faces (
const typename ::Triangulation<structdim,spacedim>::cell_iterator &cell,
2764 for (
unsigned int f=0; f<GeometryInfo<structdim>::faces_per_cell; ++f)
2766 Assert (cell->face(f)->has_children(), ExcInternalError());
2767 Assert (cell->face(f)->refinement_case() ==
2769 ExcInternalError());
2771 bool subface_is_more_refined =
false;
2772 for (
unsigned int g=0; g<GeometryInfo<structdim>::max_children_per_face; ++g)
2773 if (cell->face(f)->child(g)->has_children())
2775 subface_is_more_refined =
true;
2779 if (subface_is_more_refined ==
true)
2785 fix_up_object (cell->face(f), cell->at_boundary(f));
2794 template <
int dim,
int spacedim>
2811 internal::FixUpDistortedChildCells
2812 ::fix_up_faces (cell,
2822 if (! internal::FixUpDistortedChildCells::fix_up_object (cell,
2827 return unfixable_subset;
2832 template <
class MeshType>
2833 std::vector<typename MeshType::active_cell_iterator>
2836 Assert (cell->is_locally_owned(),
2837 ExcMessage (
"This function only makes sense if the cell for " 2838 "which you are asking for a patch, is locally " 2841 std::vector<typename MeshType::active_cell_iterator> patch;
2842 patch.push_back (cell);
2843 for (
unsigned int face_number=0; face_number<GeometryInfo<MeshType::dimension>::faces_per_cell; ++face_number)
2844 if (cell->face(face_number)->at_boundary()==
false)
2846 if (cell->neighbor(face_number)->has_children() ==
false)
2847 patch.push_back (cell->neighbor(face_number));
2852 if (MeshType::dimension > 1)
2854 for (
unsigned int subface=0; subface<cell->face(face_number)->n_children(); ++subface)
2855 patch.push_back (cell->neighbor_child_on_subface (face_number, subface));
2861 typename MeshType::cell_iterator neighbor
2862 = cell->neighbor (face_number);
2863 while (neighbor->has_children())
2864 neighbor = neighbor->child(1-face_number);
2866 Assert (neighbor->neighbor(1-face_number) == cell, ExcInternalError());
2867 patch.push_back (neighbor);
2875 template <
class Container>
2876 std::vector<typename Container::cell_iterator>
2878 const std::vector<typename Container::active_cell_iterator> &patch)
2880 Assert (patch.size() > 0,
ExcMessage(
"Vector containing patch cells should not be an empty vector!"));
2883 int min_level = patch[0]->level();
2885 for (
unsigned int i=0; i<patch.size(); ++i)
2886 min_level = std::min (min_level, patch[i]->level() );
2887 std::set<typename Container::cell_iterator> uniform_cells;
2888 typename std::vector<typename Container::active_cell_iterator>::const_iterator patch_cell;
2890 for (patch_cell=patch.begin(); patch_cell!=patch.end () ; ++patch_cell)
2894 if ((*patch_cell)->level() == min_level)
2895 uniform_cells.insert (*patch_cell);
2901 typename Container::cell_iterator parent = *patch_cell;
2903 while (parent->level() > min_level)
2904 parent = parent-> parent();
2905 uniform_cells.insert (parent);
2909 return std::vector<typename Container::cell_iterator> (uniform_cells.begin(),
2910 uniform_cells.end());
2915 template <
class Container>
2919 typename Container::active_cell_iterator> &patch_to_global_tria_map)
2922 const std::vector<typename Container::cell_iterator> uniform_cells =
2923 get_cells_at_coarsest_common_level <Container> (patch);
2925 local_triangulation.
clear();
2926 std::vector<Point<Container::space_dimension> > vertices;
2927 const unsigned int n_uniform_cells=uniform_cells.size();
2928 std::vector<CellData<Container::dimension> > cells(n_uniform_cells);
2931 typename std::vector<typename Container::cell_iterator>::const_iterator uniform_cell;
2932 for (uniform_cell=uniform_cells.begin(); uniform_cell!=uniform_cells.end(); ++uniform_cell)
2935 for (
unsigned int j=0; j< GeometryInfo<Container::dimension>::vertices_per_cell; ++j)
2938 repeat_vertex=
false;
2940 for (
unsigned int m=0; m<i; ++m)
2942 if (position == vertices[m])
2945 cells[k].vertices[j]=m;
2949 if (repeat_vertex==
false)
2951 vertices.push_back(position);
2952 cells[k].vertices[j]=i;
2962 unsigned int index=0;
2964 std::map<typename Triangulation<Container::dimension,Container::space_dimension>::cell_iterator,
2965 typename Container::cell_iterator> patch_to_global_tria_map_tmp;
2967 coarse_cell != local_triangulation.
end(); ++coarse_cell, ++index)
2969 patch_to_global_tria_map_tmp.insert (std::make_pair(coarse_cell, uniform_cells[index]));
2972 Assert(coarse_cell->center().distance( uniform_cells[index]->center())<=1e-15*coarse_cell->diameter(),
2973 ExcInternalError());
2975 bool refinement_necessary;
2980 refinement_necessary =
false;
2983 active_tria_cell != local_triangulation.
end(); ++active_tria_cell)
2985 if (patch_to_global_tria_map_tmp[active_tria_cell]->has_children())
2987 active_tria_cell -> set_refine_flag();
2988 refinement_necessary =
true;
2990 else for (
unsigned int i=0; i<patch.size(); ++i)
2992 if (patch_to_global_tria_map_tmp[active_tria_cell]==patch[i])
2994 active_tria_cell->set_user_flag();
3000 if (refinement_necessary)
3005 cell = local_triangulation.
begin();
3006 cell != local_triangulation.
end(); ++cell)
3009 if (patch_to_global_tria_map_tmp.find(cell)!=patch_to_global_tria_map_tmp.end())
3011 if (cell-> has_children())
3017 for (
unsigned int c=0; c< cell ->n_children(); ++c)
3019 if (patch_to_global_tria_map_tmp.find(cell->child(c)) ==
3020 patch_to_global_tria_map_tmp.end())
3022 patch_to_global_tria_map_tmp.insert (std::make_pair(cell ->child(c),
3023 patch_to_global_tria_map_tmp[cell]->child(c)));
3025 Assert(cell->child(c)->center().distance( patch_to_global_tria_map_tmp[cell]->child(c)->center())
3026 <=1e-15*cell->child(c)->diameter(),
3027 ExcInternalError());
3032 patch_to_global_tria_map_tmp.erase(cell);
3039 while (refinement_necessary);
3040 typename std::map<typename Triangulation<Container::dimension,Container::space_dimension>::cell_iterator,
3041 typename Container::cell_iterator>::iterator map_tmp_it =
3042 patch_to_global_tria_map_tmp.begin(),map_tmp_end = patch_to_global_tria_map_tmp.end();
3045 for (; map_tmp_it!=map_tmp_end; ++map_tmp_it)
3046 patch_to_global_tria_map[map_tmp_it->first] = map_tmp_it->second;
3052 template <
class DoFHandlerType>
3053 std::map< types::global_dof_index,std::vector<typename DoFHandlerType::active_cell_iterator> >
3067 std::map< types::global_dof_index,std::set<typename DoFHandlerType::active_cell_iterator> > dof_to_set_of_cells_map;
3069 std::vector<types::global_dof_index> local_dof_indices;
3070 std::vector<types::global_dof_index> local_face_dof_indices;
3071 std::vector<types::global_dof_index> local_line_dof_indices;
3075 std::vector<bool> user_flags;
3080 std::map<typename DoFHandlerType::active_line_iterator, typename DoFHandlerType::line_iterator > lines_to_parent_lines_map;
3081 if (DoFHandlerType::dimension == 3)
3085 dof_handler.get_triangulation().save_user_flags(user_flags);
3089 typename DoFHandlerType::active_cell_iterator cell = dof_handler.begin_active(),
3090 endc = dof_handler.end();
3091 for (; cell!=endc; ++cell)
3097 if (cell->is_artificial() ==
false)
3099 for (
unsigned int l=0; l<GeometryInfo<DoFHandlerType::dimension>::lines_per_cell; ++l)
3100 if (cell->line(l)->has_children())
3101 for (
unsigned int c=0; c<cell->line(l)->n_children(); ++c)
3103 lines_to_parent_lines_map[cell->line(l)->child(c)] = cell->line(l);
3106 cell->line(l)->child(c)->set_user_flag();
3119 typename DoFHandlerType::active_cell_iterator cell = dof_handler.begin_active(),
3120 endc = dof_handler.end();
3121 for (; cell!=endc; ++cell)
3126 if (cell->is_artificial() ==
false)
3128 const unsigned int n_dofs_per_cell = cell->get_fe().dofs_per_cell;
3129 local_dof_indices.resize(n_dofs_per_cell);
3133 cell->get_dof_indices(local_dof_indices);
3134 for (
unsigned int i=0; i< n_dofs_per_cell; ++i )
3135 dof_to_set_of_cells_map[local_dof_indices[i]].insert(cell);
3145 for (
unsigned int f=0; f<GeometryInfo<DoFHandlerType::dimension>::faces_per_cell; ++f)
3147 if (cell->face(f)->has_children())
3149 for (
unsigned int c=0; c<cell->face(f)->n_children(); ++c)
3163 Assert (cell->face(f)->child(c)->has_children() ==
false, ExcInternalError());
3165 const unsigned int n_dofs_per_face = cell->get_fe().dofs_per_face;
3166 local_face_dof_indices.resize(n_dofs_per_face);
3168 cell->face(f)->child(c)->get_dof_indices(local_face_dof_indices);
3169 for (
unsigned int i=0; i< n_dofs_per_face; ++i )
3170 dof_to_set_of_cells_map[local_face_dof_indices[i]].insert(cell);
3173 else if ((cell->face(f)->at_boundary() ==
false) && (cell->neighbor_is_coarser(f)))
3191 std::pair<unsigned int, unsigned int> neighbor_face_no_subface_no = cell->neighbor_of_coarser_neighbor(f);
3192 unsigned int face_no = neighbor_face_no_subface_no.first;
3193 unsigned int subface = neighbor_face_no_subface_no.second;
3195 const unsigned int n_dofs_per_face = cell->get_fe().dofs_per_face;
3196 local_face_dof_indices.resize(n_dofs_per_face);
3198 cell->neighbor(f)->face(face_no)->get_dof_indices(local_face_dof_indices);
3199 for (
unsigned int i=0; i< n_dofs_per_face; ++i )
3200 dof_to_set_of_cells_map[local_face_dof_indices[i]].insert(cell);
3204 for (
unsigned int c=0; c<cell->neighbor(f)->face(face_no)->n_children(); ++c)
3208 const unsigned int n_dofs_per_face = cell->get_fe().dofs_per_face;
3209 local_face_dof_indices.resize(n_dofs_per_face);
3211 Assert (cell->neighbor(f)->face(face_no)->child(c)->has_children() ==
false, ExcInternalError());
3212 cell->neighbor(f)->face(face_no)->child(c)->get_dof_indices(local_face_dof_indices);
3213 for (
unsigned int i=0; i<n_dofs_per_face; ++i )
3214 dof_to_set_of_cells_map[local_face_dof_indices[i]].insert(cell);
3228 if (DoFHandlerType::dimension == 3)
3230 for (
unsigned int l=0; l<GeometryInfo<DoFHandlerType::dimension>::lines_per_cell; ++l)
3232 if (cell->line(l)->has_children())
3234 for (
unsigned int c=0; c<cell->line(l)->n_children(); ++c)
3236 Assert (cell->line(l)->child(c)->has_children() ==
false, ExcInternalError());
3240 const unsigned int n_dofs_per_line = 2*cell->get_fe().dofs_per_vertex
3241 + cell->get_fe().dofs_per_line;
3242 local_line_dof_indices.resize(n_dofs_per_line);
3244 cell->line(l)->child(c)->get_dof_indices(local_line_dof_indices);
3245 for (
unsigned int i=0; i<n_dofs_per_line; ++i )
3246 dof_to_set_of_cells_map[local_line_dof_indices[i]].insert(cell);
3253 else if (cell->line(l)->user_flag_set() ==
true)
3255 typename DoFHandlerType::line_iterator parent_line = lines_to_parent_lines_map[cell->line(l)];
3256 Assert (parent_line->has_children(), ExcInternalError() );
3260 const unsigned int n_dofs_per_line = 2*cell->get_fe().dofs_per_vertex
3261 + cell->get_fe().dofs_per_line;
3262 local_line_dof_indices.resize(n_dofs_per_line);
3264 parent_line->get_dof_indices(local_line_dof_indices);
3265 for (
unsigned int i=0; i<n_dofs_per_line; ++i )
3266 dof_to_set_of_cells_map[local_line_dof_indices[i]].insert(cell);
3268 for (
unsigned int c=0; c<parent_line->n_children(); ++c)
3270 Assert (parent_line->child(c)->has_children() ==
false, ExcInternalError());
3272 const unsigned int n_dofs_per_line = 2*cell->get_fe().dofs_per_vertex
3273 + cell->get_fe().dofs_per_line;
3274 local_line_dof_indices.resize(n_dofs_per_line);
3276 parent_line->child(c)->get_dof_indices(local_line_dof_indices);
3277 for (
unsigned int i=0; i<n_dofs_per_line; ++i )
3278 dof_to_set_of_cells_map[local_line_dof_indices[i]].insert(cell);
3289 if (DoFHandlerType::dimension == 3)
3299 std::map< types::global_dof_index, std::vector<typename DoFHandlerType::active_cell_iterator> > dof_to_cell_patches;
3301 typename std::map<types::global_dof_index, std::set< typename DoFHandlerType::active_cell_iterator> >::iterator
3302 it = dof_to_set_of_cells_map.begin(),
3303 it_end = dof_to_set_of_cells_map.end();
3304 for ( ; it!=it_end; ++it)
3305 dof_to_cell_patches[it->first].assign( it->second.begin(), it->second.end() );
3307 return dof_to_cell_patches;
3321 template<
int spacedim>
3324 const int direction,
3328 Assert (0<=direction && direction<spacedim,
3329 ExcIndexRange (direction, 0, spacedim));
3331 Assert(matrix.
m() == matrix.
n(), ExcInternalError());
3335 if (matrix.
m() == spacedim)
3336 for (
int i = 0; i < spacedim; ++i)
3337 for (
int j = 0; j < spacedim; ++j)
3338 distance(i) += matrix(i,j) * point1(j);
3342 distance += offset - point2;
3344 for (
int i = 0; i < spacedim; ++i)
3350 if (fabs(distance(i)) > 1.e-10)
3368 template<
int dim>
struct OrientationLookupTable {};
3370 template<>
struct OrientationLookupTable<1>
3372 typedef std_cxx11::array<unsigned int, GeometryInfo<1>::vertices_per_face> MATCH_T;
3373 static inline std::bitset<3> lookup (
const MATCH_T &)
3380 template<>
struct OrientationLookupTable<2>
3382 typedef std_cxx11::array<unsigned int, GeometryInfo<2>::vertices_per_face> MATCH_T;
3383 static inline std::bitset<3> lookup (
const MATCH_T &matching)
3390 static const MATCH_T m_tff = {{ 0 , 1 }};
3391 if (matching == m_tff)
return 1;
3392 static const MATCH_T m_ttf = {{ 1 , 0 }};
3393 if (matching == m_ttf)
return 3;
3401 template<>
struct OrientationLookupTable<3>
3403 typedef std_cxx11::array<unsigned int, GeometryInfo<3>::vertices_per_face> MATCH_T;
3404 static inline std::bitset<3> lookup (
const MATCH_T &matching)
3411 static const MATCH_T m_tff = {{ 0 , 1 , 2 , 3 }};
3412 if (matching == m_tff)
return 1;
3413 static const MATCH_T m_tft = {{ 1 , 3 , 0 , 2 }};
3414 if (matching == m_tft)
return 5;
3415 static const MATCH_T m_ttf = {{ 3 , 2 , 1 , 0 }};
3416 if (matching == m_ttf)
return 3;
3417 static const MATCH_T m_ttt = {{ 2 , 0 , 3 , 1 }};
3418 if (matching == m_ttt)
return 7;
3419 static const MATCH_T m_fff = {{ 0 , 2 , 1 , 3 }};
3420 if (matching == m_fff)
return 0;
3421 static const MATCH_T m_fft = {{ 2 , 3 , 0 , 1 }};
3422 if (matching == m_fft)
return 4;
3423 static const MATCH_T m_ftf = {{ 3 , 1 , 2 , 0 }};
3424 if (matching == m_ftf)
return 2;
3425 static const MATCH_T m_ftt = {{ 1 , 0 , 3 , 2 }};
3426 if (matching == m_ftt)
return 6;
3436 template<
typename FaceIterator>
3439 const FaceIterator &face1,
3440 const FaceIterator &face2,
3441 const int direction,
3446 ExcMessage(
"The supplied matrix must be a square matrix"));
3448 static const int dim = FaceIterator::AccessorType::dimension;
3453 array<unsigned int, GeometryInfo<dim>::vertices_per_face> matching;
3455 std::set<unsigned int> face2_vertices;
3456 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face; ++i)
3457 face2_vertices.insert(i);
3459 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face; ++i)
3461 for (std::set<unsigned int>::iterator it = face2_vertices.begin();
3462 it != face2_vertices.end();
3466 direction, offset, matrix))
3469 face2_vertices.erase(it);
3476 if (face2_vertices.empty())
3477 orientation = OrientationLookupTable<dim>::lookup(matching);
3479 return face2_vertices.empty();
3484 template<
typename FaceIterator>
3487 const FaceIterator &face2,
3488 const int direction,
3493 std::bitset<3> dummy;
3502 template<
typename CellIterator>
3504 match_periodic_face_pairs
3505 (std::set<std::pair<CellIterator, unsigned int> > &pairs1,
3506 std::set<std::pair<
typename identity<CellIterator>::type,
unsigned int> > &pairs2,
3507 const int direction,
3509 const ::Tensor<1,CellIterator::AccessorType::space_dimension> &offset,
3512 static const int space_dim = CellIterator::AccessorType::space_dimension;
3514 Assert (0<=direction && direction<space_dim,
3515 ExcIndexRange (direction, 0, space_dim));
3517 Assert (pairs1.size() == pairs2.size(),
3518 ExcMessage (
"Unmatched faces on periodic boundaries"));
3520 unsigned int n_matches = 0;
3523 std::bitset<3> orientation;
3524 typedef typename std::set
3525 <std::pair<CellIterator, unsigned int> >::const_iterator PairIterator;
3526 for (PairIterator it1 = pairs1.begin(); it1 != pairs1.end(); ++it1)
3528 for (PairIterator it2 = pairs2.begin(); it2 != pairs2.end(); ++it2)
3530 const CellIterator cell1 = it1->first;
3531 const CellIterator cell2 = it2->first;
3532 const unsigned int face_idx1 = it1->second;
3533 const unsigned int face_idx2 = it2->second;
3535 cell1->face(face_idx1),
3536 cell2->face(face_idx2),
3546 {face_idx1, face_idx2},
3550 matched_pairs.push_back(matched_face);
3559 AssertThrow (n_matches == pairs1.size() && pairs2.size() == 0,
3560 ExcMessage (
"Unmatched faces on periodic boundaries"));
3565 template<
typename MeshType>
3568 (
const MeshType &mesh,
3571 const int direction,
3576 static const int dim = MeshType::dimension;
3577 static const int space_dim = MeshType::space_dimension;
3580 Assert (0<=direction && direction<space_dim,
3581 ExcIndexRange (direction, 0, space_dim));
3586 std::set<std::pair<typename MeshType::cell_iterator, unsigned int> > pairs1;
3587 std::set<std::pair<typename MeshType::cell_iterator, unsigned int> > pairs2;
3589 for (
typename MeshType::cell_iterator cell = mesh.begin(0);
3590 cell != mesh.end(0); ++cell)
3592 for (
unsigned int i = 0; i < GeometryInfo<dim>::faces_per_cell; ++i)
3594 const typename MeshType::face_iterator face = cell->face(i);
3595 if (face->at_boundary() && face->boundary_id() == b_id1)
3597 const std::pair<typename MeshType::cell_iterator, unsigned int> pair1
3598 = std::make_pair(cell, i);
3599 pairs1.insert(pair1);
3602 if (face->at_boundary() && face->boundary_id() == b_id2)
3604 const std::pair<typename MeshType::cell_iterator, unsigned int> pair2
3605 = std::make_pair(cell, i);
3606 pairs2.insert(pair2);
3611 Assert (pairs1.size() == pairs2.size(),
3612 ExcMessage (
"Unmatched faces on periodic boundaries"));
3615 match_periodic_face_pairs(pairs1, pairs2, direction, matched_pairs, offset,
3621 template<
typename MeshType>
3624 (
const MeshType &mesh,
3626 const int direction,
3631 static const int dim = MeshType::dimension;
3632 static const int space_dim = MeshType::space_dimension;
3635 Assert (0<=direction && direction<space_dim,
3636 ExcIndexRange (direction, 0, space_dim));
3639 ExcNotImplemented());
3644 std::set<std::pair<typename MeshType::cell_iterator, unsigned int> > pairs1;
3645 std::set<std::pair<typename MeshType::cell_iterator, unsigned int> > pairs2;
3647 for (
typename MeshType::cell_iterator cell = mesh.begin(0);
3648 cell != mesh.end(0); ++cell)
3650 const typename MeshType::face_iterator face_1 = cell->face(2*direction);
3651 const typename MeshType::face_iterator face_2 = cell->face(2*direction+1);
3653 if (face_1->at_boundary() && face_1->boundary_id() == b_id)
3655 const std::pair<typename MeshType::cell_iterator, unsigned int> pair1
3656 = std::make_pair(cell, 2*direction);
3657 pairs1.insert(pair1);
3660 if (face_2->at_boundary() && face_2->boundary_id() == b_id)
3662 const std::pair<typename MeshType::cell_iterator, unsigned int> pair2
3663 = std::make_pair(cell, 2*direction+1);
3664 pairs2.insert(pair2);
3668 Assert (pairs1.size() == pairs2.size(),
3669 ExcMessage (
"Unmatched faces on periodic boundaries"));
3673 const unsigned int size_old = matched_pairs.size();
3677 match_periodic_face_pairs(pairs1, pairs2, direction, matched_pairs, offset,
3682 const unsigned int size_new = matched_pairs.size();
3683 for (
unsigned int i = size_old; i < size_new; ++i)
3685 Assert(matched_pairs[i].orientation == 1,
3686 ExcMessage(
"Found a face match with non standard orientation. " 3687 "This function is only suitable for meshes with cells " 3688 "in default orientation"));
3695 template <
int dim,
int spacedim>
3697 const bool reset_boundary_ids)
3706 cell != tria.
end(); ++cell)
3707 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
3708 if (cell->face(f)->at_boundary())
3710 cell->face(f)->line(e)->set_manifold_id
3711 (static_cast<types::manifold_id>(cell->face(f)->line(e)->boundary_id()));
3716 cell != tria.
end(); ++cell)
3717 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
3718 if (cell->face(f)->at_boundary())
3721 cell->face(f)->set_manifold_id
3722 (static_cast<types::manifold_id>(cell->face(f)->boundary_id()));
3726 if (reset_boundary_ids ==
true)
3728 cell->face(f)->set_boundary_id(0);
3731 cell->face(f)->line(e)->set_boundary_id(0);
3738 template <
int dim,
int spacedim>
3740 const bool compute_face_ids)
3745 for (; cell != endc; ++cell)
3747 cell->set_manifold_id(cell->material_id());
3748 if (compute_face_ids ==
true)
3750 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
3752 if (cell->at_boundary(f) ==
false)
3753 cell->face(f)->set_manifold_id
3754 (std::min(cell->material_id(),
3755 cell->neighbor(f)->material_id()));
3757 cell->face(f)->set_manifold_id(cell->material_id());
3767 #include "grid_tools.inst" 3769 DEAL_II_NAMESPACE_CLOSE
std::vector< CellData< 1 > > boundary_lines
Transformed quadrature weights.
unsigned int get_degree() const
unsigned int n_active_cells() const
unsigned int n_vertices() const
static const unsigned int invalid_unsigned_int
void copy_boundary_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool reset_boundary_ids=false)
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &precondition)
unsigned int n_cells() const
std::list< typename Triangulation< dim, spacedim >::cell_iterator > distorted_cells
void add(const size_type i, const size_type j)
::ExceptionBase & ExcMessage(std::string arg1)
cell_iterator end() const
active_cell_iterator begin_active(const unsigned int level=0) const
void create_laplace_matrix(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim > &q, SparseMatrix< double > &matrix, const Function< spacedim > *const a=0, const ConstraintMatrix &constraints=ConstraintMatrix())
#define AssertThrow(cond, exc)
numbers::NumberTraits< Number >::real_type norm() const
virtual Point< dim > transform_real_to_unit_cell(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const Point< spacedim > &p) const =0
cell_iterator begin(const unsigned int level=0) const
ActiveSelector::active_cell_iterator active_cell_iterator
cell_iterator end() const
active_cell_iterator begin_active(const unsigned int level=0) const
const hp::FECollection< dim, spacedim > & get_fe() const
virtual void execute_coarsening_and_refinement()
T sum(const T &t, const MPI_Comm &mpi_communicator)
#define Assert(cond, exc)
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
static double distance_to_unit_cell(const Point< dim > &p)
Abstract base class for mapping classes.
virtual MPI_Comm get_communicator() const
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
const std::vector< Point< spacedim > > & get_vertices() const
types::global_dof_index n_dofs() const
void initialize(const MatrixType &A, const AdditionalData ¶meters=AdditionalData())
unsigned long long int global_vertex_index
void copy_material_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool compute_face_ids=false)
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
unsigned int subdomain_id
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
unsigned int size() const
void add_constraints(const ConstraintList &new_constraints)
static void alternating_form_at_vertices(const Point< spacedim >(&vertices)[vertices_per_cell], Tensor< spacedim-dim, spacedim >(&forms)[vertices_per_cell])
const Triangulation< dim, spacedim > & get_triangulation() const
void make_sparsity_pattern(const DoFHandlerType &dof_handler, SparsityPatternType &sparsity_pattern, const ConstraintMatrix &constraints=ConstraintMatrix(), const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
double JxW(const unsigned int quadrature_point) const
const std::vector< bool > & get_used_vertices() const
std::vector< CellData< 2 > > boundary_quads
numbers::NumberTraits< Number >::real_type square() const
virtual void distribute_dofs(const FiniteElement< dim, spacedim > &fe)
Iterator points to a valid object.
unsigned char boundary_id
types::subdomain_id locally_owned_subdomain() const
void apply_constraints(VectorType &v, const bool matrix_is_symmetric) const DEAL_II_DEPRECATED
unsigned int size() const
void reinit(const TriaIterator< DoFCellAccessor< DoFHandlerType< dim, spacedim >, level_dof_access > > &cell)
T max(const T &t, const MPI_Comm &mpi_communicator)
Task< RT > new_task(const std_cxx11::function< RT()> &function)
Triangulation< dim, spacedim > & get_triangulation()