www.cemf.ir
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  TypeInfoNV("AB3History");
34 
35  realx3 dy1_={0,0,0};
36  realx3 dy2_={0,0,0};
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 
74 :
75  public integration
76 {
77 protected:
78 
81 
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 
94  // - Constructors
95 
98  const word& baseName,
100  const pointStructure& pStruct,
101  const word& method);
102 
104  {
105  return makeUnique<AdamsBashforth3>(*this);
106  }
107 
109  virtual ~AdamsBashforth3()=default;
110 
112  add_vCtor(
113  integration,
115  word);
116 
117 
118  // - Methods
119 
120  bool predict(
121  real UNUSED(dt),
122  realx3Vector_D & UNUSED(y),
123  realx3Vector_D& UNUSED(dy)) override;
124 
125  bool correct(real dt,
126  realx3Vector_D & y,
127  realx3Vector_D& dy) override;
128 
129  bool setInitialVals(
130  const int32IndexContainer& newIndices,
131  const realx3Vector& y) override;
132 
133  bool needSetInitialVals()const override
134  {
135  return false;
136  }
137 
139  bool intAll(
140  real dt,
141  realx3Vector_D& y,
142  realx3Vector_D& dy,
143  range activeRng);
144 
146  template<typename activeFunctor>
147  bool intRange(
148  real dt,
149  realx3Vector_D& y,
150  realx3Vector_D& dy,
151  activeFunctor activeP );
152 
153 };
154 
155 
156 template<typename activeFunctor>
158  real dt,
159  realx3Vector_D& y,
160  realx3Vector_D& dy,
161  activeFunctor activeP )
162 {
163  auto d_dy = dy.deviceViewAll();
164  auto d_y = y.deviceViewAll();
165  auto d_history = history_.deviceViewAll();
166  auto activeRng = activeP.activeRange();
167 
168  Kokkos::parallel_for(
169  "AdamsBashforth3::correct",
170  rpIntegration (activeRng.first, activeRng.second),
171  LAMBDA_HD(int32 i){
172  if( activeP(i))
173  {
174  auto ldy = d_dy[i];
175  d_y[i] += dt*( static_cast<real>(23.0 / 12.0) * ldy
176  - static_cast<real>(16.0 / 12.0) * d_history[i].dy1_
177  + static_cast<real>(5.0 / 12.0) * d_history[i].dy2_);
178  d_history[i] = {ldy ,d_history[i].dy1_};
179  }
180  });
181  Kokkos::fence();
182 
183  return true;
184 }
185 
186 } // pFlow
187 
188 #endif //__integration_hpp__
pFlow::iIstream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: iIstream.cpp:238
pFlow::AdamsBashforth3::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Set the initial values for new indices.
Definition: AdamsBashforth3.cpp:79
pFlow::AdamsBashforth3::history_
pointField< VectorSingle, AB3History > & history_
Integration history.
Definition: AdamsBashforth3.hpp:80
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:66
pFlow::AdamsBashforth3::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Range policy for integration kernel.
Definition: AdamsBashforth3.hpp:87
pFlow::real
float real
Definition: builtinTypes.hpp:45
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:49
UNUSED
#define UNUSED(x)
Definition: pFlowMacros.hpp:35
pFlow::AdamsBashforth3::needSetInitialVals
bool needSetInitialVals() const override
Check if the method requires any set initial vals.
Definition: AdamsBashforth3.hpp:133
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::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::AdamsBashforth3::~AdamsBashforth3
virtual ~AdamsBashforth3()=default
Destructor.
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Default execution space, it can be device exe.
Definition: KokkosTypes.hpp:61
pFlow::AdamsBashforth3::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsBashforth3.cpp:60
pFlow::AdamsBashforth3::AdamsBashforth3
AdamsBashforth3(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Construct from components.
Definition: AdamsBashforth3.cpp:26
pFlow::token::SPACE
@ SPACE
Nul character.
Definition: token.hpp:86
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::AdamsBashforth3::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Integrate on active points in the active range.
Definition: AdamsBashforth3.hpp:157
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::AdamsBashforth3::add_vCtor
add_vCtor(integration, AdamsBashforth3, word)
Add this to the virtual constructor table.
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::AB3History::dy2_
realx3 dy2_
Definition: AdamsBashforth3.hpp:36
pFlow::AB3History::TypeInfoNV
TypeInfoNV("AB3History")
pFlow::token::END_LIST
@ END_LIST
Begin list [isseparator].
Definition: token.hpp:92
pFlow::AB3History::dy1_
realx3 dy1_
Definition: AdamsBashforth3.hpp:35
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::VectorSingle
Definition: VectorSingle.hpp:44
pFlow::AdamsBashforth3::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Integrate on all points in the active range.
Definition: AdamsBashforth3.cpp:86
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
pFlow::AdamsBashforth3::clone
uniquePtr< integration > clone() const override
Definition: AdamsBashforth3.hpp:103
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::AdamsBashforth3::TypeInfo
TypeInfo("AdamsBashforth3")
pFlow::AdamsBashforth3
Third order Adams-Bashforth integration method for solving ODE.
Definition: AdamsBashforth3.hpp:73
pFlow::integration::method
virtual word method() const =0
return integration method
pFlow::repository
Definition: repository.hpp:34
pFlow::triple< real >
pFlow::Vector< realx3 >
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39