//
//---------------------------- find_cell_5.cc ---------------------------
-// find_active_cell_around_point() uses the closest vertex
-// to find the corresponding cell. This fail(ed) if it is
-// a hanging node for that cell.
-// This test fortunately does not show this error (yet).
+// find_active_cell_around_point() stops working if some cells are refined.
+// this is most likely a rounding error, but it is frustrating.
+// check2 triggers the following error:
+/*
+An error occurred in line <838> of file </scratch/deal-trunk/deal.II/source/grid/grid_tools.cc> in function
+ std::pair<typename Container<dim, spacedim>::active_cell_iterator, dealii::Point<dim> > dealii::GridTools::find_active_cell_around_point(const dealii::Mapping<dim, spacedim>&, const Container<dim, spacedim>&, const dealii::Point<spacedim>&) [with int dim = 3, Container = dealii::Triangulation, int spacedim = 3, typename Container<dim, spacedim>::active_cell_iterator = dealii::TriaActiveIterator<dealii::CellAccessor<3, 3> >]
+The violated condition was:
+ best_cell.first.state() == IteratorState::valid
+The name and call sequence of the exception was:
+ ExcPointNotFound<spacedim>(p)
+Additional Information:
+The point <0.789000 0.313000 0.170000> could not be found inside any of the subcells of a coarse grid cell.*/
#include "../tests.h"
#include <deal.II/base/logstream.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/grid_tools.h>
#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_in.h>
#include <deal.II/grid/tria_boundary_lib.h>
#include <fstream>
#include <deal.II/fe/mapping_q1.h>
+bool inside(Triangulation<3> &tria, Point<3> &p)
+{
+
+ for(typename Triangulation<3>::cell_iterator cell = tria.begin(0);
+ cell != tria.end(0); ++cell)
+ if( cell->point_inside (p) )
+ return true;
+ return false;
+}
-
-void check (Triangulation<2> &tria)
+void check2 ()
{
- Point<2> p (0.25,0.6);
-
- Triangulation<2>::active_cell_iterator cell
- = GridTools::find_active_cell_around_point (tria, p);
+ Triangulation<3> tria;
+ GridIn<3> gridIn;
+ gridIn.attach_triangulation (tria);
+ std::ifstream inputFile("find_cell_6/grid.inp");
+ gridIn.read_ucd (inputFile);
- deallog << cell << std::endl;
- for (unsigned int v=0; v<GeometryInfo<2>::vertices_per_cell; ++v)
- deallog << "<" << cell->vertex(v) << "> ";
- deallog << std::endl;
+ Point<3> p2(304.767,-57.0113,254.766);
+ deallog << inside(tria, p2) << std::endl;
+ GridTools::find_active_cell_around_point(tria, p2); //OK
+ int idx=0;
+ for (typename Triangulation<3>::active_cell_iterator cell = tria.begin_active(); cell!=tria.end(); ++cell, ++idx)
+ {
+ if (idx==21)
+ cell->set_refine_flag();
+ }
+
+ tria.execute_coarsening_and_refinement ();
+ deallog << inside(tria, p2) << std::endl;
+ GridTools::find_active_cell_around_point(tria, p2); //triggers exception
}
+void check1 ()
+{
+ Triangulation<3> tria;
+ GridGenerator::hyper_cube (tria);
+ tria.refine_global (3);
+
+ for (int i=0;i<5;++i)
+ {
+ for (int j=0;j<10000;++j)
+ {
+ Point<3> p ((rand()%1000)/1000.0,(rand()%1000)/1000.0,(rand()%1000)/1000.0);
+ if (!inside(tria, p))
+ deallog << "NOT INSIDE" << std::endl;
+ GridTools::find_active_cell_around_point(tria, p);
+ }
+
+ for(typename Triangulation<3>::active_cell_iterator cell = tria.begin_active();
+ cell != tria.end(); ++cell)
+ for (unsigned int f=0; f<GeometryInfo<3>::faces_per_cell; ++f)
+ {
+ if (cell->face(f)->at_boundary() && (rand()%5)==1)
+ cell->set_refine_flag();
+ }
+
+ tria.execute_coarsening_and_refinement();
+ }
+}
int main ()
{
try
{
- Triangulation<2> coarse_grid;
- GridGenerator::hyper_cube (coarse_grid);
- coarse_grid.refine_global (1);
- coarse_grid.begin_active()->set_refine_flag();
- coarse_grid.execute_coarsening_and_refinement();
- check (coarse_grid);
+// check1();
+ check2();
}
catch (const std::exception &exc)
{
--- /dev/null
+# sixD mesh generator, version 1
+# omit element on surface: 1
+# nodes: x: 6 y: 4 z: 4 total: 96
+# elements: x: 5 y: 3 z: 3 total: 44
+# size: first corner: (-1000;-500;0) second corner: (1150;650;650)
+96 44 0 0 0
+1 -1000 -500 0
+2 -500 -500 0
+3 -6.10352e-05 -500 0
+4 150 -500 0
+5 650 -500 0
+6 1150 -500 0
+7 -1000 0 0
+8 -500 0 0
+9 -6.10352e-05 0 0
+10 150 0 0
+11 650 0 0
+12 1150 0 0
+13 -1000 150 0
+14 -500 150 0
+15 -6.10352e-05 150 0
+16 150 150 0
+17 650 150 0
+18 1150 150 0
+19 -1000 650 0
+20 -500 650 0
+21 -6.10352e-05 650 0
+22 150 650 0
+23 650 650 0
+24 1150 650 0
+25 -1000 -500 150
+26 -500 -500 150
+27 -6.10352e-05 -500 150
+28 150 -500 150
+29 650 -500 150
+30 1150 -500 150
+31 -1000 0 150
+32 -500 0 150
+33 -6.10352e-05 0 150
+34 150 0 150
+35 650 0 150
+36 1150 0 150
+37 -1000 150 150
+38 -500 150 150
+39 -6.10352e-05 150 150
+40 150 150 150
+41 650 150 150
+42 1150 150 150
+43 -1000 650 150
+44 -500 650 150
+45 -6.10352e-05 650 150
+46 150 650 150
+47 650 650 150
+48 1150 650 150
+49 -1000 -500 400
+50 -500 -500 400
+51 -6.10352e-05 -500 400
+52 150 -500 400
+53 650 -500 400
+54 1150 -500 400
+55 -1000 0 400
+56 -500 0 400
+57 -6.10352e-05 0 400
+58 150 0 400
+59 650 0 400
+60 1150 0 400
+61 -1000 150 400
+62 -500 150 400
+63 -6.10352e-05 150 400
+64 150 150 400
+65 650 150 400
+66 1150 150 400
+67 -1000 650 400
+68 -500 650 400
+69 -6.10352e-05 650 400
+70 150 650 400
+71 650 650 400
+72 1150 650 400
+73 -1000 -500 650
+74 -500 -500 650
+75 -6.10352e-05 -500 650
+76 150 -500 650
+77 650 -500 650
+78 1150 -500 650
+79 -1000 0 650
+80 -500 0 650
+81 -6.10352e-05 0 650
+82 150 0 650
+83 650 0 650
+84 1150 0 650
+85 -1000 150 650
+86 -500 150 650
+87 -6.10352e-05 150 650
+88 150 150 650
+89 650 150 650
+90 1150 150 650
+91 -1000 650 650
+92 -500 650 650
+93 -6.10352e-05 650 650
+94 150 650 650
+95 650 650 650
+96 1150 650 650
+1 0 hex 1 2 8 7 25 26 32 31
+2 0 hex 2 3 9 8 26 27 33 32
+3 0 hex 3 4 10 9 27 28 34 33
+4 0 hex 4 5 11 10 28 29 35 34
+5 0 hex 5 6 12 11 29 30 36 35
+6 0 hex 7 8 14 13 31 32 38 37
+7 0 hex 8 9 15 14 32 33 39 38
+8 0 hex 10 11 17 16 34 35 41 40
+9 0 hex 11 12 18 17 35 36 42 41
+10 0 hex 13 14 20 19 37 38 44 43
+11 0 hex 14 15 21 20 38 39 45 44
+12 0 hex 15 16 22 21 39 40 46 45
+13 0 hex 16 17 23 22 40 41 47 46
+14 0 hex 17 18 24 23 41 42 48 47
+15 0 hex 25 26 32 31 49 50 56 55
+16 0 hex 26 27 33 32 50 51 57 56
+17 0 hex 27 28 34 33 51 52 58 57
+18 0 hex 28 29 35 34 52 53 59 58
+19 0 hex 29 30 36 35 53 54 60 59
+20 0 hex 31 32 38 37 55 56 62 61
+21 0 hex 32 33 39 38 56 57 63 62
+22 0 hex 33 34 40 39 57 58 64 63
+23 0 hex 34 35 41 40 58 59 65 64
+24 0 hex 35 36 42 41 59 60 66 65
+25 0 hex 37 38 44 43 61 62 68 67
+26 0 hex 38 39 45 44 62 63 69 68
+27 0 hex 39 40 46 45 63 64 70 69
+28 0 hex 40 41 47 46 64 65 71 70
+29 0 hex 41 42 48 47 65 66 72 71
+30 0 hex 49 50 56 55 73 74 80 79
+31 0 hex 50 51 57 56 74 75 81 80
+32 0 hex 51 52 58 57 75 76 82 81
+33 0 hex 52 53 59 58 76 77 83 82
+34 0 hex 53 54 60 59 77 78 84 83
+35 0 hex 55 56 62 61 79 80 86 85
+36 0 hex 56 57 63 62 80 81 87 86
+37 0 hex 57 58 64 63 81 82 88 87
+38 0 hex 58 59 65 64 82 83 89 88
+39 0 hex 59 60 66 65 83 84 90 89
+40 0 hex 61 62 68 67 85 86 92 91
+41 0 hex 62 63 69 68 86 87 93 92
+42 0 hex 63 64 70 69 87 88 94 93
+43 0 hex 64 65 71 70 88 89 95 94
+44 0 hex 65 66 72 71 89 90 96 95