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;
174 (
const std::vector<Point<1> > &all_vertices,
177 return all_vertices[vertex_indices[1]][0]
178 - all_vertices[vertex_indices[0]][0];
186 (
const std::vector<Point<3> > &all_vertices,
195 const double x[8] = { all_vertices[vertex_indices[0]](0),
196 all_vertices[vertex_indices[1]](0),
197 all_vertices[vertex_indices[2]](0),
198 all_vertices[vertex_indices[3]](0),
199 all_vertices[vertex_indices[4]](0),
200 all_vertices[vertex_indices[5]](0),
201 all_vertices[vertex_indices[6]](0),
202 all_vertices[vertex_indices[7]](0)
204 const double y[8] = { all_vertices[vertex_indices[0]](1),
205 all_vertices[vertex_indices[1]](1),
206 all_vertices[vertex_indices[2]](1),
207 all_vertices[vertex_indices[3]](1),
208 all_vertices[vertex_indices[4]](1),
209 all_vertices[vertex_indices[5]](1),
210 all_vertices[vertex_indices[6]](1),
211 all_vertices[vertex_indices[7]](1)
213 const double z[8] = { all_vertices[vertex_indices[0]](2),
214 all_vertices[vertex_indices[1]](2),
215 all_vertices[vertex_indices[2]](2),
216 all_vertices[vertex_indices[3]](2),
217 all_vertices[vertex_indices[4]](2),
218 all_vertices[vertex_indices[5]](2),
219 all_vertices[vertex_indices[6]](2),
220 all_vertices[vertex_indices[7]](2)
259 const double t3 = y[3]*x[2];
260 const double t5 = z[1]*x[5];
261 const double t9 = z[3]*x[2];
262 const double t11 = x[1]*y[0];
263 const double t14 = x[4]*y[0];
264 const double t18 = x[5]*y[7];
265 const double t20 = y[1]*x[3];
266 const double t22 = y[5]*x[4];
267 const double t26 = z[7]*x[6];
268 const double t28 = x[0]*y[4];
269 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];
270 const double t37 = y[1]*x[0];
271 const double t44 = x[1]*y[5];
272 const double t46 = z[1]*x[0];
273 const double t49 = x[0]*y[2];
274 const double t52 = y[5]*x[7];
275 const double t54 = x[3]*y[7];
276 const double t56 = x[2]*z[0];
277 const double t58 = x[3]*y[2];
278 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];
279 const double t66 = x[1]*y[7];
280 const double t68 = y[0]*x[6];
281 const double t70 = x[7]*y[6];
282 const double t73 = z[5]*x[4];
283 const double t76 = x[6]*y[7];
284 const double t90 = x[4]*z[0];
285 const double t92 = x[1]*y[3];
286 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];
287 const double t102 = x[2]*y[0];
288 const double t107 = y[3]*x[7];
289 const double t114 = x[0]*y[6];
290 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];
291 const double t129 = z[0]*x[6];
292 const double t133 = y[1]*x[7];
293 const double t145 = y[1]*x[5];
294 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];
295 const double t160 = x[5]*y[4];
296 const double t165 = z[1]*x[7];
297 const double t178 = z[1]*x[3];
298 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];
299 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];
300 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];
302 return (t34+t64+t95+t125+t156+t181+t207+t228)/12.;
310 (
const std::vector<Point<2> > &all_vertices,
349 const double x[4] = { all_vertices[vertex_indices[0]](0),
350 all_vertices[vertex_indices[1]](0),
351 all_vertices[vertex_indices[2]](0),
352 all_vertices[vertex_indices[3]](0)
355 const double y[4] = { all_vertices[vertex_indices[0]](1),
356 all_vertices[vertex_indices[1]](1),
357 all_vertices[vertex_indices[2]](1),
358 all_vertices[vertex_indices[3]](1)
361 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;
366 template <
int dim,
int spacedim>
373 ExcMessage(
"Invalid SubCellData supplied according to ::check_consistency(). " 374 "This is caused by data containing objects for the wrong dimension."));
377 std::vector<bool> vertex_used (vertices.size(),
false);
378 for (
unsigned int c=0; c<cells.size(); ++c)
379 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
381 Assert(cells[c].vertices[v] < vertices.size(),
382 ExcMessage(
"Invalid vertex index encountered! cells[" 388 +
" is invalid, because only " 390 +
" vertices were supplied."));
391 vertex_used[cells[c].vertices[v]] =
true;
398 std::vector<unsigned int> new_vertex_numbers (vertices.size(), invalid_vertex);
399 unsigned int next_free_number = 0;
400 for (
unsigned int i=0; i<vertices.size(); ++i)
401 if (vertex_used[i] ==
true)
403 new_vertex_numbers[i] = next_free_number;
408 for (
unsigned int c=0; c<cells.size(); ++c)
409 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
410 cells[c].vertices[v] = new_vertex_numbers[cells[c].vertices[v]];
414 for (
unsigned int v=0; v<GeometryInfo<1>::vertices_per_cell; ++v)
417 ExcMessage(
"Invalid vertex index in subcelldata.boundary_lines. " 418 "subcelldata.boundary_lines[" 424 +
" is invalid, because only " 426 +
" vertices were supplied."));
432 for (
unsigned int v=0; v<GeometryInfo<2>::vertices_per_cell; ++v)
435 ExcMessage(
"Invalid vertex index in subcelldata.boundary_quads. " 436 "subcelldata.boundary_quads[" 442 +
" is invalid, because only " 444 +
" vertices were supplied."));
452 std::vector<Point<spacedim> > tmp;
453 tmp.reserve (std::count(vertex_used.begin(), vertex_used.end(),
true));
454 for (
unsigned int v=0; v<vertices.size(); ++v)
455 if (vertex_used[v] ==
true)
456 tmp.push_back (vertices[v]);
457 swap (vertices, tmp);
462 template <
int dim,
int spacedim>
467 std::vector<unsigned int> &considered_vertices,
473 std::vector<unsigned int> new_vertex_numbers(vertices.size());
474 for (
unsigned int i=0; i<vertices.size(); ++i)
475 new_vertex_numbers[i] = i;
479 if (considered_vertices.size()==0)
480 considered_vertices = new_vertex_numbers;
482 Assert(considered_vertices.size() <= vertices.size(),
489 for (
unsigned int i=0; i<considered_vertices.size(); ++i)
491 Assert(considered_vertices[i]<vertices.size(),
493 if (new_vertex_numbers[considered_vertices[i]]!=considered_vertices[i])
504 for (
unsigned int j=i+1; j<considered_vertices.size(); ++j)
507 for (
unsigned int d=0; d<spacedim; ++d)
508 equal &= (fabs(vertices[considered_vertices[j]](d)-vertices[considered_vertices[i]](d))<tol);
511 new_vertex_numbers[considered_vertices[j]]=considered_vertices[i];
526 for (
unsigned int c=0; c<cells.size(); ++c)
527 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
528 cells[c].vertices[v]=new_vertex_numbers[cells[c].vertices[v]];
538 template <
int spacedim>
561 Rotate2d (
const double angle)
567 return Point<2> (std::cos(angle)*p(0) - std::sin(angle) * p(1),
568 std::sin(angle)*p(0) + std::cos(angle) * p(1));
578 Rotate3d (
const double angle,
579 const unsigned int axis)
589 std::cos(angle)*p(1) - std::sin(angle) * p(2),
590 std::sin(angle)*p(1) + std::cos(angle) * p(2));
592 return Point<3> (std::cos(angle)*p(0) + std::sin(angle) * p(2),
594 -std::sin(angle)*p(0) + std::cos(angle) * p(2));
596 return Point<3> (std::cos(angle)*p(0) - std::sin(angle) * p(1),
597 std::sin(angle)*p(0) + std::cos(angle) * p(1),
602 const unsigned int axis;
605 template <
int spacedim>
609 Scale (
const double factor)
623 template <
int dim,
int spacedim>
628 transform (Shift<spacedim>(shift_vector), triangulation);
637 transform (Rotate2d(angle), triangulation);
643 const unsigned int axis,
648 transform (Rotate3d(angle, axis), triangulation);
651 template <
int dim,
int spacedim>
657 transform (Scale<spacedim>(scaling_factor), triangulation);
669 const std::map<types::global_dof_index,double> &fixed_dofs,
672 const unsigned int n_dofs=S.
n();
684 SF.add_constraints(fixed_dofs);
685 SF.apply_constraints (f,
true);
686 solver.solve(SF, u, f, PF);
709 const bool solve_for_absolute_positions)
716 dof_handler.distribute_dofs(q1);
719 dof_handler.n_dofs ());
734 std::map<types::global_dof_index,double> fixed_dofs[dim];
735 typename std::map<unsigned int,Point<dim> >::const_iterator map_end=new_points.end();
739 endc=dof_handler.end();
740 for (; cell!=endc; ++cell)
744 for (
unsigned int vertex_no=0;
745 vertex_no<GeometryInfo<dim>::vertices_per_cell; ++vertex_no)
747 const unsigned int vertex_index=cell->vertex_index(vertex_no);
748 const Point<dim> &vertex_point=cell->vertex(vertex_no);
750 const typename std::map<unsigned int,Point<dim> >::const_iterator map_iter
751 = new_points.find(vertex_index);
753 if (map_iter!=map_end)
754 for (
unsigned int i=0; i<dim; ++i)
755 fixed_dofs[i].insert(std::pair<types::global_dof_index,double>
756 (cell->vertex_dof_index(vertex_no, 0),
757 (solve_for_absolute_positions ?
758 map_iter->second(i) :
759 map_iter->second(i) - vertex_point[i])
766 for (
unsigned int i=0; i<dim; ++i)
767 us[i].reinit (dof_handler.n_dofs());
771 for (
unsigned int i=0; i<dim; ++i)
773 S, fixed_dofs[i], us[i]);
778 std::vector<bool> vertex_touched (triangulation.
n_vertices(),
false);
779 for (cell=dof_handler.begin_active(); cell!=endc; ++cell)
780 for (
unsigned int vertex_no=0;
781 vertex_no<GeometryInfo<dim>::vertices_per_cell; ++vertex_no)
782 if (vertex_touched[cell->vertex_index(vertex_no)] ==
false)
787 for (
unsigned int i=0; i<dim; ++i)
788 if (solve_for_absolute_positions)
789 v(i) = us[i](dof_index);
791 v(i) += us[i](dof_index);
793 vertex_touched[cell->vertex_index(vertex_no)] =
true;
797 template <
int dim,
int spacedim>
798 std::map<unsigned int, Point<spacedim> >
801 std::map<unsigned int, Point<spacedim> > vertex_map;
805 for (; cell!=endc; ++cell)
807 for (
unsigned int i=0; i<GeometryInfo<dim>::faces_per_cell; ++i)
811 if (face->at_boundary())
813 for (
unsigned j = 0; j < GeometryInfo<dim>::vertices_per_face; ++j)
816 const unsigned int vertex_index = face->vertex_index(j);
817 vertex_map[vertex_index] = vertex;
829 template <
int dim,
int spacedim>
833 const bool keep_boundary)
850 double almost_infinite_length = 0;
852 cell=triangulation.
begin(0); cell!=triangulation.
end(0); ++cell)
853 almost_infinite_length += cell->diameter();
855 std::vector<double> minimal_length (triangulation.
n_vertices(),
856 almost_infinite_length);
859 std::vector<bool> at_boundary (triangulation.
n_vertices(),
false);
862 if (cell->is_locally_owned())
866 for (
unsigned int i=0; i<GeometryInfo<dim>::lines_per_cell; ++i)
868 const typename Triangulation<dim,spacedim>::line_iterator line
871 if (keep_boundary && line->at_boundary())
873 at_boundary[line->vertex_index(0)] =
true;
874 at_boundary[line->vertex_index(1)] =
true;
877 minimal_length[line->vertex_index(0)]
878 = std::min(line->diameter(),
879 minimal_length[line->vertex_index(0)]);
880 minimal_length[line->vertex_index(1)]
881 = std::min(line->diameter(),
882 minimal_length[line->vertex_index(1)]);
888 for (
unsigned int vertex=0; vertex<2; ++vertex)
889 if (cell->at_boundary(vertex) ==
true)
890 at_boundary[cell->vertex_index(vertex)] =
true;
892 minimal_length[cell->vertex_index(0)]
893 = std::min(cell->diameter(),
894 minimal_length[cell->vertex_index(0)]);
895 minimal_length[cell->vertex_index(1)]
896 = std::min(cell->diameter(),
897 minimal_length[cell->vertex_index(1)]);
906 boost::random::mt19937 rng;
907 boost::random::uniform_real_distribution<> uniform_distribution(-1,1);
915 std::vector<bool> vertex_moved (triangulation.
n_vertices(),
false);
920 if (cell->is_locally_owned())
922 for (
unsigned int vertex_no=0; vertex_no<GeometryInfo<dim>::vertices_per_cell;
925 const unsigned global_vertex_no = cell->vertex_index(vertex_no);
930 if ((keep_boundary && at_boundary[global_vertex_no])
931 || vertex_moved[global_vertex_no]
932 || !locally_owned_vertices[global_vertex_no])
937 for (
unsigned int d=0; d<spacedim; ++d)
938 shift_vector(d) = uniform_distribution(rng);
940 shift_vector *= factor * minimal_length[global_vertex_no] /
941 std::sqrt(shift_vector.
square());
944 cell->vertex(vertex_no) += shift_vector;
945 vertex_moved[global_vertex_no] =
true;
949 #ifdef DEAL_II_WITH_P4EST 950 distributed_triangulation
951 ->communicate_locally_moved_vertices(locally_owned_vertices);
953 (void)distributed_triangulation;
964 const unsigned int n_vertices = triangulation.
n_vertices();
965 std::vector<Point<spacedim> > new_vertex_locations (n_vertices);
966 const std::vector<Point<spacedim> > &old_vertex_locations
969 for (
unsigned int vertex=0; vertex<n_vertices; ++vertex)
973 if (keep_boundary && at_boundary[vertex])
974 new_vertex_locations[vertex] = old_vertex_locations[vertex];
979 for (
unsigned int d=0; d<spacedim; ++d)
980 shift_vector(d) = uniform_distribution(rng);
982 shift_vector *= factor * minimal_length[vertex] /
983 std::sqrt(shift_vector.
square());
986 new_vertex_locations[vertex] = old_vertex_locations[vertex] + shift_vector;
993 for (
unsigned int vertex_no=0;
994 vertex_no<GeometryInfo<dim>::vertices_per_cell; ++vertex_no)
995 cell->vertex(vertex_no) = new_vertex_locations[cell->vertex_index(vertex_no)];
1010 endc = triangulation.
end();
1011 for (; cell!=endc; ++cell)
1012 if (!cell->is_artificial())
1013 for (
unsigned int face=0;
1014 face<GeometryInfo<dim>::faces_per_cell; ++face)
1015 if (cell->face(face)->has_children() &&
1016 !cell->face(face)->at_boundary())
1020 cell->face(face)->child(0)->vertex(1)
1021 = (cell->face(face)->vertex(0) +
1022 cell->face(face)->vertex(1)) / 2;
1025 cell->face(face)->child(0)->vertex(1)
1026 = .5*(cell->face(face)->vertex(0)
1027 +cell->face(face)->vertex(1));
1028 cell->face(face)->child(0)->vertex(2)
1029 = .5*(cell->face(face)->vertex(0)
1030 +cell->face(face)->vertex(2));
1031 cell->face(face)->child(1)->vertex(3)
1032 = .5*(cell->face(face)->vertex(1)
1033 +cell->face(face)->vertex(3));
1034 cell->face(face)->child(2)->vertex(3)
1035 = .5*(cell->face(face)->vertex(2)
1036 +cell->face(face)->vertex(3));
1039 cell->face(face)->child(0)->vertex(3)
1040 = .25*(cell->face(face)->vertex(0)
1041 +cell->face(face)->vertex(1)
1042 +cell->face(face)->vertex(2)
1043 +cell->face(face)->vertex(3));
1051 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1062 const std::vector< Point<spacedim> > &vertices = tria.
get_vertices();
1067 std::vector<bool>::const_iterator first =
1068 std::find(used.begin(), used.end(),
true);
1074 unsigned int best_vertex = std::distance(used.begin(), first);
1075 double best_dist = (p - vertices[best_vertex]).norm_square();
1079 for (
unsigned int j = best_vertex+1; j < vertices.size(); j++)
1082 double dist = (p - vertices[j]).norm_square();
1083 if (dist < best_dist)
1094 template<
int dim,
template<
int,
int>
class MeshType,
int spacedim>
1096 std::vector<typename MeshType<dim, spacedim>::active_cell_iterator>
1098 std::vector<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type>
1101 const unsigned int vertex)
1106 Assert(vertex < mesh.get_triangulation().n_vertices(),
1107 ExcIndexRange(0,mesh.get_triangulation().n_vertices(),vertex));
1108 Assert(mesh.get_triangulation().get_used_vertices()[vertex],
1114 std::set<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type> adjacent_cells;
1116 typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type
1153 for (; cell != endc; ++cell)
1155 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; v++)
1156 if (cell->vertex_index(v) == vertex)
1161 adjacent_cells.insert(cell);
1168 for (
unsigned int vface = 0; vface < dim; vface++)
1170 const unsigned int face =
1173 if (!cell->at_boundary(face)
1175 cell->neighbor(face)->active())
1187 adjacent_cells.insert (cell->neighbor(face));
1198 for (
unsigned int e=0; e<GeometryInfo<dim>::lines_per_cell; ++e)
1199 if (cell->line(e)->has_children())
1203 if (cell->line(e)->child(0)->vertex_index(1) == vertex)
1205 adjacent_cells.insert(cell);
1228 std::vector<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type>
1229 (adjacent_cells.begin(), adjacent_cells.end());
1236 template <
int dim,
template<
int,
int>
class MeshType,
int spacedim>
1237 void find_active_cell_around_point_internal
1238 (
const MeshType<dim,spacedim> &mesh,
1240 std::set<
typename MeshType<dim, spacedim>::active_cell_iterator> &searched_cells,
1241 std::set<
typename MeshType<dim, spacedim>::active_cell_iterator> &adjacent_cells)
1243 std::set<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type> &searched_cells,
1244 std::set<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type> &adjacent_cells)
1248 typedef typename MeshType<dim, spacedim>::active_cell_iterator cell_iterator;
1250 typedef typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type cell_iterator;
1254 searched_cells.insert(adjacent_cells.begin(), adjacent_cells.end());
1258 std::set<cell_iterator> adjacent_cells_new;
1260 typename std::set<cell_iterator>::const_iterator
1261 cell = adjacent_cells.
begin(),
1262 endc = adjacent_cells.end();
1263 for (; cell != endc; ++cell)
1265 std::vector<cell_iterator> active_neighbors;
1266 get_active_neighbors<MeshType<dim, spacedim> >(*cell, active_neighbors);
1267 for (
unsigned int i=0; i<active_neighbors.size(); ++i)
1268 if (searched_cells.find(active_neighbors[i]) == searched_cells.end())
1269 adjacent_cells_new.insert(active_neighbors[i]);
1271 adjacent_cells.clear();
1272 adjacent_cells.insert(adjacent_cells_new.begin(), adjacent_cells_new.end());
1273 if (adjacent_cells.size() == 0)
1281 cell_iterator it = mesh.begin_active();
1282 for ( ; it!=mesh.end(); ++it)
1283 if (searched_cells.find(it) == searched_cells.end())
1285 adjacent_cells.insert(it);
1292 template <
int dim,
template<
int,
int>
class MeshType,
int spacedim>
1294 typename MeshType<dim, spacedim>::active_cell_iterator
1296 typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type
1302 find_active_cell_around_point<dim,MeshType,spacedim>
1308 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1310 std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
Point<dim> >
1312 std::pair<typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type,
Point<dim> >
1315 const MeshType<dim,spacedim> &mesh,
1318 typedef typename ::internal::ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim> >::type active_cell_iterator;
1324 double best_distance = 1e-10;
1325 int best_level = -1;
1326 std::pair<active_cell_iterator, Point<dim> > best_cell;
1330 std::vector<active_cell_iterator> adjacent_cells_tmp
1339 std::set<active_cell_iterator> adjacent_cells (adjacent_cells_tmp.begin(),
1340 adjacent_cells_tmp.end());
1341 std::set<active_cell_iterator> searched_cells;
1349 const unsigned int n_active_cells = mesh.get_triangulation().n_active_cells();
1351 unsigned int cells_searched = 0;
1352 while (!found && cells_searched < n_active_cells)
1354 typename std::set<active_cell_iterator>::const_iterator
1355 cell = adjacent_cells.begin(),
1356 endc = adjacent_cells.end();
1357 for (; cell != endc; ++cell)
1371 if ((dist < best_distance)
1373 ((dist == best_distance)
1375 ((*cell)->level() > best_level)))
1378 best_distance = dist;
1379 best_level = (*cell)->level();
1380 best_cell = std::make_pair(*cell, p_cell);
1400 cells_searched += adjacent_cells.size();
1409 if (!found && cells_searched < n_active_cells)
1411 find_active_cell_around_point_internal<dim,MeshType,spacedim>
1412 (mesh, searched_cells, adjacent_cells);
1417 ExcPointNotFound<spacedim>(p));
1424 template <
int dim,
int spacedim>
1425 std::pair<typename hp::DoFHandler<dim,spacedim>::active_cell_iterator,
Point<dim> >
1432 ExcMessage (
"Mapping collection needs to have either size 1 " 1433 "or size equal to the number of elements in " 1434 "the FECollection."));
1438 std::pair<cell_iterator, Point<dim> > best_cell;
1442 if (mapping.
size() == 1)
1452 double best_distance = 1e-10;
1453 int best_level = -1;
1460 std::vector<cell_iterator> adjacent_cells_tmp =
1468 std::set<cell_iterator> adjacent_cells(adjacent_cells_tmp.begin(), adjacent_cells_tmp.end());
1469 std::set<cell_iterator> searched_cells;
1479 unsigned int cells_searched = 0;
1480 while (!found && cells_searched < n_cells)
1482 typename std::set<cell_iterator>::const_iterator
1483 cell = adjacent_cells.begin(),
1484 endc = adjacent_cells.end();
1485 for (; cell != endc; ++cell)
1489 const Point<dim> p_cell = mapping[(*cell)->active_fe_index()].transform_real_to_unit_cell(*cell, p);
1500 if (dist < best_distance ||
1501 (dist == best_distance && (*cell)->level() > best_level))
1504 best_distance = dist;
1505 best_level = (*cell)->level();
1506 best_cell = std::make_pair(*cell, p_cell);
1525 cells_searched += adjacent_cells.size();
1531 if (!found && cells_searched < n_cells)
1533 find_active_cell_around_point_internal<dim,hp::DoFHandler,spacedim>
1534 (mesh, searched_cells, adjacent_cells);
1541 ExcPointNotFound<spacedim>(p));
1550 template<
class MeshType>
1552 contains_locally_owned_cells (
const std::vector<typename MeshType::active_cell_iterator> &cells)
1554 for (
typename std::vector<typename MeshType::active_cell_iterator>::const_iterator
1555 it = cells.begin(); it != cells.end(); ++it)
1557 if ((*it)->is_locally_owned())
1563 template<
class MeshType>
1565 contains_artificial_cells (
const std::vector<typename MeshType::active_cell_iterator> &cells)
1567 for (
typename std::vector<typename MeshType::active_cell_iterator>::const_iterator
1568 it = cells.begin(); it != cells.end(); ++it)
1570 if ((*it)->is_artificial())
1580 template <
class MeshType>
1581 std::vector<typename MeshType::active_cell_iterator>
1583 (
const MeshType &mesh,
1584 const std_cxx11::function<
bool (
const typename MeshType::active_cell_iterator &)> &predicate)
1586 std::vector<typename MeshType::active_cell_iterator> active_halo_layer;
1587 std::vector<bool> locally_active_vertices_on_subdomain (mesh.get_triangulation().n_vertices(),
1593 for (
typename MeshType::active_cell_iterator
1594 cell = mesh.begin_active();
1595 cell != mesh.end(); ++cell)
1596 if (predicate(cell))
1597 for (
unsigned int v=0; v<GeometryInfo<MeshType::dimension>::vertices_per_cell; ++v)
1598 locally_active_vertices_on_subdomain[cell->vertex_index(v)] =
true;
1603 for (
typename MeshType::active_cell_iterator
1604 cell = mesh.begin_active();
1605 cell != mesh.end(); ++cell)
1606 if (!predicate(cell))
1607 for (
unsigned int v=0; v<GeometryInfo<MeshType::dimension>::vertices_per_cell; ++v)
1608 if (locally_active_vertices_on_subdomain[cell->vertex_index(v)] ==
true)
1610 active_halo_layer.push_back(cell);
1614 return active_halo_layer;
1619 template <
class MeshType>
1620 std::vector<typename MeshType::active_cell_iterator>
1623 std_cxx11::function<bool (const typename MeshType::active_cell_iterator &)> predicate
1626 const std::vector<typename MeshType::active_cell_iterator>
1631 Assert(contains_locally_owned_cells<MeshType>(active_halo_layer) ==
false,
1632 ExcMessage(
"Halo layer contains locally owned cells"));
1633 Assert(contains_artificial_cells<MeshType>(active_halo_layer) ==
false,
1634 ExcMessage(
"Halo layer contains artificial cells"));
1636 return active_halo_layer;
1641 template <
int dim,
int spacedim>
1642 std::vector<std::set<typename Triangulation<dim,spacedim>::active_cell_iterator> >
1645 std::vector<std::set<typename Triangulation<dim,spacedim>::active_cell_iterator> >
1648 endc = triangulation.
end();
1649 for (; cell!=endc; ++cell)
1650 for (
unsigned int i=0; i<GeometryInfo<dim>::vertices_per_cell; ++i)
1655 for (; cell!=endc; ++cell)
1657 for (
unsigned int i=0; i<GeometryInfo<dim>::faces_per_cell; ++i)
1659 if ((cell->at_boundary(i)==
false) && (cell->neighbor(i)->active()))
1663 for (
unsigned int j=0; j<GeometryInfo<dim>::vertices_per_face; ++j)
1671 for (
unsigned int i=0; i<GeometryInfo<dim>::lines_per_cell; ++i)
1672 if (cell->line(i)->has_children())
1685 template <
int dim,
int spacedim>
1686 std::map<unsigned int,types::global_vertex_index>
1690 std::map<unsigned int,types::global_vertex_index> local_to_global_vertex_index;
1692 #ifndef DEAL_II_WITH_MPI 1697 (void)triangulation;
1699 "for parallel::distributed::Triangulation " 1700 "objects if you do not have MPI enabled."));
1705 const std::vector<std::set<active_cell_iterator> > vertex_to_cell =
1710 unsigned int max_cellid_size = 0;
1711 std::set<std::pair<types::subdomain_id,types::global_vertex_index> > vertices_added;
1712 std::map<types::subdomain_id,std::set<unsigned int> > vertices_to_recv;
1715 active_cell_iterator cell = triangulation.
begin_active(),
1716 endc = triangulation.
end();
1717 std::set<active_cell_iterator> missing_vert_cells;
1718 std::set<unsigned int> used_vertex_index;
1719 for (; cell!=endc; ++cell)
1721 if (cell->is_locally_owned())
1723 for (
unsigned int i=0; i<GeometryInfo<dim>::vertices_per_cell; ++i)
1726 typename std::set<active_cell_iterator>::iterator
1727 adjacent_cell = vertex_to_cell[cell->vertex_index(i)].begin(),
1728 end_adj_cell = vertex_to_cell[cell->vertex_index(i)].end();
1729 for (; adjacent_cell!=end_adj_cell; ++adjacent_cell)
1730 lowest_subdomain_id = std::min(lowest_subdomain_id,
1731 (*adjacent_cell)->subdomain_id());
1734 if (lowest_subdomain_id==cell->subdomain_id())
1738 if (used_vertex_index.find(cell->vertex_index(i))==used_vertex_index.end())
1741 local_to_global_vertex_index[cell->vertex_index(i)] = next_index++;
1745 adjacent_cell = vertex_to_cell[cell->vertex_index(i)].begin();
1746 for (; adjacent_cell!=end_adj_cell; ++adjacent_cell)
1747 if ((*adjacent_cell)->subdomain_id()!=cell->subdomain_id())
1749 std::pair<types::subdomain_id,types::global_vertex_index>
1750 tmp((*adjacent_cell)->subdomain_id(), cell->vertex_index(i));
1751 if (vertices_added.find(tmp)==vertices_added.end())
1753 vertices_to_send[(*adjacent_cell)->subdomain_id()].push_back(
1755 std::string> (i,cell->vertex_index(i),
1756 cell->id().to_string()));
1757 if (cell->id().to_string().size() > max_cellid_size)
1758 max_cellid_size = cell->id().to_string().size();
1759 vertices_added.insert(tmp);
1762 used_vertex_index.insert(cell->vertex_index(i));
1768 vertices_to_recv[lowest_subdomain_id].insert(cell->vertex_index(i));
1769 missing_vert_cells.insert(cell);
1776 if (cell->is_ghost())
1778 for (
unsigned int i=0; i<GeometryInfo<dim>::faces_per_cell; ++i)
1780 if (cell->at_boundary(i)==
false)
1782 if (cell->neighbor(i)->active())
1786 if ((adjacent_cell->is_locally_owned()))
1789 if (cell->subdomain_id()<adj_subdomain_id)
1790 for (
unsigned int j=0; j<GeometryInfo<dim>::vertices_per_face; ++j)
1792 vertices_to_recv[cell->subdomain_id()].insert(cell->face(i)->vertex_index(j));
1793 missing_vert_cells.insert(cell);
1808 std::vector<types::global_vertex_index> indices(n_cpu);
1809 int ierr = MPI_Allgather(&next_index, 1, DEAL_II_DOF_INDEX_MPI_TYPE, &indices[0],
1810 indices.size(), DEAL_II_DOF_INDEX_MPI_TYPE, triangulation.
get_communicator());
1815 std::map<unsigned int,types::global_vertex_index>::iterator
1816 global_index_it = local_to_global_vertex_index.begin(),
1817 global_index_end = local_to_global_vertex_index.end();
1818 for (; global_index_it!=global_index_end; ++global_index_it)
1819 global_index_it->second +=
shift;
1826 std::vector<std::vector<types::global_vertex_index> > vertices_send_buffers(
1827 vertices_to_send.size());
1828 std::vector<MPI_Request> first_requests(vertices_to_send.size());
1832 vert_to_send_it = vertices_to_send.begin(),
1833 vert_to_send_end = vertices_to_send.end();
1834 for (
unsigned int i=0; vert_to_send_it!=vert_to_send_end;
1835 ++vert_to_send_it, ++i)
1837 int destination = vert_to_send_it->first;
1838 const unsigned int n_vertices = vert_to_send_it->second.size();
1839 const int buffer_size = 2*n_vertices;
1840 vertices_send_buffers[i].resize(buffer_size);
1843 for (
unsigned int j=0; j<n_vertices; ++j)
1845 vertices_send_buffers[i][2*j] = std_cxx11::get<0>(vert_to_send_it->second[j]);
1846 vertices_send_buffers[i][2*j+1] =
1847 local_to_global_vertex_index[std_cxx11::get<1>(vert_to_send_it->second[j])];
1851 ierr = MPI_Isend(&vertices_send_buffers[i][0],buffer_size,DEAL_II_VERTEX_INDEX_MPI_TYPE,
1857 std::vector<std::vector<types::global_vertex_index> > vertices_recv_buffers(
1858 vertices_to_recv.size());
1859 typename std::map<types::subdomain_id,std::set<unsigned int> >::iterator
1860 vert_to_recv_it = vertices_to_recv.begin(),
1861 vert_to_recv_end = vertices_to_recv.end();
1862 for (
unsigned int i=0; vert_to_recv_it!=vert_to_recv_end; ++vert_to_recv_it, ++i)
1864 int source = vert_to_recv_it->first;
1865 const unsigned int n_vertices = vert_to_recv_it->second.size();
1866 const int buffer_size = 2*n_vertices;
1867 vertices_recv_buffers[i].resize(buffer_size);
1870 ierr = MPI_Recv(&vertices_recv_buffers[i][0],buffer_size,DEAL_II_VERTEX_INDEX_MPI_TYPE,
1877 std::vector<std::vector<char> > cellids_send_buffers(vertices_to_send.size());
1878 std::vector<MPI_Request> second_requests(vertices_to_send.size());
1879 vert_to_send_it = vertices_to_send.begin();
1880 for (
unsigned int i=0; vert_to_send_it!=vert_to_send_end;
1881 ++vert_to_send_it, ++i)
1883 int destination = vert_to_send_it->first;
1884 const unsigned int n_vertices = vert_to_send_it->second.size();
1885 const int buffer_size = max_cellid_size*n_vertices;
1886 cellids_send_buffers[i].resize(buffer_size);
1889 unsigned int pos = 0;
1890 for (
unsigned int j=0; j<n_vertices; ++j)
1892 std::string cell_id = std_cxx11::get<2>(vert_to_send_it->second[j]);
1893 for (
unsigned int k=0; k<max_cellid_size; ++k, ++pos)
1895 if (k<cell_id.size())
1896 cellids_send_buffers[i][pos] = cell_id[k];
1900 cellids_send_buffers[i][pos] =
'-';
1905 ierr = MPI_Isend(&cellids_send_buffers[i][0], buffer_size, MPI_CHAR,
1911 std::vector<std::vector<char> > cellids_recv_buffers(vertices_to_recv.size());
1912 vert_to_recv_it = vertices_to_recv.begin();
1913 for (
unsigned int i=0; vert_to_recv_it!=vert_to_recv_end; ++vert_to_recv_it, ++i)
1915 int source = vert_to_recv_it->first;
1916 const unsigned int n_vertices = vert_to_recv_it->second.size();
1917 const int buffer_size = max_cellid_size*n_vertices;
1918 cellids_recv_buffers[i].resize(buffer_size);
1921 ierr = MPI_Recv(&cellids_recv_buffers[i][0],buffer_size, MPI_CHAR,
1928 vert_to_recv_it = vertices_to_recv.begin();
1929 for (
unsigned int i=0; vert_to_recv_it!=vert_to_recv_end; ++i, ++vert_to_recv_it)
1931 for (
unsigned int j=0; j<vert_to_recv_it->second.size(); ++j)
1933 const unsigned int local_pos_recv = vertices_recv_buffers[i][2*j];
1935 const std::string cellid_recv(&cellids_recv_buffers[i][max_cellid_size*j],
1936 &cellids_recv_buffers[i][max_cellid_size*(j+1)]);
1938 typename std::set<active_cell_iterator>::iterator
1939 cell_set_it = missing_vert_cells.begin(),
1940 end_cell_set = missing_vert_cells.end();
1941 for (; (found==
false) && (cell_set_it!=end_cell_set); ++cell_set_it)
1943 typename std::set<active_cell_iterator>::iterator
1944 candidate_cell = vertex_to_cell[(*cell_set_it)->vertex_index(i)].begin(),
1945 end_cell = vertex_to_cell[(*cell_set_it)->vertex_index(i)].end();
1946 for (; candidate_cell!=end_cell; ++candidate_cell)
1948 std::string current_cellid = (*candidate_cell)->id().to_string();
1949 current_cellid.resize(max_cellid_size,
'-');
1950 if (current_cellid.compare(cellid_recv)==0)
1952 local_to_global_vertex_index[(*candidate_cell)->vertex_index(local_pos_recv)] =
1964 return local_to_global_vertex_index;
1969 template <
int dim,
int spacedim>
1981 std::map< std::pair<unsigned int,unsigned int>,
unsigned int >
1985 cell != triangulation.
end(); ++cell)
1986 indexmap[std::pair<unsigned int,unsigned int>(cell->level(),cell->index())] = cell->active_cell_index();
1997 cell != triangulation.
end(); ++cell)
1999 const unsigned int index = cell->active_cell_index();
2000 cell_connectivity.
add (index, index);
2001 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
2002 if ((cell->at_boundary(f) ==
false)
2004 (cell->neighbor(f)->has_children() ==
false))
2006 unsigned int other_index = indexmap.find(
2007 std::pair<unsigned int,unsigned int>(cell->neighbor(f)->level(),cell->neighbor(f)->index()))->second;
2008 cell_connectivity.
add (index, other_index);
2009 cell_connectivity.
add (other_index, index);
2016 template <
int dim,
int spacedim>
2028 template <
int dim,
int spacedim>
2033 std::vector<std::vector<unsigned int> > vertex_to_cell(triangulation.
n_vertices());
2037 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
2038 vertex_to_cell[cell->vertex_index(v)].push_back(cell->active_cell_index());
2046 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
2047 for (
unsigned int n=0; n<vertex_to_cell[cell->vertex_index(v)].size(); ++n)
2048 cell_connectivity.
add(cell->active_cell_index(), vertex_to_cell[cell->vertex_index(v)][n]);
2054 template <
int dim,
int spacedim>
2062 ExcMessage (
"Objects of type parallel::distributed::Triangulation " 2063 "are already partitioned implicitly and can not be " 2064 "partitioned again explicitly."));
2068 if (n_partitions == 1)
2072 cell != triangulation.
end(); ++cell)
2073 cell->set_subdomain_id (0);
2093 template <
int dim,
int spacedim>
2102 ExcMessage (
"Objects of type parallel::distributed::Triangulation " 2103 "are already partitioned implicitly and can not be " 2104 "partitioned again explicitly."));
2107 ExcMessage (
"Connectivity graph has wrong size"));
2109 ExcMessage (
"Connectivity graph has wrong size"));
2112 if (n_partitions == 1)
2116 cell != triangulation.
end(); ++cell)
2117 cell->set_subdomain_id (0);
2125 std::vector<unsigned int> partition_indices (triangulation.
n_active_cells());
2132 cell != triangulation.
end(); ++cell)
2133 cell->set_subdomain_id (partition_indices[cell->active_cell_index()]);
2138 template <
int dim,
int spacedim>
2141 std::vector<types::subdomain_id> &subdomain)
2147 cell = triangulation.
begin_active(); cell!=triangulation.
end(); ++cell)
2148 subdomain[cell->active_cell_index()] = cell->subdomain_id();
2153 template <
int dim,
int spacedim>
2158 unsigned int count = 0;
2161 cell!=triangulation.
end(); ++cell)
2162 if (cell->subdomain_id() == subdomain)
2170 template <
int dim,
int spacedim>
2186 cell != triangulation.
end(); ++cell)
2187 if (cell->is_artificial()
2189 (cell->is_ghost() &&
2190 (cell->subdomain_id() < tr->locally_owned_subdomain())))
2191 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
2192 locally_owned_vertices[cell->vertex_index(v)] =
false;
2194 return locally_owned_vertices;
2199 template <
typename MeshType>
2200 std::list<std::pair<
typename MeshType::cell_iterator,
2201 typename MeshType::cell_iterator> >
2203 const MeshType &mesh_2)
2206 ExcMessage (
"The two meshes must be represent triangulations that " 2207 "have the same coarse meshes"));
2225 std::list<std::pair<
typename MeshType::cell_iterator,
2226 typename MeshType::cell_iterator> >
2232 typename MeshType::cell_iterator
2233 cell_1 = mesh_1.begin(0),
2234 cell_2 = mesh_2.begin(0);
2235 for (; cell_1 != mesh_1.end(0); ++cell_1, ++cell_2)
2236 cell_list.push_back (std::make_pair (cell_1, cell_2));
2240 typename CellList::iterator cell_pair = cell_list.begin();
2241 while (cell_pair != cell_list.end())
2247 if (cell_pair->first->has_children()
2249 cell_pair->second->has_children())
2251 Assert(cell_pair->first->refinement_case()==
2253 for (
unsigned int c=0; c<cell_pair->first->n_children(); ++c)
2254 cell_list.push_back (std::make_pair (cell_pair->first->child(c),
2255 cell_pair->second->child(c)));
2264 const typename CellList::iterator previous_cell_pair = cell_pair;
2267 cell_list.erase (previous_cell_pair);
2279 for (cell_pair = cell_list.begin(); cell_pair != cell_list.end(); ++cell_pair)
2280 Assert (cell_pair->first->active()
2282 cell_pair->second->active()
2284 (cell_pair->first->refinement_case()
2285 != cell_pair->second->refinement_case()),
2291 template <
int dim,
int spacedim>
2305 cell_1 = mesh_1.
begin(0),
2306 cell_2 = mesh_2.
begin(0),
2307 endc = mesh_1.
end(0);
2308 for (; cell_1!=endc; ++cell_1, ++cell_2)
2309 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
2310 if (cell_1->vertex(v) != cell_2->vertex(v))
2322 template <
typename MeshType>
2325 const MeshType &mesh_2)
2328 mesh_2.get_triangulation());
2333 template <
int dim,
int spacedim>
2337 double min_diameter = triangulation.
begin_active()->diameter();
2341 min_diameter = std::min (min_diameter,
2343 return min_diameter;
2348 template <
int dim,
int spacedim>
2352 double max_diameter = triangulation.
begin_active()->diameter();
2356 max_diameter = std::max (max_diameter,
2358 return max_diameter;
2365 namespace FixUpDistortedChildCells
2388 template <
typename Iterator,
int spacedim>
2390 objective_function (
const Iterator &
object,
2393 const unsigned int structdim = Iterator::AccessorType::structure_dimension;
2394 Assert (spacedim == Iterator::AccessorType::dimension,
2407 Tensor<spacedim-structdim,spacedim> parent_alternating_forms
2410 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2411 parent_vertices[i] = object->vertex(i);
2414 parent_alternating_forms);
2416 const Tensor<spacedim-structdim,spacedim>
2417 average_parent_alternating_form
2418 = std::accumulate (&parent_alternating_forms[0],
2432 Tensor<spacedim-structdim,spacedim> child_alternating_forms
2436 for (
unsigned int c=0; c<
object->n_children(); ++c)
2437 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2438 child_vertices[c][i] = object->child(c)->vertex(i);
2446 for (
unsigned int c=0; c<
object->n_children(); ++c)
2450 for (
unsigned int c=0; c<
object->n_children(); ++c)
2452 child_alternating_forms[c]);
2464 double objective = 0;
2465 for (
unsigned int c=0; c<
object->n_children(); ++c)
2466 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2467 objective += (child_alternating_forms[c][i] -
2468 average_parent_alternating_form/std::pow(2.,1.*structdim))
2480 template <
typename Iterator>
2482 get_face_midpoint (
const Iterator &
object,
2483 const unsigned int f,
2486 return object->vertex(f);
2496 template <
typename Iterator>
2498 get_face_midpoint (
const Iterator &
object,
2499 const unsigned int f,
2502 return object->line(f)->center();
2512 template <
typename Iterator>
2514 get_face_midpoint (
const Iterator &
object,
2515 const unsigned int f,
2518 return object->face(f)->center();
2546 template <
typename Iterator>
2548 minimal_diameter (
const Iterator &
object)
2551 structdim = Iterator::AccessorType::structure_dimension;
2553 double diameter =
object->diameter();
2554 for (
unsigned int f=0;
2555 f<GeometryInfo<structdim>::faces_per_cell;
2557 for (
unsigned int e=f+1;
2558 e<GeometryInfo<structdim>::faces_per_cell;
2564 .distance (get_face_midpoint
2584 template <
typename Iterator>
2586 fix_up_object (
const Iterator &
object,
2587 const bool respect_manifold)
2589 const Boundary<Iterator::AccessorType::dimension,
2590 Iterator::AccessorType::space_dimension>
2591 *manifold = (respect_manifold ?
2592 &
object->get_boundary() :
2595 const unsigned int structdim = Iterator::AccessorType::structure_dimension;
2596 const unsigned int spacedim = Iterator::AccessorType::space_dimension;
2620 unsigned int iteration = 0;
2621 const double diameter = minimal_diameter (
object);
2625 double current_value = objective_function (
object, object_mid_point);
2626 double initial_delta = 0;
2638 const double step_length =
diameter / 4 / (iteration + 1);
2645 for (
unsigned int d=0;
d<spacedim; ++
d)
2647 const double eps = step_length/10;
2652 if (respect_manifold ==
false)
2654 = ((objective_function (
object, object_mid_point + h)
2656 objective_function (
object, object_mid_point - h))
2661 = ((objective_function (
object,
2662 manifold->project_to_surface(
object,
2663 object_mid_point + h))
2665 objective_function (
object,
2666 manifold->project_to_surface(
object,
2667 object_mid_point - h)))
2681 if (gradient.
norm() == 0)
2696 object_mid_point -= std::min(2 * current_value / (gradient*gradient),
2697 step_length / gradient.norm()) *
2700 if (respect_manifold ==
true)
2701 object_mid_point = manifold->project_to_surface(
object,
2706 const double previous_value = current_value;
2707 current_value = objective_function (
object, object_mid_point);
2710 initial_delta = (previous_value - current_value);
2714 if ((iteration >= 1) &&
2715 ((previous_value - current_value < 0)
2717 (std::fabs (previous_value - current_value)
2719 0.001 * initial_delta)))
2724 while (iteration < 20);
2740 double old_min_product, new_min_product;
2744 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2745 parent_vertices[i] = object->vertex(i);
2747 Tensor<spacedim-structdim,spacedim> parent_alternating_forms
2750 parent_alternating_forms);
2756 for (
unsigned int c=0; c<
object->n_children(); ++c)
2757 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2758 child_vertices[c][i] = object->child(c)->vertex(i);
2760 Tensor<spacedim-structdim,spacedim> child_alternating_forms
2764 for (
unsigned int c=0; c<
object->n_children(); ++c)
2766 child_alternating_forms[c]);
2768 old_min_product = child_alternating_forms[0][0] * parent_alternating_forms[0];
2769 for (
unsigned int c=0; c<
object->n_children(); ++c)
2770 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2771 for (
unsigned int j=0; j<GeometryInfo<structdim>::vertices_per_cell; ++j)
2773 std::min<double> (old_min_product,
2774 child_alternating_forms[c][i] *
2775 parent_alternating_forms[j]);
2783 for (
unsigned int c=0; c<
object->n_children(); ++c)
2787 for (
unsigned int c=0; c<
object->n_children(); ++c)
2789 child_alternating_forms[c]);
2791 new_min_product = child_alternating_forms[0][0] * parent_alternating_forms[0];
2792 for (
unsigned int c=0; c<
object->n_children(); ++c)
2793 for (
unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
2794 for (
unsigned int j=0; j<GeometryInfo<structdim>::vertices_per_cell; ++j)
2796 std::min<double> (new_min_product,
2797 child_alternating_forms[c][i] *
2798 parent_alternating_forms[j]);
2806 if (new_min_product >= old_min_product)
2813 return (std::max (new_min_product, old_min_product) > 0);
2818 void fix_up_faces (const ::Triangulation<1,1>::cell_iterator &,
2831 template <
int structdim,
int spacedim>
2832 void fix_up_faces (
const typename ::Triangulation<structdim,spacedim>::cell_iterator &cell,
2861 for (
unsigned int f=0; f<GeometryInfo<structdim>::faces_per_cell; ++f)
2864 Assert (cell->face(f)->refinement_case() ==
2868 bool subface_is_more_refined =
false;
2869 for (
unsigned int g=0; g<GeometryInfo<structdim>::max_children_per_face; ++g)
2870 if (cell->face(f)->child(g)->has_children())
2872 subface_is_more_refined =
true;
2876 if (subface_is_more_refined ==
true)
2882 fix_up_object (cell->face(f), cell->at_boundary(f));
2891 template <
int dim,
int spacedim>
2908 internal::FixUpDistortedChildCells
2909 ::fix_up_faces (cell,
2919 if (! internal::FixUpDistortedChildCells::fix_up_object (cell,
2924 return unfixable_subset;
2929 template <
class MeshType>
2930 std::vector<typename MeshType::active_cell_iterator>
2933 Assert (cell->is_locally_owned(),
2934 ExcMessage (
"This function only makes sense if the cell for " 2935 "which you are asking for a patch, is locally " 2938 std::vector<typename MeshType::active_cell_iterator> patch;
2939 patch.push_back (cell);
2940 for (
unsigned int face_number=0; face_number<GeometryInfo<MeshType::dimension>::faces_per_cell; ++face_number)
2941 if (cell->face(face_number)->at_boundary()==
false)
2943 if (cell->neighbor(face_number)->has_children() ==
false)
2944 patch.push_back (cell->neighbor(face_number));
2949 if (MeshType::dimension > 1)
2951 for (
unsigned int subface=0; subface<cell->face(face_number)->n_children(); ++subface)
2952 patch.push_back (cell->neighbor_child_on_subface (face_number, subface));
2958 typename MeshType::cell_iterator neighbor
2959 = cell->neighbor (face_number);
2960 while (neighbor->has_children())
2961 neighbor = neighbor->child(1-face_number);
2964 patch.push_back (neighbor);
2972 template <
class Container>
2973 std::vector<typename Container::cell_iterator>
2975 const std::vector<typename Container::active_cell_iterator> &patch)
2977 Assert (patch.size() > 0,
ExcMessage(
"Vector containing patch cells should not be an empty vector!"));
2980 int min_level = patch[0]->level();
2982 for (
unsigned int i=0; i<patch.size(); ++i)
2983 min_level = std::min (min_level, patch[i]->level() );
2984 std::set<typename Container::cell_iterator> uniform_cells;
2985 typename std::vector<typename Container::active_cell_iterator>::const_iterator patch_cell;
2987 for (patch_cell=patch.begin(); patch_cell!=patch.end () ; ++patch_cell)
2991 if ((*patch_cell)->level() == min_level)
2992 uniform_cells.insert (*patch_cell);
2998 typename Container::cell_iterator parent = *patch_cell;
3000 while (parent->level() > min_level)
3001 parent = parent-> parent();
3002 uniform_cells.insert (parent);
3006 return std::vector<typename Container::cell_iterator> (uniform_cells.begin(),
3007 uniform_cells.end());
3012 template <
class Container>
3016 typename Container::active_cell_iterator> &patch_to_global_tria_map)
3019 const std::vector<typename Container::cell_iterator> uniform_cells =
3020 get_cells_at_coarsest_common_level <Container> (patch);
3022 local_triangulation.
clear();
3023 std::vector<Point<Container::space_dimension> > vertices;
3024 const unsigned int n_uniform_cells=uniform_cells.size();
3025 std::vector<CellData<Container::dimension> > cells(n_uniform_cells);
3028 typename std::vector<typename Container::cell_iterator>::const_iterator uniform_cell;
3029 for (uniform_cell=uniform_cells.begin(); uniform_cell!=uniform_cells.end(); ++uniform_cell)
3031 for (
unsigned int v=0; v<GeometryInfo<Container::dimension>::vertices_per_cell; ++v)
3034 bool repeat_vertex=
false;
3036 for (
unsigned int m=0; m<i; ++m)
3038 if (position == vertices[m])
3041 cells[k].vertices[v]=m;
3045 if (repeat_vertex==
false)
3047 vertices.push_back(position);
3048 cells[k].vertices[v]=i;
3058 unsigned int index=0;
3060 std::map<typename Triangulation<Container::dimension,Container::space_dimension>::cell_iterator,
3061 typename Container::cell_iterator> patch_to_global_tria_map_tmp;
3063 coarse_cell != local_triangulation.
end(); ++coarse_cell, ++index)
3065 patch_to_global_tria_map_tmp.insert (std::make_pair(coarse_cell, uniform_cells[index]));
3068 Assert(coarse_cell->center().distance( uniform_cells[index]->center())<=1e-15*coarse_cell->diameter(),
3071 bool refinement_necessary;
3076 refinement_necessary =
false;
3079 active_tria_cell != local_triangulation.
end(); ++active_tria_cell)
3081 if (patch_to_global_tria_map_tmp[active_tria_cell]->has_children())
3083 active_tria_cell -> set_refine_flag();
3084 refinement_necessary =
true;
3086 else for (
unsigned int i=0; i<patch.size(); ++i)
3091 if (patch_to_global_tria_map_tmp[active_tria_cell]==patch[i])
3095 for (
unsigned int v=0; v<GeometryInfo<Container::dimension>::vertices_per_cell; ++v)
3096 active_tria_cell->vertex(v) = patch[i]->vertex(v);
3098 Assert(active_tria_cell->center().distance(patch_to_global_tria_map_tmp[active_tria_cell]->center())
3101 active_tria_cell->set_user_flag();
3107 if (refinement_necessary)
3112 cell = local_triangulation.
begin();
3113 cell != local_triangulation.
end(); ++cell)
3116 if (patch_to_global_tria_map_tmp.find(cell)!=patch_to_global_tria_map_tmp.end())
3118 if (cell-> has_children())
3124 for (
unsigned int c=0; c<cell->n_children(); ++c)
3126 if (patch_to_global_tria_map_tmp.find(cell->child(c)) ==
3127 patch_to_global_tria_map_tmp.end())
3129 patch_to_global_tria_map_tmp.insert (std::make_pair(cell->child(c),
3130 patch_to_global_tria_map_tmp[cell]->child(c)));
3152 patch_to_global_tria_map_tmp.erase(cell);
3159 while (refinement_necessary);
3165 cell = local_triangulation.
begin();
3166 cell != local_triangulation.
end(); ++cell)
3168 if (cell->user_flag_set() )
3170 Assert(patch_to_global_tria_map_tmp.find(cell) != patch_to_global_tria_map_tmp.end(),
3173 Assert(cell->center().distance( patch_to_global_tria_map_tmp[cell]->center())<=1e-15*cell->diameter(),
3179 typename std::map<typename Triangulation<Container::dimension,Container::space_dimension>::cell_iterator,
3180 typename Container::cell_iterator>::iterator map_tmp_it =
3181 patch_to_global_tria_map_tmp.begin(),map_tmp_end = patch_to_global_tria_map_tmp.end();
3184 for (; map_tmp_it!=map_tmp_end; ++map_tmp_it)
3185 patch_to_global_tria_map[map_tmp_it->first] = map_tmp_it->second;
3191 template <
class DoFHandlerType>
3192 std::map< types::global_dof_index,std::vector<typename DoFHandlerType::active_cell_iterator> >
3206 std::map< types::global_dof_index,std::set<typename DoFHandlerType::active_cell_iterator> > dof_to_set_of_cells_map;
3208 std::vector<types::global_dof_index> local_dof_indices;
3209 std::vector<types::global_dof_index> local_face_dof_indices;
3210 std::vector<types::global_dof_index> local_line_dof_indices;
3214 std::vector<bool> user_flags;
3219 std::map<typename DoFHandlerType::active_line_iterator, typename DoFHandlerType::line_iterator > lines_to_parent_lines_map;
3220 if (DoFHandlerType::dimension == 3)
3224 dof_handler.get_triangulation().save_user_flags(user_flags);
3228 typename DoFHandlerType::active_cell_iterator cell = dof_handler.begin_active(),
3229 endc = dof_handler.end();
3230 for (; cell!=endc; ++cell)
3236 if (cell->is_artificial() ==
false)
3238 for (
unsigned int l=0; l<GeometryInfo<DoFHandlerType::dimension>::lines_per_cell; ++l)
3239 if (cell->line(l)->has_children())
3240 for (
unsigned int c=0; c<cell->line(l)->n_children(); ++c)
3242 lines_to_parent_lines_map[cell->line(l)->child(c)] = cell->line(l);
3245 cell->line(l)->child(c)->set_user_flag();
3258 typename DoFHandlerType::active_cell_iterator cell = dof_handler.begin_active(),
3259 endc = dof_handler.end();
3260 for (; cell!=endc; ++cell)
3265 if (cell->is_artificial() ==
false)
3267 const unsigned int n_dofs_per_cell = cell->get_fe().dofs_per_cell;
3268 local_dof_indices.resize(n_dofs_per_cell);
3272 cell->get_dof_indices(local_dof_indices);
3273 for (
unsigned int i=0; i< n_dofs_per_cell; ++i )
3274 dof_to_set_of_cells_map[local_dof_indices[i]].insert(cell);
3284 for (
unsigned int f=0; f<GeometryInfo<DoFHandlerType::dimension>::faces_per_cell; ++f)
3286 if (cell->face(f)->has_children())
3288 for (
unsigned int c=0; c<cell->face(f)->n_children(); ++c)
3304 const unsigned int n_dofs_per_face = cell->get_fe().dofs_per_face;
3305 local_face_dof_indices.resize(n_dofs_per_face);
3307 cell->face(f)->child(c)->get_dof_indices(local_face_dof_indices);
3308 for (
unsigned int i=0; i< n_dofs_per_face; ++i )
3309 dof_to_set_of_cells_map[local_face_dof_indices[i]].insert(cell);
3312 else if ((cell->face(f)->at_boundary() ==
false) && (cell->neighbor_is_coarser(f)))
3330 std::pair<unsigned int, unsigned int> neighbor_face_no_subface_no = cell->neighbor_of_coarser_neighbor(f);
3331 unsigned int face_no = neighbor_face_no_subface_no.first;
3332 unsigned int subface = neighbor_face_no_subface_no.second;
3334 const unsigned int n_dofs_per_face = cell->get_fe().dofs_per_face;
3335 local_face_dof_indices.resize(n_dofs_per_face);
3337 cell->neighbor(f)->face(face_no)->get_dof_indices(local_face_dof_indices);
3338 for (
unsigned int i=0; i< n_dofs_per_face; ++i )
3339 dof_to_set_of_cells_map[local_face_dof_indices[i]].insert(cell);
3343 for (
unsigned int c=0; c<cell->neighbor(f)->face(face_no)->n_children(); ++c)
3347 const unsigned int n_dofs_per_face = cell->get_fe().dofs_per_face;
3348 local_face_dof_indices.resize(n_dofs_per_face);
3351 cell->neighbor(f)->face(face_no)->child(c)->get_dof_indices(local_face_dof_indices);
3352 for (
unsigned int i=0; i<n_dofs_per_face; ++i )
3353 dof_to_set_of_cells_map[local_face_dof_indices[i]].insert(cell);
3367 if (DoFHandlerType::dimension == 3)
3369 for (
unsigned int l=0; l<GeometryInfo<DoFHandlerType::dimension>::lines_per_cell; ++l)
3371 if (cell->line(l)->has_children())
3373 for (
unsigned int c=0; c<cell->line(l)->n_children(); ++c)
3379 const unsigned int n_dofs_per_line = 2*cell->get_fe().dofs_per_vertex
3380 + cell->get_fe().dofs_per_line;
3381 local_line_dof_indices.resize(n_dofs_per_line);
3383 cell->line(l)->child(c)->get_dof_indices(local_line_dof_indices);
3384 for (
unsigned int i=0; i<n_dofs_per_line; ++i )
3385 dof_to_set_of_cells_map[local_line_dof_indices[i]].insert(cell);
3392 else if (cell->line(l)->user_flag_set() ==
true)
3394 typename DoFHandlerType::line_iterator parent_line = lines_to_parent_lines_map[cell->line(l)];
3399 const unsigned int n_dofs_per_line = 2*cell->get_fe().dofs_per_vertex
3400 + cell->get_fe().dofs_per_line;
3401 local_line_dof_indices.resize(n_dofs_per_line);
3403 parent_line->get_dof_indices(local_line_dof_indices);
3404 for (
unsigned int i=0; i<n_dofs_per_line; ++i )
3405 dof_to_set_of_cells_map[local_line_dof_indices[i]].insert(cell);
3407 for (
unsigned int c=0; c<parent_line->n_children(); ++c)
3411 const unsigned int n_dofs_per_line = 2*cell->get_fe().dofs_per_vertex
3412 + cell->get_fe().dofs_per_line;
3413 local_line_dof_indices.resize(n_dofs_per_line);
3415 parent_line->child(c)->get_dof_indices(local_line_dof_indices);
3416 for (
unsigned int i=0; i<n_dofs_per_line; ++i )
3417 dof_to_set_of_cells_map[local_line_dof_indices[i]].insert(cell);
3428 if (DoFHandlerType::dimension == 3)
3438 std::map< types::global_dof_index, std::vector<typename DoFHandlerType::active_cell_iterator> > dof_to_cell_patches;
3440 typename std::map<types::global_dof_index, std::set< typename DoFHandlerType::active_cell_iterator> >::iterator
3441 it = dof_to_set_of_cells_map.begin(),
3442 it_end = dof_to_set_of_cells_map.end();
3443 for ( ; it!=it_end; ++it)
3444 dof_to_cell_patches[it->first].assign( it->second.begin(), it->second.end() );
3446 return dof_to_cell_patches;
3460 template<
int spacedim>
3463 const int direction,
3467 Assert (0<=direction && direction<spacedim,
3474 if (matrix.m() == spacedim)
3475 for (
int i = 0; i < spacedim; ++i)
3476 for (
int j = 0; j < spacedim; ++j)
3477 distance(i) += matrix(i,j) * point1(j);
3481 distance += offset - point2;
3483 for (
int i = 0; i < spacedim; ++i)
3489 if (fabs(distance(i)) > 1.e-10)
3507 template<
int dim>
struct OrientationLookupTable {};
3509 template<>
struct OrientationLookupTable<1>
3511 typedef std_cxx11::array<unsigned int, GeometryInfo<1>::vertices_per_face> MATCH_T;
3512 static inline std::bitset<3> lookup (
const MATCH_T &)
3519 template<>
struct OrientationLookupTable<2>
3521 typedef std_cxx11::array<unsigned int, GeometryInfo<2>::vertices_per_face> MATCH_T;
3522 static inline std::bitset<3> lookup (
const MATCH_T &matching)
3529 static const MATCH_T m_tff = {{ 0 , 1 }};
3530 if (matching == m_tff)
return 1;
3531 static const MATCH_T m_ttf = {{ 1 , 0 }};
3532 if (matching == m_ttf)
return 3;
3540 template<>
struct OrientationLookupTable<3>
3542 typedef std_cxx11::array<unsigned int, GeometryInfo<3>::vertices_per_face> MATCH_T;
3543 static inline std::bitset<3> lookup (
const MATCH_T &matching)
3550 static const MATCH_T m_tff = {{ 0 , 1 , 2 , 3 }};
3551 if (matching == m_tff)
return 1;
3552 static const MATCH_T m_tft = {{ 1 , 3 , 0 , 2 }};
3553 if (matching == m_tft)
return 5;
3554 static const MATCH_T m_ttf = {{ 3 , 2 , 1 , 0 }};
3555 if (matching == m_ttf)
return 3;
3556 static const MATCH_T m_ttt = {{ 2 , 0 , 3 , 1 }};
3557 if (matching == m_ttt)
return 7;
3558 static const MATCH_T m_fff = {{ 0 , 2 , 1 , 3 }};
3559 if (matching == m_fff)
return 0;
3560 static const MATCH_T m_fft = {{ 2 , 3 , 0 , 1 }};
3561 if (matching == m_fft)
return 4;
3562 static const MATCH_T m_ftf = {{ 3 , 1 , 2 , 0 }};
3563 if (matching == m_ftf)
return 2;
3564 static const MATCH_T m_ftt = {{ 1 , 0 , 3 , 2 }};
3565 if (matching == m_ftt)
return 6;
3575 template<
typename FaceIterator>
3578 const FaceIterator &face1,
3579 const FaceIterator &face2,
3580 const int direction,
3584 Assert(matrix.m() == matrix.n(),
3585 ExcMessage(
"The supplied matrix must be a square matrix"));
3587 static const int dim = FaceIterator::AccessorType::dimension;
3592 array<unsigned int, GeometryInfo<dim>::vertices_per_face> matching;
3594 std::set<unsigned int> face2_vertices;
3595 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face; ++i)
3596 face2_vertices.insert(i);
3598 for (
unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face; ++i)
3600 for (std::set<unsigned int>::iterator it = face2_vertices.begin();
3601 it != face2_vertices.end();
3605 direction, offset, matrix))
3608 face2_vertices.erase(it);
3615 if (face2_vertices.empty())
3616 orientation = OrientationLookupTable<dim>::lookup(matching);
3618 return face2_vertices.empty();
3623 template<
typename FaceIterator>
3626 const FaceIterator &face2,
3627 const int direction,
3632 std::bitset<3> dummy;
3641 template<
typename CellIterator>
3643 match_periodic_face_pairs
3644 (std::set<std::pair<CellIterator, unsigned int> > &pairs1,
3645 std::set<std::pair<
typename identity<CellIterator>::type,
unsigned int> > &pairs2,
3646 const int direction,
3647 std::vector<PeriodicFacePair<CellIterator> > &matched_pairs,
3648 const ::Tensor<1,CellIterator::AccessorType::space_dimension> &offset,
3651 static const int space_dim = CellIterator::AccessorType::space_dimension;
3653 Assert (0<=direction && direction<space_dim,
3656 Assert (pairs1.size() == pairs2.size(),
3657 ExcMessage (
"Unmatched faces on periodic boundaries"));
3659 unsigned int n_matches = 0;
3662 std::bitset<3> orientation;
3663 typedef typename std::set
3664 <std::pair<CellIterator, unsigned int> >::const_iterator PairIterator;
3665 for (PairIterator it1 = pairs1.begin(); it1 != pairs1.end(); ++it1)
3667 for (PairIterator it2 = pairs2.begin(); it2 != pairs2.end(); ++it2)
3669 const CellIterator cell1 = it1->first;
3670 const CellIterator cell2 = it2->first;
3671 const unsigned int face_idx1 = it1->second;
3672 const unsigned int face_idx2 = it2->second;
3674 cell1->face(face_idx1),
3675 cell2->face(face_idx2),
3682 const PeriodicFacePair<CellIterator> matched_face =
3685 {face_idx1, face_idx2},
3689 matched_pairs.push_back(matched_face);
3698 AssertThrow (n_matches == pairs1.size() && pairs2.size() == 0,
3699 ExcMessage (
"Unmatched faces on periodic boundaries"));
3704 template<
typename MeshType>
3707 (
const MeshType &mesh,
3710 const int direction,
3715 static const int dim = MeshType::dimension;
3716 static const int space_dim = MeshType::space_dimension;
3719 Assert (0<=direction && direction<space_dim,
3725 std::set<std::pair<typename MeshType::cell_iterator, unsigned int> > pairs1;
3726 std::set<std::pair<typename MeshType::cell_iterator, unsigned int> > pairs2;
3728 for (
typename MeshType::cell_iterator cell = mesh.begin(0);
3729 cell != mesh.end(0); ++cell)
3731 for (
unsigned int i = 0; i < GeometryInfo<dim>::faces_per_cell; ++i)
3733 const typename MeshType::face_iterator face = cell->face(i);
3734 if (face->at_boundary() && face->boundary_id() == b_id1)
3736 const std::pair<typename MeshType::cell_iterator, unsigned int> pair1
3737 = std::make_pair(cell, i);
3738 pairs1.insert(pair1);
3741 if (face->at_boundary() && face->boundary_id() == b_id2)
3743 const std::pair<typename MeshType::cell_iterator, unsigned int> pair2
3744 = std::make_pair(cell, i);
3745 pairs2.insert(pair2);
3750 Assert (pairs1.size() == pairs2.size(),
3751 ExcMessage (
"Unmatched faces on periodic boundaries"));
3753 Assert (pairs1.size() > 0,
3754 ExcMessage(
"No new periodic face pairs have been found. " 3755 "Are you sure that you've selected the correct boundary " 3756 "id's and that the coarsest level mesh is colorized?"));
3759 match_periodic_face_pairs(pairs1, pairs2, direction, matched_pairs, offset,
3765 template<
typename MeshType>
3768 (
const MeshType &mesh,
3770 const int direction,
3771 std::vector<PeriodicFacePair<typename MeshType::cell_iterator> > &matched_pairs,
3775 static const int dim = MeshType::dimension;
3776 static const int space_dim = MeshType::space_dimension;
3779 Assert (0<=direction && direction<space_dim,
3788 std::set<std::pair<typename MeshType::cell_iterator, unsigned int> > pairs1;
3789 std::set<std::pair<typename MeshType::cell_iterator, unsigned int> > pairs2;
3791 for (
typename MeshType::cell_iterator cell = mesh.begin(0);
3792 cell != mesh.end(0); ++cell)
3794 const typename MeshType::face_iterator face_1 = cell->face(2*direction);
3795 const typename MeshType::face_iterator face_2 = cell->face(2*direction+1);
3797 if (face_1->at_boundary() && face_1->boundary_id() == b_id)
3799 const std::pair<typename MeshType::cell_iterator, unsigned int> pair1
3800 = std::make_pair(cell, 2*direction);
3801 pairs1.insert(pair1);
3804 if (face_2->at_boundary() && face_2->boundary_id() == b_id)
3806 const std::pair<typename MeshType::cell_iterator, unsigned int> pair2
3807 = std::make_pair(cell, 2*direction+1);
3808 pairs2.insert(pair2);
3812 Assert (pairs1.size() == pairs2.size(),
3813 ExcMessage (
"Unmatched faces on periodic boundaries"));
3815 Assert (pairs1.size() > 0,
3816 ExcMessage(
"No new periodic face pairs have been found. " 3817 "Are you sure that you've selected the correct boundary " 3818 "id's and that the coarsest level mesh is colorized?"));
3821 const unsigned int size_old = matched_pairs.size();
3825 match_periodic_face_pairs(pairs1, pairs2, direction, matched_pairs, offset,
3830 const unsigned int size_new = matched_pairs.size();
3831 for (
unsigned int i = size_old; i < size_new; ++i)
3833 Assert(matched_pairs[i].orientation == 1,
3834 ExcMessage(
"Found a face match with non standard orientation. " 3835 "This function is only suitable for meshes with cells " 3836 "in default orientation"));
3843 template <
int dim,
int spacedim>
3845 const bool reset_boundary_ids)
3854 cell != tria.
end(); ++cell)
3855 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
3856 if (cell->face(f)->at_boundary())
3858 cell->face(f)->line(e)->set_manifold_id
3859 (static_cast<types::manifold_id>(cell->face(f)->line(e)->boundary_id()));
3864 cell != tria.
end(); ++cell)
3865 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
3866 if (cell->face(f)->at_boundary())
3869 cell->face(f)->set_manifold_id
3870 (static_cast<types::manifold_id>(cell->face(f)->boundary_id()));
3874 if (reset_boundary_ids ==
true)
3876 cell->face(f)->set_boundary_id(0);
3879 cell->face(f)->line(e)->set_boundary_id(0);
3886 template <
int dim,
int spacedim>
3888 const bool compute_face_ids)
3893 for (; cell != endc; ++cell)
3895 cell->set_manifold_id(cell->material_id());
3896 if (compute_face_ids ==
true)
3898 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
3900 if (cell->at_boundary(f) ==
false)
3901 cell->face(f)->set_manifold_id
3902 (std::min(cell->material_id(),
3903 cell->neighbor(f)->material_id()));
3905 cell->face(f)->set_manifold_id(cell->material_id());
3911 template<
int dim,
int spacedim>
3912 std::pair<unsigned int, double>
3915 double max_ratio = 1;
3916 unsigned int index = 0;
3918 for (
unsigned int i = 0; i < dim; ++i)
3919 for (
unsigned int j = i+1; j < dim; ++j)
3921 unsigned int ax = i % dim;
3922 unsigned int next_ax = j % dim;
3924 double ratio = cell->extent_in_direction(ax) / cell->extent_in_direction(next_ax);
3926 if ( ratio > max_ratio )
3931 else if ( 1.0 /ratio > max_ratio )
3933 max_ratio = 1.0 /ratio;
3937 return std::make_pair(index, max_ratio);
3941 template<
int dim,
int spacedim>
3944 const bool isotropic,
3945 const unsigned int max_iterations)
3947 unsigned int iter = 0;
3948 bool continue_refinement =
true;
3954 while ( continue_refinement && (iter < max_iterations) )
3957 continue_refinement =
false;
3960 for (
unsigned int j = 0; j < GeometryInfo<dim>::faces_per_cell; j++)
3961 if (cell->at_boundary(j)==
false && cell->neighbor(j)->has_children())
3965 cell->set_refine_flag();
3966 continue_refinement =
true;
3969 continue_refinement |= cell->flag_for_face_refinement(j);
3976 template<
int dim,
int spacedim>
3979 const double max_ratio,
3980 const unsigned int max_iterations)
3982 unsigned int iter = 0;
3983 bool continue_refinement =
true;
3989 while ( continue_refinement && (iter<max_iterations) )
3992 continue_refinement =
false;
3995 std::pair<unsigned int, double> info = GridTools::get_longest_direction<dim,spacedim>(cell);
3996 if (info.second > max_ratio)
3999 continue_refinement =
true;
4010 #include "grid_tools.inst" 4012 DEAL_II_NAMESPACE_CLOSE
std::vector< CellData< 1 > > boundary_lines
Transformed quadrature weights.
unsigned int get_degree() const
static ::ExceptionBase & ExcScalingFactorNotPositive(double arg1)
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)
cell_iterator begin(const unsigned int level=0) const
unsigned int n_cells() const
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
std::list< typename Triangulation< dim, spacedim >::cell_iterator > distorted_cells
void add(const size_type i, const size_type j)
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
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
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()
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
bool check_consistency(const unsigned int dim) const
T sum(const T &t, const MPI_Comm &mpi_communicator)
unsigned int global_dof_index
#define Assert(cond, exc)
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
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
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
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
unsigned int size() const
static void alternating_form_at_vertices(const Point< spacedim >(&vertices)[vertices_per_cell], Tensor< spacedim-dim, spacedim >(&forms)[vertices_per_cell])
#define AssertThrowMPI(error_code)
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
static ::ExceptionBase & ExcNotImplemented()
Iterator points to a valid object.
unsigned char boundary_id
static ::ExceptionBase & ExcVertexNotUsed(unsigned int arg1)
types::subdomain_id locally_owned_subdomain() const
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)
static ::ExceptionBase & ExcInternalError()
Triangulation< dim, spacedim > & get_triangulation()