This commit is contained in:
omid.khs
2023-02-20 00:44:41 +03:30
parent 4a591edb87
commit 73bfd41546
13 changed files with 1202 additions and 1077 deletions

View File

@ -18,87 +18,230 @@ Licence:
-----------------------------------------------------------------------------*/
#ifndef __includeMask_hpp__
#define __includeMask_hpp__
#ifndef __IncludeMask_hpp__
#define __IncludeMask_hpp__
#include "virtualConstructor.hpp"
#include "readFromTimeFolder.hpp"
#include "dictionary.hpp"
#include "includeMask.hpp"
namespace pFlow
{
class includeMask
template<typename T>
struct greaterThanOp
{
TypeInfoNV("greaterThan");
inline
bool operator()(const T &compVal, const T &val) const {
return val > compVal; }
};
template<typename T>
struct greaterThanEqOp
{
TypeInfoNV("greaterThanEq");
inline
bool operator()(const T &compVal, const T &val) const {
return val >= compVal; }
};
template<typename T>
struct lessThanOp
{
TypeInfoNV("lessThan");
inline
bool operator()(const T &compVal, const T &val) const {
return val < compVal; }
};
template<typename T>
struct lessThanEqOp
{
TypeInfoNV("lessThanEq");
inline
bool operator()(const T &compVal, const T &val) const {
return val <= compVal; }
};
template<typename T>
struct equalOp
{
TypeInfoNV("equal");
inline
bool operator()(const T &compVal, const T &val) const {
return equal(val , compVal); }
};
template<typename T>
struct betweenOp
{
TypeInfoNV("between");
inline
bool operator()(const T &compVal1, const T &compVal2 ,const T &val) const {
return val>compVal1 && val<compVal2; }
};
template<typename T>
struct betweenEqOp
{
TypeInfoNV("betweenEq");
inline
bool operator()(const T &compVal1, const T &compVal2 ,const T &val) const {
return val>=compVal1 && val<=compVal2; }
};
template<typename T>
struct allOp
{
TypeInfoNV("all");
inline
bool operator()() const {return true; }
};
template<typename T, template<class> class Operator>
class compareOne
{
public:
using opertorType = Operator<T>;
protected:
T compValue_{};
opertorType operator_{};
public:
TypeInfoNV(Operator<T>::TYPENAME());
compareOne(const dictionary& dict)
:
compValue_(dict.getVal<T>("value"))
{}
bool operator()(const T& value)const
{
return operator_(compValue_, value);
}
};
template<typename T, template<class> class Operator>
class compareTwo
{
public:
using opertorType = Operator<T>;
protected:
T compValue1_;
T compValue2_;
opertorType operator_{};
public:
TypeInfoNV(opertorType::TYPENAME());
compareTwo(const dictionary& dict)
:
compValue1_(dict.getVal<T>("value1")),
compValue2_(dict.getVal<T>("value2"))
{}
bool operator()(const T& value)const
{
return operator_(compValue1_, compValue2_, value);
}
};
template<typename T, typename Operator>
class compareZero
{
protected:
word fieldName_;
Operator operator_{};
public:
word fieldType_;
TypeInfoNV(Operator::TYPENAME());
compareZero(const dictionary& dict);
word operatorType_;
bool operator()(const T& value) const
{
return operator_();
}
};
readFromTimeFolder& timeFolder_;
static
bool getFieldType(const dictionary& dict, readFromTimeFolder& timeFolder, word& fName, word& fType);
template<typename T, typename Operator>
class IncludeMask
:
public includeMask
{
protected:
Operator operator_;
pointField_H<T> field_;
public:
TypeInfo("includeMask");
TypeInfoTemplate2("IncludeMask", T, Operator);
includeMask(const dictionary& dict, const word& opType, readFromTimeFolder& timeFolder);
virtual ~includeMask() = default;
create_vCtor(
includeMask,
dictionary,
(
const dictionary& dict,
const word& opType,
readFromTimeFolder& timeFolder
),
(dict, opType, timeFolder)
);
word fieldName()const
{
return fieldName_;
}
word fieldType()const
{
return fieldType_;
}
word operatorType()const
{
return operatorType_;
}
auto& timeFolder()
{
return timeFolder_;
}
virtual bool isIncluded(int32 n) const = 0;
bool operator()(int32 n) const
{
return isIncluded(n);
}
static
uniquePtr<includeMask> create(
IncludeMask(
const dictionary& dict,
const word& opType,
readFromTimeFolder& timeFolder);
const word& opType,
readFromTimeFolder& timeFolder)
:
includeMask(dict, opType, timeFolder),
operator_(dict),
field_(timeFolder.readPointField_H<T>(this->fieldName()))
{}
add_vCtor(
includeMask,
IncludeMask,
dictionary);
bool isIncluded(int32 n)const override
{
return operator_(field_[n]);
}
};
template<typename T>
class IncludeMask<T,allOp<T>>
:
public includeMask
{
public:
TypeInfoTemplate2("IncludeMask", T, allOp<int8>);
IncludeMask(
const dictionary& dict,
const word& opType,
readFromTimeFolder& timeFolder)
:
includeMask(dict, opType, timeFolder)
{}
add_vCtor(
includeMask,
IncludeMask,
dictionary);
bool isIncluded(int32 n)const override
{
return true;
}
};
} // pFlow

