change for predictor-corrector and adams-moulton3

This commit is contained in:
hamidrezanorouzi
2022-10-25 19:30:57 +03:30
parent db0da79a72
commit 490577dcd2
27 changed files with 869 additions and 121 deletions

View File

@ -74,6 +74,13 @@ bool pFlow::AdamsBashforth2::correct
return true;
}
bool pFlow::AdamsBashforth2::setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y)
{
return true;
}
bool pFlow::AdamsBashforth2::intAll(
real dt,
realx3Vector_D& y,

View File

@ -68,6 +68,20 @@ public:
bool correct(real dt, realx3Vector_D& y, realx3Vector_D& dy) override;
bool setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y) override;
bool needSetInitialVals()const override
{
return false;
}
uniquePtr<integration> clone()const override
{
return makeUnique<AdamsBashforth2>(*this);
}
bool intAll(real dt, realx3Vector_D& y, realx3Vector_D& dy, range activeRng);
template<typename activeFunctor>

View File

@ -60,7 +60,7 @@ pFlow::AdamsBashforth3::AdamsBashforth3
AB3History({zero3,zero3})))
{
}
bool pFlow::AdamsBashforth3::predict
@ -94,6 +94,13 @@ bool pFlow::AdamsBashforth3::correct
return true;
}
bool pFlow::AdamsBashforth3::setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y)
{
return true;
}
bool pFlow::AdamsBashforth3::intAll(
real dt,
realx3Vector_D& y,

View File

@ -117,6 +117,20 @@ public:
realx3Vector_D & y,
realx3Vector_D& dy) override;
bool setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y) override;
bool needSetInitialVals()const override
{
return false;
}
uniquePtr<integration> clone()const override
{
return makeUnique<AdamsBashforth3>(*this);
}
bool intAll(real dt,
realx3Vector_D& y,
realx3Vector_D& dy,

View File

@ -76,6 +76,13 @@ bool pFlow::AdamsBashforth4::correct
return true;
}
bool pFlow::AdamsBashforth4::setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y)
{
return true;
}
bool pFlow::AdamsBashforth4::intAll(
real dt,
realx3Vector_D& y,

View File

@ -122,6 +122,20 @@ public:
realx3Vector_D & y,
realx3Vector_D& dy) override;
bool setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y) override;
bool needSetInitialVals()const override
{
return false;
}
uniquePtr<integration> clone()const override
{
return makeUnique<AdamsBashforth4>(*this);
}
bool intAll(real dt,
realx3Vector_D& y,
realx3Vector_D& dy,

View File

@ -76,6 +76,13 @@ bool pFlow::AdamsBashforth5::correct
return true;
}
bool pFlow::AdamsBashforth5::setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y)
{
return true;
}
bool pFlow::AdamsBashforth5::intAll(
real dt,
realx3Vector_D& y,

View File

@ -120,6 +120,20 @@ public:
realx3Vector_D & y,
realx3Vector_D& dy) override;
bool setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y) override;
bool needSetInitialVals()const override
{
return false;
}
uniquePtr<integration> clone()const override
{
return makeUnique<AdamsBashforth5>(*this);
}
bool intAll(real dt,
realx3Vector_D& y,
realx3Vector_D& dy,

View File

@ -0,0 +1,175 @@
/*------------------------------- 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.
-----------------------------------------------------------------------------*/
#include "AdamsMoulton3.H"
//const real AB2_coef[] = { 3.0 / 2.0, 1.0 / 2.0};
pFlow::AdamsMoulton3::AdamsMoulton3
(
const word& baseName,
repository& owner,
const pointStructure& pStruct,
const word& method
)
:
integration(baseName, owner, pStruct, method),
y0_(
owner.emplaceObject<realx3PointField_D>(
objectFile(
groupNames(baseName,"y0"),
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS),
pStruct,
zero3,
false
)
),
dy0_(
owner.emplaceObject<realx3PointField_D>(
objectFile(
groupNames(baseName,"dy0"),
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS),
pStruct,
zero3
)
),
dy1_(
owner.emplaceObject<realx3PointField_D>(
objectFile(
groupNames(baseName,"dy1"),
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS),
pStruct,
zero3
)
)
{
}
bool pFlow::AdamsMoulton3::predict
(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy
)
{
if(this->pStruct().allActive())
{
return predictAll(dt, y, dy, this->pStruct().activeRange());
}
else
{
return predictRange(dt, y, dy, this->pStruct().activePointsMaskD());
}
return true;
}
bool pFlow::AdamsMoulton3::correct
(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy
)
{
if(this->pStruct().allActive())
{
return intAll(dt, y, dy, this->pStruct().activeRange());
}
else
{
return intRange(dt, y, dy, this->pStruct().activePointsMaskD());
}
return true;
}
bool pFlow::AdamsMoulton3::setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y)
{
y0_.insertSetElement(newIndices, y);
//output<< "y0_ "<< y0_<<endl<<endl;
return true;
}
bool pFlow::AdamsMoulton3::predictAll(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy,
range activeRng)
{
auto d_dy = dy.deviceVectorAll();
auto d_y = y.deviceVectorAll();
auto d_y0 = y0_.deviceVectorAll();
auto d_dy0 = dy0_.deviceVectorAll();
auto d_dy1= dy1_.deviceVectorAll();
Kokkos::parallel_for(
"AdamsMoulton3::predict",
rpIntegration (activeRng.first, activeRng.second),
LAMBDA_HD(int32 i){
d_dy0[i] = d_dy[i];
d_y[i] = d_y0[i] + dt*(static_cast<real>(3.0 / 2.0) * d_dy[i] - static_cast<real>(1.0 / 2.0) * d_dy1[i]);
});
Kokkos::fence();
return true;
}
bool pFlow::AdamsMoulton3::intAll(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy,
range activeRng)
{
auto d_dy = dy.deviceVectorAll();
auto d_y = y.deviceVectorAll();
auto d_dy0 = dy0_.deviceVectorAll();
auto d_y0 = y0_.deviceVectorAll();
auto d_dy1 = dy1_.deviceVectorAll();
Kokkos::parallel_for(
"AdamsMoulton3::correct",
rpIntegration (activeRng.first, activeRng.second),
LAMBDA_HD(int32 i){
auto corrct_y = d_y0[i] + dt*(
static_cast<real>(5.0/12.0)*d_dy[i]
+ static_cast<real>(8.0/12.0)*d_dy0[i]
- static_cast<real>(1.0/12.0)*d_dy1[i]);
d_y[i] = corrct_y;
d_y0[i] = corrct_y;
d_dy1[i]= d_dy0[i];
});
Kokkos::fence();
return true;
}

