# PhasicFlow: src/phasicFlow/containers/Field/Field.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

Field.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __Field_hpp__
#define __Field_hpp__
#include "types.hpp"
#include "VectorSingle.hpp"
#include "wordVectorHost.hpp"
#include "Vector.hpp"
#include "streams.hpp"
namespace pFlow
{
template<class T, class MemorySpace = void>
class Field
:
public VectorSingle<T, MemorySpace>
{
public:
using VectorType = VectorSingle<T,MemorySpace>;
using FieldType = Field<T, MemorySpace>;
using FieldTypeHost = Field<T, HostSpace>;
using memory_space = typename VectorType::memory_space;
using execution_space = typename VectorType::execution_space;
using iterator = typename VectorType::iterator;
using const_iterator = typename VectorType::const_iterator;
using reference = typename VectorType::reference;
using const_reference = typename VectorType::const_reference;
using value_type = typename VectorType::value_type;
using pointer = typename VectorType::pointer;
using const_pointer = typename VectorType::const_pointer;
private:
static const inline word FKey = "value";
const word fieldKey_ = FKey;
public:
TypeInfoTemplateNV111("Field", T, VectorType::memoerySpaceName());
Field()
:
VectorType()
{}
Field(const word& name)
:
VectorType(name)
{}
Field(const word& name, const word& fieldKey)
:
VectorType(name),
fieldKey_(fieldKey)
{}
Field(const word& name, const word& fieldKey, size_t len)
:
VectorType(name, len),
fieldKey_(fieldKey)
{}
Field(const word& name, const word& fieldKey, size_t len, const T& val)
:
VectorType(name, len, val),
fieldKey_(fieldKey)
{}
Field(const word& name, const word& fieldKey, size_t capacity, size_t len, const T& val)
:
VectorType(name, len, len, RESERVE()),
fieldKey_(fieldKey)
{
VectorType::fill(val);
}
Field(const word& name, const word& fieldKey, size_t capacity, size_t len, RESERVE)
:
VectorType(name, capacity, len, RESERVE()),
fieldKey_(fieldKey)
{}
Field(const word& fieldKey, const Vector<T>& vec)
:
VectorType(vec.name(), vec.vectorField()),
fieldKey_(fieldKey)
{}
Field(const word& name, const word& fieldKey, const Vector<T>& vec)
:
VectorType(name, vec.vectorField()),
fieldKey_(fieldKey)
{}
Field(const word& name, const word& fieldKey, const std::vector<T>& vec)
:
VectorType(name, vec),
fieldKey_(fieldKey)
{}
Field(const word& name, const word& fieldKey, const FieldType& src):
VectorType(name, src),
fieldKey_(fieldKey)
{}
Field(const FieldType&) = default;
FieldType& operator = (const FieldType& rhs)
{
if(&rhs == this) return *this;
VectorType::operator=(rhs);
return *this;
}
Field(FieldType&&) = default;
FieldType& operator = (FieldType&&) = default;
word fieldKey()const
{
return fieldKey_;
}
word name()const
{
return VectorType::name();
}
void fillField(rangeU32 span, const T& val)
{
this->fill(span, val);
}
void fillField(const T& val)
{
this->fill(val);
}
bool read(iIstream& is);
bool write(iOstream& os)const;
bool read(iIstream& is, const IOPattern& iop, bool resume = false);
bool write(iOstream& os, const IOPattern& iop )const;
};
template<class T, class MemorySpace>
inline iIstream& operator >> (iIstream & is, Field<T, MemorySpace> & ifld )
{
if( !ifld.read(is, IOPattern::MasterProcessorOnly) )
{
ioErrorInFile (is.name(), is.lineNumber());
fatalExit;
}
return is;
}
template<typename T, typename MemorySpace>
inline iOstream& operator << (iOstream& os, const Field<T, MemorySpace>& ofld )
{
if( !ofld.write(os, IOPattern::AllProcessorsDifferent) )
{
ioErrorInFile(os.name(), os.lineNumber());
fatalExit;
}
return os;
}
}
#include "Field.cpp"
#endif //__Field_hpp__
pFlow::span
Definition: span.hpp:31
pFlow::VectorSingle::fill
INLINE_FUNCTION_H void fill(const T &val)
Fill the range [0,size) with val.
Definition: VectorSingle.cpp:365
pFlow::VectorSingle::const_pointer
const T * const_pointer
Definition: VectorSingle.hpp:66
wordVectorHost.hpp
pFlow::VectorSingle::iterator
T * iterator
Definition: VectorSingle.hpp:54
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t len)
Construct a field with name and fieldKey and specified len.
Definition: Field.hpp:99
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::Field::fillField
void fillField(const T &val)
Definition: Field.hpp:193
types.hpp
pFlow::Field::fieldKey_
const word fieldKey_
Definition: Field.hpp:71
pFlow::Field::Field
Field()
construct an empty Filed with default fieldKey
Definition: Field.hpp:81
pFlow::Field::fieldKey
word fieldKey() const
return field key
Definition: Field.hpp:177
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::Field::read
bool read(iIstream &is)
Definition: Field.cpp:23
pFlow::Field::FieldType
Field< T, MemorySpace > FieldType
Definition: Field.hpp:44
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t capacity, size_t len, RESERVE)
Construct a field with name, fieldKey, capacity and len.
Definition: Field.hpp:123
pFlow::Field::FKey
static const word FKey
Definition: Field.hpp:69
pFlow::Field
Definition: Field.hpp:36
pFlow::Field::name
word name() const
Definition: Field.hpp:182
pFlow::VectorSingle::memory_space
typename viewType::memory_space memory_space
Definition: VectorSingle.hpp:74
pFlow::Field< uint32x3 >::const_pointer
typename VectorType::const_pointer const_pointer
Definition: Field.hpp:64
pFlow::VectorSingle::pointer
T * pointer
Definition: VectorSingle.hpp:64
pFlow
Definition: demGeometry.hpp:27
pFlow::VectorSingle::execution_space
typename viewType::execution_space execution_space
Definition: VectorSingle.hpp:76
pFlow::VectorSingle::name
INLINE_FUNCTION_H word name() const
Name of the vector.
Definition: VectorSingle.cpp:290
RESERVE
Definition: Vector.hpp:40
pFlow::VectorSingle::reference
T & reference
Definition: VectorSingle.hpp:58
pFlow::Field::write
bool write(iOstream &os) const
Definition: Field.cpp:95
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::Field< uint32x3 >::value_type
typename VectorType::value_type value_type
Definition: Field.hpp:60
pFlow::IOPattern::AllProcessorsDifferent
@ AllProcessorsDifferent
Definition: IOPattern.hpp:57
VectorSingle.hpp
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t len, const T &val)
Construct a field with name, fieldKey and set length to len and value to val.
Definition: Field.hpp:108
pFlow::Field::TypeInfoTemplateNV111
TypeInfoTemplateNV111("Field", T, VectorType::memoerySpaceName())
type info
pFlow::VectorSingle::const_iterator
const T * const_iterator
Definition: VectorSingle.hpp:56
pFlow::Field< uint32x3 >::const_reference
typename VectorType::const_reference const_reference
Definition: Field.hpp:58
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::Field< uint32x3 >::const_iterator
typename VectorType::const_iterator const_iterator
Definition: Field.hpp:54
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::Field::Field
Field(const word &fieldKey, const Vector< T > &vec)
Construct a field with fieldKey and Vector vec.
Definition: Field.hpp:130
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::Range< uint32 >
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
streams.hpp
pFlow::Field::operator=
FieldType & operator=(const FieldType &rhs)
Copy assignment, name and fieldKey on the left hand side are preserved.
Definition: Field.hpp:161
pFlow::Field< uint32x3 >::pointer
typename VectorType::pointer pointer
Definition: Field.hpp:62
pFlow::VectorSingle::memoerySpaceName
static constexpr const char * memoerySpaceName()
Name of the memory space.
Definition: VectorSingle.hpp:469
Field.cpp
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t capacity, size_t len, const T &val)
Definition: Field.hpp:114
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::VectorSingle< T, void >::capacity
INLINE_FUNCTION_H uint32 capacity() const
Definition: VectorSingle.cpp:304
pFlow::Field::Field
Field(const word &name, const word &fieldKey)
Construct an empty field with name and fieldKey.
Definition: Field.hpp:92
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
pFlow::Field< uint32x3 >::iterator
typename VectorType::iterator iterator
Definition: Field.hpp:52
pFlow::Field< uint32x3 >::memory_space
typename VectorType::memory_space memory_space
Definition: Field.hpp:48
pFlow::Vector
Definition: Vector.hpp:48
pFlow::VectorSingle::operator=
VectorSingle & operator=(const VectorSingle &rhs)
Copy assignment (perform deep copy from rhs to *this)
Definition: VectorSingle.cpp:204
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const FieldType &src)
Copy construct with new name and fieldkey.
Definition: Field.hpp:151
pFlow::VectorSingle::const_reference
const T & const_reference
Definition: VectorSingle.hpp:60
pFlow::IOPattern::MasterProcessorOnly
@ MasterProcessorOnly
Definition: IOPattern.hpp:54
pFlow::Field::Field
Field(const word &name)
Definition: Field.hpp:86
Vector.hpp
pFlow::Field< uint32x3 >::execution_space
typename VectorType::execution_space execution_space
Definition: Field.hpp:50
pFlow::Field< uint32x3 >::reference
typename VectorType::reference reference
Definition: Field.hpp:56
pFlow::Field::fillField
void fillField(rangeU32 span, const T &val)
Definition: Field.hpp:188
pFlow::VectorSingle::value_type
T value_type
Definition: VectorSingle.hpp:62
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const std::vector< T > &vec)
Construct a field with name and fieldKey and std::vector.
Definition: Field.hpp:144
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const Vector< T > &vec)
Construct a field with name, fieldKey and Vector vec.
Definition: Field.hpp:137