DOLFIN-X
DOLFIN-X C++ interface
Geometry.h
1 // Copyright (C) 2006-2020 Anders Logg and Garth N. Wells
2 //
3 // This file is part of DOLFINX (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 
7 #pragma once
8 
9 #include <dolfinx/common/MPI.h>
10 #include <dolfinx/common/array2d.h>
11 #include <dolfinx/fem/CoordinateElement.h>
12 #include <dolfinx/graph/AdjacencyList.h>
13 #include <memory>
14 #include <vector>
15 
16 namespace dolfinx
17 {
18 namespace common
19 {
20 class IndexMap;
21 }
22 
23 namespace fem
24 {
25 class CoordinateElement;
26 } // namespace fem
27 
28 namespace mesh
29 {
30 class Topology;
31 
33 
34 class Geometry
35 {
36 public:
38  template <typename AdjacencyList32, typename Array, typename Vector64>
39  Geometry(const std::shared_ptr<const common::IndexMap>& index_map,
40  AdjacencyList32&& dofmap, const fem::CoordinateElement& element,
41  Array&& x, Vector64&& input_global_indices)
42  : _dim(x.shape[1]), _dofmap(std::forward<AdjacencyList32>(dofmap)),
43  _index_map(index_map), _cmap(element), _x(std::forward<Array>(x)),
44  _input_global_indices(std::forward<Vector64>(input_global_indices))
45  {
46  assert(_x.shape[1] > 0 and _x.shape[1] <= 3);
47  if (_x.shape[0] != _input_global_indices.size())
48  throw std::runtime_error("Size mis-match");
49 
50  // Make all geometry 3D
51  if (_dim != 3)
52  {
53  array2d<double> coords(_x.shape[0], 3, 0.0);
54  for (std::size_t i = 0; i < _x.shape[0]; ++i)
55  for (std::size_t j = 0; j < _x.shape[1]; ++j)
56  coords(i, j) = _x(i, j);
57  std::swap(coords, _x);
58  }
59  }
60 
62  Geometry(const Geometry&) = default;
63 
65  Geometry(Geometry&&) = default;
66 
68  ~Geometry() = default;
69 
71  Geometry& operator=(const Geometry&) = delete;
72 
74  Geometry& operator=(Geometry&&) = default;
75 
77  int dim() const;
78 
81 
83  std::shared_ptr<const common::IndexMap> index_map() const;
84 
86  array2d<double>& x();
87 
89  const array2d<double>& x() const;
90 
93  const fem::CoordinateElement& cmap() const;
94 
96  const std::vector<std::int64_t>& input_global_indices() const;
97 
98 private:
99  // Geometric dimension
100  int _dim;
101 
102  // Map per cell for extracting coordinate data
104 
105  // IndexMap for geometry 'dofmap'
106  std::shared_ptr<const common::IndexMap> _index_map;
107 
108  // The coordinate element
110 
111  // Coordinates for all points stored as a contiguous array
112  array2d<double> _x;
113 
114  // Global indices as provided on Geometry creation
115  std::vector<std::int64_t> _input_global_indices;
116 };
117 
120 mesh::Geometry create_geometry(MPI_Comm comm, const Topology& topology,
121  const fem::CoordinateElement& coordinate_element,
123  const array2d<double>& x);
124 
125 } // namespace mesh
126 } // namespace dolfinx
This class provides a dynamic 2-dimensional row-wise array data structure.
Definition: array2d.h:21
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:31
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:68
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:35
Geometry(const std::shared_ptr< const common::IndexMap > &index_map, AdjacencyList32 &&dofmap, const fem::CoordinateElement &element, Array &&x, Vector64 &&input_global_indices)
Constructor.
Definition: Geometry.h:39
const graph::AdjacencyList< std::int32_t > & dofmap() const
DOF map.
Definition: Geometry.cpp:21
array2d< double > & x()
Geometry degrees-of-freedom.
Definition: Geometry.cpp:31
~Geometry()=default
Destructor.
Geometry & operator=(Geometry &&)=default
Move Assignment.
const fem::CoordinateElement & cmap() const
The element that describes the geometry map.
Definition: Geometry.cpp:35
std::shared_ptr< const common::IndexMap > index_map() const
Index map.
Definition: Geometry.cpp:26
const std::vector< std::int64_t > & input_global_indices() const
Global user indices.
Definition: Geometry.cpp:37
Geometry & operator=(const Geometry &)=delete
Copy Assignment.
Geometry(Geometry &&)=default
Move constructor.
Geometry(const Geometry &)=default
Copy constructor.
int dim() const
Return Euclidean dimension of coordinate system.
Definition: Geometry.cpp:19
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:57
mesh::Geometry create_geometry(MPI_Comm comm, const Topology &topology, const fem::CoordinateElement &coordinate_element, const graph::AdjacencyList< std::int64_t > &cells, const array2d< double > &x)
Build Geometry FIXME: document.
Definition: Geometry.cpp:45