View File

@ -18,152 +18,147 @@ Licence:
-----------------------------------------------------------------------------*/
#ifndef __processField_hpp__
#define __processField_hpp__
#ifndef __ProcessField_hpp__
#define __ProcessField_hpp__
#include "virtualConstructor.hpp"
#include "dictionary.hpp"
#include "readFromTimeFolder.hpp"
#include "includeMask.hpp"
#include "pointRectCell.hpp"
#include "processField.hpp"
#include "rectMeshFields.hpp"
#include "twoPartEntry.hpp"
#include "fieldOperations.hpp"
#include "rectMeshFieldToVTK.hpp"
namespace pFlow
{
class repository;
class processField
template<typename T>
class ProcessField
:
public processField
{
protected:
dictionary dict_;
pointField_H<T>& field_;
pointRectCell& pointToCell_;
mutable readFromTimeFolder timeFolder_;
word processedFieldName_;
word fieldName_;
word fieldType_;
word operation_;
word includeMaskType_;
int32 threshold_ = 1;
uniquePtr<includeMask> includeMask_ = nullptr;
bool static getFieldType(
const dictionary& dict,
readFromTimeFolder& timeFolder,
word& fieldName,
word& fieldType);
rectMeshField_H<T>& processedField_;
public:
TypeInfo("processField");
processField(const dictionary& dict, pointRectCell& pToCell, repository& rep);
TypeInfoTemplate("ProcessField", T);
create_vCtor(
processField,
dictionary,
(const dictionary& dict,
pointRectCell& pToCell,
repository& rep),
(dict, pToCell, rep) );
const auto& mesh()const
{
return pointToCell_.mesh();
}
const auto& pointToCell()const
{
return pointToCell_;
}
auto& dict()
{
return dict_;
}
const auto& dict()const
{
return dict_;
}
auto& timeFolderRepository()
{
return timeFolder_.db();
}
auto& processedRepository()
{
return pointToCell_.processedRepository();
}
const word& fieldType()const
{
return fieldType_;
}
const word& fieldName()const
{
return fieldName_;
}
bool isUniform()const
{
return fieldName_ == "uniformField";
}
const word& operation()const
{
return operation_;
}
auto& timeFolder()
{
return timeFolder_;
}
const word& includeMaskType()const
{
return includeMaskType_;
}
auto threshold()const
{
return threshold_;
}
const word& processedFieldName()const
{
return processedFieldName_;
}
// requires a class to read pointField from timefolder
virtual bool process() = 0;
virtual bool writeToVTK(iOstream& is) const = 0;
static
uniquePtr<processField> create(
ProcessField(
const dictionary& dict,
pointRectCell& pToCell,
repository& rep);
repository& rep)
:
processField(dict, pToCell, rep),
field_(
this->isUniform()?
timeFolder().createUniformPointField_H(this->fieldName(), getUniformValue() ):
timeFolder().readPointField_H<T>(this->fieldName())
),
processedField_
(
processedRepository().emplaceObject<rectMeshField_H<T>>
(
objectFile
(
processedFieldName(),
"",
objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS
),
mesh(),
processedFieldName(),
T{}
)
)
{
}
add_vCtor(
processField,
ProcessField,
dictionary);
T getUniformValue()const
{
const dataEntry& entry = dict().dataEntryRef("field");
twoPartEntry tpEntry(entry);
return tpEntry.secondPartVal<T>();
}
virtual bool process() override
{
const includeMask& incMask = includeMask_();
auto numerator = sumMaksOp( field_ , this->pointToCell(), incMask);
rectMeshField_H<real> denomerator( this->mesh(), real{} );
if(operation() == "sum")
{
denomerator = rectMeshField_H<real>(this->mesh(), static_cast<real>(1.0));
}else if(operation() == "average")
{
pointField_H<real> oneFld(field_.pStruct(), static_cast<real>(1.0), static_cast<real>(1.0));
denomerator = sumOp(oneFld, this->pointToCell());
}else if(operation() == "averageMask")
{
pointField_H<real> oneFld(field_.pStruct(), static_cast<real>(1.0), static_cast<real>(1.0));
denomerator = sumMaksOp(oneFld, this->pointToCell(), incMask);
}else
{
fatalErrorInFunction<<"operation is not known: "<< operation()<<endl;
fatalExit;
}
for(int32 i=0; i<this->mesh().nx(); i++ )
{
for(int32 j=0; j<this->mesh().ny(); j++ )
{
for(int32 k=0; k<this->mesh().nz(); k++ )
{
if( pointToCell().nPointInCell(i,j,k)>= threshold() )
{
processedField_(i,j,k) = numerator(i,j,k)/denomerator(i,j,k);
}
else
{
processedField_(i,j,k) = T{};
}
}
}
}
return true;
}
bool writeToVTK(iOstream& os)const override
{
return convertRectMeshField(os, processedField_);
}
};
}
} // pFlow
#endif //__processField_hpp__
#endif //__ProcessField_hpp__