OGS
MeshLib::PropertyVector< T * > Class Template Reference

Detailed Description

template<typename T>
class MeshLib::PropertyVector< T * >

Class template PropertyVector is a std::vector with template parameter T, where T is a pointer type. The behaviour has changed for the constructor, destructor and the operator[]. The user has to provide the size and an item to group mapping for construction. The destructor takes care to delete the entries of the vector. The operator[] uses an item-to-group property map to access the correct property.

Template Parameters
Tpointer type, the type the type points to is typical a scalar, a vector or a matrix type

Definition at line 210 of file PropertyVector.h.

#include <PropertyVector.h>

Inheritance diagram for MeshLib::PropertyVector< T * >:
[legend]
Collaboration diagram for MeshLib::PropertyVector< T * >:
[legend]

Public Types

using value_type

Public Member Functions

 ~PropertyVector () override
 Destructor ensures the deletion of the heap-constructed objects.
T *const & operator[] (std::size_t id) const
T *& operator[] (std::size_t id)
void initPropertyValue (std::size_t group_id, T const &value)
void initPropertyValue (std::size_t group_id, std::vector< T > const &values)
std::size_t getNumberOfTuples () const
std::size_t size () const
PropertyVectorBaseclone (std::vector< std::size_t > const &exclude_positions) const override
T const & getComponent (std::size_t tuple_index, int component) const
 Returns the value for the given component stored in the given tuple.
constexpr std::ptrdiff_t ssize () const
constexpr const T ** data () const
constexpr T ** begin ()
constexpr T ** end ()
constexpr const T ** cbegin () const
constexpr const T ** cend () const
constexpr void resize (std::size_t const size)
constexpr void assign (R &&r)
constexpr void push_back (const T *&value)
constexpr void clear ()
constexpr bool empty () const
Public Member Functions inherited from MeshLib::PropertyVectorBase
virtual ~PropertyVectorBase ()=default
MeshItemType getMeshItemType () const
std::string const & getPropertyName () const
int getNumberOfGlobalComponents () const

Protected Member Functions

 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.
Protected Member Functions inherited from MeshLib::PropertyVectorBase
 PropertyVectorBase (std::string property_name, MeshItemType mesh_item_type, std::size_t n_components)

Private Member Functions

T * at (std::size_t)

Private Attributes

std::vector< std::size_t > _item2group_mapping
std::vector< T * > _values
std::vector< T * > data_

Friends

class Properties

Additional Inherited Members

Protected Attributes inherited from MeshLib::PropertyVectorBase
int const _n_components
MeshItemType const _mesh_item_type
std::string const _property_name

Member Typedef Documentation

◆ value_type

using MeshLib::PropertyVector< T * >::value_type

Definition at line 58 of file PropertyVector.h.

Constructor & Destructor Documentation

◆ ~PropertyVector()

template<typename T>
MeshLib::PropertyVector< T * >::~PropertyVector ( )
inlineoverride

Destructor ensures the deletion of the heap-constructed objects.

Definition at line 216 of file PropertyVector.h.

217 {
218 for (auto v : _values)
219 {
220 delete[] v;
221 }
222 }

References _values.

◆ PropertyVector()

template<typename T>
MeshLib::PropertyVector< T * >::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 )
inlineprotected

The constructor taking meta information for the data.

Parameters
n_prop_groupsnumber of different property values
item2group_mappingClass Mesh has a mapping from the mesh items (Node or Element) to an index (position in the data structure). The vector item2group_mapping must have the same number of entries as the above mapping and the values have to be in the range \([0, \text{n\_prop\_groups})\).
property_namea string describing the property
mesh_item_typethe values of the property are either assigned to nodes or cells (see enumeration MeshItemType)
n_componentsthe number of elements of a tuple

Definition at line 315 of file PropertyVector.h.

324 {
325 }
PropertyVectorBase(std::string property_name, MeshItemType mesh_item_type, std::size_t n_components)
std::vector< std::size_t > _item2group_mapping

References MeshLib::PropertyVectorBase::PropertyVectorBase(), _item2group_mapping, and _values.

Referenced by clone().

Member Function Documentation

◆ assign()

void MeshLib::PropertyVector< T * >::assign ( R && r)
inlineconstexpr

Definition at line 142 of file PropertyVector.h.

143 {
144#if __cpp_lib_containers_ranges >= 202202L
145 data_.assign_range(r);
146#else
147 if constexpr (ranges::common_range<R>)
148 {
149 data_.assign(r.begin(), r.end());
150 }
151 else
152 {
155 }
156#endif
157 }
constexpr PROP_VAL_TYPE * begin()
constexpr PROP_VAL_TYPE * end()

◆ at()

template<typename T>
T * MeshLib::PropertyVector< T * >::at ( std::size_t )
private

◆ begin()

T * * MeshLib::PropertyVector< T * >::begin ( )
inlineconstexpr

Definition at line 103 of file PropertyVector.h.

103{ return data_.data(); }

◆ cbegin()

const T * * MeshLib::PropertyVector< T * >::cbegin ( ) const
inlineconstexpr

Definition at line 106 of file PropertyVector.h.

106{ return data_.data(); }

◆ cend()

const T * * MeshLib::PropertyVector< T * >::cend ( ) const
inlineconstexpr

Definition at line 107 of file PropertyVector.h.

108 {
109 return data_.data() + data_.size();
110 }

◆ clear()

void MeshLib::PropertyVector< T * >::clear ( )
inlineconstexpr

Definition at line 164 of file PropertyVector.h.

164{ data_.clear(); }

◆ clone()

template<typename T>
PropertyVectorBase * MeshLib::PropertyVector< T * >::clone ( std::vector< std::size_t > const & exclude_positions) const
inlineoverridevirtual

◆ data()

const T * * MeshLib::PropertyVector< T * >::data ( ) const
inlineconstexpr

Definition at line 100 of file PropertyVector.h.

100{ return data_.data(); }

◆ empty()

bool MeshLib::PropertyVector< T * >::empty ( ) const
inlineconstexpr

Definition at line 165 of file PropertyVector.h.

165{ return data_.empty(); }

◆ end()

T * * MeshLib::PropertyVector< T * >::end ( )
inlineconstexpr

Definition at line 104 of file PropertyVector.h.

104{ return data_.data() + data_.size(); }

◆ getComponent()

template<typename T>
T const & MeshLib::PropertyVector< T * >::getComponent ( std::size_t tuple_index,
int component ) const
inline

Returns the value for the given component stored in the given tuple.

Definition at line 287 of file PropertyVector.h.

288 {
291
292 const double* p = this->operator[](tuple_index);
293 if (p == nullptr)
294 {
295 OGS_FATAL(
296 "No data found in the property vector {:s} "
297 "for the tuple index {:d} and component {:d}",
299 }
300 return p[component];
301 }
#define OGS_FATAL(...)
Definition Error.h:19
std::string const & getPropertyName() const
T *const & operator[](std::size_t id) const
std::size_t getNumberOfTuples() const

References MeshLib::PropertyVectorBase::_n_components, getNumberOfTuples(), MeshLib::PropertyVectorBase::getPropertyName(), OGS_FATAL, and operator[]().

◆ getNumberOfTuples()

template<typename T>
std::size_t MeshLib::PropertyVector< T * >::getNumberOfTuples ( ) const
inline

Definition at line 263 of file PropertyVector.h.

263{ return _item2group_mapping.size(); }

References _item2group_mapping.

Referenced by getComponent(), and size().

◆ initPropertyValue() [1/2]

template<typename T>
void MeshLib::PropertyVector< T * >::initPropertyValue ( std::size_t group_id,
std::vector< T > const & values )
inline

Definition at line 246 of file PropertyVector.h.

247 {
248 if (_n_components != static_cast<int>(values.size()))
249 {
250 OGS_FATAL(
251 "The size of provided values in initPropertyValue() is "
252 "not same as the number of components in PropertyVector<T*>");
253 }
254
255 auto* p = new T[values.size()];
256 for (unsigned i = 0; i < values.size(); i++)
257 {
258 p[i] = values[i];
259 }
260 _values[group_id] = p;
261 }
constexpr std::size_t size() const

References MeshLib::PropertyVectorBase::_n_components, _values, and OGS_FATAL.

◆ initPropertyValue() [2/2]

template<typename T>
void MeshLib::PropertyVector< T * >::initPropertyValue ( std::size_t group_id,
T const & value )
inline

Definition at line 233 of file PropertyVector.h.

234 {
235 if (_n_components != 1)
236 {
237 OGS_FATAL(
238 "Single-component version of initPropertyValue() is called "
239 "for a multi-components PropertyVector<T*>");
240 }
241 auto* p = new T[1];
242 p[0] = value;
243 _values[group_id] = p;
244 }

References MeshLib::PropertyVectorBase::_n_components, _values, and OGS_FATAL.

◆ operator[]() [1/2]

template<typename T>
T *& MeshLib::PropertyVector< T * >::operator[] ( std::size_t id)
inline

Definition at line 231 of file PropertyVector.h.

231{ return _values[_item2group_mapping[id]]; }

References _item2group_mapping, and _values.

◆ operator[]() [2/2]

template<typename T>
T *const & MeshLib::PropertyVector< T * >::operator[] ( std::size_t id) const
inline

The operator[] uses the item to group property map to access to the correct property value/object.

Definition at line 226 of file PropertyVector.h.

227 {
229 }

References _item2group_mapping, and _values.

Referenced by getComponent().

◆ push_back()

void MeshLib::PropertyVector< T * >::push_back ( const T * & value)
inlineconstexpr

Definition at line 159 of file PropertyVector.h.

160 {
161 data_.push_back(value);
162 }

◆ resize()

void MeshLib::PropertyVector< T * >::resize ( std::size_t const size)
inlineconstexpr

Definition at line 132 of file PropertyVector.h.

132{ data_.resize(size); }

◆ size()

template<typename T>
std::size_t MeshLib::PropertyVector< T * >::size ( ) const
inline

Method returns the number of tuples times the number of tuple components.

Definition at line 267 of file PropertyVector.h.

267{ return _n_components * getNumberOfTuples(); }

References MeshLib::PropertyVectorBase::_n_components, and getNumberOfTuples().

◆ ssize()

std::ptrdiff_t MeshLib::PropertyVector< T * >::ssize ( ) const
inlineconstexpr

Definition at line 96 of file PropertyVector.h.

96{ return std::ssize(data_); }

◆ Properties

template<typename T>
friend class Properties
friend

Definition at line 212 of file PropertyVector.h.

References Properties.

Referenced by Properties.

Member Data Documentation

◆ _item2group_mapping

template<typename T>
std::vector<std::size_t> MeshLib::PropertyVector< T * >::_item2group_mapping
private

Definition at line 328 of file PropertyVector.h.

Referenced by PropertyVector(), clone(), getNumberOfTuples(), operator[](), and operator[]().

◆ _values

template<typename T>
std::vector<T*> MeshLib::PropertyVector< T * >::_values
private

◆ data_

std::vector<T *> MeshLib::PropertyVector< T * >::data_
private

Definition at line 197 of file PropertyVector.h.


The documentation for this class was generated from the following file: