Alsvinn  0.5.3
The fast FVM simulator with UQ support
Public Member Functions | List of all members
alsfvm::memory::HostMemory< T > Class Template Reference

#include <alsfvm/memory/HostMemory.hpp>

Inheritance diagram for alsfvm::memory::HostMemory< T >:
alsfvm::memory::Memory< T > alsfvm::memory::MemoryBase

Public Member Functions

 HostMemory (size_t nx, size_t ny=1, size_t nz=1)
 
virtual std::shared_ptr< Memory< T > > makeInstance () const override
 Clones the memory area, but does not copy the content More...
 
virtual bool isOnHost () const override
 
virtual void copyFrom (const Memory< T > &other) override
 Copies the contents of the other memory area into this one. More...
 
virtual T * getPointer () override
 
virtual const T * getPointer () const override
 
virtual void copyToHost (T *bufferPointer, size_t bufferLength) const override
 
virtual void copyFromHost (const T *bufferPointer, size_t bufferLength) override
 
virtual void operator+= (const Memory< T > &other) override
 
virtual void operator*= (const Memory< T > &other) override
 
virtual void operator-= (const Memory< T > &other) override
 
virtual void operator/= (const Memory< T > &other) override
 
virtual void operator+= (real scalar) override
 
virtual void operator*= (real scalar) override
 
virtual void operator-= (real scalar) override
 
virtual void operator/= (real scalar) override
 
T & at (size_t x, size_t y=0, size_t z=0)
 at returns the data at the given index More...
 
const T & at (size_t x, size_t y=0, size_t z=0) const
 at returns the data at the given index More...
 
virtual void makeZero () override
 makeZero sets every element to zero (0) More...
 
virtual void copyInternalCells (size_t startX, size_t endX, size_t startY, size_t endY, size_t startZ, size_t endZ, T *output, size_t outputSize) override
 copyInternalCells copies the internal cells into the memory area This is ideal for removing ghost cells before outputing the solution. More...
 
virtual void addLinearCombination (T a1, T a2, const Memory< T > &v2, T a3, const Memory< T > &v3, T a4, const Memory< T > &v4, T a5, const Memory< T > &v5) override
 
virtual void addPower (const Memory< T > &other, double power) override
 
virtual void addPower (const Memory< T > &other, double power, double factor) override
 
virtual void subtractPower (const Memory< T > &other, double power) override
 
virtual std::shared_ptr< Memory< T > > getHostMemory () override
 Copies the data to host if it is on GPU, otherwise makes a copy. More...
 
virtual const std::shared_ptr< const Memory< T > > getHostMemory () const override
 
virtual real getTotalVariation (int p, const ivec3 &start, const ivec3 &end) const override
 
virtual real getTotalVariation (int direction, int p, const ivec3 &start, const ivec3 &end) const override
 
- Public Member Functions inherited from alsfvm::memory::Memory< T >
 Memory (size_t nx, size_t ny, size_t nz)
 Memory constructs new memory. More...
 
virtual ~Memory ()
 
virtual size_t getSize () const
 
virtual size_t getSizeX () const
 
virtual size_t getSizeY () const
 
virtual size_t getSizeZ () const
 
virtual size_t getExtentXInBytes () const
 
virtual size_t getExtentYInBytes () const
 
T * data ()
 
const T * data () const
 
T & operator[] (size_t i)
 
operator[] (size_t i) const
 
operator() (int x, int y, int z) const
 
T & operator() (int x, int y, int z)
 
View< T > getView ()
 getView gets the view to the memory More...
 
View< const T > getView () const
 getView gets the view to the memory (const version) More...
 
- Public Member Functions inherited from alsfvm::memory::MemoryBase
 MemoryBase ()
 
virtual ~MemoryBase ()
 

Additional Inherited Members

- Protected Attributes inherited from alsfvm::memory::Memory< T >
const size_t nx
 
const size_t ny
 
const size_t nz
 

Constructor & Destructor Documentation

◆ HostMemory()

template<class T >
alsfvm::memory::HostMemory< T >::HostMemory ( size_t  nx,
size_t  ny = 1,
size_t  nz = 1 
)
Parameters
nxthe size of the memory area in X (number of T)
nythe size of the memory area in Y (number of T)
nzthe size of the memory area in Z (number of T)

Member Function Documentation

◆ addLinearCombination()

template<class T >
void alsfvm::memory::HostMemory< T >::addLinearCombination ( a1,
a2,
const Memory< T > &  v2,
a3,
const Memory< T > &  v3,
a4,
const Memory< T > &  v4,
a5,
const Memory< T > &  v5 
)
overridevirtual

Adds the memory with coefficients to this memory area Here we compute the sum

\[ v_1^{\mathrm{new}}=a_1v_1+a_2v_2+a_3v_3+a_4v_4+a_5v_5+a_6v_6\]

where $v_1$ is the volume being operated on.

Implements alsfvm::memory::Memory< T >.

