get_barycenter() const;
/**
- * Get the barycenter of the cell.
+ * Get the center of the cell.
*/
PointWrapper
get_center(const bool respect_manifold = false,
*/
MappingQGenericWrapper(const MappingQGenericWrapper &other);
+ /**
+ * Default constructor.
+ */
+ MappingQGenericWrapper();
+
/**
* Constructor.
*/
transform_real_to_unit_cell(CellAccessorWrapper &cell, PointWrapper &point);
/**
- * Get the underlying mapping
+ * Get the underlying mapping.
*/
void *
get_mapping();
/**
* Find and return an active cell that surrounds a given point p.
- * The mapping used to determine whether the given point is inside a given
- * cell.
+ * The mapping is used to determine whether the given point is inside a
+ * given cell.
*/
CellAccessorWrapper
- find_active_cell_around_point(PointWrapper & p,
- MappingQGenericWrapper &mapping);
+ find_active_cell_around_point(
+ PointWrapper & p,
+ MappingQGenericWrapper mapping = MappingQGenericWrapper());
/**
* Assign a manifold object to a certain part of the triangulation.
return PointWrapper(barycenter_list);
}
+
+
template <int dim, int spacedim>
PointWrapper
get_center(const bool respect_manifold,
distort_random,
1,
2)
+ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(
+ find_active_cell_around_point_overloads,
+ find_active_cell_around_point,
+ 1,
+ 2)
const char n_active_cells_docstring[] =
"Return the number of active cells \n";
boost::python::args("self", "transformation"))
.def("find_active_cell_around_point",
&TriangulationWrapper::find_active_cell_around_point,
- find_active_cell_around_point_docstring,
- boost::python::args("self", "point", "mapping"))
+ find_active_cell_around_point_overloads(
+ boost::python::args("self", "point", "mapping"),
+ find_active_cell_around_point_docstring))
.def("refine_global",
&TriangulationWrapper::refine_global,
refine_global_docstring,
+ MappingQGenericWrapper::MappingQGenericWrapper()
+ : dim(-1)
+ , spacedim(-1)
+ , degree(-1)
+ , mapping_ptr(nullptr)
+ {}
+
+
+
MappingQGenericWrapper::MappingQGenericWrapper(const int dim,
const int spacedim,
const int degree)
Point<spacedim> point = *(static_cast<Point<spacedim> *>(p.get_point()));
- const MappingQGeneric<dim, spacedim> *mapping =
- static_cast<const MappingQGeneric<dim, spacedim> *>(
- mapping_wrapper.get_mapping());
-
- auto cell_pair =
- GridTools::find_active_cell_around_point(*mapping, *tria, point);
-
- return std::make_pair(cell_pair.first->level(), cell_pair.first->index());
+ if (mapping_wrapper.get_mapping() != nullptr)
+ {
+ const MappingQGeneric<dim, spacedim> *mapping =
+ static_cast<const MappingQGeneric<dim, spacedim> *>(
+ mapping_wrapper.get_mapping());
+
+ auto cell_pair =
+ GridTools::find_active_cell_around_point(*mapping, *tria, point);
+ return std::make_pair(cell_pair.first->level(),
+ cell_pair.first->index());
+ }
+ else
+ {
+ auto cell = GridTools::find_active_cell_around_point(*tria, point);
+ return std::make_pair(cell->level(), cell->index());
+ }
}
ExcMessage(
"The output Triangulation must be of dimension three"));
- if ((dim == 2) && (spacedim == 2))
- {
- Triangulation<2, 2> *tria =
- static_cast<Triangulation<2, 2> *>(triangulation);
- Triangulation<3, 3> *tria_out = static_cast<Triangulation<3, 3> *>(
- triangulation_out.get_triangulation());
- GridGenerator::extrude_triangulation(*tria,
- n_slices,
- height,
- *tria_out);
- }
+
+ Triangulation<2, 2> *tria =
+ static_cast<Triangulation<2, 2> *>(triangulation);
+ Triangulation<3, 3> *tria_out =
+ static_cast<Triangulation<3, 3> *>(triangulation_out.get_triangulation());
+ GridGenerator::extrude_triangulation(*tria, n_slices, height, *tria_out);
}
CellAccessorWrapper
TriangulationWrapper::find_active_cell_around_point(
- PointWrapper & p,
- MappingQGenericWrapper &mapping)
+ PointWrapper & p,
+ MappingQGenericWrapper mapping)
{
std::pair<int, int> level_index_pair;
if ((dim == 2) && (spacedim == 2))
import unittest
from PyDealII.Debug import *
-
class TestTriangulationWrapper(unittest.TestCase):
def setUp(self):
else:
self.assertEqual(n_cells, 64)
+
+ def test_transform(self):
+ for dim in self.dim:
+ triangulation_1 = self.build_hyper_cube_triangulation(dim)
+ triangulation_1.refine_global(1)
+ triangulation_2 = self.build_hyper_cube_triangulation(dim)
+ triangulation_2.refine_global(1)
+
+ triangulation_1.transform(lambda p: [v + 1. for v in p])
+
+ if dim[1] == '3D':
+ offset = Point([1., 1., 1.])
+ else:
+ offset = Point([1., 1.])
+
+ for (cell_1, cell_2) in zip(triangulation_1.active_cells(), triangulation_2.active_cells()):
+ self.assertTrue(cell_1.center().distance(cell_2.center() + offset) < 1e-8)
+
+
+ def test_find_active_cell_around_point(self):
+ for dim in self.dim:
+ triangulation = self.build_hyper_cube_triangulation(dim)
+ triangulation.refine_global(2)
+
+ for cell in triangulation.active_cells():
+ cell_ret = triangulation.find_active_cell_around_point(cell.center())
+ self.assertTrue(cell.center().distance(cell_ret.center()) < 1e-8)
+
+
def test_save_load(self):
for dim in self.dim:
triangulation_1 = self.build_hyper_cube_triangulation(dim)