mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-08-17 03:47:04 +00:00
The main structure is tested. functons like execute and write are added and tested.
other components are left
This commit is contained in:
@ -0,0 +1,147 @@
|
||||
#include "particleProbePostprocessComponent.hpp"
|
||||
#include "Time.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
inline
|
||||
regionField<T> porbeExecute
|
||||
(
|
||||
const word& regFieldName,
|
||||
const span<T>& field,
|
||||
const regionPoints& regPoints
|
||||
)
|
||||
{
|
||||
regionField<T> processedField(regFieldName, regPoints, T{});
|
||||
auto partIndices = regPoints.indices(0);
|
||||
|
||||
uint n = 0;
|
||||
for(auto index:partIndices)
|
||||
{
|
||||
if(index != -1)
|
||||
{
|
||||
processedField[n] = field[index];
|
||||
}
|
||||
n++;
|
||||
}
|
||||
return processedField;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool writeField
|
||||
(
|
||||
iOstream& os,
|
||||
timeValue t,
|
||||
const regionField<T>& field,
|
||||
const regionPoints& regPoints,
|
||||
const T& invalidVal = T{}
|
||||
)
|
||||
{
|
||||
auto indices = regPoints.indices(0);
|
||||
const uint32 s= field.size();
|
||||
os<< t <<tab;
|
||||
for(uint32 i=0; i<s; i++)
|
||||
{
|
||||
if constexpr(std::is_same_v<T,realx3>)
|
||||
{
|
||||
os<<field[i].x()<<' '<<field[i].y()<<' '<<field[i].z()<<tab;
|
||||
}
|
||||
else if constexpr( std::is_same_v<T,realx4> )
|
||||
{
|
||||
os<<field[i].x()<<' '<<field[i].y()<<' '<<field[i].z()<<tab<<field[i].w()<<tab;
|
||||
}
|
||||
else
|
||||
{
|
||||
os<<field[i]<<tab;
|
||||
}
|
||||
}
|
||||
os<<endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pFlow::particleProbePostprocessComponent::particleProbePostprocessComponent
|
||||
(
|
||||
const dictionary &dict,
|
||||
fieldsDataBase &fieldsDB,
|
||||
const baseTimeControl &defaultTimeControl
|
||||
)
|
||||
:
|
||||
postprocessComponent(dict, fieldsDB, defaultTimeControl),
|
||||
regionPointsPtr_
|
||||
(
|
||||
makeUnique<centerPointsRegionPoints>(dict, fieldsDB)
|
||||
),
|
||||
fieldName_
|
||||
(
|
||||
dict.getVal<word>("field")
|
||||
),
|
||||
name_(dict.name())
|
||||
{}
|
||||
|
||||
bool pFlow::particleProbePostprocessComponent::execute
|
||||
(
|
||||
const timeInfo &ti,
|
||||
bool forceExecute
|
||||
)
|
||||
{
|
||||
if( !forceExecute && !timeControl().eventTime(ti))
|
||||
{
|
||||
executed_ = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!regionPointsPtr_().update())
|
||||
{
|
||||
fatalErrorInFunction
|
||||
<< "regionPoints update for "<< name_ << " failed. \n";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto field = database().updateFieldAll(fieldName_);
|
||||
auto pFieldName = name_;
|
||||
|
||||
processedField_ = makeUnique<processedRegFieldType>
|
||||
(
|
||||
std::visit(
|
||||
[&](auto&& f) -> processedRegFieldType
|
||||
{
|
||||
return porbeExecute(
|
||||
pFieldName,
|
||||
f,
|
||||
regionPointsPtr_());
|
||||
},
|
||||
field)
|
||||
);
|
||||
|
||||
executed_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool pFlow::particleProbePostprocessComponent::write(const fileSystem& parDir)const
|
||||
{
|
||||
if(! executed_ ) return true;
|
||||
|
||||
const auto ti = database().time().TimeInfo();
|
||||
|
||||
if( !osPtr_)
|
||||
{
|
||||
// file is not open yet
|
||||
fileSystem path = parDir + (name_+".Start_"+ti.prevTimeName());
|
||||
osPtr_ = makeUnique<oFstream>(path);
|
||||
regionPointsPtr_().write(osPtr_());
|
||||
}
|
||||
|
||||
std::visit
|
||||
([&](auto&& arg)->bool
|
||||
{
|
||||
return writeField(osPtr_(), ti.t(), arg, regionPointsPtr_());
|
||||
},
|
||||
processedField_()
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
/*------------------------------- 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 __particleProbePostprocessComponent_hpp__
|
||||
#define __particleProbePostprocessComponent_hpp__
|
||||
|
||||
#include "postprocessComponent.hpp"
|
||||
#include "fieldsDataBase.hpp"
|
||||
#include "centerPointsRegionPoints.hpp"
|
||||
#include "regionField.hpp"
|
||||
#include "oFstream.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
|
||||
class particleProbePostprocessComponent
|
||||
:
|
||||
public postprocessComponent
|
||||
{
|
||||
private:
|
||||
|
||||
using processedRegFieldType = std::variant
|
||||
<
|
||||
regionField<real>,
|
||||
regionField<realx3>,
|
||||
regionField<realx4>
|
||||
>;
|
||||
|
||||
bool executed_{false};
|
||||
|
||||
uniquePtr<centerPointsRegionPoints> regionPointsPtr_;
|
||||
|
||||
uniquePtr<processedRegFieldType> processedField_ = nullptr;
|
||||
|
||||
word fieldName_;
|
||||
|
||||
word name_;
|
||||
|
||||
mutable uniquePtr<oFstream> osPtr_ = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
TypeInfo("PostprocessComponent<centerPoints,particleProbe>");
|
||||
|
||||
particleProbePostprocessComponent
|
||||
(
|
||||
const dictionary& dict,
|
||||
fieldsDataBase& fieldsDB,
|
||||
const baseTimeControl& defaultTimeControl
|
||||
);
|
||||
|
||||
~particleProbePostprocessComponent()override = default;
|
||||
|
||||
add_vCtor
|
||||
(
|
||||
postprocessComponent,
|
||||
particleProbePostprocessComponent,
|
||||
dictionary
|
||||
);
|
||||
|
||||
word name()const override
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
regionPoints& regPoints() override
|
||||
{
|
||||
return regionPointsPtr_();
|
||||
}
|
||||
|
||||
const regionPoints& regPoints() const override
|
||||
{
|
||||
return regionPointsPtr_();
|
||||
}
|
||||
|
||||
bool execute(const timeInfo& ti, bool forceExecute = false) override;
|
||||
|
||||
bool executed() const override
|
||||
{
|
||||
return executed_;
|
||||
}
|
||||
|
||||
bool write(const fileSystem& parDir)const override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //__particleProbePostprocessComponent_hpp__
|
Reference in New Issue
Block a user