DOLFIN
DOLFIN C++ interface
LocalMeshData.h
1 // Copyright (C) 2008 Ola Skavhaug
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 // Modified by Anders Logg, 2008-2009.
19 //
20 // First added: 2008-11-28
21 // Last changed: 2013-02-18
22 //
23 // Modified by Anders Logg, 2008-2009.
24 // Modified by Kent-Andre Mardal, 2011.
25 
26 #ifndef __LOCAL_MESH_DATA_H
27 #define __LOCAL_MESH_DATA_H
28 
29 #include <cstdint>
30 #include <map>
31 #include <vector>
32 #include <boost/multi_array.hpp>
33 #include <dolfin/common/MPI.h>
34 #include <dolfin/common/Variable.h>
35 #include "CellType.h"
36 
37 namespace dolfin
38 {
39 
40  class Mesh;
41 
43 
57 
58  class LocalMeshData : public Variable
59  {
60  public:
61 
63  explicit LocalMeshData(const MPI_Comm mpi_comm);
64 
66  explicit LocalMeshData(const Mesh& mesh);
67 
70 
73  void check() const;
74 
76  std::string str(bool verbose) const;
77 
79  void clear();
80 
82  void extract_mesh_data(const Mesh& mesh);
83 
86  void broadcast_mesh_data(const MPI_Comm mpi_comm);
87 
89  void receive_mesh_data(const MPI_Comm mpi_comm);
90 
92  void reorder();
93 
95  struct Geometry
96  {
99 
101  int dim;
102 
104  std::int64_t num_global_vertices;
105 
107  boost::multi_array<double, 2> vertex_coordinates;
108 
111  std::vector<std::int64_t> vertex_indices;
112 
114  void clear()
115  {
116  dim = -1;
117  num_global_vertices = -1;
118  vertex_coordinates.resize(boost::extents[0][0]);
119  vertex_indices.clear();
120  }
121 
123  void unpack_vertex_coordinates(const std::vector<double>& values);
124  };
125 
128 
130  struct Topology
131  {
133  Topology() : dim(-1), num_global_cells(-1) {}
134 
136  int dim;
137 
139  std::int64_t num_global_cells;
140 
143 
145  boost::multi_array<std::int64_t, 2> cell_vertices;
146 
148  std::vector<std::int64_t> global_cell_indices;
149 
151  std::vector<int> cell_partition;
152 
154  std::vector<std::size_t> cell_weight;
155 
156  // FIXME: this should replace the need for num_vertices_per_cell
157  // and tdim
160 
162  void clear()
163  {
164  dim = -1;
165  num_global_cells = -1;
166  num_vertices_per_cell = -1;
167  cell_vertices.resize(boost::extents[0][0]);
168  global_cell_indices.clear();
169  cell_partition.clear();
170  cell_weight.clear();
171  }
172 
174  void unpack_cell_vertices(const std::vector<std::int64_t>& values);
175 
176  };
177 
180 
182  std::map<std::size_t, std::vector<std::pair<std::pair<std::size_t,
183  std::size_t>, std::size_t>>> domain_data;
184 
186  MPI_Comm mpi_comm() const
187  { return _mpi_comm.comm(); }
188 
189  private:
190 
191  // MPI communicator
192  dolfin::MPI::Comm _mpi_comm;
193 
194  };
195 
196 }
197 
198 #endif
Common base class for DOLFIN variables.
Definition: Variable.h:35
LocalMeshData(const MPI_Comm mpi_comm)
Create empty local mesh data.
Definition: LocalMeshData.cpp:36
void extract_mesh_data(const Mesh &mesh)
Copy data from mesh.
Definition: LocalMeshData.cpp:125
void clear()
Clear data.
Definition: LocalMeshData.h:162
Definition: adapt.h:29
void unpack_vertex_coordinates(const std::vector< double > &values)
Unpack received vertex coordinates.
Definition: LocalMeshData.cpp:295
This class stores mesh data on a local processor corresponding to a portion of a (larger) global mesh...
Definition: LocalMeshData.h:58
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: LocalMeshData.cpp:69
std::map< std::size_t, std::vector< std::pair< std::pair< std::size_t, std::size_t >, std::size_t > > > domain_data
Mesh domain data [dim](line, (cell_index, local_index, value))
Definition: LocalMeshData.h:183
Holder for topology data.
Definition: LocalMeshData.h:130
std::vector< int > cell_partition
Optional process owner for each cell in global_cell_indices.
Definition: LocalMeshData.h:151
std::int64_t num_global_cells
Global number of cells.
Definition: LocalMeshData.h:139
Geometry geometry
Geometry data.
Definition: LocalMeshData.h:127
std::vector< std::size_t > cell_weight
Optional weight for each cell for partitioning.
Definition: LocalMeshData.h:154
Type
Enum for different cell types.
Definition: CellType.h:51
int dim
Topological dimension.
Definition: LocalMeshData.h:136
Topology()
Constructor.
Definition: LocalMeshData.h:133
boost::multi_array< double, 2 > vertex_coordinates
Coordinates for all vertices stored on local processor.
Definition: LocalMeshData.h:107
void receive_mesh_data(const MPI_Comm mpi_comm)
Receive mesh data from main process.
Definition: LocalMeshData.cpp:251
CellType::Type cell_type
Cell type.
Definition: LocalMeshData.h:159
int dim
Geometric dimension.
Definition: LocalMeshData.h:101
boost::multi_array< std::int64_t, 2 > cell_vertices
Global vertex indices for all cells stored on local processor.
Definition: LocalMeshData.h:145
Geometry()
Constructor.
Definition: LocalMeshData.h:98
int num_vertices_per_cell
Number of vertices per cell.
Definition: LocalMeshData.h:142
std::int64_t num_global_vertices
Global number of vertices.
Definition: LocalMeshData.h:104
void check() const
Definition: LocalMeshData.cpp:60
~LocalMeshData()
Destructor.
Definition: LocalMeshData.cpp:55
void clear()
Clear data.
Definition: LocalMeshData.h:114
std::vector< std::int64_t > global_cell_indices
Global cell numbers for all cells stored on local processor.
Definition: LocalMeshData.h:148
void reorder()
Reorder cell data.
Definition: LocalMeshData.cpp:327
Topology topology
Holder for topology data.
Definition: LocalMeshData.h:179
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: LocalMeshData.h:186
std::vector< std::int64_t > vertex_indices
Definition: LocalMeshData.h:111
Holder for geometry data.
Definition: LocalMeshData.h:95
Definition: Mesh.h:82
Definition: MPI.h:76
void broadcast_mesh_data(const MPI_Comm mpi_comm)
Definition: LocalMeshData.cpp:171
void clear()
Clear all data.
Definition: LocalMeshData.cpp:118