NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
Public Member Functions | List of all members
NeoFOAM::Field< ValueType > Class Template Reference

A class to contain the data and executors for a field and define some basic operations. More...

#include <field.hpp>

Public Member Functions

 Field (const Executor &exec, size_t size)
 Create an uninitialized Field with a given size on an executor.
 
 Field (const Executor &exec, const ValueType *in, size_t size, Executor hostExec=SerialExecutor())
 Create a Field with a given size from existing memory on an executor.
 
 Field (const Executor &exec, size_t size, ValueType value)
 Create a Field with a given size on an executor and uniform value.
 
 Field (const Executor &exec, std::vector< ValueType > in)
 Create a Field from a given vector of values on an executor.
 
 Field (const Executor &exec, const Field< ValueType > &in)
 Create a Field as a copy of a Field on a specified executor.
 
 Field (const Field< ValueType > &rhs)
 Copy constructor, creates a new field with the same size and data as the parsed field.
 
 Field (Field< ValueType > &&rhs) noexcept
 Move constructor, moves the data from the parsed field to the new field.
 
 ~Field ()
 Destroy the Field object.
 
template<typename func >
void apply (func f)
 applies a functor, transformation, to the field
 
Field< ValueType > copyToExecutor (Executor dstExec) const
 Copies the data to a new field on a specific executor.
 
Field< ValueType > copyToHost () const
 Returns a copy of the field back to the host.
 
void copyToHost (Field< ValueType > &result)
 Copies the data (from anywhere) to a parsed host field.
 
KOKKOS_INLINE_FUNCTION ValueType & operator[] (const size_t i)
 Subscript operator.
 
KOKKOS_INLINE_FUNCTION const ValueType & operator[] (const size_t i) const
 Subscript operator.
 
KOKKOS_INLINE_FUNCTION ValueType & operator() (const size_t i)
 Function call operator.
 
KOKKOS_INLINE_FUNCTION const ValueType & operator() (const size_t i) const
 Function call operator.
 
void operator= (const ValueType &rhs)
 Assignment operator, Sets the field values to that of the passed value.
 
void operator= (const Field< ValueType > &rhs)
 Assignment operator, Sets the field values to that of the parsed field.
 
Field< ValueType > & operator+= (const Field< ValueType > &rhs)
 Arithmetic add operator, addition of a second field.
 
Field< ValueType > & operator-= (const Field< ValueType > &rhs)
 Arithmetic subtraction operator, subtraction by a second field.
 
Field< ValueType > operator* (const Field< scalar > &rhs)
 Arithmetic multiply operator, multiply by a second field.
 
Field< ValueType > operator* (const scalar rhs)
 Arithmetic multiply operator, multiplies every cell in the field by a scalar.
 
void resize (const size_t size)
 Resizes the field to a new size.
 
ValueType * data ()
 Direct access to the underlying field data.
 
const ValueType * data () const
 Direct access to the underlying field data.
 
const Executorexec () const
 Gets the executor associated with the field.
 
size_t size () const
 Gets the size of the field.
 
bool empty () const
 Checks if the field is empty.
 
std::span< ValueType > span () &&=delete
 
std::span< const ValueType > span () const &&=delete
 
std::span< ValueType > span () &
 Gets the field as a span.
 
std::span< const ValueType > span () const &
 Gets the field as a span.
 
std::span< ValueType > span (std::pair< size_t, size_t > range) &&=delete
 
std::span< const ValueType > span (std::pair< size_t, size_t > range) const &&=delete
 
std::span< ValueType > span (std::pair< size_t, size_t > range) &
 Gets a sub view of the field as a span.
 
std::span< const ValueType > span (std::pair< size_t, size_t > range) const &
 Gets a sub view of the field as a span.
 
std::pair< size_t, size_trange () const
 Gets the range of the field.
 

Detailed Description

template<typename ValueType>
class NeoFOAM::Field< ValueType >

A class to contain the data and executors for a field and define some basic operations.

Definition at line 48 of file field.hpp.

Constructor & Destructor Documentation

◆ Field() [1/7]

template<typename ValueType >
NeoFOAM::Field< ValueType >::Field ( const Executor exec,
size_t  size 
)
inline

Create an uninitialized Field with a given size on an executor.

Parameters
execExecutor associated to the field
sizesize of the field

Definition at line 58 of file field.hpp.

◆ Field() [2/7]

template<typename ValueType >
NeoFOAM::Field< ValueType >::Field ( const Executor exec,
const ValueType *  in,
size_t  size,
Executor  hostExec = SerialExecutor() 
)
inline

Create a Field with a given size from existing memory on an executor.

Parameters
execExecutor associated to the field
inPointer to existing data
sizesize of the field
hostExecExecutor where the original data is located

Definition at line 76 of file field.hpp.

◆ Field() [3/7]

template<typename ValueType >
NeoFOAM::Field< ValueType >::Field ( const Executor exec,
size_t  size,
ValueType  value 
)
inline

