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

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

Definition at line 22 of file MooseArray.h.

Constructor & Destructor Documentation

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

Default constructor.

Doesn't initialize anything.

Definition at line 28 of file MooseArray.h.

28 : _data(NULL), _size(0), _allocated_size(0) {}
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
T * _data
Actual data pointer.
Definition: MooseArray.h:179
template<typename T>
MooseArray< T >::MooseArray ( const unsigned int  size)
inlineexplicit
Parameters
sizeThe initial size of the array.

Definition at line 33 of file MooseArray.h.

33 : _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:205
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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(NULL), _allocated_size(0)
41  {
42  resize(size);
43 
44  setAllValues(default_value);
45  }
void resize(const unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:205
void setAllValues(const T &value)
Sets all values of the array to the passed in value.
Definition: MooseArray.h:190
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
T * _data
Actual data pointer.
Definition: MooseArray.h:179

Member Function Documentation

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

Referenced by MooseVariableScalar::reinit(), and MooseArray< Real >::release().

199 {
200  _size = 0;
201 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
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 302 of file MooseArray.h.

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

303 {
304  unsigned int rhs_size = rhs.size();
305 
306  resize(rhs_size);
307 
308  for (unsigned int i = 0; i < rhs_size; i++)
309  _data[i] = rhs[i];
310 
311  return *this;
312 }
void resize(const unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:205
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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 316 of file MooseArray.h.

317 {
318  // mooseError("Shouldn't be doing this!");
319  resize(rhs._size);
320  // memcpy(_data,rhs._data,sizeof(T)*_size);
321 
322  for (unsigned int i = 0; i < _size; i++)
323  _data[i] = rhs._data[i];
324 
325  return *this;
326 }
void resize(const unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:205
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
T * _data
Actual data pointer.
Definition: MooseArray.h:179
template<typename T >
T & MooseArray< T >::operator[] ( const unsigned int  i)
inline

Get element i out of the array.

Definition at line 256 of file MooseArray.h.

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

257 {
258  mooseAssert(i < _size,
259  "Access out of bounds in MooseArray (i: " << i << " size: " << _size << ")");
260 
261  return _data[i];
262 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
T * _data
Actual data pointer.
Definition: MooseArray.h:179
template<typename T >
const T & MooseArray< T >::operator[] ( const unsigned int  i) const
inline

Get element i out of the array.

Definition at line 265 of file MooseArray.h.

266 {
267  mooseAssert(i < _size,
268  "Access out of bounds in MooseArray (i: " << i << " size: " << _size << ")");
269 
270  return _data[i];
271 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
T * _data
Actual data pointer.
Definition: MooseArray.h:179
template<typename T>
void MooseArray< T >::release ( )
inline

Manually deallocates the data pointer.

Definition at line 56 of file MooseArray.h.

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

57  {
58  if (_data != NULL)
59  {
60  delete[] _data;
61  _data = NULL;
62  _allocated_size = _size = 0;
63  }
64  }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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 205 of file MooseArray.h.

Referenced by MooseVariable::computeElemValues(), MooseVariable::computeElemValuesFace(), MooseVariableConstMonomial::computeElemValuesHelper(), MooseVariable::computeIncrementAtNode(), MooseVariable::computeIncrementAtQps(), NodeFaceConstraint::computeJacobian(), MooseVariable::computeNeighborValues(), MooseVariable::computeNeighborValuesFace(), MooseVariableConstMonomial::computeNeighborValuesHelper(), MooseVariable::computeNodalNeighborValues(), MooseVariable::computeNodalValues(), NodeFaceConstraint::computeOffDiagJacobian(), MooseVariable::computePerturbedElemValues(), Coupleable::Coupleable(), MooseArray< Real >::MooseArray(), MooseArray< T >::operator=(), TableOutput::outputScalarVariables(), Nemesis::outputScalarVariables(), Exodus::outputScalarVariables(), MooseVariable::prepareIC(), MooseVariableScalar::reinit(), MooseVariable::reinitAux(), MooseVariable::reinitAuxNeighbor(), Assembly::reinitNeighbor(), MooseArray< Real >::release(), Assembly::setCoordinateTransformation(), MooseVariableScalar::setValue(), and MooseVariableScalar::setValues().

206 {
207  if (size <= _allocated_size)
208  _size = size;
209  else
210  {
211  T * new_pointer = new T[size];
212  mooseAssert(new_pointer, "Failed to allocate MooseArray memory!");
213 
214  if (_data != NULL)
215  delete[] _data;
216  _data = new_pointer;
218  _size = size;
219  }
220 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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 224 of file MooseArray.h.

225 {
226  if (size > _allocated_size)
227  {
228  T * new_pointer = new T[size];
229  mooseAssert(new_pointer, "Failed to allocate MooseArray memory!");
230 
231  if (_data != NULL)
232  {
233  for (unsigned int i = 0; i < _size; i++)
234  new_pointer[i] = _data[i];
235  delete[] _data;
236  }
237 
238  _data = new_pointer;
240  }
241 
242  for (unsigned int i = _size; i < size; i++)
243  _data[i] = default_value;
244 
245  _size = size;
246 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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 190 of file MooseArray.h.

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

191 {
192  for (unsigned int i = 0; i < _size; i++)
193  _data[i] = value;
194 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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 284 of file MooseArray.h.

Referenced by Assembly::copyFaceShapes(), Assembly::copyNeighborShapes(), Assembly::copyShapes(), Assembly::reinitFE(), Assembly::reinitFEFace(), Assembly::reinitFEFaceNeighbor(), Assembly::reinitFENeighbor(), Assembly::reinitNeighborAtPhysical(), and MooseArray< Real >::release().

285 {
286  _data = rhs._data;
287  _size = rhs._size;
289 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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 293 of file MooseArray.h.

294 {
295  _data = &rhs[0];
296  _size = rhs.size();
297  _allocated_size = rhs.size();
298 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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 250 of file MooseArray.h.

Referenced by AuxKernel::compute(), ElemElemConstraint::computeElemNeighJacobian(), InterfaceKernel::computeElemNeighJacobian(), DGKernel::computeElemNeighJacobian(), ElemElemConstraint::computeElemNeighResidual(), InterfaceKernel::computeElemNeighResidual(), DGKernel::computeElemNeighResidual(), Kernel::computeJacobian(), MassLumpedTimeDerivative::computeJacobian(), TimeDerivative::computeJacobian(), EigenKernel::computeJacobian(), IntegratedBC::computeJacobian(), NonlocalKernel::computeJacobian(), NonlocalIntegratedBC::computeJacobian(), KernelGrad::computeJacobian(), KernelValue::computeJacobian(), NodeFaceConstraint::computeJacobian(), DiracKernel::computeJacobian(), NonlocalIntegratedBC::computeJacobianBlock(), IntegratedBC::computeJacobianBlock(), IntegratedBC::computeJacobianBlockScalar(), FaceFaceConstraint::computeJacobianSide(), NonlocalIntegratedBC::computeNonlocalJacobian(), NonlocalKernel::computeNonlocalJacobian(), NonlocalIntegratedBC::computeNonlocalOffDiagJacobian(), NonlocalKernel::computeNonlocalOffDiagJacobian(), InterfaceKernel::computeOffDiagElemNeighJacobian(), DGKernel::computeOffDiagElemNeighJacobian(), Kernel::computeOffDiagJacobian(), FDKernel::computeOffDiagJacobian(), EigenKernel::computeOffDiagJacobian(), NonlocalKernel::computeOffDiagJacobian(), KernelGrad::computeOffDiagJacobian(), KernelValue::computeOffDiagJacobian(), NodeFaceConstraint::computeOffDiagJacobian(), DiracKernel::computeOffDiagJacobian(), Kernel::computeOffDiagJacobianScalar(), Kernel::computeResidual(), TimeKernel::computeResidual(), EigenKernel::computeResidual(), IntegratedBC::computeResidual(), KernelValue::computeResidual(), KernelGrad::computeResidual(), NodeFaceConstraint::computeResidual(), DiracKernel::computeResidual(), FaceFaceConstraint::computeResidualSide(), NodalValueSampler::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), MultiAppVariableValueSampleTransfer::execute(), MultiAppPostprocessorToAuxScalarTransfer::execute(), MultiAppScalarToAuxScalarTransfer::execute(), ShapeUserObject< T >::executeJacobianWrapper(), GeometricSearchData::generateMortarNodes(), GeometricSearchData::generateQuadratureNodes(), MaterialStdVectorAux::getRealValue(), ElementalVariableValue::getValue(), Assembly::modifyWeightsDueToXFEM(), TableOutput::outputScalarVariables(), FDKernel::perturbedResidual(), MooseVariableScalar::reinit(), MooseArray< Real >::release(), MooseArray< T >::resize(), MooseVariable::setNodalValue(), MooseVariable::setNodalValueNeighbor(), MooseVariableScalar::setValue(), GeometricSearchData::updateMortarNodes(), and GeometricSearchData::updateQuadratureNodes().

251 {
252  return _size;
253 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
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 330 of file MooseArray.h.

Referenced by Assembly::reinitElemAndNeighbor(), and MooseArray< Real >::release().

331 {
332  return std::vector<T>(_data, _data + _size);
333 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
T * _data
Actual data pointer.
Definition: MooseArray.h:179
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 275 of file MooseArray.h.

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

276 {
277  std::swap(_data, rhs._data);
278  std::swap(_size, rhs._size);
280 }
unsigned int _size
The current number of elements the array can hold.
Definition: MooseArray.h:182
unsigned int _allocated_size
Number of allocated memory positions for storage.
Definition: MooseArray.h:185
X_global swap(X_sys)
T * _data
Actual data pointer.
Definition: MooseArray.h:179

Member Data Documentation

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

Number of allocated memory positions for storage.

Definition at line 185 of file MooseArray.h.

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

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

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