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 139 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< 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 146 of file PropertyVector.h.

147 {
148 for (auto v : _values)
149 {
150 delete[] v;
151 }
152 }

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

259 : std::vector<std::size_t>(std::move(item2group_mapping)),
260 PropertyVectorBase(property_name, mesh_item_type, n_components),
261 _values(n_prop_groups * n_components)
262 {
263 }
PropertyVectorBase(std::string property_name, MeshItemType mesh_item_type, std::size_t n_components)

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

210 {
211 // create new PropertyVector with modified mapping
212 PropertyVector<T*>* t(new PropertyVector<T*>(
213 _values.size() / _n_components,
214 BaseLib::excludeObjectCopy(*this, exclude_positions),
216 // copy pointers to property values
217 for (std::size_t j(0); j < _values.size(); j++)
218 {
219 std::vector<T> values(_values[j], _values[j] + _n_components);
220 t->initPropertyValue(j, values);
221 }
222 return t;
223 }
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:37

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

227 {
228 assert(component < _n_components);
229 assert(tuple_index < getNumberOfTuples());
230 const double* p = this->operator[](tuple_index);
231 if (p == nullptr)
232 {
233 OGS_FATAL(
234 "No data found in the property vector {:s} "
235 "for the tuple index {:d} and component {:d}",
236 getPropertyName(), tuple_index, component);
237 }
238 return p[component];
239 }
#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 196 of file PropertyVector.h.

197 {
198 return std::vector<std::size_t>::size();
199 }

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

180 {
181 if (_n_components != static_cast<int>(values.size()))
182 {
183 OGS_FATAL(
184 "The size of provided values in initPropertyValue() is "
185 "not same as the number of components in PropertyVector<T*>");
186 }
187
188 auto* p = new T[values.size()];
189 for (unsigned i = 0; i < values.size(); i++)
190 {
191 p[i] = values[i];
192 }
193 _values[group_id] = p;
194 }

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

167 {
168 if (_n_components != 1)
169 {
170 OGS_FATAL(
171 "Single-component version of initPropertyValue() is called "
172 "for a multi-components PropertyVector<T*>");
173 }
174 auto* p = new T[1];
175 p[0] = value;
176 _values[group_id] = p;
177 }

References OGS_FATAL.

◆ operator[]() [1/2]

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

Definition at line 161 of file PropertyVector.h.

162 {
163 return _values[std::vector<std::size_t>::operator[](id)];
164 }

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

157 {
158 return _values[std::vector<std::size_t>::operator[](id)];
159 }

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

204 {
205 return _n_components * std::vector<std::size_t>::size();
206 }

Friends And Related Symbol Documentation

◆ Properties

template<typename T >
friend class Properties
friend

Definition at line 142 of file PropertyVector.h.

Member Data Documentation

◆ _values

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

Definition at line 266 of file PropertyVector.h.


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