]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add changelog 11582/head
authorAlexander Grayver <agrayver@erdw.ethz.ch>
Mon, 18 Jan 2021 20:44:02 +0000 (21:44 +0100)
committerAlexander Grayver <agrayver@erdw.ethz.ch>
Thu, 21 Jan 2021 11:28:55 +0000 (12:28 +0100)
contrib/python-bindings/include/reference_cell_wrapper.h [new file with mode: 0644]
contrib/python-bindings/source/cell_accessor_wrapper.cc
contrib/python-bindings/source/export_reference_cell.cc [new file with mode: 0644]
contrib/python-bindings/source/reference_cell_wrapper.cc [new file with mode: 0644]
contrib/python-bindings/source/tria_accessor_wrapper.cc
contrib/python-bindings/source/triangulation_wrapper.cc
contrib/python-bindings/tests/triangulation_wrapper.py
doc/news/changes/minor/20210118AlexanderGrayver [new file with mode: 0644]

diff --git a/contrib/python-bindings/include/reference_cell_wrapper.h b/contrib/python-bindings/include/reference_cell_wrapper.h
new file mode 100644 (file)
index 0000000..1a8b755
--- /dev/null
@@ -0,0 +1,68 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2021 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.
+//
+// ---------------------------------------------------------------------
+
+#ifndef dealii_reference_cell_wrapper_h
+#define dealii_reference_cell_wrapper_h
+
+#include <deal.II/base/config.h>
+
+#include <deal.II/grid/reference_cell.h>
+
+#include <boost/python.hpp>
+
+DEAL_II_NAMESPACE_OPEN
+
+namespace python
+{
+  class CellTypeWrapper
+  {
+  public:
+    /**
+     * Copy constructor.
+     */
+    CellTypeWrapper(const CellTypeWrapper &other);
+
+    /**
+     * Constructor. Takes a CellKinds enum field and creates a Type class.
+     */
+    CellTypeWrapper(const ReferenceCell::Type::CellKinds &kind);
+
+    /**
+     * Constructor. Takes a CellKinds enum field and creates a Type class.
+     */
+    CellTypeWrapper(const ReferenceCell::Type &cell_type_in);
+
+    /**
+     * Constructor for an empty object.
+     */
+    CellTypeWrapper();
+
+    /**
+     * Destructor.
+     */
+    ~CellTypeWrapper();
+
+    ReferenceCell::Type::CellKinds
+    cell_kind() const;
+
+  private:
+    ReferenceCell::Type cell_type;
+  };
+
+} // namespace python
+
+DEAL_II_NAMESPACE_CLOSE
+
+#endif
index 50ce261f391e8fc95b789a48a840ea07c20f273d..016e678ad2f252c74044b670a06d70529dfcaae7 100644 (file)
@@ -796,6 +796,8 @@ namespace python
       return internal::cell_cast<3, 3>(cell_accessor)->n_faces();
   }
 
+
+
   CellTypeWrapper
   CellAccessorWrapper::reference_cell_type() const
   {
diff --git a/contrib/python-bindings/source/export_reference_cell.cc b/contrib/python-bindings/source/export_reference_cell.cc
new file mode 100644 (file)
index 0000000..7ad3d0f
--- /dev/null
@@ -0,0 +1,50 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2021 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.
+//
+// ---------------------------------------------------------------------
+
+#include <boost/python.hpp>
+
+#include <reference_cell_wrapper.h>
+
+DEAL_II_NAMESPACE_OPEN
+
+namespace python
+{
+  const char cell_kind_docstring[] =
+    "Return geometric type of the corresponding reference cell.               \n";
+
+
+  void
+  export_reference_cell()
+  {
+    boost::python::enum_<ReferenceCell::Type::CellKinds>("CellKinds")
+      .value("Vertex", ReferenceCell::Type::Vertex)
+      .value("Line", ReferenceCell::Type::Line)
+      .value("Tri", ReferenceCell::Type::Tri)
+      .value("Quad", ReferenceCell::Type::Quad)
+      .value("Tet", ReferenceCell::Type::Tet)
+      .value("Pyramid", ReferenceCell::Type::Pyramid)
+      .value("Wedge", ReferenceCell::Type::Wedge)
+      .value("Hex", ReferenceCell::Type::Hex)
+      .value("Invalid", ReferenceCell::Type::Invalid);
+
+    boost::python::class_<CellTypeWrapper>(
+      "CellType",
+      boost::python::init<ReferenceCell::Type::CellKinds>(
+        boost::python::args("kind")))
+      .add_property("kind", &CellTypeWrapper::cell_kind, cell_kind_docstring);
+  }
+} // namespace python
+
+DEAL_II_NAMESPACE_CLOSE
diff --git a/contrib/python-bindings/source/reference_cell_wrapper.cc b/contrib/python-bindings/source/reference_cell_wrapper.cc
new file mode 100644 (file)
index 0000000..b87e29d
--- /dev/null
@@ -0,0 +1,64 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2021 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.
+//
+// ---------------------------------------------------------------------
+
+#include <deal.II/grid/reference_cell.h>
+
+#include <reference_cell_wrapper.h>
+
+DEAL_II_NAMESPACE_OPEN
+
+namespace python
+{
+  CellTypeWrapper::CellTypeWrapper()
+  {}
+
+
+
+  CellTypeWrapper::CellTypeWrapper(const CellTypeWrapper &other)
+  {
+    cell_type = other.cell_type;
+  }
+
+
+
+  CellTypeWrapper::CellTypeWrapper(const ReferenceCell::Type::CellKinds &kind)
+  {
+    cell_type = kind;
+  }
+
+
+
+  CellTypeWrapper::CellTypeWrapper(const ReferenceCell::Type &cell_type_in)
+  {
+    cell_type = cell_type_in;
+  }
+
+
+
+  CellTypeWrapper::~CellTypeWrapper()
+  {}
+
+
+
+  ReferenceCell::Type::CellKinds
+  CellTypeWrapper::cell_kind() const
+  {
+    std::uint8_t kind = (std::uint8_t)cell_type;
+    return static_cast<ReferenceCell::Type::CellKinds>(kind);
+  }
+
+} // namespace python
+
+DEAL_II_NAMESPACE_CLOSE
index eebd472ff4e02cbe77607712ed2d458f546faf4b..37c442e13c096bcece653dc3f78b4ce804cf5dce 100644 (file)
@@ -1,6 +1,6 @@
 // ---------------------------------------------------------------------
 //
-// Copyright (C) 2016 - 2020 by the deal.II authors
+// Copyright (C) 2021 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
@@ -417,8 +417,18 @@ namespace python
       return internal::tria_accessor_cast<1, 2, 2>(tria_accessor)->n_vertices();
     else if ((dim == 2) && (spacedim == 3) && (structdim == 1))
       return internal::tria_accessor_cast<1, 2, 3>(tria_accessor)->n_vertices();
-    else
+    else if ((dim == 3) && (spacedim == 3) && (structdim == 1))
+      return internal::tria_accessor_cast<1, 3, 3>(tria_accessor)->n_vertices();
+    else if ((dim == 3) && (spacedim == 3) && (structdim == 2))
       return internal::tria_accessor_cast<2, 3, 3>(tria_accessor)->n_vertices();
+    else if ((dim == 3) && (spacedim == 3) && (structdim == 3))
+      return internal::tria_accessor_cast<3, 3, 3>(tria_accessor)->n_vertices();
+    else
+      {
+        AssertThrow(false,
+                    ExcMessage("Wrong structdim-dim-spacedim combination."));
+        return -1;
+      }
   }
 
 
