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.8.0
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:
26 using value_type = T;
27
30 explicit Constant(value_type c) : value({c}) {}
31
34 explicit Constant(std::span<const value_type> c)
35 : Constant(c, std::vector<std::size_t>{c.size()})
36 {
37 }
38
42 Constant(std::span<const value_type> c, std::span<const std::size_t> shape)
43 : value(c.begin(), c.end()), shape(shape.begin(), shape.end())
44 {
45 }
46
48 std::vector<value_type> value;
49
51 std::vector<std::size_t> shape;
52};
53} // namespace dolfinx::fem
Constant value which can be attached to a Form.
Definition Constant.h:23
Constant(std::span< const value_type > c, std::span< const std::size_t > shape)
Create a rank-d constant.
Definition Constant.h:42
Constant(value_type c)
Create a rank-0 (scalar-valued) constant.
Definition Constant.h:30
Constant(std::span< const value_type > c)
Create a rank-1 (vector-valued) constant.
Definition Constant.h:34
std::vector< value_type > value
Values, stored as a row-major flattened array.
Definition Constant.h:48
std::vector< std::size_t > shape
Shape.
Definition Constant.h:51
T value_type
Field type.
Definition Constant.h:26
Finite element method functionality.
Definition assemble_matrix_impl.h:26