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.7.3
DOLFINx C++ interface
Loading...
Searching...
No Matches
Constant.h
1// Copyright (C) 2019-2023 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 "dolfinx/common/types.h"
11#include <span>
12#include <vector>
13
14namespace dolfinx::fem
15{
16
21template <dolfinx::scalar T>
23{
24public:
27 explicit Constant(T c) : value({c}) {}
28
31 explicit Constant(std::span<const T> c)
32 : Constant(c, std::vector<std::size_t>{c.size()})
33 {
34 }
35
39 Constant(std::span<const T> c, std::span<const std::size_t> shape)
40 : value(c.begin(), c.end()), shape(shape.begin(), shape.end())
41 {
42 }
43
45 std::vector<T> value;
46
48 std::vector<std::size_t> shape;
49};
50} // namespace dolfinx::fem
Constant value which can be attached to a Form.
Definition Constant.h:23
Constant(std::span< const T > c, std::span< const std::size_t > shape)
Create a rank-d constant.
Definition Constant.h:39
std::vector< std::size_t > shape
Shape.
Definition Constant.h:48
std::vector< T > value
Values, stored as a row-major flattened array.
Definition Constant.h:45
Constant(std::span< const T > c)
Create a rank-1 (vector-valued) constant.
Definition Constant.h:31
Constant(T c)
Create a rank-0 (scalar-valued) constant.
Definition Constant.h:27
Finite element method functionality.
Definition assemble_matrix_impl.h:25