View File

@ -0,0 +1,179 @@
/*------------------------------- 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 __AdamsMoulton3_H__
#define __AdamsMoulton3_H__
#include "integration.H"
#include "pointFields.H"
namespace pFlow
{
class AdamsMoulton3
:
public integration
{
protected:
realx3PointField_D& y0_;
realx3PointField_D& dy0_;
realx3PointField_D& dy1_;
using rpIntegration = Kokkos::RangePolicy<
DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<int32>
>;
public:
// type info
TypeName("AdamsMoulton3");
//// - Constructors
AdamsMoulton3(
const word& baseName,
repository& owner,
const pointStructure& pStruct,
const word& method);
virtual ~AdamsMoulton3()=default;
// - add a virtual constructor
add_vCtor(
integration,
AdamsMoulton3,
word);
//// - Methods
bool predict(real dt, realx3Vector_D& y, realx3Vector_D& dy) override;
bool correct(real dt, realx3Vector_D& y, realx3Vector_D& dy) override;
bool setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y) override;
bool needSetInitialVals()const override
{
return true;
}
uniquePtr<integration> clone()const override
{
return makeUnique<AdamsMoulton3>(*this);
}
bool predictAll(real dt, realx3Vector_D& y, realx3Vector_D& dy, range activeRng);
template<typename activeFunctor>
bool predictRange(real dt, realx3Vector_D& y, realx3Vector_D& dy, activeFunctor activeP);
bool intAll(real dt, realx3Vector_D& y, realx3Vector_D& dy, range activeRng);
template<typename activeFunctor>
bool intRange(real dt, realx3Vector_D& y, realx3Vector_D& dy, activeFunctor activeP );
};
template<typename activeFunctor>
bool AdamsMoulton3::predictRange(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy,
activeFunctor activeP )
{
auto d_dy = dy.deviceVectorAll();
auto d_y = y.deviceVectorAll();
auto d_y0 = y0_.deviceVectorAll();
auto d_dy0 = dy0_.deviceVectorAll();
auto d_dy1= dy1_.deviceVectorAll();
auto activeRng = activeP.activeRange();
Kokkos::parallel_for(
"AdamsMoulton3::predictRange",
rpIntegration (activeRng.first, activeRng.second),
LAMBDA_HD(int32 i){
if(activeP(i))
{
d_dy0[i] = d_dy[i];
d_y[i] = d_y0[i] +
dt*
(
static_cast<real>(3.0 / 2.0) * d_dy[i]
- static_cast<real>(1.0 / 2.0) * d_dy1[i]
);
}
});
Kokkos::fence();
return true;
}
template<typename activeFunctor>
bool pFlow::AdamsMoulton3::intRange(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy,
activeFunctor activeP )
{
auto d_dy = dy.deviceVectorAll();
auto d_y = y.deviceVectorAll();
auto d_dy0 = dy0_.deviceVectorAll();
auto d_y0 = y0_.deviceVectorAll();
auto d_dy1 = dy1_.deviceVectorAll();
auto activeRng = activeP.activeRange();
Kokkos::parallel_for(
"AdamsMoulton3::correct",
rpIntegration (activeRng.first, activeRng.second),
LAMBDA_HD(int32 i){
if( activeP(i))
{
auto corrct_y = d_y0[i] + dt*(
static_cast<real>(5.0/12.0)*d_dy[i]
+ static_cast<real>(8.0/12.0)*d_dy0[i]
- static_cast<real>(1.0/12.0)*d_dy1[i]);
d_y[i] = corrct_y;
d_y0[i] = corrct_y;
d_dy1[i]= d_dy0[i];
}
});
Kokkos::fence();
return true;
}
} // pFlow
#endif //__integration_H__

View File

@ -5,6 +5,7 @@ AdamsBashforth5/AdamsBashforth5.C
AdamsBashforth4/AdamsBashforth4.C
AdamsBashforth3/AdamsBashforth3.C
AdamsBashforth2/AdamsBashforth2.C
AdamsMoulton3/AdamsMoulton3.C
)
set(link_libs Kokkos::kokkos phasicFlow)

View File

@ -78,6 +78,14 @@ public:
virtual bool correct(real dt, realx3Vector_D& y, realx3Vector_D& dy) = 0;
virtual bool setInitialVals(
const int32IndexContainer& newIndices,
const realx3Vector& y) = 0;
virtual bool needSetInitialVals()const = 0;
virtual uniquePtr<integration> clone()const=0;
const word& baseName()const
{
return baseName_;