Debian Codegraph @

python/src/generation.cpp

raw
1 // Copyright (C) 2017 Chris N. Richardson and Garth N. Wells
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17
18 #include <array>
19 #include <iostream>
20 #include <memory>
21 #include <string>
22 #include <pybind11/pybind11.h>
23 #include <pybind11/numpy.h>
24
25 #include <dolfin/geometry/Point.h>
26 #include <dolfin/mesh/CellType.h>
27 #include <dolfin/generation/BoxMesh.h>
28 #include <dolfin/generation/UnitTriangleMesh.h>
29 #include <dolfin/generation/UnitCubeMesh.h>
30 #include <dolfin/generation/UnitDiscMesh.h>
31 #include <dolfin/generation/SphericalShellMesh.h>
32 #include <dolfin/generation/UnitSquareMesh.h>
33 #include <dolfin/generation/UnitIntervalMesh.h>
34 #include <dolfin/generation/IntervalMesh.h>
35
36 #include "casters.h"
37
38 namespace py = pybind11;
39
40 namespace dolfin_wrappers
41 {
42
43 void generation(py::module& m)
44 {
45 // dolfin::IntervalMesh
46 py::class_<dolfin::IntervalMesh, std::shared_ptr<dolfin::IntervalMesh>, dolfin::Mesh>(m, "IntervalMesh")
47 .def(py::init<std::size_t, double, double>())
48 .def(py::init([](const MPICommWrapper comm, std::size_t n, double a, double b)
49 { return std::unique_ptr<dolfin::IntervalMesh>(new dolfin::IntervalMesh(comm.get(), n, a, b)); }));
50
51 // dolfin::UnitIntervalMesh
52 py::class_<dolfin::UnitIntervalMesh, std::shared_ptr<dolfin::UnitIntervalMesh>,
53 dolfin::IntervalMesh, dolfin::Mesh>(m, "UnitIntervalMesh")
54 .def(py::init<std::size_t>())
55 .def(py::init([](const MPICommWrapper comm, std::size_t n)
56 { return std::unique_ptr<dolfin::UnitIntervalMesh>(new dolfin::UnitIntervalMesh(comm.get(), n)); }))
57 .def_static("create", [](std::size_t n)
58 { return dolfin::UnitIntervalMesh::create(n); })
59 .def_static("create", [](const MPICommWrapper comm, std::size_t n)
60 { return dolfin::UnitIntervalMesh::create(comm.get(), n); });
61
62 // dolfin::RectangleMesh
63 py::class_<dolfin::RectangleMesh, std::shared_ptr<dolfin::RectangleMesh>, dolfin::Mesh>(m, "RectangleMesh")
64 .def_static("create", [](std::array<dolfin::Point, 2> p, std::array<std::size_t, 2> n,
65 dolfin::CellType::Type cell_type, std::string diagonal)
66 { return dolfin::RectangleMesh::create(p, n, cell_type, diagonal); },
67 py::arg("p"), py::arg("n"), py::arg("cell_type"), py::arg("diagonal")="right")
68 .def_static("create", [](const MPICommWrapper comm, std::array<dolfin::Point, 2> p,
69 std::array<std::size_t, 2> n, dolfin::CellType::Type cell_type,
70 std::string diagonal)
71 { return dolfin::RectangleMesh::create(comm.get(), p, n, cell_type, diagonal); },
72 py::arg("comm"), py::arg("p"), py::arg("n"), py::arg("cell_type"),
73 py::arg("diagonal")="right")
74 // Remove
75 .def(py::init<dolfin::Point, dolfin::Point, std::size_t, std::size_t, std::string>(),
76 py::arg("p0"), py::arg("p1"), py::arg("nx"), py::arg("ny"), py::arg("diagonal")="right")
77 .def(py::init([](const MPICommWrapper comm, const dolfin::Point& p0, const dolfin::Point& p1,
78 std::size_t nx, std::size_t ny, std::string diagonal="right")
79 { return std::unique_ptr<dolfin::RectangleMesh>(new dolfin::RectangleMesh(comm.get(), p0, p1, nx, ny, diagonal)); }),
80 py::arg("comm"), py::arg("p0"), py::arg("p1"), py::arg("nx"), py::arg("ny"), py::arg("diagonal")="right");
81
82 // dolfin::UnitSquareMesh
83 py::class_<dolfin::UnitSquareMesh, std::shared_ptr<dolfin::UnitSquareMesh>, dolfin::Mesh>(m, "UnitSquareMesh")
84 .def(py::init<std::size_t, std::size_t, std::string>(), py::arg("nx"), py::arg("ny"), py::arg("diagonal")="right")
85 .def(py::init([](const MPICommWrapper comm, std::size_t nx, std::size_t ny, std::string diagonal="right")
86 { return std::unique_ptr<dolfin::UnitSquareMesh>(new dolfin::UnitSquareMesh(comm.get(), nx, ny, diagonal)); }),
87 py::arg("comm"), py::arg("nx"), py::arg("ny"), py::arg("diagonal")="right")
88 .def_static("create", [](std::array<std::size_t, 2> n, dolfin::CellType::Type cell_type,
89 std::string diagonal)
90 { return dolfin::UnitSquareMesh::create(n, cell_type, diagonal); },
91 py::arg("n"), py::arg("cell_type"), py::arg("diagonal")="right")
92 .def_static("create", [](const MPICommWrapper comm, std::array<std::size_t, 2> n,
93 dolfin::CellType::Type cell_type, std::string diagonal="right")
94 { return dolfin::UnitSquareMesh::create(comm.get(), n, cell_type, diagonal); },
95 py::arg("comm"), py::arg("n"), py::arg("cell_type"), py::arg("diagonal")="right")
96 // Remove below for 2018.1 release
97 .def_static("create", [](std::size_t nx, std::size_t ny, dolfin::CellType::Type cell_type)
98 { return dolfin::UnitSquareMesh::create({nx, ny}, cell_type); },
99 py::arg("nx"), py::arg("ny"), py::arg("cell_type"))
100 .def_static("create", [](const MPICommWrapper comm, std::size_t nx, std::size_t ny,
101 dolfin::CellType::Type cell_type)
102 { return dolfin::UnitSquareMesh::create(comm.get(), {nx, ny}, cell_type); },
103 py::arg("comm"), py::arg("nx"), py::arg("ny"), py::arg("cell_type"));
104
105 // dolfin::UnitCubeMesh
106 py::class_<dolfin::UnitCubeMesh, std::shared_ptr<dolfin::UnitCubeMesh>, dolfin::Mesh>(m, "UnitCubeMesh")
107 .def(py::init<std::size_t, std::size_t, std::size_t>())
108 .def(py::init([](const MPICommWrapper comm, std::size_t nx, std::size_t ny, std::size_t nz)
109 { return std::unique_ptr<dolfin::UnitCubeMesh>(new dolfin::UnitCubeMesh(comm.get(), nx, ny, nz)); }),
110 py::arg("comm"), py::arg("nx"), py::arg("ny"), py::arg("nz"))
111 .def_static("create", [](std::array<std::size_t, 3> n, dolfin::CellType::Type cell_type)
112 { return dolfin::UnitCubeMesh::create(n, cell_type); },
113 py::arg("n"), py::arg("cell_type"))
114 .def_static("create", [](const MPICommWrapper comm, std::array<std::size_t, 3> n,
115 dolfin::CellType::Type cell_type)
116 { return dolfin::UnitCubeMesh::create(comm.get(), n, cell_type); },
117 py::arg("comm"), py::arg("n"), py::arg("cell_type"))
118 // Remove below for 2018.1 release
119 .def_static("create", [](std::size_t nx, std::size_t ny, std::size_t nz,
120 dolfin::CellType::Type cell_type)
121 { return dolfin::UnitCubeMesh::create({nx, ny, nz}, cell_type); },
122 py::arg("nx"), py::arg("ny"), py::arg("nz"), py::arg("cell_type"))
123 .def_static("create", [](const MPICommWrapper comm, std::size_t nx, std::size_t ny, std::size_t nz,
124 dolfin::CellType::Type cell_type)
125 { return dolfin::UnitCubeMesh::create(comm.get(), {nx, ny, nz}, cell_type); },
126 py::arg("comm"), py::arg("nx"), py::arg("ny"), py::arg("nz"), py::arg("cell_type"));
127
128 // dolfin::UnitDiscMesh
129 py::class_<dolfin::UnitDiscMesh>(m, "UnitDiscMesh")
130 .def_static("create", [](const MPICommWrapper comm, std::size_t n, std::size_t degree, std::size_t gdim)
131 { return dolfin::UnitDiscMesh::create(comm.get(), n, degree, gdim); });
132
133 // dolfin::SphericalShellMesh
134 py::class_<dolfin::SphericalShellMesh>(m, "SphericalShellMesh")
135 .def_static("create", [](const MPICommWrapper comm, std::size_t degree)
136 { return dolfin::SphericalShellMesh::create(comm.get(), degree); });
137
138 // dolfin::UnitTriangleMesh
139 py::class_<dolfin::UnitTriangleMesh>(m, "UnitTriangleMesh")
140 .def_static("create", &dolfin::UnitTriangleMesh::create);
141
142 // dolfin::BoxMesh
143 py::class_<dolfin::BoxMesh, std::shared_ptr<dolfin::BoxMesh>, dolfin::Mesh>(m, "BoxMesh")
144 .def(py::init<const dolfin::Point&, const dolfin::Point&, std::size_t, std::size_t, std::size_t>())
145 .def(py::init([](const MPICommWrapper comm, const dolfin::Point& p0, const dolfin::Point& p1,
146 std::size_t nx, std::size_t ny, std::size_t nz)
147 { return std::unique_ptr<dolfin::BoxMesh>(new dolfin::BoxMesh(comm.get(), p0, p1, nx, ny, nz)); }),
148 py::arg("comm"), py::arg("p0"), py::arg("p1"), py::arg("nx"), py::arg("ny"), py::arg("nz"))
149 .def_static("create", [](std::array<dolfin::Point, 2> p, std::array<std::size_t, 3> n,
150 dolfin::CellType::Type cell_type)
151 { return dolfin::BoxMesh::create(p, n, cell_type); },
152 py::arg("p"), py::arg("n"), py::arg("cell_type"))
153 .def_static("create", [](const MPICommWrapper comm, std::array<dolfin::Point, 2> p,
154 std::array<std::size_t, 3> n, dolfin::CellType::Type cell_type)
155 { return dolfin::BoxMesh::create(comm.get(), p, n, cell_type); },
156 py::arg("comm"), py::arg("p"), py::arg("n"), py::arg("cell_type"));
157 }
158 }