AdamsBashforth4.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 __AdamsBashforth4_hpp__
22 #define __AdamsBashforth4_hpp__
23 
24 
25 #include "integration.hpp"
26 #include "pointFields.hpp"
27 
28 namespace pFlow
29 {
30 
31 struct AB4History
32 {
33  realx3 dy1_={0,0,0};
34  realx3 dy2_={0,0,0};
35  realx3 dy3_={0,0,0};
36 
37  TypeInfoNV("AB4History");
38 };
39 
40 
43 {
44  str.readBegin("AB4History");
45 
46  str >> ab4.dy1_;
47  str >> ab4.dy2_;
48  str >> ab4.dy3_;
49 
50  str.readEnd("AB4History");
51 
52  str.check(FUNCTION_NAME);
53 
54  return str;
55 
56 }
57 
60 {
61  str << token::BEGIN_LIST << ab4.dy1_
62  << token::SPACE << ab4.dy2_
63  << token::SPACE << ab4.dy3_
64  << token::END_LIST;
65 
66  str.check(FUNCTION_NAME);
67 
68  return str;
69 }
70 
71 
73 :
74  public integration
75 {
76 protected:
77 
79  //realx3PointField_D& dy1_;
80 
81  //realx3PointField_D& dy2_;
82 
83 
84 
85  // this is a device
87 
88  using rpIntegration = Kokkos::RangePolicy<
90  Kokkos::Schedule<Kokkos::Static>,
91  Kokkos::IndexType<int32>
92  >;
93 
94 public:
95 
96  // type info
97  TypeInfo("AdamsBashforth4");
98 
101  const word& baseName,
102  repository& owner,
103  const pointStructure& pStruct,
104  const word& method);
105 
106  virtual ~AdamsBashforth4()=default;
107 
108  // - add a virtual constructor
109  add_vCtor(
110  integration,
112  word);
113 
114 
116  bool predict(
117  real UNUSED(dt),
118  realx3Vector_D & UNUSED(y),
119  realx3Vector_D& UNUSED(dy)) override;
120 
121  bool correct(real dt,
122  realx3Vector_D & y,
123  realx3Vector_D& dy) override;
124 
125  bool setInitialVals(
126  const int32IndexContainer& newIndices,
127  const realx3Vector& y) override;
128 
129  bool needSetInitialVals()const override
130  {
131  return false;
132  }
133 
135  {
136  return makeUnique<AdamsBashforth4>(*this);
137  }
138 
139  bool intAll(real dt,
140  realx3Vector_D& y,
141  realx3Vector_D& dy,
142  range activeRng);
143 
144  template<typename activeFunctor>
145  bool intRange(real dt,
146  realx3Vector_D& y,
147  realx3Vector_D& dy,
148  activeFunctor activeP );
149 
150 };
151 
152 
153 template<typename activeFunctor>
155  real dt,
156  realx3Vector_D& y,
157  realx3Vector_D& dy,
158  activeFunctor activeP )
159 {
160  auto d_dy = dy.deviceVectorAll();
161  auto d_y = y.deviceVectorAll();
162  auto d_history = history_.deviceVectorAll();
163  auto activeRng = activeP.activeRange();
164 
165  Kokkos::parallel_for(
166  "AdamsBashforth4::correct",
167  rpIntegration (activeRng.first, activeRng.second),
168  LAMBDA_HD(int32 i){
169  if( activeP(i))
170  {
171 
172  d_y[i] += dt*(
173  static_cast<real>(55.0 / 24.0) * d_dy[i]
174  - static_cast<real>(59.0 / 24.0) * d_history[i].dy1_
175  + static_cast<real>(37.0 / 24.0) * d_history[i].dy2_
176  - static_cast<real>( 9.0 / 24.0) * d_history[i].dy3_
177  );
178  d_history[i].dy3_ = d_history[i].dy2_;
179  d_history[i].dy2_ = d_history[i].dy1_;
180  d_history[i].dy1_ = d_dy[i];
181  }
182  });
183  Kokkos::fence();
184 
185  return true;
186 }
187 
188 } // pFlow
189 
190 #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 >