www.mooseframework.org
Public Types | Public Member Functions | Private Attributes | List of all members
MooseArray< T > Class Template Reference

forward declarations More...

#include <MooseArray.h>

Public Types

typedef T value_type
 

Public Member Functions

 MooseArray ()
 Default constructor. More...
 
 MooseArray (const unsigned int size)
 
 MooseArray (const unsigned int size, const T &default_value)
 
 MooseArray (const MooseArray &rhs)
 
 ~MooseArray ()=default
 
void setAllValues (const T &value)
 Sets all values of the array to the passed in value. More...
 
void release ()
 Manually deallocates the data pointer. More...
 
void clear ()
 Change the number of elements the array can store to zero. More...
 
template<bool value_initialize = false>
void resize (unsigned int size)
 Change the number of elements the array can store. More...
 
void resize (unsigned int size, const T &default_value)
 Change the number of elements the array can store. More...
 
unsigned int size () const
 The number of elements that can currently be stored in the array. More...
 
T & operator[] (const unsigned int i)
 Get element i out of the array. More...
 
const T & operator[] (const unsigned int i) const
 Get element i out of the array. More...
 
void swap (MooseArray &rhs)
 Swap memory in this object with the 'rhs' object. More...
 
void shallowCopy (const MooseArray &rhs)
 Doesn't actually make a copy of the data. More...
 
void shallowCopy (std::vector< T > &rhs)
 Doesn't actually make a copy of the data. More...
 
MooseArray< T > & operator= (const std::vector< T > &rhs)
 Actual operator=... More...
 
MooseArray< T > & operator= (const MooseArray< T > &rhs)
 Actual operator=... More...
 
std::vector< T > stdVector () const
 Extremely inefficient way to produce a std::vector from a MooseArray! More...
 
const T * data () const
 Reference to first element of array. More...
 

Private Attributes

std::unique_ptr< T[]> _data_ptr
 Smart pointer storage. More...
 
T * _data
 
unsigned int _size
 The current number of elements the array can hold. More...
 
unsigned int _allocated_size
 Number of allocated memory positions for storage. More...
 

Detailed Description

template<typename T>
class MooseArray< T >

forward declarations

Definition at line 17 of file MooseArray.h.

Member Typedef Documentation

◆ value_type

template<typename T>
typedef T MooseArray< T >::value_type

Definition at line 20 of file MooseArray.h.

Constructor & Destructor Documentation

◆ MooseArray() [1/4]

template<typename T>
MooseArray< T >::MooseArray ( )
inline

Default constructor.

Doesn't initialize anything.

Definition at line 25 of file MooseArray.h.

25 : _data(nullptr), _size(0), _allocated_size(0) {}
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192

◆ MooseArray() [2/4]

template<typename T>
MooseArray< T >::MooseArray ( const unsigned int  size)
inlineexplicit
Parameters
sizeThe initial size of the array.

Definition at line 30 of file MooseArray.h.

30  : _data(nullptr), _size(0), _allocated_size(0)
31  {
32  resize(size);
33  }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:256
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:213

◆ MooseArray() [3/4]

template<typename T>
MooseArray< T >::MooseArray ( const unsigned int  size,
const T &  default_value 
)
inlineexplicit
Parameters
sizeThe initial size of the array.
default_valueThe default value to set.

Definition at line 39 of file MooseArray.h.

40  : _data(nullptr), _size(0), _allocated_size(0)
41  {
42  resize(size);
43 
44  setAllValues(default_value);
45  }
void setAllValues(const T &value)
Sets all values of the array to the passed in value.
Definition: MooseArray.h:197
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:256
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:213

◆ MooseArray() [4/4]

template<typename T>
MooseArray< T >::MooseArray ( const MooseArray< T > &  rhs)
inlineexplicit

Definition at line 47 of file MooseArray.h.

47  : _data(nullptr), _size(0), _allocated_size(0)
48  {
49  resize(rhs._size);
50 
51  for (unsigned int i = 0; i < _size; i++)
52  _data[i] = rhs._data[i];
53  }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:213

◆ ~MooseArray()

template<typename T>
MooseArray< T >::~MooseArray ( )
default