Create a Field with a given size on an executor and uniform value.

Parameters
execExecutor associated to the field
sizesize of the field
valuethe default value

Definition at line 97 of file field.hpp.

◆ Field() [4/7]

template<typename ValueType >
NeoFOAM::Field< ValueType >::Field ( const Executor exec,
std::vector< ValueType >  in 
)
inline

Create a Field from a given vector of values on an executor.

Parameters
execExecutor associated to the field
ina vector of elements to copy over

Definition at line 113 of file field.hpp.

◆ Field() [5/7]

template<typename ValueType >
NeoFOAM::Field< ValueType >::Field ( const Executor exec,
const Field< ValueType > &  in 
)
inline

Create a Field as a copy of a Field on a specified executor.

Parameters
execExecutor associated to the field
ina Field of elements to copy over

Definition at line 120 of file field.hpp.

◆ Field() [6/7]

template<typename ValueType >
NeoFOAM::Field< ValueType >::Field ( const Field< ValueType > &  rhs)
inline

Copy constructor, creates a new field with the same size and data as the parsed field.

Parameters
rhsThe field to copy from.

Definition at line 128 of file field.hpp.

◆ Field() [7/7]

template<typename ValueType >
NeoFOAM::Field< ValueType >::Field ( Field< ValueType > &&  rhs)
inlinenoexcept

Move constructor, moves the data from the parsed field to the new field.

Parameters
rhsThe field to move from.

Definition at line 138 of file field.hpp.

◆ ~Field()

template<typename ValueType >
NeoFOAM::Field< ValueType >::~Field ( )
inline

Destroy the Field object.

Definition at line 147 of file field.hpp.

Member Function Documentation

◆ apply()

template<typename ValueType >
template<typename func >
void NeoFOAM::Field< ValueType >::apply ( func  f)
inline

applies a functor, transformation, to the field

Parameters
fThe functor to map over the field.
Note
Ideally the f should be a KOKKOS_LAMBA

Definition at line 159 of file field.hpp.

◆ copyToExecutor()

template<typename ValueType >
Field< ValueType > NeoFOAM::Field< ValueType >::copyToExecutor ( Executor  dstExec) const
inline

Copies the data to a new field on a specific executor.

Parameters
dstExecThe executor on which the data should be copied.
Returns
A copy of the field on the host.

Definition at line 169 of file field.hpp.

◆ copyToHost() [1/2]

template<typename ValueType >
Field< ValueType > NeoFOAM::Field< ValueType >::copyToHost ( ) const
inline

Returns a copy of the field back to the host.

Returns
A copy of the field on the host.

Definition at line 183 of file field.hpp.

◆ copyToHost() [2/2]

template<typename ValueType >
void NeoFOAM::Field< ValueType >::copyToHost ( Field< ValueType > &  result)
inline

Copies the data (from anywhere) to a parsed host field.

Parameters
resultThe field into which the data must be copied. Must be sized.
Warning
exits if the size of the result field is not the same as the source field.

Definition at line 193 of file field.hpp.

◆ data() [1/2]

template<typename ValueType >
ValueType * NeoFOAM::Field< ValueType >::data ( )
inline

Direct access to the underlying field data.

Returns
Pointer to the first cell data in the field.

Definition at line 337 of file field.hpp.

◆ data() [2/2]

template<typename ValueType >
const ValueType * NeoFOAM::Field< ValueType >::data ( ) const
inline

Direct access to the underlying field data.

Returns
Pointer to the first cell data in the field.

Definition at line 343 of file field.hpp.

◆ empty()

template<typename ValueType >
bool NeoFOAM::Field< ValueType >::empty ( ) const
inline

Checks if the field is empty.

Returns
True if the field is empty, false otherwise.

Definition at line 361 of file field.hpp.

◆ exec()

template<typename ValueType >
const Executor & NeoFOAM::Field< ValueType >::exec ( ) const
inline

Gets the executor associated with the field.

Returns
Reference to the executor.

Definition at line 349 of file field.hpp.

◆ operator()() [1/2]

template<typename ValueType >
KOKKOS_INLINE_FUNCTION ValueType & NeoFOAM::Field< ValueType >::operator() ( const size_t  i)
inline

Function call operator.

Parameters
iThe index of cell in the field
Returns
The value at the index i

Definition at line 223 of file field.hpp.

◆ operator()() [2/2]

template<typename ValueType >
KOKKOS_INLINE_FUNCTION const ValueType & NeoFOAM::Field< ValueType >::operator() ( const size_t  i) const
inline

Function call operator.

Parameters
iThe index of cell in the field
Returns
The value at the index i

Definition at line 231 of file field.hpp.

◆ operator*() [1/2]

template<typename ValueType >
Field< ValueType > NeoFOAM::Field< ValueType >::operator* ( const Field< scalar > &  rhs)
inline

Arithmetic multiply operator, multiply by a second field.

