16 #include <unordered_set>
33 class GeometricalObject;
61 using CellType = std::vector<GeometricalObject*>;
74 template<
typename TIteratorType>
76 TIteratorType GeometricalObjectsBegin,
77 TIteratorType GeometricalObjectsEnd,
78 const double Tolerance = 1
e-12
81 mTolerance = Tolerance;
82 const std::size_t number_of_objects = std::distance(GeometricalObjectsBegin, GeometricalObjectsEnd);
83 if (number_of_objects > 0){
84 mBoundingBox.Set(GeometricalObjectsBegin->GetGeometry().begin(), GeometricalObjectsBegin->GetGeometry().end());
85 for (TIteratorType i_object = GeometricalObjectsBegin ; i_object != GeometricalObjectsEnd ; i_object++){
86 mBoundingBox.Extend(i_object->GetGeometry().begin() , i_object->GetGeometry().end());
88 mBoundingBox.Extend(Tolerance);
90 CalculateCellSize(number_of_objects);
91 mCells.resize(GetTotalNumberOfCells());
92 AddObjectsToCells(GeometricalObjectsBegin, GeometricalObjectsEnd);
100 template<
typename TContainer>
102 TContainer& rGeometricalObjectsVector,
103 const double Tolerance = 1
e-12)
156 std::vector<ResultType>& rResults
168 template<
typename TPo
intIteratorType>
170 TPointIteratorType itPointBegin,
171 TPointIteratorType itPointEnd,
173 std::vector<std::vector<ResultType>>& rResults
176 const std::size_t number_of_points = std::distance(itPointBegin, itPointEnd);
177 rResults.resize(number_of_points);
178 for (
auto it_point = itPointBegin ; it_point != itPointEnd ; it_point++){
179 SearchInRadius(*it_point, Radius, rResults[it_point - itPointBegin]);
192 ResultType SearchNearestInRadius(
208 template<
typename TPo
intIteratorType>
210 TPointIteratorType itPointBegin,
211 TPointIteratorType itPointEnd,
216 std::vector<ResultType> results;
217 const std::size_t number_of_points = std::distance(itPointBegin, itPointEnd);
218 results.resize(number_of_points);
219 for (
auto it_point = itPointBegin ; it_point != itPointEnd ; it_point++){
220 results[it_point - itPointBegin] = SearchNearestInRadius(*it_point, Radius);
232 ResultType SearchNearest(
const PointType& rPoint);
243 template<
typename TPo
intIteratorType>
245 TPointIteratorType itPointBegin,
246 TPointIteratorType itPointEnd
250 std::vector<ResultType> results;
251 const std::size_t number_of_points = std::distance(itPointBegin, itPointEnd);
252 results.resize(number_of_points);
253 for (
auto it_point = itPointBegin ; it_point != itPointEnd ; it_point++){
254 results[it_point - itPointBegin] = SearchNearest(*it_point);
268 ResultType SearchIsInside(
const PointType& rPoint);
281 template<
typename TPo
intIteratorType>
283 TPointIteratorType itPointBegin,
284 TPointIteratorType itPointEnd
288 std::vector<ResultType> results;
289 const std::size_t number_of_points = std::distance(itPointBegin, itPointEnd);
290 results.resize(number_of_points);
291 for (
auto it_point = itPointBegin ; it_point != itPointEnd ; it_point++){
292 results[it_point - itPointBegin] = SearchIsInside(*it_point);
322 return mNumberOfCells;
330 return mNumberOfCells[0] * mNumberOfCells[1] * mNumberOfCells[2];
343 virtual std::string
Info()
const
345 std::stringstream buffer;
346 buffer <<
"GeometricalObjectsBins" ;
351 virtual void PrintInfo(std::ostream& rOStream)
const {rOStream <<
"GeometricalObjectsBins";}
372 static constexpr
unsigned int Dimension = 3;
402 bool PointIsInsideBoundingBoxWithTolerance(
404 const double Tolerance
412 void CalculateCellSize(
const std::size_t NumberOfCells);
421 template<
typename TIteratorType>
423 TIteratorType GeometricalObjectsBegin,
424 TIteratorType GeometricalObjectsEnd
427 for(
auto i_geometrical_object = GeometricalObjectsBegin ; i_geometrical_object != GeometricalObjectsEnd ; i_geometrical_object++){
430 CalculateMinMaxPositions(i_geometrical_object->GetGeometry(), min_position, max_position);
431 for(std::size_t
k = min_position[2] ;
k < max_position[2] ;
k++){
432 for(std::size_t
j = min_position[1] ;
j < max_position[1] ;
j++){
433 for(std::size_t
i = min_position[0] ;
i < max_position[0] ;
i++){
434 auto cell_bounding_box = GetCellBoundingBox(
i,
j,
k);
435 if(IsIntersected(i_geometrical_object->GetGeometry(), cell_bounding_box, mTolerance)){
436 GetCell(
i,
j,
k).push_back(&(*i_geometrical_object));
462 template<
typename TGeometryType>
463 void CalculateMinMaxPositions(
464 const TGeometryType& rGeometry,
469 if(rGeometry.empty())
474 for(
unsigned int i = 0;
i < 3;
i++ ) {
487 const double Coordinate,
488 const int ThisDimension
500 template<
typename TGeometryType>
501 static inline bool IsIntersected(
502 TGeometryType& rGeometry,
503 const BoundingBox<PointType>& rBox,
504 const double ThisTolerance
510 for(
unsigned int i = 0;
i<3;
i++) {
511 low_point_tolerance[
i] = rBox.GetMinPoint()[
i] - ThisTolerance;
512 high_point_tolerance[
i] = rBox.GetMaxPoint()[
i] + ThisTolerance;
515 return rGeometry.HasIntersection(low_point_tolerance,high_point_tolerance);
526 void SearchInRadiusInCell(
527 const CellType& rCell,
530 std::unordered_map<GeometricalObject*, double>& rResults
541 void SearchNearestInCell(
542 const CellType& rCell,
545 const double MaxRadius
555 void SearchIsInsideInCell(
556 const CellType& rCell,
576 GeometricalObjectsBins&
operator=(GeometricalObjectsBins
const& rOther) =
delete;
579 GeometricalObjectsBins(GeometricalObjectsBins
const& rOther) =
delete;
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
This defines the geometrical object, base definition of the element and condition entities.
Definition: geometrical_object.h:58
A bins container for 3 dimensional GeometricalObject entities.
Definition: geometrical_objects_bins.h:46
array_1d< double, 3 > mInverseOfCellSize
The size of each cell in each direction.
Definition: geometrical_objects_bins.h:381
virtual std::string Info() const
Turn back information as a string.
Definition: geometrical_objects_bins.h:343
std::vector< ResultType > SearchNearest(TPointIteratorType itPointBegin, TPointIteratorType itPointEnd)
This method takes a point and finds the nearest object to it (iterative version).
Definition: geometrical_objects_bins.h:244
KRATOS_CLASS_POINTER_DEFINITION(GeometricalObjectsBins)
Pointer definition of GeometricalObjectsBins.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: geometrical_objects_bins.h:351
const BoundingBox< PointType > & GetBoundingBox() const
Getting the bins bounding box.
Definition: geometrical_objects_bins.h:305
virtual ~GeometricalObjectsBins()
Destructor.
Definition: geometrical_objects_bins.h:109
std::size_t GetTotalNumberOfCells()
The total number of cells in the container.
Definition: geometrical_objects_bins.h:329
const array_1d< std::size_t, 3 > & GetNumberOfCells()
returns a 3D array having the number of cells in direction x, y and z
Definition: geometrical_objects_bins.h:321
void AddObjectsToCells(TIteratorType GeometricalObjectsBegin, TIteratorType GeometricalObjectsEnd)
Adding objects to the cells that intersecting with it.
Definition: geometrical_objects_bins.h:422
GeometricalObjectsBins(TIteratorType GeometricalObjectsBegin, TIteratorType GeometricalObjectsEnd, const double Tolerance=1e-12)
The constructor with all geometries to be stored. Please note that all of them should be available at...
Definition: geometrical_objects_bins.h:75
BoundingBox< PointType > mBoundingBox
Definition: geometrical_objects_bins.h:378
array_1d< std::size_t, Dimension > mNumberOfCells
The bounding box of the domain.
Definition: geometrical_objects_bins.h:379
array_1d< double, 3 > mCellSizes
The number of cells in each direction.
Definition: geometrical_objects_bins.h:380
GeometricalObjectsBins(TContainer &rGeometricalObjectsVector, const double Tolerance=1e-12)
The constructor with all geometries to be stored. Please note that all of them should be available at...
Definition: geometrical_objects_bins.h:101
std::vector< ResultType > SearchIsInside(TPointIteratorType itPointBegin, TPointIteratorType itPointEnd)
This method takes a point and search if it's inside an geometrical object of the domain (iterative ve...
Definition: geometrical_objects_bins.h:282
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: geometrical_objects_bins.h:354
std::vector< CellType > mCells
The inverse of the size of each cell in each direction.
Definition: geometrical_objects_bins.h:382
void SearchInRadius(TPointIteratorType itPointBegin, TPointIteratorType itPointEnd, const double Radius, std::vector< std::vector< ResultType >> &rResults)
This method takes a point and finds all of the objects in the given radius to it (iterative version).
Definition: geometrical_objects_bins.h:169
double mTolerance
The cells of the domain.
Definition: geometrical_objects_bins.h:383
std::vector< GeometricalObject * > CellType
The type of geometrical object to be stored in the bins.
Definition: geometrical_objects_bins.h:61
std::vector< ResultType > SearchNearestInRadius(TPointIteratorType itPointBegin, TPointIteratorType itPointEnd, const double Radius)
This method takes a point and finds the nearest object to it in a given radius (iterative version).
Definition: geometrical_objects_bins.h:209
GeometricalObjectsBins()=default
Default constructor protected.
const array_1d< double, 3 > & GetCellSizes()
return an array with the x,y and z size of the cube
Definition: geometrical_objects_bins.h:313
Point class.
Definition: point.h:59
This class is the result of the spatial searches.
Definition: spatial_search_result.h:40
end
Definition: DEM_benchmarks.py:180
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
bool CalculatePosition(Geometry< Node > &geom, const double xc, const double yc, const double zc, array_1d< double, 3 > &N)
Definition: transfer_utility.h:343
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
J
Definition: sensitivityMatrix.py:58
K
Definition: sensitivityMatrix.py:73
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31
Configure::PointType PointType
Definition: transfer_utility.h:245