9 #include <dolfinx/common/array2d.h> 
   10 #include <dolfinx/mesh/Mesh.h> 
   14 #include <xtensor/xarray.hpp> 
   15 #include <xtl/xspan.hpp> 
   48       const std::function<
void(T*, 
const T*, 
const T*, 
const double*)> fn,
 
   63   const std::vector<std::shared_ptr<const fem::Function<T>>>&
 
   74     std::vector<int> n{0};
 
   75     for (
const auto& c : _coefficients)
 
   78         throw std::runtime_error(
"Not all form coefficients have been set.");
 
   79       n.push_back(n.back() + c->function_space()->element()->space_dimension());
 
   90   void eval(
const xtl::span<const std::int32_t>& active_cells, U& values)
 const 
   92     static_assert(std::is_same<T, typename U::value_type>::value,
 
   93                   "Expression and array types must be the same");
 
  106         = _mesh->geometry().dofmap();
 
  110     const std::size_t num_dofs_g = x_dofmap.
num_links(0);
 
  111     const xt::xtensor<double, 2>& x_g = _mesh->geometry().x();
 
  114     std::vector<double> coordinate_dofs(3 * num_dofs_g);
 
  118     for (std::size_t c = 0; c < active_cells.size(); ++c)
 
  120       const std::int32_t cell = active_cells[c];
 
  122       auto x_dofs = x_dofmap.
links(cell);
 
  123       for (std::size_t i = 0; i < x_dofs.size(); ++i)
 
  125         std::copy_n(xt::row(x_g, x_dofs[i]).cbegin(), 3,
 
  126                     std::next(coordinate_dofs.begin(), 3 * i));
 
  129       auto coeff_cell = coeffs.
row(cell);
 
  130       std::fill(values_e.begin(), values_e.end(), 0.0);
 
  131       fn(values_e.data(), coeff_cell.data(), constant_data.data(),
 
  132          coordinate_dofs.data());
 
  134       for (std::size_t j = 0; j < values_e.size(); ++j)
 
  135         values(c, j) = values_e[j];
 
  141   const std::function<void(T*, 
const T*, 
const T*, 
const double*)>&
 
  151   const std::vector<std::shared_ptr<const fem::Constant<T>>>& 
constants()
 const 
  158   std::shared_ptr<const mesh::Mesh> 
mesh()
 const { 
return _mesh; }
 
  177   std::vector<std::shared_ptr<const fem::Function<T>>> _coefficients;
 
  180   std::vector<std::shared_ptr<const fem::Constant<T>>> _constants;
 
  183   std::function<void(T*, 
const T*, 
const T*, 
const double*)> _fn;
 
  189   std::shared_ptr<const mesh::Mesh> _mesh;
 
  192   std::size_t _value_size;
 
This class provides a dynamic 2-dimensional row-wise array data structure.
Definition: array2d.h:21
 
constexpr xtl::span< value_type > row(size_type i)
Access a row in the array.
Definition: array2d.h:114
 
A constant value which can be attached to a Form. Constants may be scalar (rank 0),...
Definition: Constant.h:19
 
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:29
 
Represents a mathematical expression evaluated at a pre-defined set of points on the reference cell....
Definition: Expression.h:33
 
void eval(const xtl::span< const std::int32_t > &active_cells, U &values) const
Evaluate the expression on cells.
Definition: Expression.h:90
 
const std::size_t value_size() const
Get value size.
Definition: Expression.h:166
 
Expression(const std::vector< std::shared_ptr< const fem::Function< T >>> &coefficients, const std::vector< std::shared_ptr< const fem::Constant< T >>> &constants, const std::shared_ptr< const mesh::Mesh > &mesh, const array2d< double > &X, const std::function< void(T *, const T *, const T *, const double *)> fn, const std::size_t value_size)
Create an Expression.
Definition: Expression.h:44
 
const std::vector< std::shared_ptr< const fem::Constant< T > > > & constants() const
Access constants.
Definition: Expression.h:151
 
Expression(Expression &&form)=default
Move constructor.
 
const std::vector< std::shared_ptr< const fem::Function< T > > > & coefficients() const
Access coefficients.
Definition: Expression.h:64
 
std::shared_ptr< const mesh::Mesh > mesh() const
Get mesh.
Definition: Expression.h:158
 
const array2d< double > & x() const
Get evaluation points on reference cell.
Definition: Expression.h:162
 
std::vector< int > coefficient_offsets() const
Offset for each coefficient expansion array on a cell. Used to pack data for multiple coefficients in...
Definition: Expression.h:72
 
virtual ~Expression()=default
Destructor.
 
const std::size_t num_points() const
Get number of points.
Definition: Expression.h:170
 
const std::function< void(T *, const T *, const T *, const double *)> & get_tabulate_expression() const
Get function for tabulate_expression.
Definition: Expression.h:142
 
T scalar_type
Scalar type (T).
Definition: Expression.h:173
 
This class represents a function  in a finite element function space , given by.
Definition: Function.h:47
 
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:47
 
xtl::span< T > links(int node)
Get the links (edges) for given node.
Definition: AdjacencyList.h:130
 
int num_links(int node) const
Number of connections for given node.
Definition: AdjacencyList.h:120
 
Finite element method functionality.
Definition: assemble_matrix_impl.h:23
 
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:508
 
array2d< typename U::scalar_type > pack_coefficients(const U &u)
Pack coefficients of u of generic type U ready for assembly.
Definition: utils.h:423