# PhasicFlow: src/phasicFlow/containers/Field/Field.hpp Source File

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 "VectorSingle.hpp"
#include "vocabs.hpp"
namespace pFlow
{
template<template<class, class> class VectorField, class T, class PropType=void>
class Field
:
public VectorField<T, PropType>
{
public:
using VectorType = VectorField<T,PropType>;
using FieldType = Field<VectorField, T, PropType>;
using iterator = typename VectorType::iterator;
using constIterator = typename VectorType::constIterator;
using reference = typename VectorType::reference;
using constReference = typename VectorType::constReference;
using valueType = typename VectorType::valueType;
using pointer = typename VectorType::pointer;
using constPointer = typename VectorType::constPointer;
protected:
static const inline word FKey = "value";
const word fieldKey_ = FKey;
bool readUniform( iIstream& is, size_t len, bool readLength = true);
bool readNonUniform( iIstream& is, size_t len);
public:
// - type info
TypeInfoTemplateNV2("Field", T, VectorType::memoerySpaceName());
// construct an empty Filed with default fieldKey
Field()
:
VectorType()
{}
// construct an empty Field with fieldKey
Field(const word& fieldKey)
:
VectorType(),
fieldKey_(fieldKey)
{}
// construct an empty field with name and fieldKey
Field(const word& name, const word& fieldKey)
:
VectorType(name),
fieldKey_(fieldKey)
{}
// construct an empty Filed with default fieldKey
Field(size_t len)
:
VectorType(len)
{}
// construct an empty Field with fieldKey
Field(const word& fieldKey, size_t len)
:
VectorType(len),
fieldKey_(fieldKey)
{}
// construct an empty field with name and fieldKey
Field(const word& name, const word& fieldKey, size_t len)
:
VectorType(name, len),
fieldKey_(fieldKey)
{}
// construct an empty Filed with default fieldKey and set vector to val
Field(size_t len, const T& val)
:
VectorType(len, val)
{}
// construct an empty Field with fieldKey and set vector to val
Field(const word& fieldKey, size_t len, const T& val)
:
VectorType(len, val),
fieldKey_(fieldKey)
{}
// construct an empty field with name and fieldKey and set vector to val
Field(const word& name, const word& fieldKey, size_t len, const T& val)
:
VectorType(name, len, val),
fieldKey_(fieldKey)
{}
// construct a field with capacity and len and default fieldKey
Field(size_t capacity, size_t len, RESERVE)
:
VectorType(capacity, len, RESERVE())
{}
// construct an empty Field with fieldKey
Field(const word& fieldKey, size_t capacity, size_t len, RESERVE)
:
VectorType(capacity, len, RESERVE()),
fieldKey_(fieldKey)
{}
// construct an empty field with name and fieldKey
Field(const word& name, const word& fieldKey, size_t capacity, size_t len, RESERVE)
:
VectorType(name, capacity, len, RESERVE()),
fieldKey_(fieldKey)
{}
// construct with vec and default fieldKey
Field(const Vector<T>& vec)
:
VectorType(vec)
{}
// construct an empty Field with fieldKey
Field(const word& fieldKey, const Vector<T>& vec)
:
VectorType(vec),
fieldKey_(fieldKey)
{}
// construct an empty field with name and fieldKey
Field(const word& name, const word& fieldKey, const Vector<T>& vec)
:
VectorType(name, vec),
fieldKey_(fieldKey)
{}
// - copy construct with new name and fieldkey
Field(const word& name, const word& fieldKey, const FieldType& src):
VectorType(name, src),
fieldKey_(fieldKey)
{}
// - default copy constructor
Field(const FieldType&) = default;
// - default copy assignment
FieldType& operator = (const FieldType&) = default;
// - no move constructor
Field(FieldType&&) = delete;
// - no move assignment
FieldType& operator = (FieldType&&) = delete;
// - clone as a uniquePtr
INLINE_FUNCTION_H
uniquePtr<FieldType> clone() const
{
return makeUnique<FieldType>(*this);
}
// - clone as a raw pointer
INLINE_FUNCTION_H
FieldType* clonePtr()const
{
return new FieldType(*this);
}
const word& fieldKey()const
{
return fieldKey_;
}
bool readField(iIstream& is, const size_t len, bool readLength = true);
bool readField(iIstream& is );
bool writeField(iOstream& os)const;
bool read(iIstream& is)
{
return readField(is);
}
bool write(iOstream& os)const
{
return writeField(os);
}
};
template<template<class, class> class VectorField, class T, class PropType>
inline iIstream& operator >> (iIstream & is, Field<VectorField, T, PropType> & ifld )
{
if( !ifld.readField(is) )
{
ioErrorInFile (is.name(), is.lineNumber());
fatalExit;
}
return is;
}
template<template<class, class> class VectorField, class T, class PropType>
inline iOstream& operator << (iOstream& os, const Field<VectorField, T, PropType>& ofld )
{
if( !ofld.writeField(os) )
{
ioErrorInFile(os.name(), os.lineNumber());
fatalExit;
}
return os;
}
}
#include "Field.cpp"
#endif //__Field_hpp__
pFlow::Field::Field
Field(const Vector< T > &vec)
Definition: Field.hpp:157
pFlow::VectorDual< int8, void >::iterator
int8 * iterator
Definition: VectorDual.hpp:51
pFlow::Field::TypeInfoTemplateNV2
TypeInfoTemplateNV2("Field", T, VectorType::memoerySpaceName())
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t len)
Definition: Field.hpp:110
pFlow::Field< VectorDual, int8 >::constReference
typename VectorType::constReference constReference
Definition: Field.hpp:50
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::Field::fieldKey_
const word fieldKey_
Definition: Field.hpp:63
pFlow::Field::Field
Field()
Definition: Field.hpp:77
pFlow::Field::Field
Field(const word &fieldKey, size_t len, const T &val)
Definition: Field.hpp:123
pFlow::Field< VectorDual, int8 >::constPointer
typename VectorType::constPointer constPointer
Definition: Field.hpp:56
pFlow::Field::clonePtr
INLINE_FUNCTION_H FieldType * clonePtr() const
Definition: Field.hpp:204
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::Field::read
bool read(iIstream &is)
Definition: Field.hpp:226
pFlow::Field::Field
Field(size_t len)
Definition: Field.hpp:97
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t capacity, size_t len, RESERVE)
Definition: Field.hpp:150
pFlow::Field::FKey
static const word FKey
Definition: Field.hpp:61
pFlow::Field::FieldType
Field< VectorField, T, PropType > FieldType
Definition: Field.hpp:42
pFlow::Field
Definition: Field.hpp:33
pFlow
Definition: demComponent.hpp:28
RESERVE
Definition: Vector.hpp:38
pFlow::VectorDual< int8, void >::pointer
int8 * pointer
Definition: VectorDual.hpp:61
pFlow::Field::readNonUniform
bool readNonUniform(iIstream &is, size_t len)
Definition: Field.cpp:62
pFlow::Field::Field
Field(const word &fieldKey, size_t len)
Definition: Field.hpp:103
pFlow::Field::write
bool write(iOstream &os) const
Definition: Field.hpp:231
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::VectorDual< int8, void >
pFlow::VectorDual< int8, void >::valueType
int8 valueType
Definition: VectorDual.hpp:59
pFlow::VectorDual< int8, void >::reference
int8 & reference
Definition: VectorDual.hpp:55
VectorSingle.hpp
pFlow::Field::Field
Field(const word &name, const word &fieldKey, size_t len, const T &val)
Definition: Field.hpp:130
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
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)
Definition: Field.hpp:163
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::VectorDual< int8, void >::constIterator
const int8 * constIterator
Definition: VectorDual.hpp:53
pFlow::VectorDual< int8, void >::constReference
const int8 & constReference
Definition: VectorDual.hpp:57
pFlow::Field::Field
Field(const word &fieldKey)
Definition: Field.hpp:83
pFlow::Field::fieldKey
const word & fieldKey() const
Definition: Field.hpp:211
pFlow::Field::readField
bool readField(iIstream &is, const size_t len, bool readLength=true)
Definition: Field.cpp:104
pFlow::Field::Field
Field(const word &fieldKey, size_t capacity, size_t len, RESERVE)
Definition: Field.hpp:143
pFlow::Field::Field
Field(size_t len, const T &val)
Definition: Field.hpp:117
pFlow::Field< VectorDual, int8 >::pointer
typename VectorType::pointer pointer
Definition: Field.hpp:54
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
Field.cpp
pFlow::Field::Field
Field(size_t capacity, size_t len, RESERVE)
Definition: Field.hpp:137
pFlow::Field::readUniform
bool readUniform(iIstream &is, size_t len, bool readLength=true)
Definition: Field.cpp:23
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::Field< VectorDual, int8 >::valueType
typename VectorType::valueType valueType
Definition: Field.hpp:52
pFlow::VectorDual< int8, void >::constPointer
const int8 * constPointer
Definition: VectorDual.hpp:63
pFlow::Field::Field
Field(const word &name, const word &fieldKey)
Definition: Field.hpp:90
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::Field< VectorDual, int8 >::iterator
typename VectorType::iterator iterator
Definition: Field.hpp:44
pFlow::Field::operator=
FieldType & operator=(const FieldType &)=default
pFlow::Field::writeField
bool writeField(iOstream &os) const
Definition: Field.cpp:163
vocabs.hpp
pFlow::Vector
Definition: Vector.hpp:46
pFlow::Field< VectorDual, int8 >::constIterator
typename VectorType::constIterator constIterator
Definition: Field.hpp:46
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const FieldType &src)
Definition: Field.hpp:178
pFlow::Field< VectorDual, int8 >::reference
typename VectorType::reference reference
Definition: Field.hpp:48
pFlow::Field::clone
INLINE_FUNCTION_H uniquePtr< FieldType > clone() const
Definition: Field.hpp:197
pFlow::Field::Field
Field(const word &name, const word &fieldKey, const Vector< T > &vec)
Definition: Field.hpp:170