@@ -430,8 +440,18 @@ namespace python
       return internal::tria_accessor_cast<1, 2, 2>(tria_accessor)->n_lines();
     else if ((dim == 2) && (spacedim == 3) && (structdim == 1))
       return internal::tria_accessor_cast<1, 2, 3>(tria_accessor)->n_lines();
-    else
+    else if ((dim == 3) && (spacedim == 3) && (structdim == 1))
+      return internal::tria_accessor_cast<1, 3, 3>(tria_accessor)->n_lines();
+    else if ((dim == 3) && (spacedim == 3) && (structdim == 2))
       return internal::tria_accessor_cast<2, 3, 3>(tria_accessor)->n_lines();
+    else if ((dim == 3) && (spacedim == 3) && (structdim == 3))
+      return internal::tria_accessor_cast<3, 3, 3>(tria_accessor)->n_lines();
+    else
+      {
+        AssertThrow(false,
+                    ExcMessage("Wrong structdim-dim-spacedim combination."));
+        return -1;
+      }
   }
 
 
@@ -441,10 +461,16 @@ namespace python
   {
     if ((dim == 2) && (spacedim == 2) && (structdim == 1))
       return internal::tria_accessor_cast<1, 2, 2>(tria_accessor)->n_faces();
-    else if ((dim == 2) && (spacedim == 3) && (structdim == 1))
-      return internal::tria_accessor_cast<1, 2, 3>(tria_accessor)->n_faces();
-    else
+    else if ((dim == 3) && (spacedim == 3) && (structdim == 2))
       return internal::tria_accessor_cast<2, 3, 3>(tria_accessor)->n_faces();
+    else if ((dim == 3) && (spacedim == 3) && (structdim == 3))
+      return internal::tria_accessor_cast<3, 3, 3>(tria_accessor)->n_faces();
+    else
+      {
+        AssertThrow(false,
+                    ExcMessage("Wrong structdim-dim-spacedim combination."));
+        return -1;
+      }
   }
 
 } // namespace python
index 511df8b73698cc3645a63ce9eea3c462e832094d..5d5cb5e7dce2c95954f3d346c16f9112225e8e46 100644 (file)
@@ -1549,6 +1549,7 @@ namespace python
   }
 
 
+
   void
   TriangulationWrapper::convert_hypercube_to_simplex_mesh(
     TriangulationWrapper &tria_out)
@@ -1569,6 +1570,7 @@ namespace python
   }
 
 
+
   void
   TriangulationWrapper::extrude_triangulation(
     const unsigned int    n_slices,
index 09445d2f4a8b3f5b4c00ed802420347898243eb0..e6eb29ab591d445f040fdd7f698fe238d1d58036 100644 (file)
@@ -438,6 +438,18 @@ class TestTriangulationWrapper(unittest.TestCase):
                 self.assertTrue(cell.center().distance(cell_ret.center()) < 1e-8)
 
 
+    def test_simplex(self):
+        for dim in self.dim:
+            triangulation_hex = self.build_hyper_cube_triangulation(dim)
+            triangulation_simplex = Triangulation(dim[0], dim[1])
+            triangulation_hex.convert_hypercube_to_simplex_mesh(triangulation_simplex)
+
+            if dim[0] == '3D':
+                self.assertTrue(triangulation_simplex.n_active_cells() == 24)
+            else:
+                self.assertTrue(triangulation_simplex.n_active_cells() == 8)
+
+
     def test_save_load(self):
         for dim in self.dim:
             triangulation_1 = self.build_hyper_cube_triangulation(dim)
diff --git a/doc/news/changes/minor/20210118AlexanderGrayver b/doc/news/changes/minor/20210118AlexanderGrayver
new file mode 100644 (file)
index 0000000..927449f
--- /dev/null
@@ -0,0 +1,3 @@
+New: Added python wrappers to enable support for simplex and mixed meshes.
+<br>
+(Alexander Grayver, 2021/01/18)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.