www.cemf.ir
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  TypeInfoNV("AB5History");
34 
35  realx3 dy1_={0,0,0};
36  realx3 dy2_={0,0,0};
37  realx3 dy3_={0,0,0};
38  realx3 dy4_={0,0,0};
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 
80 :
81  public integration
82 {
83 protected:
84 
87 
89  using rpIntegration = Kokkos::RangePolicy<
91  Kokkos::Schedule<Kokkos::Static>,
92  Kokkos::IndexType<int32>
93  >;
94 
95 public:
96 
98  TypeInfo("AdamsBashforth5");
99 
100  // - Constructors
101 
103  const word& baseName,
104  repository& owner,
105  const pointStructure& pStruct,
106  const word& method);
107 
109  {
110  return makeUnique<AdamsBashforth5>(*this);
111  }
112 
113  virtual ~AdamsBashforth5()=default;
114 
116  add_vCtor(
117  integration,
119  word);
120 
121 
122  // - Methods
123 
124  bool predict(
125  real UNUSED(dt),
126  realx3Vector_D & UNUSED(y),
127  realx3Vector_D& UNUSED(dy)) override;
128 
129  bool correct(
130  real dt,
131  realx3Vector_D & y,
132  realx3Vector_D& dy) override;
133 
134  bool setInitialVals(
135  const int32IndexContainer& newIndices,
136  const realx3Vector& y) override;
137 
138  bool needSetInitialVals()const override
139  {
140  return false;
141  }
142 
144  bool intAll(
145  real dt,
146  realx3Vector_D& y,
147  realx3Vector_D& dy,
148  range activeRng);
149 
151  template<typename activeFunctor>
152  bool intRange(
153  real dt,
154  realx3Vector_D& y,
155  realx3Vector_D& dy,
156  activeFunctor activeP );
157 
158 };
159 
160 
161 template<typename activeFunctor>
163  real dt,
164  realx3Vector_D& y,
165  realx3Vector_D& dy,
166  activeFunctor activeP )
167 {
168  auto d_dy = dy.deviceViewAll();
169  auto d_y = y.deviceViewAll();
170  auto d_history = history_.deviceViewAll();
171  auto activeRng = activeP.activeRange();
172 
173  Kokkos::parallel_for(
174  "AdamsBashforth5::correct",
175  rpIntegration (activeRng.first, activeRng.second),
176  LAMBDA_HD(int32 i){
177  if( activeP(i))
178  {
179 
180  d_y[i] += dt*(
181  static_cast<real>(1901.0 / 720.0) * d_dy[i]
182  - static_cast<real>(2774.0 / 720.0) * d_history[i].dy1_
183  + static_cast<real>(2616.0 / 720.0) * d_history[i].dy2_
184  - static_cast<real>(1274.0 / 720.0) * d_history[i].dy3_
185  + static_cast<real>( 251.0 / 720.0) * d_history[i].dy4_
186  );
187  d_history[i] = {d_dy[i] ,d_history[i].dy1_, d_history[i].dy2_, d_history[i].dy3_};
188  }
189  });
190  Kokkos::fence();
191 
192  return true;
193 }
194 
195 } // pFlow
196 
197 #endif //
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::AdamsBashforth5::add_vCtor
add_vCtor(integration, AdamsBashforth5, word)
Add this to the virtual constructor table.
pFlow::AdamsBashforth5::history_
pointField< VectorSingle, AB5History > & history_
Integration history.
Definition: AdamsBashforth5.hpp:86
pFlow::real
float real
Definition: builtinTypes.hpp:45
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::AB5History::dy4_
realx3 dy4_
Definition: AdamsBashforth5.hpp:38
pFlow::AdamsBashforth5::AdamsBashforth5
AdamsBashforth5(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: AdamsBashforth5.cpp:26
pFlow::integration
Base class for integrating the first order ODE (IVP)
Definition: integration.hpp:51
pFlow::internalField< T, void >::deviceViewAll
const auto & deviceViewAll() const
Definition: internalField.hpp:92
pFlow::AdamsBashforth5::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Set the initial values for new indices.
Definition: AdamsBashforth5.cpp:79
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::AB5History::dy3_
realx3 dy3_
Definition: AdamsBashforth5.hpp:37
pFlow::token::SPACE
@ SPACE
Nul character.
Definition: token.hpp:86
pFlow::integration::baseName
const word & baseName() const
Base name.
Definition: integration.hpp:122
pFlow::AdamsBashforth5
Fifth order Adams-Bashforth integration method for solving ODE.
Definition: AdamsBashforth5.hpp:79
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::AB5History
Definition: AdamsBashforth5.hpp:31
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::AB5History::dy2_
realx3 dy2_
Definition: AdamsBashforth5.hpp:36
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::AdamsBashforth5::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Integrate on all points in the active range.
Definition: AdamsBashforth5.cpp:86
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::AB5History::dy1_
realx3 dy1_
Definition: AdamsBashforth5.hpp:35
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
Begin list [isseparator].
Definition: token.hpp:92
pFlow::AdamsBashforth5::clone
uniquePtr< integration > clone() const override
Definition: AdamsBashforth5.hpp:108
pFlow::AdamsBashforth5::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Integrate on active points in the active range.
Definition: AdamsBashforth5.hpp:162
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::AdamsBashforth5::~AdamsBashforth5
virtual ~AdamsBashforth5()=default
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::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::integration::method
virtual word method() const =0
return integration method
pFlow::repository
Definition: repository.hpp:34
pFlow::AdamsBashforth5::TypeInfo
TypeInfo("AdamsBashforth5")
Type info.
pFlow::triple< real >
pFlow::Vector< realx3 >
pFlow::AdamsBashforth5::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Range policy for integration kernel.
Definition: AdamsBashforth5.hpp:93
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::AdamsBashforth5::predict
bool predict(real UNUSED(dt), realx3Vector_D &UNUSED(y), realx3Vector_D &UNUSED(dy)) override
Definition: AdamsBashforth5.cpp:49
pFlow::AdamsBashforth5::needSetInitialVals
bool needSetInitialVals() const override
Check if the method requires any set initial vals.
Definition: AdamsBashforth5.hpp:138
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39
pFlow::AB5History::TypeInfoNV
TypeInfoNV("AB5History")