AdamsBashforth5.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 __AdamsBashforth5_hpp__
22 #define __AdamsBashforth5_hpp__
23 
24 
25 #include "integration.hpp"
26 #include "pointFields.hpp"
27 
28 namespace pFlow
29 {
30 
31 struct AB5History
32 {
33  realx3 dy1_={0,0,0};
34  realx3 dy2_={0,0,0};
35  realx3 dy3_={0,0,0};
36  realx3 dy4_={0,0,0};
37 
38  TypeInfoNV("AB5History");
39 };
40 
41 
44 {
45  str.readBegin("AB5History");
46 
47  str >> ab5.dy1_;
48  str >> ab5.dy2_;
49  str >> ab5.dy3_;
50  str >> ab5.dy4_;
51 
52  str.readEnd("AB5History");
53 
54  str.check(FUNCTION_NAME);
55 
56  return str;
57 
58 }
59 
62 {
63  str << token::BEGIN_LIST << ab5.dy1_
64  << token::SPACE << ab5.dy2_
65  << token::SPACE << ab5.dy3_
66  << token::SPACE << ab5.dy4_
67  << token::END_LIST;
68 
69  str.check(FUNCTION_NAME);
70 
71  return str;
72 }
73 
74 
76 :
77  public integration
78 {
79 protected:
80 
82 
83  // this is a device
85 
86  using rpIntegration = Kokkos::RangePolicy<
88  Kokkos::Schedule<Kokkos::Static>,
89  Kokkos::IndexType<int32>
90  >;
91 
92 public:
93 
94  // type info
95  TypeInfo("AdamsBashforth5");
96 
99  const word& baseName,
100  repository& owner,
101  const pointStructure& pStruct,
102  const word& method);
103 
104  virtual ~AdamsBashforth5()=default;
105 
106  // - add a virtual constructor
107  add_vCtor(
108  integration,
110  word);
111 
112 
114  bool predict(
115  real UNUSED(dt),
116  realx3Vector_D & UNUSED(y),
117  realx3Vector_D& UNUSED(dy)) override;
118 
119  bool correct(real dt,
120  realx3Vector_D & y,
121  realx3Vector_D& dy) override;
122 
123  bool setInitialVals(
124  const int32IndexContainer& newIndices,
125  const realx3Vector& y) override;
126 
127  bool needSetInitialVals()const override
128  {
129  return false;
130  }
131 
133  {
134  return makeUnique<AdamsBashforth5>(*this);
135  }
136 
137  bool intAll(real dt,
138  realx3Vector_D& y,
139  realx3Vector_D& dy,
140  range activeRng);
141 
142  template<typename activeFunctor>
143  bool intRange(real dt,
144  realx3Vector_D& y,
145  realx3Vector_D& dy,
146  activeFunctor activeP );
147 
148 };
149 
150 
151 template<typename activeFunctor>
153  real dt,
154  realx3Vector_D& y,
155  realx3Vector_D& dy,
156  activeFunctor activeP )
157 {
158  auto d_dy = dy.deviceVectorAll();
159  auto d_y = y.deviceVectorAll();
160  auto d_history = history_.deviceVectorAll();
161  auto activeRng = activeP.activeRange();
162 
163  Kokkos::parallel_for(
164  "AdamsBashforth5::correct",
165  rpIntegration (activeRng.first, activeRng.second),
166  LAMBDA_HD(int32 i){
167  if( activeP(i))
168  {
169 
170  d_y[i] += dt*(
171  static_cast<real>(1901.0 / 720.0) * d_dy[i]
172  - static_cast<real>(2774.0 / 720.0) * d_history[i].dy1_
173  + static_cast<real>(2616.0 / 720.0) * d_history[i].dy2_
174  - static_cast<real>(1274.0 / 720.0) * d_history[i].dy3_
175  + static_cast<real>( 251.0 / 720.0) * d_history[i].dy4_
176  );
177  d_history[i] = {d_dy[i] ,d_history[i].dy1_, d_history[i].dy2_, d_history[i].dy3_};
178  }
179  });
180  Kokkos::fence();
181 
182  return true;
183 }
184 
185 } // pFlow
186 
187 #endif //__integration_hpp__
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Definition: iIstream.cpp:203
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:62
pFlow::AdamsBashforth5::add_vCtor
add_vCtor(integration, AdamsBashforth5, word)
pFlow::real
float real
Definition: builtinTypes.hpp:46
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::AB5History::dy4_
realx3 dy4_
Definition: AdamsBashforth5.hpp:36
pFlow::AdamsBashforth5::AdamsBashforth5
AdamsBashforth5(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: AdamsBashforth5.cpp:26
pFlow::integration
Definition: integration.hpp:35
pFlow::AdamsBashforth5::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Definition: AdamsBashforth5.cpp:79
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::AB5History::dy3_
realx3 dy3_
Definition: AdamsBashforth5.hpp:35
pFlow::token::SPACE
@ SPACE
Space [isspace].
Definition: token.hpp:84
pFlow::integration::baseName
const word & baseName() const
Definition: integration.hpp:89
pFlow::AdamsBashforth5
Definition: AdamsBashforth5.hpp:75
pFlow::AdamsBashforth5::history_
HistoryFieldType & history_
Definition: AdamsBashforth5.hpp:84
pFlow
Definition: demComponent.hpp:28
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
pFlow::AB5History
Definition: AdamsBashforth5.hpp:31
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::AB5History::dy2_
realx3 dy2_
Definition: AdamsBashforth5.hpp:34
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::AdamsBashforth5::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsBashforth5.cpp:86
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::AB5History::dy1_
realx3 dy1_
Definition: AdamsBashforth5.hpp:33
pFlow::AdamsBashforth5::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsBashforth5.cpp:60
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::AdamsBashforth5::clone
uniquePtr< integration > clone() const override
Definition: AdamsBashforth5.hpp:132
pFlow::AdamsBashforth5::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Definition: AdamsBashforth5.hpp:152
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::AdamsBashforth5::~AdamsBashforth5
virtual ~AdamsBashforth5()=default
pFlow::integration::owner
repository & owner()
Definition: integration.hpp:94
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::repository
Definition: repository.hpp:34
pFlow::AdamsBashforth5::TypeInfo
TypeInfo("AdamsBashforth5")
pFlow::VectorSingle::deviceVectorAll
INLINE_FUNCTION_H viewType & deviceVectorAll()
Definition: VectorSingle.hpp:295
pFlow::triple< real >
pFlow::Vector< realx3 >
pFlow::AdamsBashforth5::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Definition: AdamsBashforth5.hpp:90
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::AdamsBashforth5::predict
bool predict(real UNUSED(dt), realx3Vector_D &UNUSED(y), realx3Vector_D &UNUSED(dy)) override
Definition: AdamsBashforth5.cpp:49
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::AdamsBashforth5::needSetInitialVals
bool needSetInitialVals() const override
Definition: AdamsBashforth5.hpp:127
pFlow::indexContainer< int32 >
pFlow::AB5History::TypeInfoNV
TypeInfoNV("AB5History")