1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// Copyright (C) 2019-2023 Chris Richardson, Michal Habera and Garth N.
// Wells
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once
#include "dolfinx/common/types.h"
#include <span>
#include <vector>
namespace dolfinx::fem
{
/// @brief Constant (in space) value which can be attached to a Form.
///
/// Constants may be scalar (rank 0), vector (rank 1), or tensor-valued.
/// @tparam T Scalar type of the Constant.
template <dolfinx::scalar T>
class Constant
{
public:
/// Field type
using value_type = T;
/// @brief Create a rank-0 (scalar-valued) constant.
/// @param[in] c Value of the constant.
explicit Constant(value_type c) : value({c}) {}
/// @brief Create a rank-1 (vector-valued) constant.
/// @param[in] c Value of the constant.
explicit Constant(std::span<const value_type> c)
: Constant(c, std::vector<std::size_t>{c.size()})
{
}
/// @brief Create a rank-d constant
/// @param[in] c Value of the Constant (row-majors storage)
/// @param[in] shape Shape of the Constant
Constant(std::span<const value_type> c, std::span<const std::size_t> shape)
: value(c.begin(), c.end()), shape(shape.begin(), shape.end())
{
}
/// Values, stored as a row-major flattened array
std::vector<value_type> value;
/// Shape
std::vector<std::size_t> shape;
};
} // namespace dolfinx::fem
|