AdamsBashforth2.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __AdamsBashforth2_hpp__
22 #define __AdamsBashforth2_hpp__
23 
24 
25 #include "integration.hpp"
26 #include "pointFields.hpp"
27 
28 namespace pFlow
29 {
30 
31 
33 :
34  public integration
35 {
36 protected:
37 
39 
40  using rpIntegration = Kokkos::RangePolicy<
42  Kokkos::Schedule<Kokkos::Static>,
43  Kokkos::IndexType<int32>
44  >;
45 public:
46 
47  // type info
48  TypeInfo("AdamsBashforth2");
49 
52  const word& baseName,
54  const pointStructure& pStruct,
55  const word& method);
56 
57  virtual ~AdamsBashforth2()=default;
58 
59  // - add a virtual constructor
60  add_vCtor(
63  word);
64 
65 
67  bool predict(real UNUSED(dt), realx3Vector_D& UNUSED(y), realx3Vector_D& UNUSED(dy)) override;
68 
69  bool correct(real dt, realx3Vector_D& y, realx3Vector_D& dy) override;
70 
71  bool setInitialVals(
72  const int32IndexContainer& newIndices,
73  const realx3Vector& y) override;
74 
75  bool needSetInitialVals()const override
76  {
77  return false;
78  }
79 
80  uniquePtr<integration> clone()const override
81  {
82  return makeUnique<AdamsBashforth2>(*this);
83  }
84 
85  bool intAll(real dt, realx3Vector_D& y, realx3Vector_D& dy, range activeRng);
86 
87  template<typename activeFunctor>
88  bool intRange(real dt, realx3Vector_D& y, realx3Vector_D& dy, activeFunctor activeP );
89 
90 };
91 
92 template<typename activeFunctor>
94  real dt,
95  realx3Vector_D& y,
96  realx3Vector_D& dy,
97  activeFunctor activeP )
98 {
99 
100  auto d_dy = dy.deviceVectorAll();
101  auto d_y = y.deviceVectorAll();
102  auto d_dy1= dy1_.deviceVectorAll();
103  auto activeRng = activeP.activeRange();
104 
105  Kokkos::parallel_for(
106  "AdamsBashforth2::correct",
107  rpIntegration (activeRng.first, activeRng.second),
108  LAMBDA_HD(int32 i){
109  if( activeP(i))
110  {
111  d_y[i] += dt*(static_cast<real>(3.0 / 2.0) * d_dy[i] - static_cast<real>(1.0 / 2.0) * d_dy1[i]);
112  d_dy1[i] = d_dy[i];
113  }
114  });
115  Kokkos::fence();
116 
117 
118  return true;
119 }
120 
121 } // pFlow
122 
123 #endif //__integration_hpp__
pFlow::AdamsBashforth2::needSetInitialVals
bool needSetInitialVals() const override
Definition: AdamsBashforth2.hpp:75
pFlow::AdamsBashforth2::dy1_
realx3PointField_D & dy1_
Definition: AdamsBashforth2.hpp:38
pFlow::AdamsBashforth2::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsBashforth2.cpp:59
pFlow::AdamsBashforth2::clone
uniquePtr< integration > clone() const override
Definition: AdamsBashforth2.hpp:80
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::AdamsBashforth2::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Definition: AdamsBashforth2.hpp:93
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::AdamsBashforth2::~AdamsBashforth2
virtual ~AdamsBashforth2()=default
pFlow::integration
Definition: integration.hpp:35
pFlow::integration::pStruct
const auto & pStruct() const
Definition: integration.hpp:72
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pointFields.hpp
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Definition: KokkosTypes.hpp:47
pFlow::AdamsBashforth2::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Definition: AdamsBashforth2.cpp:77
pFlow::integration::baseName
const word & baseName() const
Definition: integration.hpp:89
pFlow
Definition: demComponent.hpp:28
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::pointField::activeRange
range activeRange() const
Definition: pointField.hpp:138
pFlow::VectorSingle
Definition: VectorSingle.hpp:45
pFlow::integration::owner
repository & owner()
Definition: integration.hpp:94
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::AdamsBashforth2
Definition: AdamsBashforth2.hpp:32
integration.hpp
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::AdamsBashforth2::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsBashforth2.cpp:84
pFlow::AdamsBashforth2::AdamsBashforth2
AdamsBashforth2(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: AdamsBashforth2.cpp:26
pFlow::AdamsBashforth2::TypeInfo
TypeInfo("AdamsBashforth2")
pFlow::repository
Definition: repository.hpp:34
pFlow::VectorSingle::deviceVectorAll
INLINE_FUNCTION_H viewType & deviceVectorAll()
Definition: VectorSingle.hpp:295
pFlow::Vector< realx3 >
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::indexContainer< int32 >
pFlow::AdamsBashforth2::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Definition: AdamsBashforth2.hpp:44
pFlow::AdamsBashforth2::add_vCtor
add_vCtor(integration, AdamsBashforth2, word)
pFlow::AdamsBashforth2::predict
bool predict(real UNUSED(dt), realx3Vector_D &UNUSED(y), realx3Vector_D &UNUSED(dy)) override
Definition: AdamsBashforth2.cpp:48