www.cemf.ir
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  TypeInfoNV("AB4History");
34 
35  realx3 dy1_={0,0,0};
36  realx3 dy2_={0,0,0};
37  realx3 dy3_={0,0,0};
38 
39 };
40 
41 
44 {
45  str.readBegin("AB4History");
46 
47  str >> ab4.dy1_;
48  str >> ab4.dy2_;
49  str >> ab4.dy3_;
50 
51  str.readEnd("AB4History");
52 
53  str.check(FUNCTION_NAME);
54 
55  return str;
56 
57 }
58 
61 {
62  str << token::BEGIN_LIST << ab4.dy1_
63  << token::SPACE << ab4.dy2_
64  << token::SPACE << ab4.dy3_
65  << token::END_LIST;
66 
67  str.check(FUNCTION_NAME);
68 
69  return str;
70 }
71 
78 :
79  public integration
80 {
81 protected:
82 
85 
87  using rpIntegration = Kokkos::RangePolicy<
89  Kokkos::Schedule<Kokkos::Static>,
90  Kokkos::IndexType<int32>
91  >;
92 
93 public:
94 
96  TypeInfo("AdamsBashforth4");
97 
98  // - Constructors
99 
102  const word& baseName,
103  repository& owner,
104  const pointStructure& pStruct,
105  const word& method);
106 
108  {
109  return makeUnique<AdamsBashforth4>(*this);
110  }
111 
113  virtual ~AdamsBashforth4()=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  "AdamsBashforth4::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>(55.0 / 24.0) * d_dy[i]
182  - static_cast<real>(59.0 / 24.0) * d_history[i].dy1_
183  + static_cast<real>(37.0 / 24.0) * d_history[i].dy2_
184  - static_cast<real>( 9.0 / 24.0) * d_history[i].dy3_
185  );
186  d_history[i].dy3_ = d_history[i].dy2_;
187  d_history[i].dy2_ = d_history[i].dy1_;
188  d_history[i].dy1_ = d_dy[i];
189  }
190  });
191  Kokkos::fence();
192 
193  return true;
194 }
195 
196 } // pFlow
197 
198 #endif //__integration_hpp__
pFlow::AB4History::dy3_
realx3 dy3_
Definition: AdamsBashforth4.hpp:37
pFlow::AdamsBashforth4::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Integrate on active points in the active range.
Definition: AdamsBashforth4.hpp:162
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::real
float real
Definition: builtinTypes.hpp:45
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::integration
Base class for integrating the first order ODE (IVP)
Definition: integration.hpp:51
pFlow::AdamsBashforth4::clone
uniquePtr< integration > clone() const override
Definition: AdamsBashforth4.hpp:107
pFlow::internalField< T, void >::deviceViewAll
const auto & deviceViewAll() const
Definition: internalField.hpp:92
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::AdamsBashforth4::add_vCtor
add_vCtor(integration, AdamsBashforth4, word)
Add a this to the virtual constructor table.
pFlow::token::SPACE
@ SPACE
Nul character.
Definition: token.hpp:86
pFlow::AdamsBashforth4::TypeInfo
TypeInfo("AdamsBashforth4")
Type info.
pFlow::integration::baseName
const word & baseName() const
Base name.
Definition: integration.hpp:122
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::AdamsBashforth4::~AdamsBashforth4
virtual ~AdamsBashforth4()=default
Destructor.
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::AdamsBashforth4::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Range policy for integration kernel.
Definition: AdamsBashforth4.hpp:91
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
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
Check if the method requires any set initial vals.
Definition: AdamsBashforth4.hpp:138
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::AdamsBashforth4
Fourth order Adams-Bashforth integration method for solving ODE.
Definition: AdamsBashforth4.hpp:77
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
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::AdamsBashforth4::AdamsBashforth4
AdamsBashforth4(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Construct from components.
Definition: AdamsBashforth4.cpp:26
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::AdamsBashforth4::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Set the initial values for new indices.
Definition: AdamsBashforth4.cpp:79
pFlow::integration::method
virtual word method() const =0
return integration method
pFlow::repository
Definition: repository.hpp:34
pFlow::AdamsBashforth4::history_
pointField< VectorSingle, AB4History > & history_
Integration history.
Definition: AdamsBashforth4.hpp:84
pFlow::AB4History::dy1_
realx3 dy1_
Definition: AdamsBashforth4.hpp:35
pFlow::triple< real >
pFlow::AB4History
Definition: AdamsBashforth4.hpp:31
pFlow::AdamsBashforth4::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Integrate on all points in the active range.
Definition: AdamsBashforth4.cpp:86
pFlow::Vector< realx3 >
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::AB4History::dy2_
realx3 dy2_
Definition: AdamsBashforth4.hpp:36
pFlow::AdamsBashforth4::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsBashforth4.cpp:60
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39