AdamsMoulton3.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 __AdamsMoulton3_hpp__
22 #define __AdamsMoulton3_hpp__
23 
24 
25 #include "integration.hpp"
26 #include "pointFields.hpp"
27 
28 namespace pFlow
29 {
30 
31 
33 :
34  public integration
35 {
36 protected:
37 
39 
41 
43 
44  using rpIntegration = Kokkos::RangePolicy<
46  Kokkos::Schedule<Kokkos::Static>,
47  Kokkos::IndexType<int32>
48  >;
49 public:
50 
51  // type info
52  TypeInfo("AdamsMoulton3");
53 
56  const word& baseName,
58  const pointStructure& pStruct,
59  const word& method);
60 
61  virtual ~AdamsMoulton3()=default;
62 
63  // - add a virtual constructor
64  add_vCtor(
67  word);
68 
69 
71  bool predict(real dt, realx3Vector_D& y, realx3Vector_D& dy) override;
72 
73  bool correct(real dt, realx3Vector_D& y, realx3Vector_D& dy) override;
74 
75  bool setInitialVals(
76  const int32IndexContainer& newIndices,
77  const realx3Vector& y) override;
78 
79  bool needSetInitialVals()const override
80  {
81  return true;
82  }
83 
84  uniquePtr<integration> clone()const override
85  {
86  return makeUnique<AdamsMoulton3>(*this);
87  }
88 
89  bool predictAll(real dt, realx3Vector_D& y, realx3Vector_D& dy, range activeRng);
90 
91  template<typename activeFunctor>
92  bool predictRange(real dt, realx3Vector_D& y, realx3Vector_D& dy, activeFunctor activeP);
93 
94  bool intAll(real dt, realx3Vector_D& y, realx3Vector_D& dy, range activeRng);
95 
96  template<typename activeFunctor>
97  bool intRange(real dt, realx3Vector_D& y, realx3Vector_D& dy, activeFunctor activeP );
98 
99 };
100 
101 
102 template<typename activeFunctor>
104  real dt,
105  realx3Vector_D& y,
106  realx3Vector_D& dy,
107  activeFunctor activeP )
108 {
109  auto d_dy = dy.deviceVectorAll();
110  auto d_y = y.deviceVectorAll();
111  auto d_y0 = y0_.deviceVectorAll();
112  auto d_dy0 = dy0_.deviceVectorAll();
113  auto d_dy1= dy1_.deviceVectorAll();
114 
115  auto activeRng = activeP.activeRange();
116 
117  Kokkos::parallel_for(
118  "AdamsMoulton3::predictRange",
119  rpIntegration (activeRng.first, activeRng.second),
120  LAMBDA_HD(int32 i){
121  if(activeP(i))
122  {
123  d_dy0[i] = d_dy[i];
124  d_y[i] = d_y0[i] +
125  dt*
126  (
127  static_cast<real>(3.0 / 2.0) * d_dy[i]
128  - static_cast<real>(1.0 / 2.0) * d_dy1[i]
129  );
130  }
131  });
132  Kokkos::fence();
133 
134  return true;
135 
136 }
137 
138 
139 template<typename activeFunctor>
141  real dt,
142  realx3Vector_D& y,
143  realx3Vector_D& dy,
144  activeFunctor activeP )
145 {
146 
147  auto d_dy = dy.deviceVectorAll();
148  auto d_y = y.deviceVectorAll();
149 
150  auto d_dy0 = dy0_.deviceVectorAll();
151  auto d_y0 = y0_.deviceVectorAll();
152  auto d_dy1 = dy1_.deviceVectorAll();
153 
154  auto activeRng = activeP.activeRange();
155 
156  Kokkos::parallel_for(
157  "AdamsMoulton3::correct",
158  rpIntegration (activeRng.first, activeRng.second),
159  LAMBDA_HD(int32 i){
160  if( activeP(i))
161  {
162  auto corrct_y = d_y0[i] + dt*(
163  static_cast<real>(5.0/12.0)*d_dy[i]
164  + static_cast<real>(8.0/12.0)*d_dy0[i]
165  - static_cast<real>(1.0/12.0)*d_dy1[i]);
166  d_dy1[i]= d_dy0[i];
167  d_y0[i] = corrct_y;
168  d_y[i] = corrct_y;
169  }
170  });
171  Kokkos::fence();
172 
173 
174  return true;
175 }
176 
177 } // pFlow
178 
179 #endif //__integration_hpp__
pFlow::AdamsMoulton3::TypeInfo
TypeInfo("AdamsMoulton3")
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::AdamsMoulton3::add_vCtor
add_vCtor(integration, AdamsMoulton3, word)
pFlow::integration
Definition: integration.hpp:35
pFlow::integration::pStruct
const auto & pStruct() const
Definition: integration.hpp:72
pFlow::AdamsMoulton3::AdamsMoulton3
AdamsMoulton3(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: AdamsMoulton3.cpp:26
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pointFields.hpp
pFlow::AdamsMoulton3::intAll
bool intAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsMoulton3.cpp:146
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Definition: KokkosTypes.hpp:47
pFlow::AdamsMoulton3::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< int32 > > rpIntegration
Definition: AdamsMoulton3.hpp:48
pFlow::integration::baseName
const word & baseName() const
Definition: integration.hpp:89
pFlow
Definition: demComponent.hpp:28
pFlow::AdamsMoulton3::predictRange
bool predictRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Definition: AdamsMoulton3.hpp:103
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::AdamsMoulton3::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) override
Definition: AdamsMoulton3.cpp:111
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::AdamsMoulton3::dy0_
realx3PointField_D & dy0_
Definition: AdamsMoulton3.hpp:40
pFlow::pointField::activeRange
range activeRange() const
Definition: pointField.hpp:138
pFlow::VectorSingle
Definition: VectorSingle.hpp:45
pFlow::AdamsMoulton3::clone
uniquePtr< integration > clone() const override
Definition: AdamsMoulton3.hpp:84
pFlow::integration::owner
repository & owner()
Definition: integration.hpp:94
pFlow::AdamsMoulton3::intRange
bool intRange(real dt, realx3Vector_D &y, realx3Vector_D &dy, activeFunctor activeP)
Definition: AdamsMoulton3.hpp:140
pFlow::AdamsMoulton3::predictAll
bool predictAll(real dt, realx3Vector_D &y, realx3Vector_D &dy, range activeRng)
Definition: AdamsMoulton3.cpp:120
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
integration.hpp
pFlow::AdamsMoulton3::dy1_
realx3PointField_D & dy1_
Definition: AdamsMoulton3.hpp:42
pFlow::AdamsMoulton3::predict
bool predict(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton3.cpp:73
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::AdamsMoulton3::y0_
realx3PointField_D & y0_
Definition: AdamsMoulton3.hpp:38
pFlow::AdamsMoulton3::correct
bool correct(real dt, realx3Vector_D &y, realx3Vector_D &dy) override
Definition: AdamsMoulton3.cpp:93
pFlow::AdamsMoulton3::~AdamsMoulton3
virtual ~AdamsMoulton3()=default
pFlow::repository
Definition: repository.hpp:34
pFlow::AdamsMoulton3
Definition: AdamsMoulton3.hpp:32
pFlow::VectorSingle::deviceVectorAll
INLINE_FUNCTION_H viewType & deviceVectorAll()
Definition: VectorSingle.hpp:295
pFlow::Vector< realx3 >
pFlow::AdamsMoulton3::needSetInitialVals
bool needSetInitialVals() const override
Definition: AdamsMoulton3.hpp:79
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
pFlow::indexContainer< int32 >