KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
bins_dynamic_objects_periodic.h
Go to the documentation of this file.
1 // Author: Guillermo Casas
2 
3 #if !defined(KRATOS_BINS_DYNAMIC_OBJECTS_CONTAINER_PERIODIC_H_INCLUDED)
4 #define KRATOS_BINS_DYNAMIC_OBJECTS_CONTAINER_PERIODIC_H_INCLUDED
5 
6 // System includes
7 #include <string>
8 #include <iostream>
9 #include <cmath>
10 #include <algorithm>
11 #include <time.h>
12 
13 #ifdef _OPENMP
14 #include <omp.h>
15 #endif
16 #include "DEM_application.h"
17 #include "includes/define.h"
21 
22 namespace Kratos
23 {
24 
27 
31 
35 
39 
43 
44 
46 
48 template<class TConfigure>
49 class BinsObjectDynamicPeriodic: public BinsObjectDynamic<TConfigure> {
50 public:
53 enum { Dimension = TConfigure::Dimension };
55 typedef TConfigure Configure;
57 typedef typename TConfigure::PointerType PointerType;
62 typedef typename TConfigure::DistanceIteratorType DistanceIteratorType;
63 
65 typedef std::vector<CellType> CellContainerType;
66 typedef typename CellContainerType::iterator CellContainerIterator;
67 
69 typedef typename TreeNodeType::CoordinateType CoordinateType; // double
70 typedef typename TreeNodeType::SizeType SizeType; // std::size_t
71 typedef typename TreeNodeType::IndexType IndexType; // std::size_t
72 
73 
77 
80 //typedef typename TreeNodeType::SearchStructureType SearchStructureType;
82 
83 
86 
90 
94 
95 BinsObjectDynamicPeriodic (IteratorType const& ObjectsBegin, IteratorType const& ObjectsEnd, const array_1d<double, 3> domain_min, const array_1d<double, 3> domain_max)
96 {
97  // : BinsObjectDynamic<TConfigure>(ObjectsBegin, ObjectsEnd)
98 
99  // we must repeat these operations here if we want to still derive from the regular BinsObjectDynamic (template) class
100  this->mObjectsBegin = ObjectsBegin;
101  this->mObjectsEnd = ObjectsEnd;
103  SetDomainLimits(domain_min, domain_max);
104  this->CalculateCellSize(this->mObjectsSize);
105  this->AllocateContainer();
106  GenerateBins();
107 }
108 
111 
112 IndexType CalculatePosition(CoordinateType const& ThisCoord, const SizeType& ThisDimension) override
113 {
114  CoordinateType d_index = ThisCoord;
115  if (ThisCoord < this->mDomainMin[ThisDimension]){
116  CoordinateType domain_period = this->mDomainMax[ThisDimension] - this->mDomainMin[ThisDimension];
117  d_index += domain_period;
118  }
119 
120  else if (ThisCoord > this->mDomainMax[ThisDimension]){
121  CoordinateType domain_period = this->mDomainMax[ThisDimension] - this->mDomainMin[ThisDimension];
122  d_index -= domain_period;
123  }
124 
125  d_index -= this->mMinPoint[ThisDimension];
126 
127  IndexType index = static_cast<IndexType>(d_index * this->mInvCellSize[ThisDimension]);
128 
129  return index;
130 }
131 
133  const double& Radius,
134  ResultIteratorType& Results,
135  const SizeType& MaxNumberOfResults) override
136 {
137  PointType Low, High;
139  SizeType NumberOfResults = 0;
140 
141  TConfigure::CalculateBoundingBox(ThisObject, Low, High, Radius);
142 
143  Box.Set(this->CalculateCell(Low), this->CalculateCell(High), this->mN );
144 
146  Radius,
147  Results,
148  NumberOfResults,
149  MaxNumberOfResults,
150  Box);
151 
152  return NumberOfResults;
153 }
154 
156  const double& Radius,
157  ResultIteratorType& Results,
158  DistanceIteratorType ResultDistances,
159  const SizeType& MaxNumberOfResults) override
160 {
161  PointType Low, High;
163  SizeType NumberOfResults = 0;
164 
165  TConfigure::CalculateBoundingBox(ThisObject, Low, High, Radius);
166 
167  Box.Set(this->CalculateCell(Low), this->CalculateCell(High), this->mN );
168 
170  Radius,
171  Results,
172  ResultDistances,
173  NumberOfResults,
174  MaxNumberOfResults,
175  Box);
176 
177  return NumberOfResults;
178 }
179 
180 protected:
181 
182 void GenerateBins() override
183 {
184  PointType Low, High;
187 
188  for (IteratorType i_object = this->mObjectsBegin ; i_object != this->mObjectsEnd ; i_object++){
189  TConfigure::CalculateBoundingBox(*i_object, Low, High);
190  Box.Set( this->CalculateCell(Low), this->CalculateCell(High), this->mN );
191  FillObjectPeriodic(Box, *i_object);
192  }
193 }
194 
196  CoordinateType const& Radius,
197  ResultIteratorType& Result,
198  SizeType& NumberOfResults,
199  const SizeType& MaxNumberOfResults,
200  SearchStructureType& Box)
201 {
202 
203  PointType MinCell, MaxCell;
204  PointType MinBox, MaxBox;
205 
206  for (SizeType i = 0; i < 3; ++i){
207  MinBox[i] = static_cast<CoordinateType>(Box.Axis[i].Min) * this->mCellSize[i] + this->mMinPoint[i];
208  MaxBox[i] = MinBox[i] + this->mCellSize[i];
209  }
210 
211  IndexType I_begin = Box.Axis[0].BeginIndex();
212  IndexType II_begin = Box.Axis[1].BeginIndex();
213  IndexType III_begin = Box.Axis[2].BeginIndex();
214  MinCell[2] = MinBox[2];
215  MaxCell[2] = MaxBox[2];
216  int III_size = int(Box.Axis[2].Size()) + 1;
217 
218  for (IndexType III = III_begin; III_size > 0; NextIndex(III, III_size, MinCell, MaxCell, Box.Axis, 2)){
219  MinCell[1] = MinBox[1];
220  MaxCell[1] = MaxBox[1];
221  int II_size = int(Box.Axis[1].Size()) + 1;
222 
223  for (IndexType II = II_begin; II_size > 0; NextIndex(II, II_size, MinCell, MaxCell, Box.Axis, 1)){
224  MinCell[0] = MinBox[0];
225  MaxCell[0] = MaxBox[0];
226  int I_size = int(Box.Axis[0].Size()) + 1;
227 
228  for (IndexType I = I_begin; I_size > 0; NextIndex(I, I_size, MinCell, MaxCell, Box.Axis, 0)){
229  IndexType GlobalIndex = III * Box.Axis[2].Block + II * Box.Axis[1].Block + I * Box.Axis[0].Block;
230  //this->mCells[GlobalIndex].SearchObjectsInRadiusExclusive(ThisObject, Radius, Result, NumberOfResults, MaxNumberOfResults);
231  if (TConfigure::IntersectionBox(ThisObject, MinCell, MaxCell, Radius)){
232  this->mCells[GlobalIndex].SearchObjectsInRadiusExclusive(ThisObject,
233  Radius,
234  Result,
235  NumberOfResults,
236  MaxNumberOfResults);
237  }
238  }
239  }
240  }
241 }
242 
244  CoordinateType const& Radius,
245  ResultIteratorType& Result,
246  DistanceIteratorType ResultDistances,
247  SizeType& NumberOfResults,
248  const SizeType& MaxNumberOfResults,
249  SearchStructureType& Box)
250 {
251  PointType MinCell, MaxCell;
252  PointType MinBox, MaxBox;
253 
254  for (SizeType i = 0; i < 3; ++i){
255  MinBox[i] = static_cast<CoordinateType>(Box.Axis[i].Min) * this->mCellSize[i] + this->mMinPoint[i];
256  MaxBox[i] = MinBox[i] + this->mCellSize[i];
257  }
258 
259  IndexType I_begin = Box.Axis[0].BeginIndex();
260  IndexType II_begin = Box.Axis[1].BeginIndex();
261  IndexType III_begin = Box.Axis[2].BeginIndex();
262  MinCell[2] = MinBox[2];
263  MaxCell[2] = MaxBox[2];
264 
265  int III_size = int(Box.Axis[2].Size()) + 1;
266 
267  for (IndexType III = III_begin; III_size > 0; NextIndex(III, III_size, MinCell, MaxCell, Box.Axis, 2)){
268  MinCell[1] = MinBox[1];
269  MaxCell[1] = MaxBox[1];
270  int II_size = int(Box.Axis[1].Size()) + 1;
271 
272  for (IndexType II = II_begin; II_size > 0; NextIndex(II, II_size, MinCell, MaxCell, Box.Axis, 1)){
273  MinCell[0] = MinBox[0];
274  MaxCell[0] = MaxBox[0];
275  int I_size = int(Box.Axis[0].Size()) + 1;
276 
277  for (IndexType I = I_begin; I_size > 0; NextIndex(I, I_size, MinCell, MaxCell, Box.Axis, 0)){
278  IndexType GlobalIndex = III * Box.Axis[2].Block + II * Box.Axis[1].Block + I * Box.Axis[0].Block;
279  //this->mCells[GlobalIndex].SearchObjectsInRadiusExclusive(ThisObject, Radius, Result, ResultDistances, NumberOfResults, MaxNumberOfResults);
280  if (TConfigure::IntersectionBox(ThisObject, MinCell, MaxCell, Radius)){
281  this->mCells[GlobalIndex].SearchObjectsInRadiusExclusive(ThisObject,
282  Radius,
283  Result,
284  ResultDistances,
285  NumberOfResults,
286  MaxNumberOfResults);
287  }
288  }
289  }
290  }
291 }
292 
294 {
295  PointType MinCell, MaxCell;
296  PointType MinBox, MaxBox;
297 
298  for(SizeType i = 0; i < 3; ++i){
299  MinBox[i] = static_cast<CoordinateType>(Box.Axis[i].Min) * this->mCellSize[i] + this->mMinPoint[i];
300  MaxBox[i] = MinBox[i] + this->mCellSize[i];
301  }
302 
303  MinCell[2] = MinBox[2];
304  MaxCell[2] = MaxBox[2];
305  IndexType I_begin = Box.Axis[0].BeginIndex();
306  IndexType II_begin = Box.Axis[1].BeginIndex();
307  IndexType III_begin = Box.Axis[2].BeginIndex();
308 
309  int III_size = int(Box.Axis[2].Size()) + 1;
310 
311  for (IndexType III = III_begin; III_size > 0; NextIndex(III, III_size, MinCell, MaxCell, Box.Axis, 2)){
312  MinCell[1] = MinBox[1];
313  MaxCell[1] = MaxBox[1];
314  int II_size = int(Box.Axis[1].Size()) + 1;
315 
316  for (IndexType II = II_begin; II_size > 0; NextIndex(II, II_size, MinCell, MaxCell, Box.Axis, 1)){
317  MinCell[0] = MinBox[0];
318  MaxCell[0] = MaxBox[0];
319  int I_size = int(Box.Axis[0].Size()) + 1;
320 
321  for (IndexType I = I_begin; I_size > 0; NextIndex(I, I_size, MinCell, MaxCell, Box.Axis, 0)){
322  IndexType GlobalIndex = III * Box.Axis[2].Block + II * Box.Axis[1].Block + I * Box.Axis[0].Block;
323  this->mCells[GlobalIndex].Add(i_object);
324  // if (TConfigure::IntersectionBox(i_object, MinCell,MaxCell)){
325  // this->mCells[GlobalIndex].Add(i_object);
326  // }
327  }
328  }
329  }
330 }
331 
332 
333 private:
334 
335 array_1d<double, 3> mDomainMin;
336 array_1d<double, 3> mDomainMax;
337 
338 void SetDomainLimits(const array_1d<double, 3> domain_min, const array_1d<double, 3> domain_max)
339 {
340  mDomainMin[0] = domain_min[0];
341  mDomainMin[1] = domain_min[1];
342  mDomainMin[2] = domain_min[2];
343  mDomainMax[0] = domain_max[0];
344  mDomainMax[1] = domain_max[1];
345  mDomainMax[2] = domain_max[2];
346 
347 // for (SizeType i = 0 ; i < Dimension ; ++i){
348 // this->mMaxPoint[i] = std::min(this->mMaxPoint[i], mDomainMax[i]);
349 // this->mMinPoint[i] = std::max(this->mMinPoint[i], mDomainMin[i]);
350 // }
351 
352  for (SizeType i = 0 ; i < Dimension ; ++i){
353  this->mMaxPoint[i] = mDomainMax[i];
354  this->mMinPoint[i] = mDomainMin[i];
355  }
356 }
357 
358 inline void NextIndex(IndexType& Index, int& box_size_counter, PointType& MinCell, PointType& MaxCell, const SubBinAxisPeriodic<IndexType,SizeType> Axis[3], const SizeType dimension)
359 {
360  if (Index < this->mN[dimension] - 1){
361  Index += 1;
362  MinCell[dimension] += this->mCellSize[dimension];
363  MaxCell[dimension] += this->mCellSize[dimension];
364  }
365  else {
366  Index = 0;
367  MinCell[dimension] = 0;
368  MaxCell[dimension] = this->mCellSize[dimension];
369  }
370 
371  --box_size_counter;
372 }
373 
374 
378 
379 
383 
387 
388 
392 
393 
398 
399 
400 public:
403  {
404  this-> mMinPoint = rOther.mMinPoint;
405  this-> mMaxPoint = rOther.mMaxPoint;
406  this->mObjectsBegin = rOther.mObjectsBegin;
407  this->mObjectsEnd = rOther.mObjectsEnd;
408  this->mObjectsSize = rOther.mObjectsSize;
409  this->mCellSize = rOther.mCellSize;
410  this->mInvCellSize = rOther.mInvCellSize;
411  this->mN = rOther.mN;
412  this->mCells = rOther.mCells;
413  return *this;
414  }
415 
418  {
419  *this = rOther;
420  }
421 
423  template<class T>
425  {
426  *this = rOther;
427  }
428 
429 }; // Class BinsObjectDynamicPeriodic
430 
432 
435 
436 
440 
441 
443 template<class TConfigure>
444 inline std::istream& operator >> (std::istream& rIStream,
446 {
447  return rIStream;
448 }
449 
451 template<class TConfigure>
452 inline std::ostream& operator << (std::ostream& rOStream,
454 {
455  rThis.PrintInfo(rOStream);
456  rOStream << std::endl;
457  rThis.PrintData(rOStream);
458 
459  return rOStream;
460 }
462 
463 
464 } // namespace Kratos.
465 
466 #endif // KRATOS_FILENAME_H_INCLUDED defined
Short class definition.
Definition: bins_dynamic_objects.h:57
TreeNodeType::CoordinateType CoordinateType
Definition: bins_dynamic_objects.h:75
CellContainerType mCells
Definition: bins_dynamic_objects.h:1721
IteratorType mObjectsEnd
Definition: bins_dynamic_objects.h:1715
TConfigure::PointerType PointerType
Definition: bins_dynamic_objects.h:66
IndexArray CalculateCell(const GenericCoordType &ThisObject)
Definition: bins_dynamic_objects.h:588
TConfigure::PointType PointType
Definition: bins_dynamic_objects.h:65
PointType mMinPoint
Definition: bins_dynamic_objects.h:1710
CoordinateArray mCellSize
Definition: bins_dynamic_objects.h:1717
virtual void PrintData(std::ostream &rOStream, std::string const &Perfix=std::string()) const
Definition: bins_dynamic_objects.h:707
virtual void PrintInfo(std::ostream &rOStream) const
Definition: bins_dynamic_objects.h:698
TConfigure::IteratorType IteratorType
Definition: bins_dynamic_objects.h:68
PointType mMaxPoint
Definition: bins_dynamic_objects.h:1711
void AllocateContainer()
Definition: bins_dynamic_objects.h:1662
TConfigure::ResultIteratorType ResultIteratorType
Definition: bins_dynamic_objects.h:70
TConfigure::DistanceIteratorType DistanceIteratorType
Definition: bins_dynamic_objects.h:71
TreeNodeType::IndexType IndexType
Definition: bins_dynamic_objects.h:77
IteratorType mObjectsBegin
Definition: bins_dynamic_objects.h:1714
void CalculateCellSize(std::size_t ApproximatedSize)
Calculates the cell size of the bins.
Definition: bins_dynamic_objects.h:826
SizeArray mN
Definition: bins_dynamic_objects.h:1719
SizeType mObjectsSize
Definition: bins_dynamic_objects.h:1713
CoordinateArray mInvCellSize
Definition: bins_dynamic_objects.h:1718
TreeNodeType::SizeType SizeType
Definition: bins_dynamic_objects.h:76
Short class definition.
Definition: bins_dynamic_objects_periodic.h:49
BinsObjectDynamic< TConfigure > BaseClassBins
Definition: bins_dynamic_objects_periodic.h:54
TConfigure::ResultContainerType ResultContainerType
Definition: bins_dynamic_objects_periodic.h:60
virtual ~BinsObjectDynamicPeriodic()
Destructor.
Definition: bins_dynamic_objects_periodic.h:110
Tvector< CoordinateType, Dimension > CoordinateArray
Definition: bins_dynamic_objects_periodic.h:76
Tvector< IndexType, Dimension > IndexArray
Definition: bins_dynamic_objects_periodic.h:74
TConfigure::DistanceIteratorType DistanceIteratorType
Definition: bins_dynamic_objects_periodic.h:62
void SearchInRadiusExclusivePeriodic(PointerType &ThisObject, CoordinateType const &Radius, ResultIteratorType &Result, DistanceIteratorType ResultDistances, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults, SearchStructureType &Box)
Definition: bins_dynamic_objects_periodic.h:243
TConfigure::IteratorType IteratorType
Definition: bins_dynamic_objects_periodic.h:59
TConfigure::ResultIteratorType ResultIteratorType
Definition: bins_dynamic_objects_periodic.h:61
std::vector< CellType > CellContainerType
Definition: bins_dynamic_objects_periodic.h:65
TreeNode< Dimension, PointType, PointerType, IteratorType, typename TConfigure::DistanceIteratorType > TreeNodeType
Definition: bins_dynamic_objects_periodic.h:68
TreeNodeType::IteratorIteratorType IteratorIteratorType
typedef TreeNodeType LeafType;
Definition: bins_dynamic_objects_periodic.h:79
TConfigure Configure
Definition: bins_dynamic_objects_periodic.h:55
TConfigure::PointType PointType
Definition: bins_dynamic_objects_periodic.h:56
void SearchInRadiusExclusivePeriodic(PointerType &ThisObject, CoordinateType const &Radius, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults, SearchStructureType &Box)
Definition: bins_dynamic_objects_periodic.h:195
TConfigure::PointerType PointerType
Definition: bins_dynamic_objects_periodic.h:57
void FillObjectPeriodic(SearchStructureType &Box, const PointerType &i_object)
Definition: bins_dynamic_objects_periodic.h:293
TConfigure::ContainerType ContainerType
Definition: bins_dynamic_objects_periodic.h:58
SearchStructurePeriodic< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, Dimension > SearchStructureType
Definition: bins_dynamic_objects_periodic.h:81
@ Dimension
Definition: bins_dynamic_objects_periodic.h:53
BinsObjectDynamicPeriodic< TConfigure > & operator=(const BinsObjectDynamicPeriodic< TConfigure > &rOther)
Assignment operator.
Definition: bins_dynamic_objects_periodic.h:402
SizeType SearchObjectsInRadiusExclusive(PointerType &ThisObject, const double &Radius, ResultIteratorType &Results, const SizeType &MaxNumberOfResults) override
Definition: bins_dynamic_objects_periodic.h:132
SizeType SearchObjectsInRadiusExclusive(PointerType &ThisObject, const double &Radius, ResultIteratorType &Results, DistanceIteratorType ResultDistances, const SizeType &MaxNumberOfResults) override
Definition: bins_dynamic_objects_periodic.h:155
BinsObjectDynamicPeriodic(IteratorType const &ObjectsBegin, IteratorType const &ObjectsEnd, const array_1d< double, 3 > domain_min, const array_1d< double, 3 > domain_max)
Constructor de bins a bounding box.
Definition: bins_dynamic_objects_periodic.h:95
BinsObjectDynamicPeriodic(const BinsObjectDynamicPeriodic< T > &rOther)
Copy constructor.
Definition: bins_dynamic_objects_periodic.h:424
TreeNodeType::SizeType SizeType
Definition: bins_dynamic_objects_periodic.h:70
TreeNodeType::CoordinateType CoordinateType
Definition: bins_dynamic_objects_periodic.h:69
Tvector< SizeType, Dimension > SizeArray
Definition: bins_dynamic_objects_periodic.h:75
CellContainerType::iterator CellContainerIterator
Definition: bins_dynamic_objects_periodic.h:66
BinsObjectDynamicPeriodic(const BinsObjectDynamicPeriodic &rOther)
Copy constructor.
Definition: bins_dynamic_objects_periodic.h:417
IndexType CalculatePosition(CoordinateType const &ThisCoord, const SizeType &ThisDimension) override
Definition: bins_dynamic_objects_periodic.h:112
TreeNodeType::IndexType IndexType
Definition: bins_dynamic_objects_periodic.h:71
void GenerateBins() override
Definition: bins_dynamic_objects_periodic.h:182
BinsObjectDynamicPeriodic()
Default constructor.
Definition: bins_dynamic_objects_periodic.h:92
Cell< Configure > CellType
Definition: bins_dynamic_objects_periodic.h:64
KRATOS_CLASS_POINTER_DEFINITION(BinsObjectDynamicPeriodic)
Pointer definition of BinsObjectDynamicPeriodic.
Definition: cell.h:49
Definition: search_structure.h:309
void Set(IndexVector const &IndexCell, SizeVector const &_MaxSize, IteratorIteratorType const &IteratorBegin)
Definition: search_structure.h:363
SubBinAxis< IndexType, SizeType > Axis[3]
Definition: search_structure.h:326
Definition: search_structure_periodic.h:119
Short class definition.
Definition: tree.h:61
typename std::vector< IteratorType >::iterator IteratorIteratorType
Define IteratorIteratorType as an iterator type for a vector of IteratorType.
Definition: tree.h:94
double CoordinateType
Define CoordinateType as double.
Definition: tree.h:76
std::size_t IndexType
Define IndexType as std::size_t.
Definition: tree.h:73
std::size_t SizeType
Define SizeType as std::size_t.
Definition: tree.h:70
Short class definition.
Definition: search_structure.h:53
std::size_t PointerDistance(TPointerType const &PointerBegin, TPointerType const &PointerEnd)
Definition: search_structure.h:91
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
def Index()
Definition: hdf5_io_tools.py:38
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
integer i
Definition: TensorModule.f:17
Configure::ResultIteratorType ResultIteratorType
Definition: transfer_utility.h:252
Configure::IteratorType IteratorType
Definition: transfer_utility.h:249
Configure::PointType PointType
Definition: transfer_utility.h:245
Configure::ResultContainerType ResultContainerType
Definition: transfer_utility.h:250
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247