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
evaluate.h
1 // Copyright (C) 2020 Jack S. Hale
2 //
3 // This file is part of DOLFINx (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 //
7 
8 #pragma once
9 
10 #include <dolfinx/common/array2d.h>
11 #include <dolfinx/fem/utils.h>
12 #include <dolfinx/mesh/Mesh.h>
13 #include <vector>
14 #include <xtl/xspan.hpp>
15 
16 namespace dolfinx::fem
17 {
18 
19 template <typename T>
20 class Expression;
21 
27 template <typename T>
28 void eval(array2d<T>& values, const fem::Expression<T>& e,
29  const xtl::span<const std::int32_t>& active_cells)
30 {
31  // Extract data from Expression
32  auto mesh = e.mesh();
33  assert(mesh);
34 
35  // Prepare coefficients
37 
38  // Prepare constants
39  const std::vector<T> constant_values = dolfinx::fem::pack_constants(e);
40 
41  const auto& fn = e.get_tabulate_expression();
42 
43  // Prepare cell geometry
45  = mesh->geometry().dofmap();
46  const fem::CoordinateElement& cmap = mesh->geometry().cmap();
47 
48  // Prepate cell permutation info
49  mesh->topology_mutable().create_entity_permutations();
50  const std::vector<std::uint32_t>& cell_info
51  = mesh->topology().get_cell_permutation_info();
52 
53  // FIXME: Add proper interface for num coordinate dofs
54  const std::size_t num_dofs_g = x_dofmap.num_links(0);
55  const xt::xtensor<double, 2>& x_g = mesh->geometry().x();
56 
57  // Create data structures used in evaluation
58  const std::size_t gdim = mesh->geometry().dim();
59  std::vector<double> coordinate_dofs(num_dofs_g * gdim);
60 
61  // Iterate over cells and 'assemble' into values
62  std::vector<T> values_e(e.num_points() * e.value_size(), 0);
63  for (std::size_t c = 0; c < active_cells.size(); ++c)
64  {
65  const std::int32_t cell = active_cells[c];
66 
67  auto x_dofs = x_dofmap.links(c);
68  for (std::size_t i = 0; i < x_dofs.size(); ++i)
69  {
70  std::copy_n(xt::row(x_g, x_dofs[i]).cbegin(), gdim,
71  std::next(coordinate_dofs.begin(), i * gdim));
72  }
73 
74  auto coeff_cell = coeffs.row(cell);
75  std::fill(values_e.begin(), values_e.end(), 0.0);
76  fn(values_e.data(), coeff_cell.data(), constant_values.data(),
77  coordinate_dofs.data());
78 
79  for (std::size_t j = 0; j < values_e.size(); ++j)
80  values(c, j) = values_e[j];
81  }
82 }
83 
84 } // namespace dolfinx::fem
dolfinx::fem::eval
void eval(array2d< T > &values, const fem::Expression< T > &e, const xtl::span< const std::int32_t > &active_cells)
Evaluate a UFC expression.
Definition: evaluate.h:28
dolfinx::graph::AdjacencyList::num_links
int num_links(int node) const
Number of connections for given node.
Definition: AdjacencyList.h:120
dolfinx::fem::Expression
Represents a mathematical expression evaluated at a pre-defined set of points on the reference cell....
Definition: evaluate.h:20
dolfinx::fem::Expression::mesh
std::shared_ptr< const mesh::Mesh > mesh() const
Get mesh.
Definition: Expression.h:121
dolfinx::fem::pack_constants
std::vector< typename U::scalar_type > pack_constants(const U &u)
Pack constants of u of generic type U ready for assembly.
Definition: utils.h:431
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::fem::pack_coefficients
array2d< typename U::scalar_type > pack_coefficients(const U &u)
Pack coefficients of u of generic type U ready for assembly.
Definition: utils.h:376
dolfinx::fem::Expression::get_tabulate_expression
const std::function< void(T *, const T *, const T *, const double *)> & get_tabulate_expression() const
Get function for tabulate_expression.
Definition: Expression.h:105
dolfinx::fem::Expression::num_points
const std::size_t num_points() const
Get number of points.
Definition: Expression.h:133
dolfinx::fem::Expression::value_size
const std::size_t value_size() const
Get value size.
Definition: Expression.h:129
dolfinx::fem
Finite element method functionality.
Definition: assemble_matrix_impl.h:22
dolfinx::array2d
This class provides a dynamic 2-dimensional row-wise array data structure.
Definition: array2d.h:20
dolfinx::array2d::row
constexpr xtl::span< value_type > row(size_type i)
Access a row in the array.
Definition: array2d.h:116
dolfinx::graph::AdjacencyList::links
xtl::span< T > links(int node)
Get the links (edges) for given node.
Definition: AdjacencyList.h:130
dolfinx::fem::CoordinateElement
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:30