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_static_objects.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Nelson Lafontaine
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <string>
17 #include <iostream>
18 #include <cmath>
19 #include <algorithm>
20 #include <array>
21 //#include <time.h>
22 
23 // Project includes
24 #include "tree.h"
25 //#include "cell.h"
26 
27 #ifdef _OPENMP
28 #include <omp.h>
29 #endif
30 
31 
32 namespace Kratos
33 {
34 
37 
41 
45 
49 
53 
54 
56 
58 template<class TConfigure>
60 {
61 public:
64 
65  enum { Dimension = TConfigure::Dimension };
66 
67  typedef TConfigure Configure;
68  typedef typename TConfigure::PointType PointType;
69  typedef typename TConfigure::PointerType PointerType;
74 
76 
77  typedef typename TreeNodeType::CoordinateType CoordinateType; // double
78  typedef typename TreeNodeType::SizeType SizeType; // std::size_t
79  typedef typename TreeNodeType::IndexType IndexType; // std::size_t
80 
84 
87 
88  // Local Container ( PointPointer Container per Cell )
89  // can be different to ContainerType
90  // not always PointVector == ContainerType ( if ContainerType = C array )
91  typedef std::vector<PointerType> LocalContainerType;
92  typedef typename LocalContainerType::iterator LocalIteratorType;
93 
95  typedef typename TConfigure::ContainerContactType ContainerContactType;
96  typedef typename TConfigure::IteratorContactType IteratorContactType;
97 
98  typedef std::vector<IndexType> IndexContainer;
99  typedef typename IndexContainer::iterator IndexIterator;
100 
101  // Legacy typedef ( to preserve compativility in case someone was using this definitions)
102  typedef std::vector<IteratorType> IteratorVector;
103  typedef typename IteratorVector::iterator IteratorIterator;
104  typedef typename IteratorVector::const_iterator IteratorConstIterator;
105 
108 
112 
116 
117  BinsObjectStatic (IteratorType const& ObjectsBegin, IteratorType const& ObjectsEnd)
118  : mObjectsBegin(ObjectsBegin), mObjectsEnd(ObjectsEnd)
119  {
120  auto mNumPoints = std::distance(mObjectsBegin, mObjectsEnd);
121 
123  CalculateCellSize(mNumPoints);
124  GenerateBins();
125  }
126 
127  BinsObjectStatic (IteratorType const& ObjectsBegin, IteratorType const& ObjectsEnd, const SizeType Nx, const SizeType Ny, const SizeType Nz )
128  : mObjectsBegin(ObjectsBegin), mObjectsEnd(ObjectsEnd)
129  {
131 
132  mN[0] = Nx;
133  mN[1] = Ny;
134  mN[2] = Nz;
135 
136  double delta[Dimension];
137 // double mult_delta = 1.00;
138  SizeType index = 0;
139  for(SizeType i = 0 ; i < Dimension ; i++)
140  {
141  delta[i] = mMaxPoint[i] - mMinPoint[i];
142  if ( delta[i] > delta[index] )
143  index = i;
144  delta[i] = (delta[i] == 0.00) ? 1.00 : delta[i];
145  }
146 
147  for(SizeType i = 0 ; i < Dimension ; i++)
148  {
149  mCellSize[i] = delta[i] / mN[i];
150  mInvCellSize[i] = 1.00 / mCellSize[i];
151  }
152 
153  GenerateBins();
154  }
155 
156 
158  virtual ~BinsObjectStatic() {}
159 
160 
164 
165 
169 
170 
174 
175 
179 
180 
184 
186  virtual std::string Info() const
187  {
188  return "BinsObjectStatic : ";
189  }
190 
192  virtual void PrintInfo(std::ostream& rOStream) const
193  {
194  rOStream << Info();
195  }
196 
198  virtual void PrintData(std::ostream& rOStream) const
199  {
200  // Container Size
201  rOStream << " Container Size: ";
202  for(SizeType i = 0 ; i < Dimension ; i++)
203  rOStream << "[" << mN[i] << "]";
204  rOStream << std::endl;
205  // CellSize
206  rOStream << " Cell Size: ";
207  for(SizeType i = 0 ; i < Dimension ; i++)
208  rOStream << "[" << mCellSize[i] << "]";
209  rOStream << std::endl;
210  rOStream << " Contained Objects: " << SearchUtils::PointerDistance(mObjectsBegin,mObjectsEnd) << std::endl;
211  rOStream << " Total Object Storaged: " << mObjectList.size() << std::endl;
212  }
213 
215  void PrintSize( std::ostream& rout )
216  {
217  rout << " Container Size: ";
218  for(SizeType i = 0 ; i < Dimension ; i++)
219  rout << "[" << this->mN[i] << "]";
220  rout << std::endl;
221  }
222 
224  void PrintBox( std::ostream& rout )
225  {
226  rout << " BinsBox: Min [";
227  mMinPoint.Print(rout);
228  rout << "]; Max [";
229  mMaxPoint.Print(rout);
230  rout << "]; Size [";
231  mCellSize.Print(rout);
232  rout << "]" << std::endl;
233  }
234 
241  return mN;
242  }
243 
250  return mCellSize;
251  }
252 
259  return mMinPoint;
260  }
261 
268  return mMaxPoint;
269  }
270 
271 //************************************************************************
272 //************************************************************************
273 
277 
278 
280 
283 
284 
288 
289 
293 
296  {
297 
298  PointType Low, High;
299  TConfigure::CalculateBoundingBox(*mObjectsBegin,mMinPoint,mMaxPoint);
300 
301  std::size_t size = SearchUtils::PointerDistance(mObjectsBegin,mObjectsEnd); // std::distance(mObjectsBegin, mObjectsEnd);
302 #ifdef _OPENMP
303  int number_of_threads = omp_get_max_threads();
304 #else
305  int number_of_threads = 1;
306 #endif
307 
308  std::vector<unsigned int> node_partition;
309  CreatePartition(number_of_threads, size, node_partition);
310 
311  std::vector<PointType> Max(number_of_threads);
312  std::vector<PointType> Min(number_of_threads);
313 
314  for(int k=0; k<number_of_threads; k++ )
315  {
316  Max[k] = mMaxPoint;
317  Min[k] = mMinPoint;
318  }
319 
320 
321 // #ifdef _OPENMP
322 // double start_prod = omp_get_wtime();
323 // #endif
324 
325  #pragma omp parallel for private(High, Low)
326  for(int k=0; k<number_of_threads; k++)
327  {
328  IteratorType i_begin = mObjectsBegin + node_partition[k];
329  IteratorType i_end = mObjectsBegin + node_partition[k+1];
330 
331  for ( IteratorType i_object = i_begin ; i_object != i_end ; i_object++ )
332  {
333  TConfigure::CalculateBoundingBox(*i_object, Low, High);
334  for(std::size_t i = 0 ; i < Dimension ; i++)
335  {
336 
337  Max[k][i] = (Max[k][i] < High[i]) ? High[i] : Max[k][i];
338  Min[k][i] = (Min[k][i] > Low[i]) ? Low[i] : Min[k][i];
339  }
340  }
341  }
342 
343  for(int k=0; k<number_of_threads; k++)
344  {
345  for(std::size_t i = 0 ; i < Dimension ; i++)
346  {
347  mMaxPoint[i] = (mMaxPoint[i] < Max[k][i]) ? Max[k][i] : mMaxPoint[i];
348  mMinPoint[i] = (mMinPoint[i] > Min[k][i]) ? Min[k][i] : mMinPoint[i];
349  }
350  }
351 
352 // #ifdef _OPENMP
353 // double stop_prod = omp_get_wtime();
354 // std::cout << "Time Calculating Bounding Boxes = " << stop_prod - start_prod << std::endl;
355 // #endif
356 
357  }
358 
359 
360 //************************************************************************
361 //************************************************************************
362 
370  void CalculateCellSize(std::size_t ApproximatedSize)
371  {
372  std::size_t average_number_of_cells = static_cast<std::size_t>(std::pow(static_cast<double>(ApproximatedSize), 1.00 / Dimension));
373 
374  std::array<double, 3> lengths;
375  double average_length = 0.00;
376 
377  for (int i = 0; i < Dimension; i++) {
378  lengths[i] = mMaxPoint[i] - mMinPoint[i];
379  average_length += lengths[i];
380  }
381  average_length *= 1.00 / 3.00;
382 
383  if (average_length < std::numeric_limits<double>::epsilon()) {
384  for(int i = 0; i < Dimension; i++) {
385  mN[i] = 1;
386  }
387  return;
388  }
389 
390  for (int i = 0; i < Dimension; i++) {
391  mN[i] = static_cast<std::size_t>(lengths[i] / average_length * (double)average_number_of_cells) + 1;
392 
393  if (mN[i] > 1) {
394  mCellSize[i] = lengths[i] / mN[i];
395  } else {
396  mCellSize[i] = average_length;
397  }
398 
399  mInvCellSize[i] = 1.00 / mCellSize[i];
400  }
401  }
402 
403 
404 //************************************************************************
405 //************************************************************************
406 
408  {
409  PointType Low, High;
411 
412 // SizeType n_objects = SearchUtils::PointerDistance(mObjectsBegin,mObjectsEnd); /// WARNING
413 
414  // Allocate CellAcess
415 
416  SizeType Size = 1;
417  for(SizeType i = 0 ; i < Dimension ; i++)
418  Size *= mN[i];
419  mObjectsAccess.resize(Size+1,0);
420 
421  // Update storage counter, storing ahead
422  for( IteratorType i_object = mObjectsBegin ; i_object != mObjectsEnd ; i_object++)
423  {
424  TConfigure::CalculateBoundingBox(*i_object,Low,High);
425  Box.Set( CalculateCell(Low), CalculateCell(High), mN );
426  CountObject(Box,*i_object);
427  }
428 
429  // Storage/reshufing pass 1
430 
431  // Update storage counter and store
432  for( IndexIterator cell = mObjectsAccess.begin()+1 ; cell != mObjectsAccess.end() ; cell++)
433  *cell += *(cell-1);
434 
435  mObjectList.resize(mObjectsAccess[Size]);
436 
437  // Point pass 2
438  // Store the points in lbin1
439 
440  // Update storage counter, storing in lbin1
441  for( IteratorType i_object = mObjectsBegin ; i_object != mObjectsEnd ; i_object++)
442  {
443  TConfigure::CalculateBoundingBox(*i_object,Low,High);
444  Box.Set( CalculateCell(Low), CalculateCell(High), mN );
445  FillObject(Box,*i_object);
446  }
447 
448  // Storage/reshuffing pass 2
449 
450  // Loop over bins, in reverse order
451  for(IndexIterator Iter = mObjectsAccess.end()-1; Iter != mObjectsAccess.begin(); Iter--)
452  *Iter = *(Iter-1);
453  mObjectsAccess[0] = 0;
454 
455  }
456 
457 
458 
459 
460 //************************************************************************
461 //************************************************************************
462 
463  // Dimension = 1
465  {
466  PointType MinCell, MaxCell;
467 
468  MinCell[0] = static_cast<CoordinateType>(Box.Axis[0].Min) * mCellSize[0] + mMinPoint[0]; //
469  MaxCell[0] = MinCell[0] + mCellSize[0];
470 
471  for(IndexType I = Box.Axis[0].Begin() ; I <= Box.Axis[0].End() ; I += Box.Axis[0].Block, MinCell[0]+=mCellSize[0], MaxCell[0]+=mCellSize[0] )
472  if(TConfigure::IntersectionBox(object,MinCell,MaxCell))
473  mObjectsAccess[I+1]++;
474  }
475 
476 //************************************************************************
477 //************************************************************************
478 
479  // Dimension = 2
481  {
482  PointType MinCell, MaxCell;
483  PointType MinBox, MaxBox;
484 
485  for(SizeType i = 0; i < 2; i++)
486  {
487  MinBox[i] = static_cast<CoordinateType>(Box.Axis[i].Min) * mCellSize[i] + mMinPoint[i]; //
488  MaxBox[i] = MinBox[i] + mCellSize[i];
489  }
490 
491  MinCell[1] = MinBox[1];
492  MaxCell[1] = MaxBox[1];
493  for(IndexType II = Box.Axis[1].Begin() ; II <= Box.Axis[1].End() ; II += Box.Axis[1].Block, MinCell[1]+=mCellSize[1], MaxCell[1]+=mCellSize[1] )
494  {
495  MinCell[0] = MinBox[0];
496  MaxCell[0] = MaxBox[0];
497  for(IndexType I = II + Box.Axis[0].Begin() ; I <= II + Box.Axis[0].End() ; I += Box.Axis[0].Block, MinCell[0]+=mCellSize[0], MaxCell[0]+=mCellSize[0] )
498  if(TConfigure::IntersectionBox(object,MinCell,MaxCell))
499  mObjectsAccess[I+1]++;
500  }
501  }
502 
503 //************************************************************************
504 //************************************************************************
505 
506  // Dimension = 3
508  {
509  PointType MinCell, MaxCell;
510  PointType MinBox, MaxBox;
511 
512  for(SizeType i = 0; i < 3; i++)
513  {
514  MinBox[i] = static_cast<CoordinateType>(Box.Axis[i].Min) * mCellSize[i] + mMinPoint[i]; //
515  MaxBox[i] = MinBox[i] + mCellSize[i];
516  }
517 
518  MinCell[2] = MinBox[2];
519  MaxCell[2] = MaxBox[2];
520  for(IndexType III = Box.Axis[2].Begin() ; III <= Box.Axis[2].End() ; III += Box.Axis[2].Block, MinCell[2]+=mCellSize[2], MaxCell[2]+=mCellSize[2] )
521  {
522  MinCell[1] = MinBox[1];
523  MaxCell[1] = MaxBox[1];
524  for(IndexType II = III + Box.Axis[1].Begin() ; II <= III + Box.Axis[1].End() ; II += Box.Axis[1].Block, MinCell[1]+=mCellSize[1], MaxCell[1]+=mCellSize[1] )
525  {
526  MinCell[0] = MinBox[0];
527  MaxCell[0] = MaxBox[0];
528  for(IndexType I = II + Box.Axis[0].Begin() ; I <= II + Box.Axis[0].End() ; I += Box.Axis[0].Block, MinCell[0]+=mCellSize[0], MaxCell[0]+=mCellSize[0] )
529  if(TConfigure::IntersectionBox(object,MinCell,MaxCell))
530  mObjectsAccess[I+1]++;
531  }
532  }
533  }
534 
535 //************************************************************************
536 //************************************************************************
537 
538  SizeType SearchObjects(PointerType& ThisObject, ResultIteratorType& Result, const SizeType& MaxNumberOfResults )
539  {
540  PointType Low, High;
542  SizeType NumberOfResults = 0;
543  TConfigure::CalculateBoundingBox(ThisObject, Low, High);
544  Box.Set( CalculateCell(Low), CalculateCell(High), mN );
545  SearchInBoxLocal(ThisObject, Result, NumberOfResults, MaxNumberOfResults, Box );
546  return NumberOfResults;
547  }
548 
549 
550 //************************************************************************
551 //************************************************************************
552 
554  {
555  PointType Low, High;
557  TConfigure::CalculateBoundingBox(ThisObject, Low, High);
558  Box.Set( CalculateCell(Low), CalculateCell(High), mN );
559  SearchInBoxLocal(ThisObject, Result, Box );
560  return Result.size();
561  }
562 
563 //************************************************************************
564 //************************************************************************
565  /*
566  void SearchContact(ContainerContactType& Results)
567  {
568  for (CellContainerIterator icell = mCells.begin() ; icell!= mCells.end(); icell++)
569  if(icell->Size()>1)
570  icell->SearchContact(Results);
571  }
572  */
573 //************************************************************************
574 //************************************************************************
575  /*
576  SizeType SearchContact(IteratorContactType& Result, const SizeType& MaxNumberOfResults )
577  {
578  SizeType NumberOfResults = 0;
579  for (CellContainerIterator icell = mCells.begin() ; icell!= mCells.end(); icell++)
580  if(icell->Size()>1)
581  icell->SearchContact(Result, NumberOfResults, MaxNumberOfResults);
582  return NumberOfResults;
583  }
584  */
585 //************************************************************************
586 //************************************************************************
587 
588  void SearchObjectRow(PointerType& ThisObject, LocalIteratorType RowBegin, LocalIteratorType RowEnd, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults)
589  {
590  for(LocalIteratorType iter = RowBegin ; iter != RowEnd && NumberOfResults < MaxNumberOfResults ; iter++)
591  {
592  if(TConfigure::Intersection(ThisObject,*iter))
593  {
594  if( std::find(Result-NumberOfResults, Result, *iter) == Result )
595  {
596  *Result = *iter;
597  Result++;
598  NumberOfResults++;
599  }
600  }
601  }
602  }
603 
604  // **** THREAD SAFE
605 
606  // Dimension = 1
607  void SearchInBoxLocal(PointerType& ThisObject, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults,
609  {
610  SearchObjectRow(ThisObject,mObjectList.begin()+mObjectsAccess[Box.Axis[0].Begin()],mObjectList.begin()+mObjectsAccess[Box.Axis[0].End()+1],Result,NumberOfResults,MaxNumberOfResults);
611  }
612 
613  // Dimension = 2
614  void SearchInBoxLocal(PointerType& ThisObject, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults,
616  {
617  for(IndexType I = Box.Axis[1].Begin() ; I <= Box.Axis[1].End() ; I += Box.Axis[1].Block )
618  SearchObjectRow(ThisObject,mObjectList.begin()+mObjectsAccess[I+Box.Axis[0].Begin()],mObjectList.begin()+mObjectsAccess[I+Box.Axis[0].End()+1],Result,NumberOfResults,MaxNumberOfResults);
619  }
620 
621  // Dimension = 3
622  void SearchInBoxLocal(PointerType& ThisObject, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults,
624  {
625  for(IndexType II = Box.Axis[2].Begin() ; II <= Box.Axis[2].End() ; II += Box.Axis[2].Block )
626  for(IndexType I = II + Box.Axis[1].Begin() ; I <= II + Box.Axis[1].End() ; I += Box.Axis[1].Block )
627  SearchObjectRow(ThisObject,mObjectList.begin()+mObjectsAccess[I+Box.Axis[0].Begin()],mObjectList.begin()+mObjectsAccess[I+Box.Axis[0].End()+1],Result,NumberOfResults,MaxNumberOfResults);
628  }
629 
630  // Dimension = 3
631  void SearchInBoxLocal_(PointerType& ThisObject, ResultIteratorType& Result, SizeType& NumberOfResults, const SizeType& MaxNumberOfResults,
633  {
634  PointType MinCell, MaxCell;
635  PointType MinBox, MaxBox;
636  IndexType objects_begin, objects_end;
637 
638  for(SizeType i = 0; i < 3; i++)
639  {
640  MinBox[i] = static_cast<CoordinateType>(Box.Axis[i].Min) * mCellSize[i] + mMinPoint[i]; //
641  MaxBox[i] = MinBox[i] + mCellSize[i];
642  }
643  CoordinateType MaxBox_ = static_cast<CoordinateType>(Box.Axis[0].Min+1) * mCellSize[0] + mMinPoint[0]; //
644  MinCell[2] = MinBox[2];
645  MaxCell[2] = MaxBox[2];
646  for(IndexType III = Box.Axis[2].Begin() ; III <= Box.Axis[2].End() ; III += Box.Axis[2].Block, MinCell[2]+=mCellSize[2], MaxCell[2]+=mCellSize[2] )
647  {
648  MinCell[1] = MinBox[1];
649  MaxCell[1] = MaxBox[1];
650  for(IndexType II = III + Box.Axis[1].Begin() ; II <= III + Box.Axis[1].End() ; II += Box.Axis[1].Block, MinCell[1]+=mCellSize[1], MaxCell[1]+=mCellSize[1] )
651  {
652  MinCell[0] = MinBox[0];
653  MaxCell[0] = MaxBox[0];
654  objects_begin = mObjectsAccess[II + Box.Axis[0].Begin()];
655  for(IndexType I = II + Box.Axis[0].Begin() ; I <= II + Box.Axis[0].End() ; I += Box.Axis[0].Block, MinCell[0]+=mCellSize[0], MaxCell[0]+=mCellSize[0] )
656  {
657  if(TConfigure::IntersectionBox(ThisObject,MinCell,MaxCell))
658  {
659  objects_begin = mObjectsAccess[I];
660  break;
661  }
662  }
663  MinCell[0] = MaxBox_-mCellSize[0];
664  MaxCell[0] = MaxBox_;
665  objects_end = mObjectsAccess[II+Box.Axis[0].End()+1];
666  for(IndexType I = II + Box.Axis[0].End() ; I >= II + Box.Axis[0].Begin() ; I -= Box.Axis[0].Block, MinCell[0]-=mCellSize[0], MaxCell[0]-=mCellSize[0] )
667  {
668  if(TConfigure::IntersectionBox(ThisObject,MinCell,MaxCell))
669  {
670  objects_end = mObjectsAccess[I+1];
671  break;
672  }
673  }
674  SearchObjectRow(ThisObject,mObjectList.begin()+objects_begin,mObjectList.begin()+objects_end,Result,NumberOfResults,MaxNumberOfResults);
675  }
676  }
677  }
678 
679 //************************************************************************
680 //************************************************************************
681 
682 
684  {
685  for(LocalIteratorType iter = RowBegin ; iter != RowEnd ; iter++)
686  {
687  if(TConfigure::Intersection(ThisObject,*iter))
688  if( std::find(Results.begin(), Results.end(), *iter) == Results.end() )
689  Results.push_back(*iter);
690  }
691  }
692 
693  // **** THREAD SAFE
694 
695  // Dimension = 1
698  {
699  SearchObjectRow(ThisObject,mObjectList.begin()+mObjectsAccess[Box.Axis[0].Begin()],mObjectList.begin()+mObjectsAccess[Box.Axis[0].End()+1],Results);
700  }
701 
702  // Dimension = 2
705  {
706  for(IndexType I = Box.Axis[1].Begin() ; I <= Box.Axis[1].End() ; I += Box.Axis[1].Block )
707  SearchObjectRow(ThisObject,mObjectList.begin()+mObjectsAccess[I+Box.Axis[0].Begin()],mObjectList.begin()+mObjectsAccess[I+Box.Axis[0].End()+1],Results);
708  }
709 
710  // Dimension = 3
713  {
714  for(IndexType II = Box.Axis[2].Begin() ; II <= Box.Axis[2].End() ; II += Box.Axis[2].Block )
715  for(IndexType I = II + Box.Axis[1].Begin() ; I <= II + Box.Axis[1].End() ; I += Box.Axis[1].Block )
716  SearchObjectRow(ThisObject,mObjectList.begin()+mObjectsAccess[I+Box.Axis[0].Begin()],mObjectList.begin()+mObjectsAccess[I+Box.Axis[0].End()+1],Results);
717  }
718 
719 
720 
721 //************************************************************************
722 //************************************************************************
723 
725  {
727  for(SizeType i = 0 ; i < Dimension ; i++)
728  Cell[i] = CalculatePosition(ThisPoint[i],i);
729  return Cell;
730  }
731 
732 
733 //************************************************************************
734 //************************************************************************
735 
736  // Dimension = 1
738  {
739  PointType MinCell, MaxCell;
740 
741  MinCell[0] = static_cast<CoordinateType>(Box.Axis[0].Min) * mCellSize[0] + mMinPoint[0]; //
742  MaxCell[0] = MinCell[0] + mCellSize[0];
743  for(IndexType I = Box.Axis[0].Begin() ; I <= Box.Axis[0].End() ; I += Box.Axis[0].Block, MinCell[0]+=mCellSize[0], MaxCell[0]+=mCellSize[0] )
744  if(TConfigure::IntersectionBox(object,MinCell,MaxCell))
745  mObjectList[mObjectsAccess[I]++] = object;
746  }
747 
748 
749  // Dimension = 2
751  {
752  PointType MinCell, MaxCell;
753  PointType MinBox, MaxBox;
754 
755  for(SizeType i = 0; i < 2; i++)
756  {
757  MinBox[i] = static_cast<CoordinateType>(Box.Axis[i].Min) * mCellSize[i] + mMinPoint[i]; //
758  MaxBox[i] = MinBox[i] + mCellSize[i];
759  }
760 
761  MinCell[1] = MinBox[1];
762  MaxCell[1] = MaxBox[1];
763  for(IndexType II = Box.Axis[1].Begin() ; II <= Box.Axis[1].End() ; II += Box.Axis[1].Block, MinCell[1]+=mCellSize[1], MaxCell[1]+=mCellSize[1] )
764  {
765  MinCell[0] = MinBox[0];
766  MaxCell[0] = MaxBox[0];
767  for(IndexType I = II + Box.Axis[0].Begin() ; I <= II + Box.Axis[0].End() ; I += Box.Axis[0].Block, MinCell[0]+=mCellSize[0], MaxCell[0]+=mCellSize[0] )
768  if(TConfigure::IntersectionBox(object,MinCell,MaxCell))
769  mObjectList[mObjectsAccess[I]++] = object;
770  }
771  }
772 
773 
774  // Dimension = 3
776  {
777  PointType MinCell, MaxCell;
778  PointType MinBox, MaxBox;
779 
780  for(SizeType i = 0; i < 3; i++)
781  {
782  MinBox[i] = static_cast<CoordinateType>(Box.Axis[i].Min) * mCellSize[i] + mMinPoint[i]; //
783  MaxBox[i] = MinBox[i] + mCellSize[i];
784  }
785 
786  MinCell[2] = MinBox[2];
787  MaxCell[2] = MaxBox[2];
788  for(IndexType III = Box.Axis[2].Begin() ; III <= Box.Axis[2].End() ; III += Box.Axis[2].Block, MinCell[2]+=mCellSize[2], MaxCell[2]+=mCellSize[2] )
789  {
790  MinCell[1] = MinBox[1];
791  MaxCell[1] = MaxBox[1];
792  for(IndexType II = III + Box.Axis[1].Begin() ; II <= III + Box.Axis[1].End() ; II += Box.Axis[1].Block, MinCell[1]+=mCellSize[1], MaxCell[1]+=mCellSize[1] )
793  {
794  MinCell[0] = MinBox[0];
795  MaxCell[0] = MaxBox[0];
796  for(IndexType I = II + Box.Axis[0].Begin() ; I <= II + Box.Axis[0].End() ; I += Box.Axis[0].Block, MinCell[0]+=mCellSize[0], MaxCell[0]+=mCellSize[0] )
797  if(TConfigure::IntersectionBox(object,MinCell,MaxCell))
798  mObjectList[mObjectsAccess[I]++] = object;
799  }
800  }
801  }
802 
803 //************************************************************************
804 //************************************************************************
805 
806 
807  IndexType CalculatePosition( CoordinateType const& ThisCoord, SizeType& ThisDimension )
808  {
809  CoordinateType d_index = (ThisCoord - mMinPoint[ThisDimension]) * mInvCellSize[ThisDimension];
810  IndexType index = static_cast<IndexType>( (d_index < 0.00) ? 0.00 : d_index );
811  return (index > mN[ThisDimension]-1) ? mN[ThisDimension]-1 : index;
812 
813  }
814 
815 
816 
817 //************************************************************************
818 //************************************************************************
819 
823 
824 
828 
829 
833 
834 
838 
839 
841 
842 private:
845 
846 
850 
851  PointType mMinPoint;
852  PointType mMaxPoint;
853 
854  IteratorType mObjectsBegin;
855  IteratorType mObjectsEnd;
856 
857  CoordinateArray mCellSize;
858  CoordinateArray mInvCellSize;
859  SizeArray mN;
860 
861  LocalContainerType mObjectList;
862  IndexContainer mObjectsAccess;
863 
864 
865 
866 
870 
871 
875 
876  inline void CreatePartition(unsigned int number_of_threads, const int number_of_rows, std::vector<unsigned int>& partitions)
877  {
878  partitions.resize(number_of_threads+1);
879  int partition_size = number_of_rows / number_of_threads;
880  partitions[0] = 0;
881  partitions[number_of_threads] = number_of_rows;
882  for(unsigned int i = 1; i<number_of_threads; i++)
883  partitions[i] = partitions[i-1] + partition_size ;
884  }
885 
886 
890 
891 
895 
896 
900 
901 
903  BinsObjectStatic& operator=(BinsObjectStatic const& rOther) {}
904 
906  BinsObjectStatic(BinsObjectStatic const& rOther) {}
907 
908 
910 
911 
912 }; // Class BinsObjectStatic
913 
915 
918 
919 
923 
924 
926 template<class TConfigure>
927 inline std::istream& operator >> (std::istream& rIStream,BinsObjectStatic<TConfigure>& rThis)
928 {
929  return rIStream;
930 }
931 
932 
934 template<class TConfigure>
935 inline std::ostream& operator << (std::ostream& rOStream,
936  const BinsObjectStatic<TConfigure> & rThis)
937 {
938  rThis.PrintInfo(rOStream);
939  rOStream << std::endl;
940  rThis.PrintData(rOStream);
941 
942  return rOStream;
943 }
945 
946 
947 } // namespace Kratos.
948 
949 
Short class definition.
Definition: bins_static_objects.h:60
TreeNodeType::CoordinateType CoordinateType
Definition: bins_static_objects.h:77
void FillObject(SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 2 > &Box, const PointerType &object)
Definition: bins_static_objects.h:750
void SearchInBoxLocal(PointerType &ThisObject, ResultContainerType &Results, SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 1 > &Box)
Definition: bins_static_objects.h:696
void FillObject(SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 1 > &Box, const PointerType &object)
Definition: bins_static_objects.h:737
void CountObject(SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 2 > &Box, PointerType object)
Definition: bins_static_objects.h:480
void PrintBox(std::ostream &rout)
Print Limits Points of the Container.
Definition: bins_static_objects.h:224
void GenerateBins()
Definition: bins_static_objects.h:407
BinsObjectStatic(IteratorType const &ObjectsBegin, IteratorType const &ObjectsEnd)
Constructor de bins a bounding box.
Definition: bins_static_objects.h:117
Tvector< SizeType, Dimension > SizeArray
Definition: bins_static_objects.h:82
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: bins_static_objects.h:198
IndexType CalculatePosition(CoordinateType const &ThisCoord, SizeType &ThisDimension)
Definition: bins_static_objects.h:807
Tvector< CoordinateType, Dimension > CoordinateArray
Definition: bins_static_objects.h:81
void CalculateBoundingBox()
Computa los boxes de cada uno de los elementos del model part.
Definition: bins_static_objects.h:295
TreeNodeType::IteratorIteratorType IteratorIteratorType
Definition: bins_static_objects.h:85
PointType & GetMaxPoint()
Get the Max Point object.
Definition: bins_static_objects.h:267
virtual std::string Info() const
Turn back information as a string.
Definition: bins_static_objects.h:186
SizeType SearchObjects(PointerType &ThisObject, ResultContainerType &Result)
Definition: bins_static_objects.h:553
TreeNodeType::SearchStructureType SearchStructureType
Definition: bins_static_objects.h:86
BinsObjectStatic()
Default constructor.
Definition: bins_static_objects.h:114
TConfigure Configure
Definition: bins_static_objects.h:67
TreeNodeType::SizeType SizeType
Definition: bins_static_objects.h:78
LocalContainerType::iterator LocalIteratorType
Definition: bins_static_objects.h:92
void SearchInBoxLocal(PointerType &ThisObject, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults, SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 3 > &Box)
Definition: bins_static_objects.h:622
SizeArray & GetDivisions()
Get the Divisions object.
Definition: bins_static_objects.h:240
PointType & GetMinPoint()
Get the Min Point object.
Definition: bins_static_objects.h:258
Tvector< IndexType, Dimension > CalculateCell(const PointType &ThisPoint)
Definition: bins_static_objects.h:724
void FillObject(SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 3 > &Box, const PointerType &object)
Definition: bins_static_objects.h:775
void SearchObjectRow(PointerType &ThisObject, LocalIteratorType RowBegin, LocalIteratorType RowEnd, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults)
Definition: bins_static_objects.h:588
CoordinateArray & GetCellSize()
Get the Cell Size object.
Definition: bins_static_objects.h:249
virtual ~BinsObjectStatic()
Destructor.
Definition: bins_static_objects.h:158
void SearchObjectRow(PointerType &ThisObject, LocalIteratorType RowBegin, LocalIteratorType RowEnd, ResultContainerType &Results)
Definition: bins_static_objects.h:683
TConfigure::IteratorType IteratorType
Definition: bins_static_objects.h:71
void PrintSize(std::ostream &rout)
Print Size of Container.
Definition: bins_static_objects.h:215
TConfigure::ResultIteratorType ResultIteratorType
Definition: bins_static_objects.h:73
std::vector< IndexType > IndexContainer
Definition: bins_static_objects.h:98
void CalculateCellSize(std::size_t ApproximatedSize)
Calculates the cell size of the bins.
Definition: bins_static_objects.h:370
BinsObjectStatic(IteratorType const &ObjectsBegin, IteratorType const &ObjectsEnd, const SizeType Nx, const SizeType Ny, const SizeType Nz)
Definition: bins_static_objects.h:127
void SearchInBoxLocal(PointerType &ThisObject, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults, SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 2 > &Box)
Definition: bins_static_objects.h:614
KRATOS_CLASS_POINTER_DEFINITION(BinsObjectStatic)
Pointer definition of BinsObjectStatic.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: bins_static_objects.h:192
TConfigure::IteratorContactType IteratorContactType
Definition: bins_static_objects.h:96
TConfigure::PointerType PointerType
Definition: bins_static_objects.h:69
@ Dimension
Definition: bins_static_objects.h:65
TConfigure::ContainerContactType ContainerContactType
Contact Pair.
Definition: bins_static_objects.h:95
void SearchInBoxLocal(PointerType &ThisObject, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults, SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 1 > &Box)
Definition: bins_static_objects.h:607
std::vector< IteratorType > IteratorVector
Definition: bins_static_objects.h:102
TreeNodeType::IndexType IndexType
Definition: bins_static_objects.h:79
void SearchInBoxLocal(PointerType &ThisObject, ResultContainerType &Results, SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 3 > &Box)
Definition: bins_static_objects.h:711
TreeNode< Dimension, PointType, PointerType, IteratorType, typename TConfigure::DistanceIteratorType > TreeNodeType
Definition: bins_static_objects.h:75
void SearchInBoxLocal_(PointerType &ThisObject, ResultIteratorType &Result, SizeType &NumberOfResults, const SizeType &MaxNumberOfResults, SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 3 > &Box)
Definition: bins_static_objects.h:631
TConfigure::ResultContainerType ResultContainerType
Definition: bins_static_objects.h:72
void SearchInBoxLocal(PointerType &ThisObject, ResultContainerType &Results, SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 2 > &Box)
Definition: bins_static_objects.h:703
Tvector< IndexType, Dimension > IndexArray
Definition: bins_static_objects.h:83
IteratorVector::iterator IteratorIterator
Definition: bins_static_objects.h:103
void CountObject(SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 3 > &Box, PointerType object)
Definition: bins_static_objects.h:507
SizeType SearchObjects(PointerType &ThisObject, ResultIteratorType &Result, const SizeType &MaxNumberOfResults)
Definition: bins_static_objects.h:538
std::vector< PointerType > LocalContainerType
Definition: bins_static_objects.h:91
IndexContainer::iterator IndexIterator
Definition: bins_static_objects.h:99
TConfigure::PointType PointType
Definition: bins_static_objects.h:68
TConfigure::ContainerType ContainerType
Definition: bins_static_objects.h:70
void CountObject(SearchStructure< IndexType, SizeType, CoordinateType, IteratorType, IteratorIteratorType, 1 > &Box, PointerType object)
Definition: bins_static_objects.h:464
IteratorVector::const_iterator IteratorConstIterator
Definition: bins_static_objects.h:104
Definition: cell.h:49
Point class.
Definition: point.h:59
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
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
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
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::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int k
Definition: quadrature.py:595
integer i
Definition: TensorModule.f:17
double precision, dimension(3, 3), public delta
Definition: TensorModule.f:16
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