Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.1.0/v0.9.0/cpp
DOLFINx  0.1.0
DOLFINx 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/fem/CoordinateElement.h>
11 #include <dolfinx/graph/AdjacencyList.h>
12 #include <memory>
13 #include <vector>
14 #include <xtensor/xbuilder.hpp>
15 #include <xtensor/xtensor.hpp>
16 #include <xtensor/xview.hpp>
17 
18 namespace dolfinx
19 {
20 namespace common
21 {
22 class IndexMap;
23 }
24 
25 namespace fem
26 {
27 class CoordinateElement;
28 } // namespace fem
29 
30 namespace mesh
31 {
32 class Topology;
33 
35 
36 class Geometry
37 {
38 public:
40  template <typename AdjacencyList32, typename Array, typename Vector64>
41  Geometry(const std::shared_ptr<const common::IndexMap>& index_map,
42  AdjacencyList32&& dofmap, const fem::CoordinateElement& element,
43  Array&& x, Vector64&& input_global_indices)
44  : _dim(x.shape(1)), _dofmap(std::forward<AdjacencyList32>(dofmap)),
45  _index_map(index_map), _cmap(element), _x(std::forward<Array>(x)),
46  _input_global_indices(std::forward<Vector64>(input_global_indices))
47  {
48  assert(_x.shape(1) > 0 and _x.shape(1) <= 3);
49  if (_x.shape(0) != _input_global_indices.size())
50  throw std::runtime_error("Size mis-match");
51 
52  // Make all geometry 3D
53  if (_dim != 3)
54  {
55  xt::xtensor<double, 2> c
56  = xt::zeros<double>({_x.shape(0), static_cast<std::size_t>(3)});
57  xt::view(c, xt::all(), xt::range(0, _dim)) = _x;
58  std::swap(c, _x);
59  }
60  }
61 
63  Geometry(const Geometry&) = default;
64 
66  Geometry(Geometry&&) = default;
67 
69  ~Geometry() = default;
70 
72  Geometry& operator=(const Geometry&) = delete;
73 
75  Geometry& operator=(Geometry&&) = default;
76 
78  int dim() const;
79 
82 
84  std::shared_ptr<const common::IndexMap> index_map() const;
85 
87  xt::xtensor<double, 2>& x();
88 
90  const xt::xtensor<double, 2>& x() const;
91 
94  const fem::CoordinateElement& cmap() const;
95 
97  const std::vector<std::int64_t>& input_global_indices() const;
98 
99 private:
100  // Geometric dimension
101  int _dim;
102 
103  // Map per cell for extracting coordinate data
105 
106  // IndexMap for geometry 'dofmap'
107  std::shared_ptr<const common::IndexMap> _index_map;
108 
109  // The coordinate element
111 
112  // Coordinates for all points stored as a contiguous array
113  xt::xtensor<double, 2> _x;
114 
115  // Global indices as provided on Geometry creation
116  std::vector<std::int64_t> _input_global_indices;
117 };
118 
121 mesh::Geometry create_geometry(MPI_Comm comm, const Topology& topology,
122  const fem::CoordinateElement& coordinate_element,
124  const xt::xtensor<double, 2>& x);
125 
126 } // namespace mesh
127 } // namespace dolfinx
dolfinx::mesh::Geometry::dofmap
const graph::AdjacencyList< std::int32_t > & dofmap() const
DOF map.
Definition: Geometry.cpp:21
dolfinx::mesh::Geometry::x
xt::xtensor< double, 2 > & x()
Geometry degrees-of-freedom.
Definition: Geometry.cpp:31
dolfinx::mesh::Geometry::cmap
const fem::CoordinateElement & cmap() const
The element that describes the geometry map.
Definition: Geometry.cpp:35
dolfinx::graph::AdjacencyList
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:46
dolfinx::mesh::Geometry::Geometry
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:41
dolfinx::mesh::create_geometry
mesh::Geometry create_geometry(MPI_Comm comm, const Topology &topology, const fem::CoordinateElement &coordinate_element, const graph::AdjacencyList< std::int64_t > &cells, const xt::xtensor< double, 2 > &x)
Build Geometry FIXME: document.
Definition: Geometry.cpp:45
dolfinx::mesh::Geometry::operator=
Geometry & operator=(const Geometry &)=delete
Copy Assignment.
dolfinx::mesh::Geometry::dim
int dim() const
Return Euclidean dimension of coordinate system.
Definition: Geometry.cpp:19
dolfinx::mesh::Geometry::index_map
std::shared_ptr< const common::IndexMap > index_map() const
Index map.
Definition: Geometry.cpp:26
dolfinx::mesh::Geometry::~Geometry
~Geometry()=default
Destructor.
dolfinx::mesh::Geometry::input_global_indices
const std::vector< std::int64_t > & input_global_indices() const
Global user indices.
Definition: Geometry.cpp:37
dolfinx::mesh::Geometry
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:36
dolfinx::fem::CoordinateElement
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:30