Member Function Documentation

◆ clear()

template<typename T >
void MooseArray< T >::clear ( )
inline

Change the number of elements the array can store to zero.

Will destroy data currently in array!

Note that this does not free unused memory. This is done for speed.

Definition at line 205 of file MooseArray.h.

206 {
207  _size = 0;
208 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189

◆ data()

template<typename T>
const T* MooseArray< T >::data ( ) const
inline

Reference to first element of array.

Definition at line 179 of file MooseArray.h.

179 { return _data; }

◆ operator=() [1/2]

template<typename T>
MooseArray< T > & MooseArray< T >::operator= ( const std::vector< T > &  rhs)
inline

Actual operator=...

really does make a copy of the data

If you don't want a copy use shallowCopy()

Definition at line 313 of file MooseArray.h.

314 {
315  unsigned int rhs_size = rhs.size();
316 
317  resize(rhs_size);
318 
319  for (unsigned int i = 0; i < rhs_size; i++)
320  _data[i] = rhs[i];
321 
322  return *this;
323 }
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:213

◆ operator=() [2/2]

template<typename T>
MooseArray< T > & MooseArray< T >::operator= ( const MooseArray< T > &  rhs)
inline

Actual operator=...

really does make a copy of the data

If you don't want a copy use shallowCopy()

Definition at line 327 of file MooseArray.h.

328 {
329  // mooseError("Shouldn't be doing this!");
330  resize(rhs._size);
331  // memcpy(_data,rhs._data,sizeof(T)*_size);
332 
333  for (unsigned int i = 0; i < _size; i++)
334  _data[i] = rhs._data[i];
335 
336  return *this;
337 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:213

◆ operator[]() [1/2]

template<typename T >
T & MooseArray< T >::operator[] ( const unsigned int  i)
inline

Get element i out of the array.

Definition at line 263 of file MooseArray.h.

264 {
265  mooseAssert(i < _size,
266  "Access out of bounds in MooseArray (i: " << i << " size: " << _size << ")");
267 
268  return _data[i];
269 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189

◆ operator[]() [2/2]

template<typename T >
const T & MooseArray< T >::operator[] ( const unsigned int  i) const
inline

Get element i out of the array.

Definition at line 273 of file MooseArray.h.

274 {
275  mooseAssert(i < _size,
276  "Access out of bounds in MooseArray (i: " << i << " size: " << _size << ")");
277 
278  return _data[i];
279 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189

◆ release()

template<typename T>
void MooseArray< T >::release ( )
inline

Manually deallocates the data pointer.

Definition at line 66 of file MooseArray.h.

Referenced by Assembly::modifyFaceWeightsDueToXFEM(), Assembly::modifyWeightsDueToXFEM(), Assembly::~Assembly(), NodeElemConstraint::~NodeElemConstraint(), and NodeFaceConstraint::~NodeFaceConstraint().

67  {
68  if (_data_ptr)
69  {
70  _data_ptr.reset();
71  _data = nullptr;
72  _allocated_size = _size = 0;
73  }
74  }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
Definition: MooseArray.h:183

◆ resize() [1/2]

template<typename T >
template<bool value_initialize>
void MooseArray< T >::resize ( unsigned int  size)
inline

Change the number of elements the array can store.

Will allocate more memory if necessary.

Can destroy data currently in array! Basically, data retention not guaranteed.

Note that this does not free unused memory. This is done for speed.

Parameters
sizeThe new size of the array
Template Parameters
value_initializeWhether to perform value initialization of the array instead of default initialization

Definition at line 213 of file MooseArray.h.

Referenced by MooseVariableScalar::computeAD(), Assembly::computeADFace(), NodeFaceConstraint::computeJacobian(), NodeFaceConstraint::computeOffDiagJacobian(), Coupleable::coupledArrayDotDu(), Coupleable::coupledDot(), Coupleable::coupledDotDot(), Coupleable::coupledDotDotDu(), Coupleable::coupledDotDotOld(), Coupleable::coupledDotDu(), Coupleable::coupledDotOld(), Coupleable::coupledNodalDotDot(), Coupleable::coupledNodalDotDotOld(), Coupleable::coupledNodalDotOld(), Coupleable::coupledVectorDotDotDu(), Coupleable::coupledVectorDotDu(), MooseVariableDataBase< OutputType >::getArrayDoFValues(), NodeElemConstraint::getConnectedDofIndices(), MooseVariableDataBase< OutputType >::matrixTagValue(), MooseArray< libMesh::VectorValue >::MooseArray(), MooseVariableDataBase< OutputType >::MooseVariableDataBase(), MooseVariableDataBase< OutputType >::nodalMatrixTagValue(), Assembly::reinitFVFace(), Assembly::reinitNeighborAtPhysical(), and Assembly::resizeADMappingObjects().

214 {
215  if (size > _allocated_size)
216  {
217  if constexpr (value_initialize)
218  _data_ptr.reset(new T[size]());
219  else
220  _data_ptr = std::make_unique<T[]>(size);
221  mooseAssert(_data_ptr, "Failed to allocate MooseArray memory!");
222 
223  _data = _data_ptr.get();
225  }
226 
227  _size = size;
228 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:256
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
Definition: MooseArray.h:183

◆ resize() [2/2]

template<typename T>
void MooseArray< T >::resize ( unsigned int  size,
const T &  default_value 
)
inline

Change the number of elements the array can store.

Will allocate more memory if necessary.

Can destroy data currently in array! Basically, data retention not guaranteed.

Note that this does not free unused memory. This is done for speed.

Also note that default_value is only applied to NEW entries.

Definition at line 232 of file MooseArray.h.

233 {
234  if (size > _allocated_size)
235  {
236  auto new_pointer = std::make_unique<T[]>(size);
237  mooseAssert(new_pointer, "Failed to allocate MooseArray memory!");
238 
239  if (_data)
240  for (unsigned int i = 0; i < _size; i++)
241  new_pointer[i] = _data[i];
242 
243  _data_ptr = std::move(new_pointer);
244  _data = _data_ptr.get();
246  }
247 
248  for (unsigned int i = _size; i < size; i++)
249  _data[i] = default_value;
250 
251  _size = size;
252 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:256
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
Definition: MooseArray.h:183

◆ setAllValues()

template<typename T>
void MooseArray< T >::setAllValues ( const T &  value)
inline

Sets all values of the array to the passed in value.

Parameters
valueThe value every entry of the array will be set to.

Definition at line 197 of file MooseArray.h.

Referenced by MooseArray< libMesh::VectorValue >::MooseArray().

198 {
199  for (unsigned int i = 0; i < _size; i++)
200  _data[i] = value;
201 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189

◆ shallowCopy() [1/2]

template<typename T >
void MooseArray< T >::shallowCopy ( const MooseArray< T > &  rhs)
inline

Doesn't actually make a copy of the data.

Just makes this object operate on the same data.

Definition at line 293 of file MooseArray.h.

Referenced by Assembly::reinitElemFaceRef(), Assembly::reinitFE(), Assembly::reinitFEFace(), Assembly::reinitFEFaceNeighbor(), Assembly::reinitMortarElem(), Assembly::reinitNeighbor(), and Assembly::reinitNeighborFaceRef().

294 {
295  _data_ptr.reset();
296  _data = rhs._data;
297  _size = rhs._size;
299 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
Definition: MooseArray.h:183

◆ shallowCopy() [2/2]

template<typename T>
void MooseArray< T >::shallowCopy ( std::vector< T > &  rhs)
inline

Doesn't actually make a copy of the data.

Just makes this object operate on the same data.

Definition at line 303 of file MooseArray.h.

304 {
305  _data_ptr.reset();
306  _data = &rhs[0];
307  _size = rhs.size();
308  _allocated_size = rhs.size();
309 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
Definition: MooseArray.h:183

◆ size()

template<typename T >
unsigned int MooseArray< T >::size ( ) const
inline

The number of elements that can currently be stored in the array.

Definition at line 256 of file MooseArray.h.

Referenced by NodalPatchRecovery::compute(), ArrayDGKernel::computeElemNeighJacobian(), ArrayDGKernel::computeElemNeighResidual(), TimeDerivative::computeJacobian(), Kernel::computeJacobian(), ArrayKernel::computeJacobian(), IntegratedBC::computeJacobian(), ArrayIntegratedBC::computeJacobian(), EigenKernel::computeJacobian(), FVBoundaryScalarLagrangeMultiplierConstraint::computeJacobian(), NonlocalKernel::computeJacobian(), KernelValue::computeJacobian(), KernelGrad::computeJacobian(), NonlocalIntegratedBC::computeJacobian(), NodeElemConstraint::computeJacobian(), NodeFaceConstraint::computeJacobian(), ArrayLowerDIntegratedBC::computeLowerDJacobian(), ArrayDGLowerDKernel::computeLowerDJacobian(), ArrayLowerDIntegratedBC::computeLowerDOffDiagJacobian(), ArrayDGLowerDKernel::computeLowerDResidual(), ArrayDGKernel::computeOffDiagElemNeighJacobian(), ArrayKernel::computeOffDiagJacobian(), FVScalarLagrangeMultiplierConstraint::computeOffDiagJacobian(), NodeElemConstraint::computeOffDiagJacobian(), ArrayKernel::computeOffDiagJacobianScalar(), ArrayDGLowerDKernel::computeOffDiagLowerDJacobian(), ArrayKernel::computeResidual(), ArrayLowerDIntegratedBC::computeResidual(), FVBoundaryScalarLagrangeMultiplierConstraint::computeResidual(), FVScalarLagrangeMultiplierConstraint::computeResidual(), MultiAppVariableValueSampleTransfer::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), ConservativeAdvection::fullUpwind(), Assembly::modifyArbitraryWeights(), Assembly::modifyFaceWeightsDueToXFEM(), Assembly::modifyWeightsDueToXFEM(), MooseArray< libMesh::VectorValue >::MooseArray(), NodalPatchRecoveryBase::nodalPatchRecovery(), MooseVariableData< OutputType >::phiFaceSize(), MooseVariableData< OutputType >::phiSize(), Assembly::reinitFEFace(), and MaterialPropertyBase< T, false >::size().

257 {
258  return _size;
259 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189

◆ stdVector()

template<class T >
std::vector< T > MooseArray< T >::stdVector ( ) const

Extremely inefficient way to produce a std::vector from a MooseArray!

Returns
A copy of the MooseArray contents.

Definition at line 341 of file MooseArray.h.

Referenced by Assembly::reinitElemAndNeighbor().

342 {
343  return std::vector<T>(_data, _data + _size);
344 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189

◆ swap()

template<typename T >
void MooseArray< T >::swap ( MooseArray< T > &  rhs)
inline

Swap memory in this object with the 'rhs' object.

Parameters
rhsThe object we are swapping with

Definition at line 283 of file MooseArray.h.

284 {
285  _data_ptr.swap(rhs._data_ptr);
286  std::swap(_data, rhs._data);
287  std::swap(_size, rhs._size);
289 }
void swap(std::vector< T > &data, const std::size_t idx0, const std::size_t idx1, const libMesh::Parallel::Communicator &comm)
Swap function for serial or distributed vector of data.
Definition: Shuffle.h:494
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:189
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:192
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
Definition: MooseArray.h:183

Member Data Documentation

◆ _allocated_size

template<typename T>
unsigned int MooseArray< T >::_allocated_size
private

Number of allocated memory positions for storage.

Definition at line 192 of file MooseArray.h.

Referenced by MooseArray< libMesh::VectorValue >::release(), MooseArray< libMesh::VectorValue >::shallowCopy(), and MooseArray< libMesh::VectorValue >::swap().

◆ _data

template<typename T>
T* MooseArray< T >::_data
private

◆ _data_ptr

template<typename T>
std::unique_ptr<T[]> MooseArray< T >::_data_ptr
private

Smart pointer storage.

Definition at line 183 of file MooseArray.h.

Referenced by MooseArray< libMesh::VectorValue >::release(), and MooseArray< libMesh::VectorValue >::swap().

◆ _size

template<typename T>
unsigned int MooseArray< T >::_size
private

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