www.cemf.ir
pointStructure.cpp
Go to the documentation of this file.
1 
2 /*------------------------------- phasicFlow ---------------------------------
3  O C enter of
4  O O E ngineering and
5  O O M ultiscale modeling of
6  OOOOOOO F luid flow
7 ------------------------------------------------------------------------------
8  Copyright (C): www.cemf.ir
9  email: hamid.r.norouzi AT gmail.com
10 ------------------------------------------------------------------------------
11 Licence:
12  This file is part of phasicFlow code. It is a free software for simulating
13  granular and multiphase flows. You can redistribute it and/or modify it under
14  the terms of GNU General Public License v3 or any other later versions.
15 
16  phasicFlow is distributed to help others in their research in the field of
17  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
18  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 
20 -----------------------------------------------------------------------------*/
21 
22 #include "pointStructure.hpp"
23 #include "systemControl.hpp"
24 #include "vocabs.hpp"
25 #include "anyList.hpp"
26 
28 {
29  PointsTypeHost hPoints
30  (
31  pointPosition().name(),
32  pointPosition().fieldKey()
33  );
34 
35  hPoints.assign(points);
36 
37  return setupPointStructure(hPoints);
38 }
39 
41 {
42  if(!simulationDomain_->initialUpdateDomains(points.getSpan()))
43  {
45  "error in updating domains"<<endl;
46  return false;
47  }
48 
49  uint32 thisN = simulationDomain_->initialNumberInThis();
50 
51  PointsTypeHost internal
52  (
53  pointPosition().name(),
54  pointPosition().fieldKey(),
55  thisN,
56  thisN,
57  RESERVE()
58  );
59 
60  auto pSpan = points.getSpan();
61 
62  if(auto iSpan = internal.getSpan();
63  !simulationDomain_->initialTransferBlockData(pSpan, iSpan))
64  {
66  "Error in transfering the block data "<<endl;
67  return false;
68  }
69 
70  if( !initializePoints(internal) )
71  {
73  return false;
74  }
75 
76  boundaries_.createBoundaries();
77  boundaries_.updateNeighborLists(0u, true);
78 
79  return true;
80 }
81 
82 
84 {
85  pointPosition().assignFromHost(points);
86 
87  createDeviceFlag(pointPosition().capacity(), 0, pointPosition().size());
88  syncPFlag();
89 
90  return true;
91 }
92 
94 (
95  systemControl& control
96 )
97 :
98  IOobject
99  (
100  objectFile
101  (
103  "",
106  ),
108  &control.time()
109  ),
110  demComponent("particlesCenterMass", control),
111  internalPoints(),
112  simulationDomain_
113  (
114  simulationDomain::create(control)
115  ),
116  //pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")),
117  boundaries_
118  (
119  *this
120  ),
121  boundaryUpdateTimer_("boundaryUpdate", &timers()),
122  boundaryDataTransferTimer_("boundaryDataTransferTimer", &timers())
123 {
124  REPORT(1)<< "Reading "<< Green_Text("pointStructure")<<
125  " from "<<IOobject::path()<<END_REPORT;
126 
127  if( !IOobject::readObject() )
128  {
130  "Error in reading from file "<<IOobject::path()<<endl;
131  fatalExit;
132  }
133 
134  pointSorting_ = makeUnique<pointSorting>(simulationDomain_->subDictOrCreate("pointSorting"));
135 }
136 
137 
139  systemControl& control,
140  const realx3Vector &posVec)
141 :
142  IOobject
143  (
144  objectFile
145  (
147  "",
148  objectFile::READ_NEVER,
149  objectFile::WRITE_ALWAYS
150  ),
151  IOPattern::MasterProcessorDistribute,
152  &control.time()
153  ),
154  demComponent("particlesCenterMass", control),
155  internalPoints(),
156  simulationDomain_
157  (
158  simulationDomain::create(control)
159  ),
160  //pointSorting_(simulationDomain_->subDictOrCreate("pointSorting")),
161  boundaries_
162  (
163  *this
164  )
165 {
166  if(!setupPointStructure(posVec))
167  {
169  "Error in seting up pointStructure"<<endl;
170  fatalExit;
171  }
172  pointSorting_ = makeUnique<pointSorting>(simulationDomain_->subDictOrCreate("pointSorting"));
173 }
174 
176 {
177  const timeInfo ti = TimeInfo();
178 
179  if(pointSorting_().sortTime(ti.iter(), ti.t(), ti.dt()))
180  {
181  auto sortedIndices = pointSorting_().getSortedIndices(
182  simulationDomain_().globalBox(),
183  pointPositionDevice(),
184  activePointsMaskDevice()
185  );
186 
187  if( !sortPoints(sortedIndices) )
188  {
190  return false;
191  }
192 
193  boundaryUpdateTimer_.start();
194  boundaries_.beforeIteration(ti, true);
195  boundaryUpdateTimer_.end();
196 
197  INFORMATION<<"Reordering of particles has been done. New active range for particles is "<<
198  activeRange()<<END_INFO;
199 
200 
201  message msg;
202  anyList varList;
203 
204  varList.emplaceBack(
206  sortedIndices);
207 
208  if(!notify(ti, msg, varList))
209  {
211  "cannot notify for reordering items."<<endl;
212  return false;
213  }
214  return true;
215  // notify others about this change
216  }
217  else
218  {
219  boundaryUpdateTimer_.start();
220  if( !boundaries_.beforeIteration(ti) )
221  {
223  "Unable to perform beforeIteration for boundaries"<<endl;
224  return false;
225  }
226  boundaryUpdateTimer_.end();
227  }
228 
229  return true;
230 }
231 
233 {
234  if( !boundaries_.iterate(TimeInfo()) )
235  {
237  "Unable to perform iterate for boundaries"<<endl;
238  return false;
239  }
240 
241  return true;
242 }
243 
245 {
246  boundaryDataTransferTimer_.start();
247  if( !boundaries_.afterIteration(TimeInfo()) )
248  {
250  "Unable to perform afterIteration for boundaries"<<endl;
251  return false;
252  }
253  boundaryDataTransferTimer_.end();
254  return true;
255 }
256 
258  iIstream &is,
259  const IOPattern& iop)
260 {
261 
262  PointsTypeHost fRead
263  (
264  this->pointPosition().name(),
265  this->pointPosition().fieldKey()
266  );
267 
268  if( !fRead.read(is, iop))
269  {
271  "Error in reading pointPosition from stream "<< is.name()<<endl;
272  return false;
273  }
274 
275  return setupPointStructure(fRead);
276 }
277 
279 (
280  iOstream& os,
281  const IOPattern& iop
282 )const
283 {
284  return internalPoints::write(os, iop);
285 }
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
anyList.hpp
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::message
Definition: message.hpp:33
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::pointStructure::read
bool read(iIstream &is, const IOPattern &iop) override
read the point structure from the input stream.
Definition: pointStructure.cpp:257
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::pointStructure::beforeIteration
bool beforeIteration() override
In the time loop before iterate.
Definition: pointStructure.cpp:175
systemControl.hpp
pFlow::pointStructure::pointStructure
pointStructure(systemControl &control)
an empty pointStructure, good for reading from file
Definition: pointStructure.cpp:94
pFlow::internalPoints::pointPosition
const PointsType & pointPosition() const
Definition: internalPoints.cpp:209
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:43
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::timeInfo
Definition: timeInfo.hpp:28
pFlow::message::ITEM_REARRANGE
@ ITEM_REARRANGE
Definition: message.hpp:44
pFlow::pointStructure::pointSorting_
uniquePtr< pointSorting > pointSorting_
Definition: pointStructure.hpp:57
pFlow::IOobject
Definition: IOobject.hpp:35
RESERVE
Definition: Vector.hpp:40
pFlow::anyList
Definition: anyList.hpp:35
pFlow::pointStructureFile__
const char *const pointStructureFile__
Definition: vocabs.hpp:42
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::IOobject::readObject
bool readObject(bool rdHdr=true)
Definition: IOobject.cpp:83
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::IOfileHeader::path
fileSystem path() const
Definition: IOfileHeader.cpp:63
pFlow::demComponent
A base class for every main component of DEM system.
Definition: demComponent.hpp:42
pFlow::objectFile::name
virtual const word & name() const
Definition: objectFile.hpp:101
pFlow::systemControl::time
const Time & time() const
Definition: systemControl.hpp:122
pFlow::objectFile::READ_ALWAYS
@ READ_ALWAYS
Definition: objectFile.hpp:36
pFlow::internalPoints::PointsTypeHost
typename PointsType::FieldTypeHost PointsTypeHost
Definition: internalPoints.hpp:48
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::pointStructure::write
bool write(iOstream &os, const IOPattern &iop) const override
Write.
Definition: pointStructure.cpp:279
pFlow::timeInfo::dt
const real & dt() const
Definition: timeInfo.hpp:51
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::pointStructure::iterate
bool iterate() override
This is called in time loop.
Definition: pointStructure.cpp:232
pFlow::pointStructure::initializePoints
bool initializePoints(const PointsTypeHost &points)
Definition: pointStructure.cpp:83
pFlow::timeInfo::t
const real & t() const
Definition: timeInfo.hpp:47
pFlow::message::addAndName
const word & addAndName(EVENT evnt)
Definition: message.hpp:119
pFlow::simulationDomain::create
static uniquePtr< simulationDomain > create(systemControl &control)
Definition: simulationDomain.cpp:121
pFlow::timeInfo::iter
const uint32 & iter() const
Definition: timeInfo.hpp:55
pFlow::pointStructure::setupPointStructure
bool setupPointStructure(const realx3Vector &points)
Definition: pointStructure.cpp:27
pFlow::pointStructure::simulationDomain_
uniquePtr< simulationDomain > simulationDomain_
Definition: pointStructure.hpp:55
pFlow::simulationDomain
Definition: simulationDomain.hpp:38
pFlow::internalPoints::write
bool write(iOstream &os) const
Write.
Definition: internalPoints.cpp:556
pFlow::pointStructure::afterIteration
bool afterIteration() override
This is called in time loop, after iterate.
Definition: pointStructure.cpp:244
vocabs.hpp
pFlow::Vector< realx3 >
END_INFO
#define END_INFO
Definition: streams.hpp:37
pointStructure.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::IOPattern::MasterProcessorDistribute
@ MasterProcessorDistribute
Definition: IOPattern.hpp:56
pFlow::anyList::emplaceBack
reference emplaceBack(const word &name, Args &&... args)
Create variable using constructor in-place.
Definition: anyList.hpp:84
INFORMATION
#define INFORMATION
Definition: streams.hpp:36