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

forward declarations More...

#include <MooseArray.h>

Public Member Functions

 MooseArray ()
 Default constructor. More...
 
 MooseArray (const unsigned int size)
 
 MooseArray (const unsigned int size, const T &default_value)
 
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...
 
void resize (const unsigned int size)
 Change the number of elements the array can store. More...
 
void resize (const 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 ()
 Extremely inefficient way to produce a std::vector from a MooseArray! More...
 

Private Attributes

T * _data
 Actual data pointer. More...
 
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.

Constructor & Destructor Documentation

◆ MooseArray() [1/3]

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

Default constructor.

Doesn't initialize anything.

Definition at line 23 of file MooseArray.h.

23 : _data(NULL), _size(0), _allocated_size(0) {}
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
T * _data
Actual data pointer.
Definition: MooseArray.h:174

◆ MooseArray() [2/3]

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

Definition at line 28 of file MooseArray.h.

28 : _data(NULL), _allocated_size(0) { resize(size); }
void resize(const unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:200
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:245
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
T * _data
Actual data pointer.
Definition: MooseArray.h:174

◆ MooseArray() [3/3]

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

35  : _data(NULL), _allocated_size(0)
36  {
37  resize(size);
38 
39  setAllValues(default_value);
40  }
void resize(const unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:200
void setAllValues(const T &value)
Sets all values of the array to the passed in value.
Definition: MooseArray.h:185
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:245
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

Referenced by MooseVariableScalar::reinit().

194 {
195  _size = 0;
196 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177

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

298 {
299  unsigned int rhs_size = rhs.size();
300 
301  resize(rhs_size);
302 
303  for (unsigned int i = 0; i < rhs_size; i++)
304  _data[i] = rhs[i];
305 
306  return *this;
307 }
void resize(const unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:200
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

312 {
313  // mooseError("Shouldn't be doing this!");
314  resize(rhs._size);
315  // memcpy(_data,rhs._data,sizeof(T)*_size);
316 
317  for (unsigned int i = 0; i < _size; i++)
318  _data[i] = rhs._data[i];
319 
320  return *this;
321 }
void resize(const unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:200
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

252 {
253  mooseAssert(i < _size,
254  "Access out of bounds in MooseArray (i: " << i << " size: " << _size << ")");
255 
256  return _data[i];
257 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

261 {
262  mooseAssert(i < _size,
263  "Access out of bounds in MooseArray (i: " << i << " size: " << _size << ")");
264 
265  return _data[i];
266 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
T * _data
Actual data pointer.
Definition: MooseArray.h:174

◆ release()

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

Manually deallocates the data pointer.

Definition at line 51 of file MooseArray.h.

Referenced by Assembly::modifyFaceWeightsDueToXFEM(), Assembly::modifyWeightsDueToXFEM(), TableOutput::outputScalarVariables(), Assembly::~Assembly(), Coupleable::~Coupleable(), MooseVariableScalar::~MooseVariableScalar(), NodeElemConstraint::~NodeElemConstraint(), and NodeFaceConstraint::~NodeFaceConstraint().

52  {
53  if (_data != NULL)
54  {
55  delete[] _data;
56  _data = NULL;
57  _allocated_size = _size = 0;
58  }
59  }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
T * _data
Actual data pointer.
Definition: MooseArray.h:174

◆ resize() [1/2]

template<typename T >
void MooseArray< T >::resize ( const 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.

Definition at line 200 of file MooseArray.h.

Referenced by NodeElemConstraint::computeJacobian(), NodeFaceConstraint::computeJacobian(), MooseVariableConstMonomial::computeMonomialNeighborValuesHelper(), MooseVariableConstMonomial::computeMonomialValuesHelper(), NodeElemConstraint::computeOffDiagJacobian(), NodeFaceConstraint::computeOffDiagJacobian(), Coupleable::Coupleable(), EqualValueEmbeddedConstraint::getConnectedDofIndices(), MooseArray< Real >::MooseArray(), TableOutput::outputScalarVariables(), Nemesis::outputScalarVariables(), Exodus::outputScalarVariables(), MooseVariableScalar::reinit(), Assembly::reinitNeighbor(), Assembly::setCoordinateTransformation(), MooseVariableScalar::setValue(), and MooseVariableScalar::setValues().

201 {
202  if (size <= _allocated_size)
203  _size = size;
204  else
205  {
206  T * new_pointer = new T[size];
207  mooseAssert(new_pointer, "Failed to allocate MooseArray memory!");
208 
209  if (_data != NULL)
210  delete[] _data;
211  _data = new_pointer;
213  _size = size;
214  }
215 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:245
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
T * _data
Actual data pointer.
Definition: MooseArray.h:174

◆ resize() [2/2]

template<typename T>
void MooseArray< T >::resize ( const 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 219 of file MooseArray.h.

220 {
221  if (size > _allocated_size)
222  {
223  T * new_pointer = new T[size];
224  mooseAssert(new_pointer, "Failed to allocate MooseArray memory!");
225 
226  if (_data != NULL)
227  {
228  for (unsigned int i = 0; i < _size; i++)
229  new_pointer[i] = _data[i];
230  delete[] _data;
231  }
232 
233  _data = new_pointer;
235  }
236 
237  for (unsigned int i = _size; i < size; i++)
238  _data[i] = default_value;
239 
240  _size = size;
241 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:245
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

Referenced by MooseArray< Real >::MooseArray().

186 {
187  for (unsigned int i = 0; i < _size; i++)
188  _data[i] = value;
189 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

Note! You can leak memory with this function if you don't take care to have a copy of this array somewhere else. This is because the data pointer will get overridden here.

Definition at line 279 of file MooseArray.h.

Referenced by Assembly::copyFaceShapes(), Assembly::copyNeighborShapes(), Assembly::copyShapes(), Assembly::reinitFE(), Assembly::reinitFEFace(), Assembly::reinitFEFaceNeighbor(), Assembly::reinitFENeighbor(), and Assembly::reinitNeighborAtPhysical().

280 {
281  _data = rhs._data;
282  _size = rhs._size;
284 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

Note! You can leak memory with this function if you don't take care to have a copy of this array somewhere else. This is because the data pointer will get overridden here.

I repeat! This is an extremely dangerous function!

DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING!

YOU HAVE BEEN WARNED!

Definition at line 288 of file MooseArray.h.

289 {
290  _data = &rhs[0];
291  _size = rhs.size();
292  _allocated_size = rhs.size();
293 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

Referenced by AuxKernel::compute(), NodalPatchRecovery::compute(), ElemElemConstraint::computeElemNeighJacobian(), InterfaceKernel::computeElemNeighJacobian(), DGKernel::computeElemNeighJacobian(), ElemElemConstraint::computeElemNeighResidual(), InterfaceKernel::computeElemNeighResidual(), DGKernel::computeElemNeighResidual(), TimeDerivative::computeJacobian(), MassLumpedTimeDerivative::computeJacobian(), Kernel::computeJacobian(), EigenKernel::computeJacobian(), IntegratedBC::computeJacobian(), VectorKernel::computeJacobian(), EqualValueEmbeddedConstraint::computeJacobian(), VectorIntegratedBC::computeJacobian(), NonlocalIntegratedBC::computeJacobian(), NonlocalKernel::computeJacobian(), KernelGrad::computeJacobian(), KernelValue::computeJacobian(), NodeElemConstraint::computeJacobian(), NodeFaceConstraint::computeJacobian(), DiracKernel::computeJacobian(), IntegratedBC::computeJacobianBlock(), NonlocalIntegratedBC::computeJacobianBlock(), VectorIntegratedBC::computeJacobianBlock(), IntegratedBC::computeJacobianBlockScalar(), VectorIntegratedBC::computeJacobianBlockScalar(), MortarConstraint::computeJacobianSide(), NonlocalKernel::computeNonlocalJacobian(), NonlocalIntegratedBC::computeNonlocalJacobian(), NonlocalIntegratedBC::computeNonlocalOffDiagJacobian(), NonlocalKernel::computeNonlocalOffDiagJacobian(), InterfaceKernel::computeOffDiagElemNeighJacobian(), DGKernel::computeOffDiagElemNeighJacobian(), Kernel::computeOffDiagJacobian(), EigenKernel::computeOffDiagJacobian(), EqualValueEmbeddedConstraint::computeOffDiagJacobian(), VectorKernel::computeOffDiagJacobian(), NonlocalKernel::computeOffDiagJacobian(), KernelGrad::computeOffDiagJacobian(), KernelValue::computeOffDiagJacobian(), NodeElemConstraint::computeOffDiagJacobian(), NodeFaceConstraint::computeOffDiagJacobian(), DiracKernel::computeOffDiagJacobian(), VectorKernel::computeOffDiagJacobianScalar(), Kernel::computeOffDiagJacobianScalar(), Kernel::computeResidual(), TimeKernel::computeResidual(), VectorKernel::computeResidual(), IntegratedBC::computeResidual(), EigenKernel::computeResidual(), VectorIntegratedBC::computeResidual(), KernelValue::computeResidual(), KernelGrad::computeResidual(), NodeElemConstraint::computeResidual(), NodeFaceConstraint::computeResidual(), DiracKernel::computeResidual(), MortarConstraint::computeResidualSide(), NodalValueSampler::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), MultiAppVariableValueSampleTransfer::execute(), MultiAppScalarToAuxScalarTransfer::execute(), MultiAppPostprocessorToAuxScalarTransfer::execute(), RankTwoTensorTempl< Real >::fillFromScalarVariable(), ConservativeAdvection::fullUpwind(), GeometricSearchData::generateMortarNodes(), GeometricSearchData::generateQuadratureNodes(), MaterialStdVectorAux::getRealValue(), ElementalVariableValue::getValue(), Assembly::modifyFaceWeightsDueToXFEM(), Assembly::modifyWeightsDueToXFEM(), MooseArray< Real >::MooseArray(), TableOutput::outputScalarVariables(), MooseVariableFE< Real >::phiFaceNeighborSize(), MooseVariableFE< Real >::phiFaceSize(), MooseVariableFE< Real >::phiNeighborSize(), MooseVariableFE< Real >::phiSize(), MooseVariableScalar::reinit(), MooseVariableScalar::setValue(), GeometricSearchData::updateMortarNodes(), and GeometricSearchData::updateQuadratureNodes().

246 {
247  return _size;
248 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177

◆ stdVector()

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

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

Returns
A copy of the MooseArray contents.

Definition at line 325 of file MooseArray.h.

Referenced by Assembly::reinitElemAndNeighbor().

326 {
327  return std::vector<T>(_data, _data + _size);
328 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

271 {
272  std::swap(_data, rhs._data);
273  std::swap(_size, rhs._size);
275 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:177
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:180
X_global swap(X_sys)
T * _data
Actual data pointer.
Definition: MooseArray.h:174

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

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

◆ _data

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

◆ _size

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

The current number of elements the array can hold.

Definition at line 177 of file MooseArray.h.

Referenced by MooseArray< Real >::operator=(), MooseArray< Real >::release(), MooseArray< Real >::shallowCopy(), and MooseArray< Real >::swap().


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