Processing math: 100%
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 214 of file PropertyVector.h.

#include <PropertyVector.h>

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

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.
 
- 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
 

Friends

class Properties
 

Additional Inherited Members

- Public Attributes inherited from MeshLib::PropertyVectorBase
bool is_for_output = true
 
- Protected Attributes inherited from MeshLib::PropertyVectorBase
int const _n_components
 
MeshItemType const _mesh_item_type
 
std::string const _property_name
 

Constructor & Destructor Documentation

◆ ~PropertyVector()

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

Destructor ensures the deletion of the heap-constructed objects.

Definition at line 220 of file PropertyVector.h.

221 {
222 for (auto v : _values)
223 {
224 delete[] v;
225 }
226 }

◆ 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 319 of file PropertyVector.h.

325 : PropertyVectorBase(property_name, mesh_item_type, n_components),
326 _item2group_mapping(std::move(item2group_mapping)),
327 _values(n_prop_groups * n_components)
328 {
329 }
PropertyVectorBase(std::string property_name, MeshItemType mesh_item_type, std::size_t n_components)
std::vector< std::size_t > _item2group_mapping

Member Function Documentation

◆ at()

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

◆ clone()

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

Implements MeshLib::PropertyVectorBase.

Definition at line 273 of file PropertyVector.h.

275 {
276 // create new PropertyVector with modified mapping
277 PropertyVector<T*>* t(new PropertyVector<T*>(
278 _values.size() / _n_components,
281 // copy pointers to property values
282 for (std::size_t j(0); j < _values.size(); j++)
283 {
284 std::vector<T> values(_values[j], _values[j] + _n_components);
285 t->initPropertyValue(j, values);
286 }
287 return t;
288 }
MeshItemType const _mesh_item_type
std::string const _property_name
std::vector< T > excludeObjectCopy(std::vector< T > const &src_vec, std::vector< std::size_t > const &exclude_positions)
Definition Algorithm.h:42

References BaseLib::excludeObjectCopy().

◆ 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 291 of file PropertyVector.h.

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

References OGS_FATAL.

◆ getNumberOfTuples()

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

Definition at line 267 of file PropertyVector.h.

267{ return _item2group_mapping.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 250 of file PropertyVector.h.

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

References 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 237 of file PropertyVector.h.

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

References OGS_FATAL.

◆ operator[]() [1/2]

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

Definition at line 235 of file PropertyVector.h.

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

◆ 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 230 of file PropertyVector.h.

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

◆ 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 271 of file PropertyVector.h.

271{ return _n_components * getNumberOfTuples(); }

Friends And Related Symbol Documentation

◆ Properties

template<typename T >
friend class Properties
friend

Definition at line 216 of file PropertyVector.h.

Member Data Documentation

◆ _item2group_mapping

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

Definition at line 332 of file PropertyVector.h.

◆ _values

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

Definition at line 333 of file PropertyVector.h.


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