14#include <range/v3/range/concepts.hpp>
15#include <range/v3/view/common.hpp>
29 std::vector<std::size_t>
const& exclude_positions)
const = 0;
40 std::size_t n_components)
56template <
typename PROP_VAL_TYPE>
71 PROP_VAL_TYPE&
getComponent(std::size_t tuple_index,
int component)
88 std::vector<std::size_t>
const& exclude_positions)
const override
98 constexpr std::size_t
size()
const {
return data_.size(); }
100 constexpr std::ptrdiff_t
ssize()
const {
return std::ssize(
data_); }
104 constexpr const PROP_VAL_TYPE*
data()
const {
return data_.data(); }
105 constexpr PROP_VAL_TYPE*
data() {
return data_.data(); }
110 constexpr const PROP_VAL_TYPE*
cbegin()
const {
return data_.data(); }
111 constexpr const PROP_VAL_TYPE*
cend()
const
111 constexpr const PROP_VAL_TYPE*
cend()
const {
…}
116 constexpr const PROP_VAL_TYPE*
end()
const {
return cend(); }
120 if constexpr (std::is_same_v<PROP_VAL_TYPE, bool>)
122 static_assert(!std::is_same_v<PROP_VAL_TYPE, bool>,
123 "PropertyVector<bool>::operator[] cannot be "
124 "instantiated for booleans.");
131 constexpr PROP_VAL_TYPE
const&
operator[](std::size_t
const pos)
const
131 constexpr PROP_VAL_TYPE
const&
operator[](std::size_t
const pos)
const {
…}
137 constexpr void resize(std::size_t
const size,
const PROP_VAL_TYPE& value)
137 constexpr void resize(std::size_t
const size,
const PROP_VAL_TYPE& value) {
…}
142 template <
typename R>
143 requires std::ranges::input_range<R> &&
144 std::convertible_to<std::ranges::range_value_t<R>,
148#if __cpp_lib_containers_ranges >= 202202L
149 data_.assign_range(r);
151 if constexpr (ranges::common_range<R>)
153 data_.assign(r.begin(), r.end());
157 data_.assign(ranges::views::common(r).
begin(),
158 ranges::views::common(r).
end());
165 data_.push_back(value);
179 std::size_t n_components)
192 std::string
const& property_name,
194 std::size_t n_components)
196 data_(n_property_values * n_components)
222 for (
auto v : _values)
232 return _values[_item2group_mapping[id]];
235 T*&
operator[](std::size_t
id) {
return _values[_item2group_mapping[id]]; }
239 if (_n_components != 1)
242 "Single-component version of initPropertyValue() is called "
243 "for a multi-components PropertyVector<T*>");
247 _values[group_id] = p;
252 if (_n_components !=
static_cast<int>(values.size()))
255 "The size of provided values in initPropertyValue() is "
256 "not same as the number of components in PropertyVector<T*>");
259 auto* p =
new T[values.size()];
260 for (
unsigned i = 0; i < values.size(); i++)
264 _values[group_id] = p;
271 std::size_t
size()
const {
return _n_components * getNumberOfTuples(); }
274 std::vector<std::size_t>
const& exclude_positions)
const override
278 _values.size() / _n_components,
280 _property_name, _mesh_item_type, _n_components));
282 for (std::size_t j(0); j < _values.size(); j++)
284 std::vector<T> values(_values[j], _values[j] + _n_components);
285 t->initPropertyValue(j, values);
293 assert(component < _n_components);
294 assert(tuple_index < getNumberOfTuples());
296 const double* p = this->operator[](tuple_index);
300 "No data found in the property vector {:s} "
301 "for the tuple index {:d} and component {:d}",
302 getPropertyName(), tuple_index, component);
320 std::vector<std::size_t>
322 std::string
const& property_name,
324 std::size_t n_components)
326 _item2group_mapping(std::move(item2group_mapping)),
327 _values(n_prop_groups * n_components)
338static_assert(ranges::contiguous_range<PropertyVector<double>>);
339static_assert(ranges::sized_range<PropertyVector<double>>);
Definition of mesh-related Enumerations.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
virtual PropertyVectorBase * clone(std::vector< std::size_t > const &exclude_positions) const =0
MeshItemType getMeshItemType() const
MeshItemType const _mesh_item_type
PropertyVectorBase(std::string property_name, MeshItemType mesh_item_type, std::size_t n_components)
virtual ~PropertyVectorBase()=default
std::string const _property_name
int getNumberOfGlobalComponents() const
std::string const & getPropertyName() const
T const & getComponent(std::size_t tuple_index, int component) const
Returns the value for the given component stored in the given tuple.
PropertyVectorBase * clone(std::vector< std::size_t > const &exclude_positions) const override
std::vector< T * > _values
std::vector< std::size_t > _item2group_mapping
T *& operator[](std::size_t id)
void initPropertyValue(std::size_t group_id, std::vector< T > const &values)
PropertyVector(std::size_t n_prop_groups, std::vector< std::size_t > item2group_mapping, std::string const &property_name, MeshItemType mesh_item_type, std::size_t n_components)
The constructor taking meta information for the data.
T *const & operator[](std::size_t id) const
~PropertyVector() override
Destructor ensures the deletion of the heap-constructed objects.
void initPropertyValue(std::size_t group_id, T const &value)
std::size_t getNumberOfTuples() const
constexpr std::size_t size() const
constexpr PROP_VAL_TYPE & operator[](std::size_t const pos)
PROP_VAL_TYPE const & getComponent(std::size_t tuple_index, int component) const
Returns the value for the given component stored in the given tuple.
constexpr bool empty() const
PROP_VAL_TYPE & getComponent(std::size_t tuple_index, int component)
Returns the value for the given component stored in the given tuple.
constexpr PROP_VAL_TYPE * end()
constexpr void push_back(const PROP_VAL_TYPE &value)
constexpr const PROP_VAL_TYPE * cend() const
constexpr PROP_VAL_TYPE * data()
constexpr PROP_VAL_TYPE const & operator[](std::size_t const pos) const
constexpr std::size_t getNumberOfTuples() const
PropertyVector(std::string const &property_name, MeshItemType mesh_item_type, std::size_t n_components)
The constructor taking meta information for the data.
constexpr void resize(std::size_t const size, const PROP_VAL_TYPE &value)
constexpr const PROP_VAL_TYPE * end() const
PropertyVectorBase * clone(std::vector< std::size_t > const &exclude_positions) const override
constexpr const PROP_VAL_TYPE * data() const
PropertyVector(std::size_t n_property_values, std::string const &property_name, MeshItemType mesh_item_type, std::size_t n_components)
The constructor taking meta information for the data.
constexpr const PROP_VAL_TYPE * begin() const
constexpr void resize(std::size_t const size)
constexpr void assign(R &&r)
constexpr const PROP_VAL_TYPE * cbegin() const
std::vector< PROP_VAL_TYPE > data_
constexpr std::ptrdiff_t ssize() const
constexpr PROP_VAL_TYPE * begin()
std::vector< T > excludeObjectCopy(std::vector< T > const &src_vec, std::vector< std::size_t > const &exclude_positions)