Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.3.0/v0.9.0/cpp
DOLFINx  0.3.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 <dolfinx/graph/scotch.h>
13 #include <functional>
14 #include <memory>
15 #include <vector>
16 #include <xtensor/xbuilder.hpp>
17 #include <xtensor/xtensor.hpp>
18 #include <xtensor/xview.hpp>
19 
20 namespace dolfinx::common
21 {
22 class IndexMap;
23 }
24 
25 namespace dolfinx::fem
26 {
27 class CoordinateElement;
28 }
29 
30 namespace dolfinx::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 
58  // The below should work, but misbehaves with the Intel icpx compiler
59  // xt::view(c, xt::all(), xt::range(0, _dim)) = _x;
60  auto x_view = xt::view(c, xt::all(), xt::range(0, _dim));
61  x_view.assign(_x);
62 
63  std::swap(c, _x);
64  }
65  }
66 
68  Geometry(const Geometry&) = default;
69 
71  Geometry(Geometry&&) = default;
72 
74  ~Geometry() = default;
75 
77  Geometry& operator=(const Geometry&) = delete;
78 
80  Geometry& operator=(Geometry&&) = default;
81 
83  int dim() const;
84 
87 
89  std::shared_ptr<const common::IndexMap> index_map() const;
90 
92  xt::xtensor<double, 2>& x();
93 
95  const xt::xtensor<double, 2>& x() const;
96 
99  const fem::CoordinateElement& cmap() const;
100 
102  const std::vector<std::int64_t>& input_global_indices() const;
103 
104 private:
105  // Geometric dimension
106  int _dim;
107 
108  // Map per cell for extracting coordinate data
110 
111  // IndexMap for geometry 'dofmap'
112  std::shared_ptr<const common::IndexMap> _index_map;
113 
114  // The coordinate element
116 
117  // Coordinates for all points stored as a contiguous array
118  xt::xtensor<double, 2> _x;
119 
120  // Global indices as provided on Geometry creation
121  std::vector<std::int64_t> _input_global_indices;
122 };
123 
127 create_geometry(MPI_Comm comm, const Topology& topology,
128  const fem::CoordinateElement& coordinate_element,
130  const xt::xtensor<double, 2>& x,
131  const std::function<std::vector<int>(
132  const graph::AdjacencyList<std::int32_t>&)>& reorder_fn
133  = nullptr);
134 
135 } // namespace dolfinx::mesh
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:29
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:47
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:37
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
const graph::AdjacencyList< std::int32_t > & dofmap() const
DOF map.
Definition: Geometry.cpp:22
~Geometry()=default
Destructor.
Geometry & operator=(Geometry &&)=default
Move Assignment.
const fem::CoordinateElement & cmap() const
The element that describes the geometry map.
Definition: Geometry.cpp:36
xt::xtensor< double, 2 > & x()
Geometry degrees-of-freedom.
Definition: Geometry.cpp:32
std::shared_ptr< const common::IndexMap > index_map() const
Index map.
Definition: Geometry.cpp:27
const std::vector< std::int64_t > & input_global_indices() const
Global user indices.
Definition: Geometry.cpp:38
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:20
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:56
Miscellaneous classes, functions and types.
Finite element method functionality.
Definition: assemble_matrix_impl.h:23
Mesh data structures and algorithms on meshes.
Definition: DirichletBC.h:20
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, const std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &reorder_fn=nullptr)
Build Geometry.
Definition: Geometry.cpp:45