◆ addPower() [1/2]

template<class T >
void alsfvm::memory::HostMemory< T >::addPower ( const Memory< T > &  other,
double  power 
)
overridevirtual

Adds a power of the other memory area to this memory area, ie

\[this += pow(other, power)\]

Parameters
otherthe other memory area to the the power of
powerthe power to use

Implements alsfvm::memory::Memory< T >.

◆ addPower() [2/2]

template<class T >
void alsfvm::memory::HostMemory< T >::addPower ( const Memory< T > &  other,
double  power,
double  factor 
)
overridevirtual

Adds a power of the other memory area to this memory area, ie

\[this += factor*pow(other, power)\]

Parameters
otherthe other memory area to the the power of
powerthe power to use

Implements alsfvm::memory::Memory< T >.

◆ at() [1/2]

template<class T >
T & alsfvm::memory::HostMemory< T >::at ( size_t  x,
size_t  y = 0,
size_t  z = 0 
)

at returns the data at the given index

Parameters
xthe x index
ythe y index
zthe z index
Returns
the data at the given index

◆ at() [2/2]

template<class T >
const T & alsfvm::memory::HostMemory< T >::at ( size_t  x,
size_t  y = 0,
size_t  z = 0 
) const

at returns the data at the given index

Parameters
xthe x index
ythe y index
zthe z index
Returns
the data at the given index

◆ copyFrom()

template<class T >
void alsfvm::memory::HostMemory< T >::copyFrom ( const Memory< T > &  other)
overridevirtual

Copies the contents of the other memory area into this one.

Implements alsfvm::memory::Memory< T >.

◆ copyFromHost()

template<class T >
void alsfvm::memory::HostMemory< T >::copyFromHost ( const T *  bufferPointer,
size_t  bufferLength 
)
overridevirtual

Copies the memory from the buffer (assumed to be on Host/CPU)

