www.cemf.ir
AdamsBashforth2.cpp
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 #include "AdamsBashforth2.hpp"
22 #include "pointStructure.hpp"
23 #include "Time.hpp"
24 #include "vocabs.hpp"
25 
26 namespace pFlow
27 {
28 
30 using rpIntegration = Kokkos::RangePolicy<
32  Kokkos::Schedule<Kokkos::Static>,
33  Kokkos::IndexType<uint32>
34  >;
35 
37  real dt,
38  realx3Field_D& y,
40  realx3PointField_D& dy1)
41 {
42 
43  auto d_dy = dy.deviceView();
44  auto d_y = y.deviceView();
45  auto d_dy1= dy1.deviceView();
46  auto activeRng = dy1.activeRange();
47 
48  Kokkos::parallel_for(
49  "AdamsBashforth2::correct",
50  rpIntegration (activeRng.start(), activeRng.end()),
51  LAMBDA_HD(uint32 i){
52  d_y[i] += dt*(static_cast<real>(1.5) * d_dy[i] - static_cast<real>(0.5) * d_dy1[i]);
53  d_dy1[i] = d_dy[i];
54  });
55  Kokkos::fence();
56 
57  return true;
58 }
59 
60 bool intScattered
61 (
62  real dt,
63  realx3Field_D& y,
66 )
67 {
68 
69  auto d_dy = dy.deviceView();
70  auto d_y = y.deviceView();
71  auto d_dy1 = dy1.deviceView();
72  auto activeRng = dy1.activeRange();
73  const auto& activeP = dy1.activePointsMaskDevice();
74 
75  Kokkos::parallel_for(
76  "AdamsBashforth2::correct",
77  rpIntegration (activeRng.start(), activeRng.end()),
78  LAMBDA_HD(uint32 i){
79  if( activeP(i))
80  {
81  d_y[i] += dt*(static_cast<real>(1.5) * d_dy[i] - static_cast<real>(0.5) * d_dy1[i]);
82  d_dy1[i] = d_dy[i];
83  }
84  });
85  Kokkos::fence();
86 
87 
88  return true;
89 }
90 
91 }
92 
94 (
95  const word& baseName,
97  const word& method,
98  const realx3Field_D& initialValField
99 )
100 :
101  integration(baseName, pStruct, method, initialValField),
103  (
104  objectFile
105  (
106  groupNames(baseName,"dy1"),
107  pStruct.time().integrationFolder(),
108  objectFile::READ_IF_PRESENT,
109  objectFile::WRITE_ALWAYS
110  ),
111  pStruct,
112  zero3,
113  zero3
114  ),
115  boundaryList_(pStruct, method, *this)
116 {}
117 
119 {
121 }
122 
124  real UNUSED(dt),
127 {
128  return true;
129 }
130 
132 (
133  real dt,
134  realx3Field_D &y,
136 )
137 {
138  return true;
139 }
140 
142 (
143  real dt,
146 )
147 {
148  auto& dy1l = dy1();
149  bool success = false;
150  if(dy1l.isAllActive())
151  {
152  success = intAllActive(dt, y.field(), dy, dy1l);
153  }
154  else
155  {
156  success = intScattered(dt, y.field(), dy, dy1l);
157  }
158 
159  success = success && boundaryList_.correct(dt, y, dy);
160 
161  return success;
162 
163 }
164 
166  real dt,
168  realx3PointField_D &vel)
169 {
170  auto& dy1l = dy1();
171  bool success = false;
172  if(dy1l.isAllActive())
173  {
174  success = intAllActive(dt, pStruct.pointPosition(), vel, dy1l);
175  }
176  else
177  {
178  success = intScattered(dt, pStruct.pointPosition(), vel, dy1l);
179  }
180 
181  success = success && boundaryList_.correctPStruct(dt, pStruct, vel);
182 
183  return success;
184 }
185 
186 
188  const int32IndexContainer& newIndices,
189  const realx3Vector& y)
190 {
191  return true;
192 }
193 
pFlow::AdamsBashforth2::predict
bool predict(real UNUSED(dt), realx3PointField_D &UNUSED(y), realx3PointField_D &UNUSED(dy)) final
Definition: AdamsBashforth2.cpp:123
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::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::AdamsBashforth2::AdamsBashforth2
AdamsBashforth2(const word &baseName, pointStructure &pStruct, const word &method, const realx3Field_D &initialValField)
Construct from components.
Definition: AdamsBashforth2.cpp:94
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::internalField::activePointsMaskDevice
const pFlagTypeDevice & activePointsMaskDevice() const
Definition: internalField.hpp:120
pFlow::realx3PointField_D
pointField_D< realx3 > realx3PointField_D
Definition: pointFields.hpp:52
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:137
pFlow::DefaultExecutionSpace
Kokkos::DefaultExecutionSpace DefaultExecutionSpace
Default execution space, it can be device exe.
Definition: KokkosTypes.hpp:61
pFlow::intAllActive
bool intAllActive(real dt, realx3Field_D &y, realx3PointField_D &dy, realx3PointField_D &dy1)
Definition: AdamsBashforth2.cpp:36
pFlow::Field< realx3 >
pFlow::AdamsBashforth2::correct
bool correct(real dt, realx3PointField_D &y, realx3PointField_D &dy) final
Correction/main integration step.
Definition: AdamsBashforth2.cpp:142
pFlow::intScattered
bool intScattered(real dt, realx3Field_D &y, realx3PointField_D &dy, realx3PointField_D &dy1)
Definition: AdamsBashforth2.cpp:61
pFlow
Definition: demGeometry.hpp:27
pFlow::VectorSingle::deviceView
INLINE_FUNCTION_H auto deviceView() const
Device view range [0, size)
Definition: VectorSingle.cpp:263
pFlow::baseName
word baseName(const word &w, char sep='.')
Find the base in a group separated by "." and return it.
Definition: bTypesFunctions.cpp:185
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::AdamsBashforth2::correctPStruct
bool correctPStruct(real dt, pointStructure &pStruct, realx3PointField_D &vel) final
Definition: AdamsBashforth2.cpp:165
pFlow::internalField::field
const FieldType & field() const
Definition: internalField.hpp:109
pFlow::rpIntegration
Kokkos::RangePolicy< DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< uint32 > > rpIntegration
Range policy for integration kernel (alias)
Definition: AdamsBashforth2.cpp:34
Time.hpp
pFlow::pointField::activeRange
range activeRange() const
Definition: pointField_old.hpp:138
pFlow::objectFile
Definition: objectFile.hpp:30
AdamsBashforth2.hpp
pFlow::AdamsBashforth2::setInitialVals
bool setInitialVals(const int32IndexContainer &newIndices, const realx3Vector &y) final
Set the initial values for new indices.
Definition: AdamsBashforth2.cpp:187
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::pointField::updateBoundariesSlaveToMasterIfRequested
void updateBoundariesSlaveToMasterIfRequested()
update boundaries if it is requested previousely (slave to master).
Definition: pointField.hpp:115
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:58
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Group words and output bw.tw.
Definition: bTypesFunctions.cpp:179
pFlow::AdamsBashforth2::updateBoundariesSlaveToMasterIfRequested
void updateBoundariesSlaveToMasterIfRequested() override
Definition: AdamsBashforth2.cpp:118
vocabs.hpp
pFlow::Vector< realx3 >
pointStructure.hpp
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39
pFlow::internalField::deviceView
auto deviceView() const
Definition: internalField.hpp:97