DOLFIN
DOLFIN C++ interface
BoxMesh.h
1 // Copyright (C) 2005-2017 Anders Logg 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 #ifndef __BOX_H
19 #define __BOX_H
20 
21 #include <array>
22 #include <cstddef>
23 #include <dolfin/log/log.h>
24 #include <dolfin/common/MPI.h>
25 #include <dolfin/mesh/Mesh.h>
26 
27 namespace dolfin
28 {
29 
34 
35  class BoxMesh : public Mesh
36  {
37  public:
38 
58  static Mesh create(const std::array<Point,2 >& p, std::array<std::size_t, 3> n, CellType::Type cell_type)
59  { return create(MPI_COMM_WORLD, p, n, cell_type); }
60 
82  static Mesh create(MPI_Comm comm, const std::array<Point, 2>& p,
83  std::array<std::size_t, 3> n, CellType::Type cell_type)
84  {
85  Mesh mesh(comm);
86  if (cell_type == CellType::Type::tetrahedron)
87  build_tet(mesh, p, n);
88  else if (cell_type == CellType::Type::hexahedron)
89  build_hex(mesh, p, n);
90  else
91  {
92  dolfin_error("BoxMesh.h",
93  "generate box mesh",
94  "Wrong cell type '%d'", cell_type);
95  }
96 
97  return mesh;
98  }
99 
124  BoxMesh(const Point& p0, const Point& p1,
125  std::size_t nx, std::size_t ny, std::size_t nz);
126 
153  BoxMesh(MPI_Comm comm, const Point& p0, const Point& p1,
154  std::size_t nx, std::size_t ny, std::size_t nz);
155 
156  private:
157 
158  // Build mesh
159  static void build_tet(Mesh& mesh, const std::array<Point, 2>& p,
160  std::array<std::size_t, 3> n);
161 
162  static void build_hex(Mesh& mesh, const std::array<Point, 2>& p,
163  std::array<std::size_t, 3> n);
164 
165  };
166 
167 }
168 
169 #endif
Definition: adapt.h:29
Definition: Point.h:40
static Mesh create(const std::array< Point, 2 > &p, std::array< std::size_t, 3 > n, CellType::Type cell_type)
Definition: BoxMesh.h:58
Definition: BoxMesh.h:35
static Mesh create(MPI_Comm comm, const std::array< Point, 2 > &p, std::array< std::size_t, 3 > n, CellType::Type cell_type)
Definition: BoxMesh.h:82
Type
Enum for different cell types.
Definition: CellType.h:51
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
Definition: Mesh.h:82
BoxMesh(const Point &p0, const Point &p1, std::size_t nx, std::size_t ny, std::size_t nz)
Definition: BoxMesh.cpp:37