DOLFINx
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 <type_traits>
11#include <vector>
12#include <xtensor/xarray.hpp>
13
14namespace dolfinx::fem
15{
16
19template <typename T>
21{
22public:
25 template <
26 typename = std::enable_if_t<
27 std::is_arithmetic_v<
28 T> || std::is_same_v<T, std::complex<float>> || std::is_same_v<T, std::complex<double>>>>
29 Constant(T c) : value({c})
30 {
31 }
32
35 Constant(const xt::xarray<T>& c)
36 : shape(c.shape().begin(), c.shape().end()), value(c.begin(), c.end())
37 {
38 }
39
41 std::vector<int> shape;
42
44 std::vector<T> value;
45};
46} // namespace dolfinx::fem
Constant value which can be attached to a Form. Constants may be scalar (rank 0), vector (rank 1),...
Definition: Constant.h:21
std::vector< int > shape
Shape.
Definition: Constant.h:41
Constant(T c)
Create a rank-0 (scalar-valued) constant.
Definition: Constant.h:29
std::vector< T > value
Values, stored as a row-major flattened array.
Definition: Constant.h:44
Constant(const xt::xarray< T > &c)
Create a rank-d constant.
Definition: Constant.h:35
Finite element method functionality.
Definition: assemble_matrix_impl.h:24