2022-09-01 17:05:35 +00:00
|
|
|
/*------------------------------- 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.
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
2022-12-09 22:02:54 +00:00
|
|
|
#ifndef __Field_hpp__
|
|
|
|
#define __Field_hpp__
|
2022-09-01 17:05:35 +00:00
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
//#include "VectorSingle.hpp"
|
|
|
|
//#include "vocabs.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include "types.hpp"
|
|
|
|
#include "Vector.hpp"
|
|
|
|
|
2022-09-01 17:05:35 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/*bool readUniform( iIstream& is, size_t len, bool readLength = true);
|
2022-09-01 17:05:35 +00:00
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
bool readNonUniform( iIstream& is, size_t len);*/
|
2022-09-01 17:05:35 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// type info
|
2022-12-09 22:02:54 +00:00
|
|
|
TypeInfoTemplateNV2("Field", T, VectorType::memoerySpaceName());
|
2022-09-01 17:05:35 +00:00
|
|
|
|
|
|
|
//// - Constructors
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// construct an empty Filed with default fieldKey
|
2022-09-01 17:05:35 +00:00
|
|
|
Field()
|
|
|
|
:
|
|
|
|
VectorType()
|
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
|
|
|
|
/// Construct an empty field with name and fieldKey
|
2022-09-01 17:05:35 +00:00
|
|
|
Field(const word& name, const word& fieldKey)
|
|
|
|
:
|
|
|
|
VectorType(name),
|
|
|
|
fieldKey_(fieldKey)
|
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
|
|
|
|
/// Construct a field with name and fieldKey and specified len
|
2022-09-01 17:05:35 +00:00
|
|
|
Field(const word& name, const word& fieldKey, size_t len)
|
|
|
|
:
|
|
|
|
VectorType(name, len),
|
|
|
|
fieldKey_(fieldKey)
|
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
|
|
|
|
/// Construct a field with name, fieldKey and
|
|
|
|
/// set length to len and value to val
|
2022-09-01 17:05:35 +00:00
|
|
|
Field(const word& name, const word& fieldKey, size_t len, const T& val)
|
|
|
|
:
|
|
|
|
VectorType(name, len, val),
|
|
|
|
fieldKey_(fieldKey)
|
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Construct a field with name, fieldKey, capacity and len
|
2022-09-01 17:05:35 +00:00
|
|
|
Field(const word& name, const word& fieldKey, size_t capacity, size_t len, RESERVE)
|
|
|
|
:
|
|
|
|
VectorType(name, capacity, len, RESERVE()),
|
|
|
|
fieldKey_(fieldKey)
|
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Construct a field with fieldKey and Vector vec
|
|
|
|
Field(const word& fieldKey, const Vector<T>& vec)
|
2022-09-01 17:05:35 +00:00
|
|
|
:
|
2023-10-28 08:39:40 +00:00
|
|
|
VectorType(vec.name(), vec.vectorField()),
|
|
|
|
fieldKey_(fieldKey)
|
2022-09-01 17:05:35 +00:00
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Construct a field with name, fieldKey and Vector vec
|
|
|
|
Field(const word& name, const word& fieldKey, const Vector<T>& vec)
|
2022-09-01 17:05:35 +00:00
|
|
|
:
|
2023-10-28 08:39:40 +00:00
|
|
|
VectorType(name, vec.vectorField()),
|
2022-09-01 17:05:35 +00:00
|
|
|
fieldKey_(fieldKey)
|
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Construct a field with name and fieldKey and std::vector
|
|
|
|
Field(const word& name, const word& fieldKey, const std::vector<T>& vec)
|
2022-09-01 17:05:35 +00:00
|
|
|
:
|
|
|
|
VectorType(name, vec),
|
|
|
|
fieldKey_(fieldKey)
|
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Copy construct with new name and fieldkey
|
2022-09-01 17:05:35 +00:00
|
|
|
Field(const word& name, const word& fieldKey, const FieldType& src):
|
|
|
|
VectorType(name, src),
|
|
|
|
fieldKey_(fieldKey)
|
|
|
|
{}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Default copy constructor
|
2022-09-01 17:05:35 +00:00
|
|
|
Field(const FieldType&) = default;
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Copy assignment, name and fieldKey
|
|
|
|
/// on the left hand side are preserved
|
|
|
|
FieldType& operator = (const FieldType& rhs)
|
|
|
|
{
|
|
|
|
if(&rhs == this) return *this;
|
|
|
|
VectorType::operator=(rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
2022-09-01 17:05:35 +00:00
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Move constructor
|
|
|
|
Field(FieldType&&) = default;
|
2022-09-01 17:05:35 +00:00
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// Move assignment
|
|
|
|
FieldType& operator = (FieldType&&) = default;
|
2022-09-01 17:05:35 +00:00
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// clone as a uniquePtr
|
2022-09-01 17:05:35 +00:00
|
|
|
INLINE_FUNCTION_H
|
|
|
|
uniquePtr<FieldType> clone() const
|
|
|
|
{
|
|
|
|
return makeUnique<FieldType>(*this);
|
|
|
|
}
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// clone as a raw pointer
|
2022-09-01 17:05:35 +00:00
|
|
|
INLINE_FUNCTION_H
|
|
|
|
FieldType* clonePtr()const
|
|
|
|
{
|
|
|
|
return new FieldType(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//// - Methods
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
/// return field key
|
2022-09-01 17:05:35 +00:00
|
|
|
const word& fieldKey()const
|
|
|
|
{
|
|
|
|
return fieldKey_;
|
|
|
|
}
|
|
|
|
|
|
|
|
//// - IO operations
|
2023-10-28 08:39:40 +00:00
|
|
|
/*bool readField(iIstream& is, const size_t len, bool resume, bool readLength = true);
|
2022-09-01 17:05:35 +00:00
|
|
|
|
|
|
|
|
2023-04-12 05:19:36 +00:00
|
|
|
bool readField(iIstream& is, bool resume );
|
2022-09-01 17:05:35 +00:00
|
|
|
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
bool writeField(iOstream& os)const;*/
|
2022-09-01 17:05:35 +00:00
|
|
|
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
bool read(iIstream& is, IOPattern::IOType iotype);
|
|
|
|
|
2022-09-01 17:05:35 +00:00
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
bool write(iOstream& os, IOPattern::IOType iotype )const;
|
|
|
|
|
2022-09-01 17:05:35 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<template<class, class> class VectorField, class T, class PropType>
|
|
|
|
inline iIstream& operator >> (iIstream & is, Field<VectorField, T, PropType> & ifld )
|
|
|
|
{
|
2023-10-28 08:39:40 +00:00
|
|
|
if( !ifld.read(is, IOPattern::MasterProcessor) )
|
2022-09-01 17:05:35 +00:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
|
2023-10-28 08:39:40 +00:00
|
|
|
if( !ofld.write(os, IOPattern::AllProcessorsDifferent) )
|
2022-09-01 17:05:35 +00:00
|
|
|
{
|
|
|
|
ioErrorInFile(os.name(), os.lineNumber());
|
|
|
|
fatalExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-09 22:02:54 +00:00
|
|
|
#include "Field.cpp"
|
2022-09-01 17:05:35 +00:00
|
|
|
|
|
|
|
|
2022-12-09 22:02:54 +00:00
|
|
|
#endif //__Field_hpp__
|