Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/d3/d32/Constant_8h_source.html
DOLFINx  0.5.1
DOLFINx C++ interface
Constant.h
1 // Copyright (C) 2019-2021 Chris Richardson, Michal Habera and Garth N.
2 // Wells
3 //
4 // This file is part of DOLFINx (https://www.fenicsproject.org)
5 //
6 // SPDX-License-Identifier: LGPL-3.0-or-later
7 
8 #pragma once
9 
10 #include <span>
11 #include <vector>
12 
13 namespace dolfinx::fem
14 {
15 
18 template <typename T>
19 class Constant
20 {
21 public:
24  explicit Constant(T c) : value({c}) {}
25 
28  explicit Constant(std::span<const T> c)
29  : Constant(c, std::vector<std::size_t>{c.size()})
30  {
31  }
32 
36  Constant(std::span<const T> c, std::span<const std::size_t> shape)
37  : value(c.begin(), c.end()), shape(shape.begin(), shape.end())
38  {
39  }
40 
42  std::vector<T> value;
43 
45  std::vector<std::size_t> shape;
46 };
47 } // namespace dolfinx::fem
Constant value which can be attached to a Form. Constants may be scalar (rank 0), vector (rank 1),...
Definition: Constant.h:20
Constant(std::span< const T > c, std::span< const std::size_t > shape)
Create a rank-d constant.
Definition: Constant.h:36
std::vector< std::size_t > shape
Shape.
Definition: Constant.h:45
std::vector< T > value
Values, stored as a row-major flattened array.
Definition: Constant.h:42
Constant(std::span< const T > c)
Create a rank-1 (vector-valued) constant.
Definition: Constant.h:28
Constant(T c)
Create a rank-0 (scalar-valued) constant.
Definition: Constant.h:24
Finite element method functionality.
Definition: assemble_matrix_impl.h:25