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