https://mooseframework.inl.gov
Public Types | Public Member Functions | Private Attributes | List of all members
MooseArray< T > Class Template Reference

forward declarations More...

#include <DiffusionLHDGAssemblyHelper.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...
 
T * data ()
 

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 25 of file DiffusionLHDGAssemblyHelper.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:192
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:195

◆ 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:192
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:259
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:195
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:216

◆ 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:200
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:192
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:259
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:195
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:216

◆ 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:192
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:195
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:216

◆ ~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 208 of file MooseArray.h.

209 {
210  _size = 0;
211 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:192

◆ data() [1/2]

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

Reference to first element of array.

Definition at line 180 of file MooseArray.h.

180 { return _data; }

◆ data() [2/2]

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

Definition at line 181 of file MooseArray.h.

181 { 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 316 of file MooseArray.h.

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

◆ 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 330 of file MooseArray.h.

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

◆ 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 266 of file MooseArray.h.

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

◆ 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 276 of file MooseArray.h.

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

◆ 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(), NodeElemConstraintBase::~NodeElemConstraintBase(), 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:192
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:195
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
Definition: MooseArray.h:186

◆ 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 216 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(), and Assembly::resizeADMappingObjects().

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

◆ 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 235 of file MooseArray.h.

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

◆ 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 200 of file MooseArray.h.

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

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

◆ 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 296 of file MooseArray.h.

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

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

◆ 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 306 of file MooseArray.h.

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

◆ 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 259 of file MooseArray.h.

Referenced by NodalPatchRecovery::compute(), ArrayDGKernel::computeElemNeighJacobian(), ArrayDGKernel::computeElemNeighResidual(), TimeDerivative::computeJacobian(), Kernel::computeJacobian(), ArrayKernel::computeJacobian(), IntegratedBC::computeJacobian(), ArrayIntegratedBC::computeJacobian(), EigenKernel::computeJacobian(), NodeElemConstraint::computeJacobian(), FVBoundaryScalarLagrangeMultiplierConstraint::computeJacobian(), KernelValue::computeJacobian(), KernelGrad::computeJacobian(), NonlocalKernel::computeJacobian(), NonlocalIntegratedBC::computeJacobian(), NodeFaceConstraint::computeJacobian(), ArrayLowerDIntegratedBC::computeLowerDJacobian(), ArrayLowerDIntegratedBC::computeLowerDOffDiagJacobian(), ArrayDGKernel::computeOffDiagElemNeighJacobian(), ArrayKernel::computeOffDiagJacobian(), NodeElemConstraint::computeOffDiagJacobian(), FVScalarLagrangeMultiplierConstraint::computeOffDiagJacobian(), ArrayKernel::computeOffDiagJacobianScalar(), ArrayKernel::computeResidual(), ArrayLowerDIntegratedBC::computeResidual(), FVBoundaryScalarLagrangeMultiplierConstraint::computeResidual(), FVScalarLagrangeMultiplierConstraint::computeResidual(), MultiAppVariableValueSampleTransfer::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), 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().

260 {
261  return _size;
262 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:192

◆ 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 344 of file MooseArray.h.

Referenced by Assembly::reinitElemAndNeighbor().

345 {
346  return std::vector<T>(_data, _data + _size);
347 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:192

◆ 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 286 of file MooseArray.h.

287 {
288  _data_ptr.swap(rhs._data_ptr);
289  std::swap(_data, rhs._data);
290  std::swap(_size, rhs._size);
292 }
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:192
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:195
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
Definition: MooseArray.h:186

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 195 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 186 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 files: