# PhasicFlow: src/Integration/AdamsBashforth4/AdamsBashforth4.hpp Source File

AdamsBashforth4.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 __AdamsBashforth4_hpp__
#define __AdamsBashforth4_hpp__
#include "integration.hpp"
#include "pointFields.hpp"
namespace pFlow
{
struct AB4History
{
realx3 dy1_={0,0,0};
realx3 dy2_={0,0,0};
realx3 dy3_={0,0,0};
TypeInfoNV("AB4History");
};
INLINE_FUNCTION
iIstream& operator>>(iIstream& str, AB4History& ab4)
{
str.readBegin("AB4History");
str >> ab4.dy1_;
str >> ab4.dy2_;
str >> ab4.dy3_;
str.readEnd("AB4History");
str.check(FUNCTION_NAME);
return str;
}
INLINE_FUNCTION
iOstream& operator<<(iOstream& str, const AB4History& ab4)
{
str << token::BEGIN_LIST << ab4.dy1_
<< token::SPACE << ab4.dy2_
<< token::SPACE << ab4.dy3_
<< token::END_LIST;
str.check(FUNCTION_NAME);
return str;
}
class AdamsBashforth4
:
public integration
{
protected:
using HistoryFieldType = pointField<VectorSingle,AB4History>;
//realx3PointField_D& dy1_;
//realx3PointField_D& dy2_;
// this is a device
HistoryFieldType& history_;
using rpIntegration = Kokkos::RangePolicy<
DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<int32>
>;
public:
// type info
TypeInfo("AdamsBashforth4");
AdamsBashforth4(
const word& baseName,
repository& owner,
const pointStructure& pStruct,
const word& method);
virtual ~AdamsBashforth4()=default;
// - add a virtual constructor
add_vCtor(
integration,
AdamsBashforth4,
word);
bool predict(
real UNUSED(dt),
realx3Vector_D & UNUSED(y),
realx3Vector_D& UNUSED(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 false;
}
uniquePtr<integration> clone()const override
{
return makeUnique<AdamsBashforth4>(*this);
}
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 pFlow::AdamsBashforth4::intRange(
real dt,
realx3Vector_D& y,
realx3Vector_D& dy,
activeFunctor activeP )
{
auto d_dy = dy.deviceVectorAll();
auto d_y = y.deviceVectorAll();
auto d_history = history_.deviceVectorAll();
auto activeRng = activeP.activeRange();
Kokkos::parallel_for(
"AdamsBashforth4::correct",
rpIntegration (activeRng.first, activeRng.second),
LAMBDA_HD(int32 i){
if( activeP(i))
{
d_y[i] += dt*(
static_cast< real >(55.0 / 24.0) * d_dy[i]
- static_cast< real >(59.0 / 24.0) * d_history[i].dy1_
+ static_cast< real >(37.0 / 24.0) * d_history[i].dy2_
- static_cast< real >( 9.0 / 24.0) * d_history[i].dy3_
);
d_history[i].dy3_ = d_history[i].dy2_;
d_history[i].dy2_ = d_history[i].dy1_;
d_history[i].dy1_ = d_dy[i];
}
});
Kokkos::fence();
return true;
}
} // pFlow
#endif //__integration_hpp__
pFlow::AB4History::dy3_
realx3 dy3_
Definition: AdamsBashforth4.hpp:35
pFlow::AdamsBashforth4::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Definition: AdamsBashforth4.hpp:154
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Definition: iIstream.cpp:203
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:62
pFlow::real
float real
Definition: builtinTypes.hpp:46
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::integration
Definition: integration.hpp:35
pFlow::AdamsBashforth4::clone
uniquePtr< integration > clone() const override
Definition: AdamsBashforth4.hpp:134
pFlow::integration::pStruct
const auto & pStruct() const
Definition: integration.hpp:72
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::iIstream::readEnd
bool readEnd(const char *funcName)
Definition: iIstream.cpp:223
pointFields.hpp
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Definition: KokkosTypes.hpp:47
pFlow::AdamsBashforth4::add_vCtor
add_vCtor(integration, AdamsBashforth4, word)
pFlow::token::SPACE
@ SPACE
Space [isspace].
Definition: token.hpp:84
pFlow::AdamsBashforth4::TypeInfo
TypeInfo("AdamsBashforth4")
pFlow::integration::baseName
const word & baseName() const
Definition: integration.hpp:89
pFlow
Definition: demComponent.hpp:28
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
pFlow::AdamsBashforth4::~AdamsBashforth4
virtual ~AdamsBashforth4()=default
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::AdamsBashforth4::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Definition: AdamsBashforth4.hpp:92
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::AdamsBashforth4::predict
bool predict(real UNUSED(dt), realx3Vector_D &UNUSED(y), realx3Vector_D &UNUSED(dy)) override
Definition: AdamsBashforth4.cpp:49
pFlow::AB4History::TypeInfoNV
TypeInfoNV("AB4History")
pFlow::AdamsBashforth4::needSetInitialVals
bool needSetInitialVals() const override
Definition: AdamsBashforth4.hpp:129
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::token::END_LIST
@ END_LIST
End list [isseparator].
Definition: token.hpp:90
pFlow::AdamsBashforth4
Definition: AdamsBashforth4.hpp:72
pFlow::pointField::activeRange
range activeRange() const
Definition: pointField.hpp:138
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::VectorSingle
Definition: VectorSingle.hpp:45
pFlow::integration::owner
repository & owner()
Definition: integration.hpp:94
pFlow::AdamsBashforth4::AdamsBashforth4
AdamsBashforth4(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: AdamsBashforth4.cpp:26
pFlow::token::BEGIN_LIST
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.hpp:89
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
integration.hpp
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::AdamsBashforth4::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Definition: AdamsBashforth4.cpp:79
pFlow::AdamsBashforth4::history_
HistoryFieldType & history_
Definition: AdamsBashforth4.hpp:86
pFlow::repository
Definition: repository.hpp:34
pFlow::AB4History::dy1_
realx3 dy1_
Definition: AdamsBashforth4.hpp:33
pFlow::VectorSingle::deviceVectorAll
INLINE_FUNCTION_H viewType & deviceVectorAll()
Definition: VectorSingle.hpp:295
pFlow::triple< real >
pFlow::AB4History
Definition: AdamsBashforth4.hpp:31
pFlow::AdamsBashforth4::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsBashforth4.cpp:86
pFlow::Vector< realx3 >
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::AB4History::dy2_
realx3 dy2_
Definition: AdamsBashforth4.hpp:34
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::AdamsBashforth4::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsBashforth4.cpp:60
pFlow::indexContainer< int32 >