int
get_manifold_id() const;
+ /**
+ * Do as set_manifold_id() but also set the manifold indicators of
+ * the objects that bound the current object.
+ */
+ void
+ set_all_manifold_ids(const int manifold_id);
+
/**
* Return the ith neighbor of a cell. If the neighbor does not exist,
* i.e., if the ith face of the current object is at the boundary,
boost::python::list
faces() const;
+ /**
+ * Compute the dim-dimensional measure of the object.
+ * For a dim-dimensional cell in dim-dimensional space,
+ * this equals its volume. On the other hand, for a 2d
+ * cell in 3d space, or if the current object pointed to
+ * is a 2d face of a 3d cell in 3d space, then the function
+ * computes the area the object occupies. For a
+ * one-dimensional object, return its length.
+ */
+ double
+ measure() const;
+
/**
* Exception.
*/
void *
get_manifold() const;
+ /**
+ * Return the dimension of the underlying object
+ */
+ int
+ get_dim() const;
+
+ /**
+ * Return the space dimension of the underlying object
+ */
+ int
+ get_spacedim() const;
private:
/**
bool
at_boundary() const;
+ /**
+ * Compute the dim-dimensional measure of the object.
+ * For a dim-dimensional cell in dim-dimensional space,
+ * this equals its volume. On the other hand, for a 2d
+ * cell in 3d space, or if the current object pointed to
+ * is a 2d face of a 3d cell in 3d space, then the function
+ * computes the area the object occupies. For a
+ * one-dimensional object, return its length.
+ */
+ double
+ measure() const;
+
/**
* Exception.
*/
generate_hyper_shell(PointWrapper & center,
const double inner_radius,
const double outer_radius,
- const unsigned n_cells = 0);
+ const unsigned n_cells = 0,
+ bool colorize = false);
/**
* Shift each vertex of the Triangulation by the given @p shift_list.
flatten_triangulation(TriangulationWrapper &tria_out);
/**
- *
+ * Assign a manifold object to a certain part of the triangulation.
+ * If an object with manifold number is refined, this object
+ * is used to find the location of new vertices (see the results
+ * section of step-49 for a more in-depth discussion of this, with
+ * examples). It is also used for non-linear (i.e.: non-Q1)
+ * transformations of cells to the unit cell in shape function
+ * calculations.
*/
void
set_manifold(const int number, ManifoldWrapper &manifold);
+ /**
+ * Reset those parts of the triangulation with the given manifold_number to
+ * use a FlatManifold object. This is the default state of a non-curved
+ * triangulation, and undoes assignment of a different Manifold object by
+ * the function Triangulation::set_manifold().
+ */
+ void
+ reset_manifold(const int number);
+
/**
* Refine all the cells @p n times.
*/
+ template <int dim, int spacedim>
+ void
+ set_all_manifold_ids(const int manifold_id, void *cell_accessor)
+ {
+ const CellAccessor<dim, spacedim> *cell =
+ static_cast<const CellAccessor<dim, spacedim> *>(cell_accessor);
+ return cell->set_all_manifold_ids(manifold_id);
+ }
+
+
+
template <int dim, int spacedim>
bool
at_boundary(const void *cell_accessor)
return faces_list;
}
+
+
+
+ template <int dim, int spacedim>
+ double
+ measure(const void *cell_accessor)
+ {
+ const CellAccessor<dim, spacedim> *cell =
+ static_cast<const CellAccessor<dim, spacedim> *>(cell_accessor);
+
+ return cell->measure();
+ }
} // namespace internal
+ void
+ CellAccessorWrapper::set_all_manifold_ids(const int manifold_id)
+ {
+ if ((dim == 2) && (spacedim == 2))
+ internal::set_all_manifold_ids<2, 2>(manifold_id, cell_accessor);
+ else if ((dim == 2) && (spacedim == 3))
+ internal::set_all_manifold_ids<2, 3>(manifold_id, cell_accessor);
+ else
+ internal::set_all_manifold_ids<3, 3>(manifold_id, cell_accessor);
+ }
+
+
+
bool
CellAccessorWrapper::at_boundary() const
{
return internal::faces<3, 3>(cell_accessor);
}
+
+
+ double
+ CellAccessorWrapper::measure() const
+ {
+ if ((dim == 2) && (spacedim == 2))
+ return internal::measure<2, 2>(cell_accessor);
+ else if ((dim == 2) && (spacedim == 3))
+ return internal::measure<2, 3>(cell_accessor);
+ else
+ return internal::measure<3, 3>(cell_accessor);
+ }
+
} // namespace python
DEAL_II_NAMESPACE_CLOSE
+ const char set_all_manifold_ids_docstring[] =
+ "Do as set_manifold_id() but also set the manifold indicators of \n"
+ "the objects that bound the current object. \n";
+
+
+
const char barycenter_docstring[] =
"Return the barycenter of the current cell \n";
+ const char measure_docstring[] =
+ " Compute the dim-dimensional measure of the object. \n";
+
+
+
void
export_cell_accessor()
{
&CellAccessorWrapper::get_manifold_id,
&CellAccessorWrapper::set_manifold_id,
manifold_id_docstring)
+ .def("set_all_manifold_ids",
+ &CellAccessorWrapper::set_all_manifold_ids,
+ set_all_manifold_ids_docstring,
+ boost::python::args("self", "number"))
.def("barycenter",
&CellAccessorWrapper::get_barycenter,
barycenter_docstring,
.def("faces",
&CellAccessorWrapper::faces,
faces_docstring,
+ boost::python::args("self"))
+ .def("measure",
+ &CellAccessorWrapper::measure,
+ measure_docstring,
boost::python::args("self"));
}
} // namespace python
const char at_boundary_docstring[] =
" Return whether the face is at the boundary \n";
+ const char measure_docstring[] =
+ " Compute the dim-dimensional measure of the object. \n";
+
void
export_tria_accessor()
{
.def("set_all_boundary_ids",
&TriaAccessorWrapper::set_all_boundary_ids,
set_all_boundary_ids_docstring,
- boost::python::args("self", "boundary_id"));
+ boost::python::args("self", "boundary_id"))
+ .def("measure",
+ &TriaAccessorWrapper::measure,
+ measure_docstring,
+ boost::python::args("self"));
}
} // namespace python
generate_half_hyper_ball,
1,
2)
-
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generate_hyper_shell_overloads,
generate_hyper_shell,
3,
- 4)
+ 5)
const char n_active_cells_docstring[] =
"Return the number of active cells \n";
+ const char reset_manifold_docstring[] =
+ "Reset those parts of the triangulation with the given manifold_number \n"
+ "to use a FlatManifold object. \n";
+
+
+
void
export_triangulation()
{
"center",
"inner_radius",
"outer_radius",
- "n_cells"),
+ "n_cells",
+ "colorize"),
generate_hyper_shell_docstring))
.def("shift",
&TriangulationWrapper::shift,
.def("set_manifold",
&TriangulationWrapper::set_manifold,
set_manifold_docstring,
- boost::python::args("self", "number", "manifold"));
+ boost::python::args("self", "number", "manifold"))
+ .def("reset_manifold",
+ &TriangulationWrapper::reset_manifold,
+ reset_manifold_docstring,
+ boost::python::args("self", "number"));
}
} // namespace python
}
+
void *
ManifoldWrapper::get_manifold() const
{
return manifold_ptr;
}
+
+
+ int
+ ManifoldWrapper::get_dim() const
+ {
+ return dim;
+ }
+
+
+
+ int
+ ManifoldWrapper::get_spacedim() const
+ {
+ return spacedim;
+ }
+
+
} // namespace python
DEAL_II_NAMESPACE_CLOSE
tria_accessor);
return accessor->at_boundary();
}
+
+
+ template <int structdim, int dim, int spacedim>
+ double
+ measure(const void *tria_accessor)
+ {
+ const TriaAccessor<structdim, dim, spacedim> *accessor =
+ static_cast<const TriaAccessor<structdim, dim, spacedim> *>(
+ tria_accessor);
+ return accessor->measure();
+ }
} // namespace internal
return internal::at_boundary<2, 3, 3>(tria_accessor);
}
+
+
+ double
+ TriaAccessorWrapper::measure() const
+ {
+ if ((dim == 2) && (spacedim == 2) && (structdim == 1))
+ return internal::measure<1, 2, 2>(tria_accessor);
+ else if ((dim == 2) && (spacedim == 3) && (structdim == 1))
+ return internal::measure<1, 2, 3>(tria_accessor);
+ else
+ return internal::measure<2, 3, 3>(tria_accessor);
+ }
+
} // namespace python
DEAL_II_NAMESPACE_CLOSE
const double inner_radius,
const double outer_radius,
const unsigned n_cells,
+ bool colorize,
void * triangulation)
{
// Cast the PointWrapper object to Point<dim>
static_cast<Triangulation<dim> *>(triangulation);
tria->clear();
GridGenerator::hyper_shell(
- *tria, center_point, inner_radius, outer_radius, n_cells);
+ *tria, center_point, inner_radius, outer_radius, n_cells, colorize);
}
TriangulationWrapper::generate_hyper_shell(PointWrapper & center,
const double inner_radius,
const double outer_radius,
- const unsigned n_cells)
+ const unsigned n_cells,
+ bool colorize)
{
AssertThrow(
dim == spacedim,
"This function is only implemented for dim equal to spacedim."));
if (dim == 2)
internal::generate_hyper_shell<2>(
- center, inner_radius, outer_radius, n_cells, triangulation);
+ center, inner_radius, outer_radius, n_cells, colorize, triangulation);
else
internal::generate_hyper_shell<3>(
- center, inner_radius, outer_radius, n_cells, triangulation);
+ center, inner_radius, outer_radius, n_cells, colorize, triangulation);
}
TriangulationWrapper::set_manifold(const int number,
ManifoldWrapper &manifold)
{
+ AssertThrow(
+ dim == manifold.get_dim(),
+ ExcMessage(
+ "The Triangulation and Manifold should have the same dimension."));
+ AssertThrow(
+ spacedim == manifold.get_spacedim(),
+ ExcMessage(
+ "The Triangulation and Manifold should have the same space dimension."));
+
if ((dim == 2) && (spacedim == 2))
{
Triangulation<2, 2> *tria =
+ void
+ TriangulationWrapper::reset_manifold(const int number)
+ {
+ if ((dim == 2) && (spacedim == 2))
+ {
+ Triangulation<2, 2> *tria =
+ static_cast<Triangulation<2, 2> *>(triangulation);
+ tria->reset_manifold(number);
+ }
+ else if ((dim == 2) && (spacedim == 3))
+ {
+ Triangulation<2, 3> *tria =
+ static_cast<Triangulation<2, 3> *>(triangulation);
+ tria->reset_manifold(number);
+ }
+ else
+ {
+ Triangulation<3, 3> *tria =
+ static_cast<Triangulation<3, 3> *>(triangulation);
+ tria->reset_manifold(number);
+ }
+ }
+
+
+
void
TriangulationWrapper::setup(const std::string &dimension,
const std::string &spacedimension)
--- /dev/null
+# ---------------------------------------------------------------------
+#
+# Copyright (C) 2016 by the deal.II authors
+#
+# This file is part of the deal.II library.
+#
+# The deal.II library is free software; you can use it, redistribute
+# it, and/or modify it under the terms of the GNU Lesser General
+# Public License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# The full text of the license can be found in the file LICENSE.md at
+# the top level directory of deal.II.
+#
+# ---------------------------------------------------------------------
+
+import math
+import unittest
+from PyDealII.Debug import *
+
+class TestManifoldWrapperShell(unittest.TestCase):
+
+ def setUp(self):
+ self.triangulation = Triangulation('2D')
+ p_center = Point([0, 0])
+ self.triangulation.generate_hyper_shell(center = p_center, inner_radius = 0.5, outer_radius = 1., n_cells = 0, colorize = True)
+
+ self.manifold = Manifold(dim = 2, spacedim = 2)
+ self.manifold.create_polar(p_center)
+
+ def test_manifold(self):
+ self.triangulation.set_manifold(0, self.manifold)
+ for cell in self.triangulation.active_cells():
+ cell.manifold_id = 0
+
+ self.triangulation.refine_global(3)
+
+ circumference = 0
+ for cell in self.triangulation.active_cells():
+ for face in cell.faces():
+ if face.at_boundary() and face.boundary_id == 1:
+ circumference += face.measure()
+
+ self.assertTrue(abs(circumference - 2*math.pi)/(2*math.pi) < 1e-2)
+
+class TestManifoldWrapperBall(unittest.TestCase):
+
+ def setUp(self):
+ self.triangulation = Triangulation('3D')
+ p_center = Point([0., 0., 0.])
+ self.triangulation.generate_hyper_ball(center = p_center, radius = 1.)
+
+ self.manifold = Manifold(dim = 3, spacedim = 3)
+ self.manifold.create_spherical(p_center)
+
+ def test_manifold(self):
+ self.triangulation.reset_manifold(number = 0)
+ self.triangulation.set_manifold(number = 0, manifold = self.manifold)
+ for cell in self.triangulation.active_cells():
+ if cell.at_boundary():
+ cell.manifold_id = 0
+
+ self.triangulation.refine_global(3)
+
+ volume = 0
+ for cell in self.triangulation.active_cells():
+ volume += cell.measure()
+
+ self.assertTrue(abs(volume - 4./3. * math.pi) / (4./3.*math.pi) < 2e-2)
+
+if __name__ == '__main__':
+ unittest.main()
#
# ---------------------------------------------------------------------
-import os
-import sys
-module_path = os.path.abspath('/home/agrayver/lib/dealii/build_gofem/lib/python3.7/site-packages')
-if module_path not in sys.path:
- sys.path.append(module_path)
-
import unittest
from PyDealII.Debug import *