Parameters
rhsThe field to subtract from this field.
Returns
The result of the multiply.

Definition at line 284 of file field.hpp.

◆ operator*() [2/2]

template<typename ValueType >
Field< ValueType > NeoFOAM::Field< ValueType >::operator* ( const scalar  rhs)
inline

Arithmetic multiply operator, multiplies every cell in the field by a scalar.

Parameters
rhsThe scalar to multiply with the field.
Returns
The result of the multiplication.

Definition at line 299 of file field.hpp.

◆ operator+=()

template<typename ValueType >
Field< ValueType > & NeoFOAM::Field< ValueType >::operator+= ( const Field< ValueType > &  rhs)
inline

Arithmetic add operator, addition of a second field.

Parameters
rhsThe field to add with this field.
Returns
The result of the addition.

Definition at line 260 of file field.hpp.

◆ operator-=()

template<typename ValueType >
Field< ValueType > & NeoFOAM::Field< ValueType >::operator-= ( const Field< ValueType > &  rhs)
inline

Arithmetic subtraction operator, subtraction by a second field.

Parameters
rhsThe field to subtract from this field.
Returns
The result of the subtraction.

Definition at line 272 of file field.hpp.

◆ operator=() [1/2]

template<typename ValueType >
void NeoFOAM::Field< ValueType >::operator= ( const Field< ValueType > &  rhs)
inline

Assignment operator, Sets the field values to that of the parsed field.

Parameters
rhsThe field to copy from.
Warning
This field will be sized to the size of the parsed field.

Definition at line 245 of file field.hpp.

◆ operator=() [2/2]

template<typename ValueType >
void NeoFOAM::Field< ValueType >::operator= ( const ValueType &  rhs)
inline

Assignment operator, Sets the field values to that of the passed value.

Parameters
rhsThe value to set the field to.

Definition at line 237 of file field.hpp.

◆ operator[]() [1/2]

template<typename ValueType >
KOKKOS_INLINE_FUNCTION ValueType & NeoFOAM::Field< ValueType >::operator[] ( const size_t  i)
inline

Subscript operator.

Parameters
iThe index of cell in the field
Returns
The value at the index i

Definition at line 207 of file field.hpp.

◆ operator[]() [2/2]

template<typename ValueType >
KOKKOS_INLINE_FUNCTION const ValueType & NeoFOAM::Field< ValueType >::operator[] ( const size_t  i) const
inline

Subscript operator.

Parameters
iThe index of cell in the field
Returns
The value at the index i

Definition at line 215 of file field.hpp.

◆ range()

template<typename ValueType >
std::pair< size_t, size_t > NeoFOAM::Field< ValueType >::range ( ) const
inline

Gets the range of the field.

Returns
The range of the field {0, size()}.

Definition at line 412 of file field.hpp.

◆ resize()

template<typename ValueType >
void NeoFOAM::Field< ValueType >::resize ( const size_t  size)
inline

Resizes the field to a new size.

Parameters
sizeThe new size to set the field to.

Definition at line 311 of file field.hpp.

◆ size()

template<typename ValueType >
size_t NeoFOAM::Field< ValueType >::size ( ) const
inline

Gets the size of the field.

Returns
The size of the field.

Definition at line 355 of file field.hpp.

◆ span() [1/8]

template<typename ValueType >
std::span< ValueType > NeoFOAM::Field< ValueType >::span ( ) &
inline

Gets the field as a span.

Returns
Span of the field.

Definition at line 373 of file field.hpp.

◆ span() [2/8]

template<typename ValueType >
std::span< ValueType > NeoFOAM::Field< ValueType >::span ( ) &&
delete

◆ span() [3/8]

template<typename ValueType >
std::span< const ValueType > NeoFOAM::Field< ValueType >::span ( ) const &
inline

Gets the field as a span.

Returns
Span of the field.

Definition at line 379 of file field.hpp.

◆ span() [4/8]

template<typename ValueType >
std::span< const ValueType > NeoFOAM::Field< ValueType >::span ( ) const &&
delete

◆ span() [5/8]

template<typename ValueType >
std::span< ValueType > NeoFOAM::Field< ValueType >::span ( std::pair< size_t, size_t range) &
inline

Gets a sub view of the field as a span.

Returns
Span of the field.

Definition at line 394 of file field.hpp.

◆ span() [6/8]

template<typename ValueType >
std::span< ValueType > NeoFOAM::Field< ValueType >::span ( std::pair< size_t, size_t range) &&
delete

◆ span() [7/8]

template<typename ValueType >
std::span< const ValueType > NeoFOAM::Field< ValueType >::span ( std::pair< size_t, size_t range) const &
inline

Gets a sub view of the field as a span.

Returns
Span of the field.

Definition at line 403 of file field.hpp.

◆ span() [8/8]

template<typename ValueType >
std::span< const ValueType > NeoFOAM::Field< ValueType >::span ( std::pair< size_t, size_t range) const &&
delete

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