# PhasicFlow: src/Integration/AdamsBashforth4/AdamsBashforth4.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

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
{
TypeInfoNV("AB4History");
realx3 dy1_={0,0,0};
realx3 dy2_={0,0,0};
realx3 dy3_={0,0,0};
};
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:
pointField<VectorSingle,AB4History>& history_;
using rpIntegration = Kokkos::RangePolicy<
DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<int32>
>;
public:
TypeInfo("AdamsBashforth4");
// - Constructors
AdamsBashforth4(
const word& baseName,
repository& owner,
const pointStructure& pStruct,
const word& method);
uniquePtr<integration> clone()const override
{
return makeUnique<AdamsBashforth4>(*this);
}
virtual ~AdamsBashforth4()=default;
add_vCtor(
integration,
AdamsBashforth4,
word);
// - Methods
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;
}
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.deviceViewAll();
auto d_y = y.deviceViewAll();
auto d_history = history_.deviceViewAll();
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:37
pFlow::AdamsBashforth4::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Integrate on active points in the active range.
Definition: AdamsBashforth4.hpp:162
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:238
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:66
pFlow::real
float real
Definition: builtinTypes.hpp:45
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::integration
Base class for integrating the first order ODE (IVP)
Definition: integration.hpp:51
pFlow::AdamsBashforth4::clone
uniquePtr< integration > clone() const override
Definition: AdamsBashforth4.hpp:107
pFlow::internalField< T, void >::deviceViewAll
const auto & deviceViewAll() const
Definition: internalField.hpp:92
pFlow::integration::pStruct
const auto & pStruct() const
Const ref to pointStructure.
Definition: integration.hpp:115
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::iIstream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')' return true or FatalIOError.
Definition: iIstream.cpp:258
pointFields.hpp
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Default execution space, it can be device exe.
Definition: KokkosTypes.hpp:61
pFlow::AdamsBashforth4::add_vCtor
add_vCtor(integration, AdamsBashforth4, word)
Add a this to the virtual constructor table.
pFlow::token::SPACE
@ SPACE
Nul character.
Definition: token.hpp:86
pFlow::AdamsBashforth4::TypeInfo
TypeInfo("AdamsBashforth4")
Type info.
pFlow::integration::baseName
const word & baseName() const
Base name.
Definition: integration.hpp:122
pFlow
Definition: demGeometry.hpp:27
pFlow::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
pFlow::AdamsBashforth4::~AdamsBashforth4
virtual ~AdamsBashforth4()=default
Destructor.
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::AdamsBashforth4::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Range policy for integration kernel.
Definition: AdamsBashforth4.hpp:91
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
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
Check if the method requires any set initial vals.
Definition: AdamsBashforth4.hpp:138
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::token::END_LIST
@ END_LIST
Begin list [isseparator].
Definition: token.hpp:92
pFlow::AdamsBashforth4
Fourth order Adams-Bashforth integration method for solving ODE.
Definition: AdamsBashforth4.hpp:77
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::integration::owner
repository & owner()
Ref to the owner repository.
Definition: integration.hpp:129
pFlow::VectorSingle::deviceViewAll
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Definition: VectorSingle.cpp:249
pFlow::AdamsBashforth4::AdamsBashforth4
AdamsBashforth4(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Construct from components.
Definition: AdamsBashforth4.cpp:26
pFlow::token::BEGIN_LIST
@ BEGIN_LIST
End entry [isseparator].
Definition: token.hpp:91
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
integration.hpp
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::AdamsBashforth4::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Set the initial values for new indices.
Definition: AdamsBashforth4.cpp:79
pFlow::integration::method
virtual word method() const =0
return integration method
pFlow::repository
Definition: repository.hpp:34
pFlow::AdamsBashforth4::history_
pointField< VectorSingle, AB4History > & history_
Integration history.
Definition: AdamsBashforth4.hpp:84
pFlow::AB4History::dy1_
realx3 dy1_
Definition: AdamsBashforth4.hpp:35
pFlow::triple< real >
pFlow::AB4History
Definition: AdamsBashforth4.hpp:31
pFlow::AdamsBashforth4::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Integrate on all points in the active range.
Definition: AdamsBashforth4.cpp:86
pFlow::Vector< realx3 >
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::AB4History::dy2_
realx3 dy2_
Definition: AdamsBashforth4.hpp:36
pFlow::AdamsBashforth4::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsBashforth4.cpp:60
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39