Note
bufferLength must be at least getSize()
Parameters
bufferPointerthe buffer to write to
bufferLengththe size of the buffer (in number of T's)

Implements alsfvm::memory::Memory< T >.

◆ copyInternalCells()

template<class T >
void alsfvm::memory::HostMemory< T >::copyInternalCells ( size_t  startX,
size_t  endX,
size_t  startY,
size_t  endY,
size_t  startZ,
size_t  endZ,
T *  output,
size_t  outputSize 
)
overridevirtual

copyInternalCells copies the internal cells into the memory area This is ideal for removing ghost cells before outputing the solution.

Parameters
startXstart index (inclusive) for x direction
endXend index (exclusive) for x direction
startYstart index (inclusive) for y direction
endYend index (exclusive) for y direction
startZstart index (inclusive) for z direction
endZend index (exclusive) for z direction
outputthe output buffer
outputSizemust be at least the size of the written memory

This is essentially equivalent to doing

size_t numberOfZ = endZ-startZ;
size_t numberOfY = endY-startY;
size_t numberOfX = endX-startX;
for(size_t z = startZ; z < endZ; z++) {
for(size_t y = startY; y < endY; y++) {
for(size_t x = startX; x < endX; x++) {
size_t indexIn = z * nx * ny + y * nx + x;
size_t indexOut = (z-startZ) * numberOfX * numberOfY
+ (y - startY) * numberOfY + (x - startX);
output[indexOut] = data[indexIn];
}
}
}

Implements alsfvm::memory::Memory< T >.

◆ copyToHost()

template<class T >
void alsfvm::memory::HostMemory< T >::copyToHost ( T *  bufferPointer,
size_t  bufferLength 
) const
overridevirtual

Copies the memory to the given buffer

Note
bufferLength must be at least getSize()
Parameters
bufferPointerthe buffer to write to
bufferLengththe size of the buffer (in number of T's)

Implements alsfvm::memory::Memory< T >.

◆ getHostMemory() [1/2]

template<class T >
std::shared_ptr< Memory< T > > alsfvm::memory::HostMemory< T >::getHostMemory ( )
overridevirtual

Copies the data to host if it is on GPU, otherwise makes a copy.

Implements alsfvm::memory::Memory< T >.

◆ getHostMemory() [2/2]

template<class T >
const std::shared_ptr< const Memory< T > > alsfvm::memory::HostMemory< T >::getHostMemory ( ) const
overridevirtual

Copies the data to host if it is on GPU, otherwise makes a copy Const version

Implements alsfvm::memory::Memory< T >.

◆ getPointer() [1/2]

template<class T >
T * alsfvm::memory::HostMemory< T >::getPointer ( )
overridevirtual

Gets the pointer to the data (need not be on the host!)

Note
If this is an OpenCL implementation, the pointer will be useless! If you want to use the OpenCL memory, you should first cast to OpenCL memory, then get the OpenCL buffer pointer.

Implements alsfvm::memory::Memory< T >.

◆ getPointer() [2/2]

template<class T >
const T * alsfvm::memory::HostMemory< T >::getPointer ( ) const
overridevirtual

Gets the pointer to the data (need not be on the host!)

Note
If this is an OpenCL implementation, the pointer will be useless! If you want to use the OpenCL memory, you should first cast to OpenCL memory, then get the OpenCL buffer pointer.

Implements alsfvm::memory::Memory< T >.

◆ getTotalVariation() [1/2]

template<class T >
real alsfvm::memory::HostMemory< T >::getTotalVariation ( int  p,
const ivec3 start,
const ivec3 end 
) const
overridevirtual

Computes the total variation, given here as

\[\sum_{i,j,k} \sqrt(\sum_{n=1}^d|u_{(i,j,k)}-u_{(i,j,k)-e_n}|^2)^p.\]

Note
This function gives no performance guarantees
Parameters
pthe exponent p
startthe index to start at (inclusive)
endthe maximum index (exclusive)

Implements alsfvm::memory::Memory< T >.

◆ getTotalVariation() [2/2]

template<class T >
real alsfvm::memory::HostMemory< T >::getTotalVariation ( int  direction,
int  p,
const ivec3 start,
const ivec3 end 
) const
overridevirtual

$

\[\sum_{i,j,k} |u_{(i,j,k)}-u_{(i,j,k)-e_n}|^p.\]

Note
This function gives no performance guarantees
Parameters
pthe exponent p
directionthe direction (between 0 and 2 inclusive)
startthe index to start at (inclusive)
endthe maximum index (exclusive)

Implements alsfvm::memory::Memory< T >.

◆ isOnHost()

template<class T >
bool alsfvm::memory::HostMemory< T >::isOnHost ( ) const
overridevirtual

Checks if the memory area is on the host (CPU) or on some device, if the latter, one needs to copy to host before reading it.

Returns
true if the memory is on host, false otherwise

Implements alsfvm::memory::Memory< T >.

◆ makeInstance()

template<class T >
std::shared_ptr< Memory< T > > alsfvm::memory::HostMemory< T >::makeInstance ( ) const
overridevirtual

Clones the memory area, but does not copy the content

Implements alsfvm::memory::Memory< T >.

◆ makeZero()

template<class T >
void alsfvm::memory::HostMemory< T >::makeZero ( )
overridevirtual

makeZero sets every element to zero (0)

Implements alsfvm::memory::Memory< T >.

◆ operator*=() [1/2]

template<class T >
void alsfvm::memory::HostMemory< T >::operator*= ( const Memory< T > &  other)
overridevirtual

Mutliplies the other memory area to this one

Parameters
otherthe memory area to multiply from

Implements alsfvm::memory::Memory< T >.

◆ operator*=() [2/2]

template<class T >
void alsfvm::memory::HostMemory< T >::operator*= ( real  scalar)
overridevirtual

Multiplies the scalar to each component

Parameters
scalarthe scalar to multiply

Implements alsfvm::memory::Memory< T >.

◆ operator+=() [1/2]

template<class T >
void alsfvm::memory::HostMemory< T >::operator+= ( const Memory< T > &  other)
overridevirtual

Adds the other memory area to this one

Parameters
otherthe memory area to add from

Implements alsfvm::memory::Memory< T >.

◆ operator+=() [2/2]

template<class T >
void alsfvm::memory::HostMemory< T >::operator+= ( real  scalar)
overridevirtual

Adds the scalar to each component

Parameters
scalarthe scalar to add

Implements alsfvm::memory::Memory< T >.

◆ operator-=() [1/2]

template<class T >
void alsfvm::memory::HostMemory< T >::operator-= ( const Memory< T > &  other)
overridevirtual

Subtracts the other memory area to this one

Parameters
otherthe memory area to subtract from

Implements alsfvm::memory::Memory< T >.

◆ operator-=() [2/2]

template<class T >
void alsfvm::memory::HostMemory< T >::operator-= ( real  scalar)
overridevirtual

Subtracts the scalar from each component

Parameters
scalarthe scalar to subtract

Implements alsfvm::memory::Memory< T >.

◆ operator/=() [1/2]

template<class T >
void alsfvm::memory::HostMemory< T >::operator/= ( const Memory< T > &  other)
overridevirtual

Divides the other memory area to this one

Parameters
otherthe memory area to divide from

Implements alsfvm::memory::Memory< T >.

◆ operator/=() [2/2]

template<class T >
void alsfvm::memory::HostMemory< T >::operator/= ( real  scalar)
overridevirtual

Divides the each component by the scalar

Parameters
scalarthe scalar to divide

Implements alsfvm::memory::Memory< T >.

◆ subtractPower()

template<class T >
void alsfvm::memory::HostMemory< T >::subtractPower ( const Memory< T > &  other,
double  power 
)
overridevirtual

Subtracts a power of the other memory area to this memory area, ie

\[this -= pow(other, power)\]

Parameters
otherthe other memory area to the the power of
powerthe power to use

Implements alsfvm::memory::Memory< T >.


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