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.
omp_dem_search.h
Go to the documentation of this file.
1 //
2 // Project Name: Kratos
3 // Last Modified by: $Author: clabra $
4 // Date: $Date: 2007-03-29 19:37:47 $
5 // Revision: $Revision: 1.2 $
6 //
7 //
8 
9 #if !defined(KRATOS_OMP_DEM_SEARCH_H_INCLUDED )
10 #define KRATOS_OMP_DEM_SEARCH_H_INCLUDED
11 
12 // System includes
13 #include <string>
14 #include <iostream>
15 
16 // include kratos definitions
17 #include "includes/define.h"
18 
19 // Project includes
21 #include "utilities/openmp_utils.h"
22 
23 // Configures
26 #include "node_configure.h"
27 
28 // Search
32 
33 // External includes
34 
35 /* Timer defines */
36 #include "utilities/timer.h"
37 #ifdef CUSTOMTIMER
38 #define KRATOS_TIMER_START(t) Timer::Start(t);
39 #define KRATOS_TIMER_STOP(t) Timer::Stop(t);
40 #else
41 #define KRATOS_TIMER_START(t)
42 #define KRATOS_TIMER_STOP(t)
43 #endif
44 
45 namespace Kratos
46 {
47 
50 
54 
58 
62 
66 
68 
71 class OMP_DEMSearch : public DEMSearch<OMP_DEMSearch>
72 {
73  public:
76 
79 
81  typedef std::vector<PtrPointType>* PointVector;
82  typedef std::vector<PtrPointType>::iterator PointIterator;
83 
84  typedef double* DistanceVector;
85  typedef double* DistanceIterator;
86 
87  //Configure Types
91 
92  //Bin Types
95  typedef std::unique_ptr<BinsType> BinsUniquePointerType;
98  typedef std::unique_ptr<NodeBinsType> NodeBinsUniquePointerType;
100 
101  //GeoimetricalObject
103 
104 
108 
110 
111  OMP_DEMSearch(const double domain_min_x = 0.0, const double domain_min_y = 0.0, const double domain_min_z = 0.0,
112  const double domain_max_x = -1.0, const double domain_max_y = -1.0, const double domain_max_z = -1.0)
113  {
114  mDomainPeriodicity = (domain_min_x <= domain_max_x) ? true : false;
115  }
116 
119  }
120 
121 
125 
126 
130 
132  ElementsContainerType const& rStructureElements,
133  ElementsContainerType const& rElements,
134  const RadiusArrayType & Radius,
136  VectorDistanceType& rResultsDistance )
137  {
138 // KRATOS_TRY
139 //
140 // int MaxNumberOfElements = rStructureElements.size();
141 //
142 // ElementsContainerType::ContainerType& elements_bins = const_cast<ElementsContainerType::ContainerType&>(rStructureElements.GetContainer());
143 // ElementsContainerType::ContainerType& elements_sear = const_cast<ElementsContainerType::ContainerType&>(rElements.GetContainer());
144 //
145 // GeometricalObjectType::ContainerType SearElementPointerToGeometricalObjecPointerTemporalVector;
146 // GeometricalObjectType::ContainerType BinsElementPointerToGeometricalObjecPointerTemporalVector;
147 //
148 // BinsElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_bins.size());
149 // SearElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_sear.size());
150 //
151 // for (ElementsContainerType::ContainerType::iterator it = elements_bins.begin(); it != elements_bins.end(); it++)
152 // BinsElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
153 //
154 // for (ElementsContainerType::ContainerType::iterator it = elements_sear.begin(); it != elements_sear.end(); it++)
155 // SearElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
156 //
157 // GeometricalBinsType bins(BinsElementPointerToGeometricalObjecPointerTemporalVector.begin(), BinsElementPointerToGeometricalObjecPointerTemporalVector.end());
158 //
159 // #pragma omp parallel
160 // {
161 // GeometricalObjectType::ContainerType localResults(MaxNumberOfElements);
162 // DistanceType localResultsDistances(MaxNumberOfElements);
163 // std::size_t NumberOfResults = 0;
164 //
165 // #pragma omp for
166 // for (std::size_t i = 0; i < elements_sear.size(); ++i)
167 // {
168 // GeometricalObjectType::ContainerType::iterator ResultsPointer = localResults.begin();
169 // DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
170 //
171 // NumberOfResults = bins.SearchObjectsInRadiusExclusive(SearElementPointerToGeometricalObjecPointerTemporalVector[i],Radius[i],ResultsPointer,ResultsDistancesPointer,MaxNumberOfElements);
172 //
173 // rResults[i].reserve(NumberOfResults);
174 //
175 // for (GeometricalObjectType::ContainerType::iterator it = localResults.begin(); it != localResults.begin() + NumberOfResults; it++)
176 // {
177 // Element::Pointer elem = dynamic_pointer_cast<Element>(*it);
178 // rResults[i].push_back(elem);
179 // rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
180 // }
181 // }
182 // }
183 //
184 // KRATOS_CATCH("")
185 
186  KRATOS_TRY
187 
188  int MaxNumberOfElements = rStructureElements.size();
189  ElementsContainerType::ContainerType& elements_array = const_cast<ElementsContainerType::ContainerType&>(rElements.GetContainer());
190  ElementsContainerType::ContainerType& elements_ModelPart = const_cast<ElementsContainerType::ContainerType&>(rStructureElements.GetContainer());
191  BinsUniquePointerType p_bins = GetBins(elements_ModelPart);
192 
193  #pragma omp parallel
194  {
195  ResultElementsContainerType localResults(MaxNumberOfElements);
196  DistanceType localResultsDistances(MaxNumberOfElements);
197  std::size_t NumberOfResults = 0;
198 
199  #pragma omp for schedule(dynamic, 100) //schedule(guided)
200  for (int i = 0; i < static_cast<int>(elements_array.size()); ++i){
201  ResultElementsContainerType::iterator ResultsPointer = localResults.begin();
202  DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
203 
204  SphericParticle* p_particle = dynamic_cast<SphericParticle*>(&*elements_array[i]);
205  const double radius = p_particle->GetSearchRadius();
206 
207  NumberOfResults = p_bins->SearchObjectsInRadiusExclusive(elements_array[i],radius,ResultsPointer,ResultsDistancesPointer,MaxNumberOfElements);
208 
209  rResults[i].insert(rResults[i].begin(),localResults.begin(),localResults.begin()+NumberOfResults);
210  rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
211  }
212  }
213  //MAJOR TODO: creating and destroying (when leaving the function) this BINS is not parallel and takes a significant time if we search at every time step. Can we re-use a bins and avoid allocation and deallocation?? MA
214  KRATOS_CATCH("")
215  }
216 
218  ElementsContainerType const& rStructureElements,
219  ElementsContainerType const& rElements,
220  const RadiusArrayType& Radius,
222  VectorDistanceType& rResultsDistance )
223  {
224  KRATOS_TRY
225 
226  int MaxNumberOfElements = rStructureElements.size();
227 
228  ElementsContainerType::ContainerType& elements_array = const_cast<ElementsContainerType::ContainerType&>(rElements.GetContainer());
229  ElementsContainerType::ContainerType& elements_ModelPart = const_cast<ElementsContainerType::ContainerType&>(rStructureElements.GetContainer());
230  BinsUniquePointerType p_bins = GetBins(elements_ModelPart);
231 
232  #pragma omp parallel
233  {
234  ResultElementsContainerType localResults(MaxNumberOfElements);
235  DistanceType localResultsDistances(MaxNumberOfElements);
236  std::size_t NumberOfResults = 0;
237 
238  #pragma omp for
239  for (int i = 0; i < static_cast<int>(elements_array.size()); ++i){
240  ResultElementsContainerType::iterator ResultsPointer = localResults.begin();
241  DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
242 
243  SphericParticle* p_particle = dynamic_cast<SphericParticle*>(&*elements_array[i]);
244  const double radius = p_particle->GetSearchRadius();
245 
246  NumberOfResults = p_bins->SearchObjectsInRadius(elements_array[i],radius,ResultsPointer,ResultsDistancesPointer,MaxNumberOfElements);
247 
248  rResults[i].insert(rResults[i].begin(),localResults.begin(),localResults.begin()+NumberOfResults);
249  rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
250  }
251  }
252 
253  KRATOS_CATCH("")
254  }
255 
257  ElementsContainerType const& rStructureElements,
258  ElementsContainerType const& rElements,
259  const RadiusArrayType & Radius,
261  {
262  KRATOS_TRY
263 
264  int MaxNumberOfElements = rStructureElements.size();
265 
266  ElementsContainerType::ContainerType& elements_array = const_cast<ElementsContainerType::ContainerType&>(rElements.GetContainer());
267  ElementsContainerType::ContainerType& elements_ModelPart = const_cast<ElementsContainerType::ContainerType&>(rStructureElements.GetContainer());
268  BinsUniquePointerType p_bins = GetBins(elements_ModelPart);
269 
270  #pragma omp parallel
271  {
272  ResultElementsContainerType localResults(MaxNumberOfElements);
273  std::size_t NumberOfResults = 0;
274 
275  #pragma omp for
276  for (int i = 0; i < static_cast<int>(elements_array.size()); ++i){
277  ResultElementsContainerType::iterator ResultsPointer = localResults.begin();
278 
279  SphericParticle* p_particle = dynamic_cast<SphericParticle*>(&*elements_array[i]);
280  const double radius = p_particle->GetSearchRadius();
281  NumberOfResults = p_bins->SearchObjectsInRadiusExclusive(elements_array[i],radius,ResultsPointer,MaxNumberOfElements);
282 
283  rResults[i].insert(rResults[i].begin(),localResults.begin(),localResults.begin()+NumberOfResults);
284  }
285  }
286 
287  KRATOS_CATCH("")
288  }
289 
291  ElementsContainerType const& rStructureElements,
292  ElementsContainerType const& rElements,
293  const RadiusArrayType & Radius,
295  {
296  KRATOS_TRY
297 
298  int MaxNumberOfElements = rStructureElements.size();
299 
300  ElementsContainerType::ContainerType& elements_array = const_cast<ElementsContainerType::ContainerType&>(rElements.GetContainer());
301  ElementsContainerType::ContainerType& elements_ModelPart = const_cast<ElementsContainerType::ContainerType&>(rStructureElements.GetContainer());
302 
303  BinsType bins(elements_ModelPart.begin(), elements_ModelPart.end());
304 
305  #pragma omp parallel
306  {
307  ResultElementsContainerType localResults(MaxNumberOfElements);
308  std::size_t NumberOfResults = 0;
309 
310  #pragma omp for
311  for (int i = 0; i < static_cast<int>(elements_array.size()); ++i){
312  ResultElementsContainerType::iterator ResultsPointer = localResults.begin();
313 
314  SphericParticle* p_particle = dynamic_cast<SphericParticle*>(&*elements_array[i]);
315  const double radius = p_particle->GetSearchRadius();
316 
317  NumberOfResults = bins.SearchObjectsInRadius(elements_array[i],radius,ResultsPointer,MaxNumberOfElements);
318 
319  rResults[i].insert(rResults[i].begin(),localResults.begin(),localResults.begin()+NumberOfResults);
320  }
321  }
322 
323  KRATOS_CATCH("")
324  }
325 
327  NodesContainerType const& rStructureNodes,
328  NodesContainerType const& rNodes,
329  const RadiusArrayType & Radius,
331  VectorDistanceType& rResultsDistance )
332  {
333  KRATOS_TRY
334 
335  int MaxNumberOfNodes = rNodes.size();
336 
337  NodesContainerType::ContainerType& nodes_ModelPart = const_cast<NodesContainerType::ContainerType&>(rNodes.GetContainer());
338  NodesContainerType::ContainerType& nodes_array = const_cast<NodesContainerType::ContainerType&>(rStructureNodes.GetContainer());
339 
340  // NodeBinsType bins(nodes_ModelPart.begin(), nodes_ModelPart.end());
341  NodeBinsUniquePointerType p_bins = GetBins(nodes_ModelPart);
342 
343  #pragma omp parallel
344  {
345  ResultNodesContainerType localResults(MaxNumberOfNodes);
346  DistanceType localResultsDistances(MaxNumberOfNodes);
347  std::size_t NumberOfResults = 0;
348 
349  #pragma omp for
350  for (int i = 0; i < static_cast<int>(nodes_array.size()); ++i){
351  ResultNodesContainerType::iterator ResultsPointer = localResults.begin();
352  DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
353 
354  NumberOfResults = p_bins->SearchObjectsInRadiusExclusive(nodes_array[i], Radius[i], ResultsPointer, ResultsDistancesPointer, MaxNumberOfNodes);
355  rResults[i].insert(rResults[i].begin(),localResults.begin(),localResults.begin()+NumberOfResults);
356  rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
357  }
358  }
359 
360  KRATOS_CATCH("")
361  }
362 
364  NodesContainerType const& rStructureNodes,
365  NodesContainerType const& rNodes,
366  const RadiusArrayType & Radius,
368  VectorDistanceType& rResultsDistance )
369  {
370  KRATOS_TRY
371 
372  int MaxNumberOfNodes = rStructureNodes.size();
373 
374  NodesContainerType::ContainerType& nodes_array = const_cast<NodesContainerType::ContainerType&>(rNodes.GetContainer());
375  NodesContainerType::ContainerType& nodes_ModelPart = const_cast<NodesContainerType::ContainerType&>(rStructureNodes.GetContainer());
376 
377  NodeBinsType bins(nodes_ModelPart.begin(), nodes_ModelPart.end());
378 
379  #pragma omp parallel
380  {
381  ResultNodesContainerType localResults(MaxNumberOfNodes);
382  DistanceType localResultsDistances(MaxNumberOfNodes);
383  std::size_t NumberOfResults = 0;
384 
385  #pragma omp for
386  for (int i = 0; i < static_cast<int>(nodes_array.size()); ++i){
387  ResultNodesContainerType::iterator ResultsPointer = localResults.begin();
388  DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
389 
390  NumberOfResults = bins.SearchObjectsInRadius(nodes_array[i],Radius[i],ResultsPointer,ResultsDistancesPointer,MaxNumberOfNodes);
391 
392  rResults[i].insert(rResults[i].begin(),localResults.begin(),localResults.begin()+NumberOfResults);
393  rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
394  }
395  }
396 
397  KRATOS_CATCH("")
398  }
399 
401  NodesContainerType const& rStructureNodes,
402  NodesContainerType const& rNodes,
403  const RadiusArrayType & Radius,
405  {
406  KRATOS_TRY
407 
408  int MaxNumberOfNodes = rStructureNodes.size();
409 
410  NodesContainerType::ContainerType& nodes_array = const_cast<NodesContainerType::ContainerType&>(rNodes.GetContainer());
411  NodesContainerType::ContainerType& nodes_ModelPart = const_cast<NodesContainerType::ContainerType&>(rStructureNodes.GetContainer());
412 
413  NodeBinsType bins(nodes_ModelPart.begin(), nodes_ModelPart.end());
414 
415  #pragma omp parallel
416  {
417  ResultNodesContainerType localResults(MaxNumberOfNodes);
418  std::size_t NumberOfResults = 0;
419 
420  #pragma omp for
421  for (int i = 0; i < static_cast<int>(nodes_array.size()); ++i){
422  ResultNodesContainerType::iterator ResultsPointer = localResults.begin();
423 
424  NumberOfResults = bins.SearchObjectsInRadiusExclusive(nodes_array[i],Radius[i],ResultsPointer,MaxNumberOfNodes);
425 
426  rResults[i].insert(rResults[i].begin(),localResults.begin(),localResults.begin()+NumberOfResults);
427  }
428  }
429 
430  KRATOS_CATCH("")
431  }
432 
434  NodesContainerType const& rStructureNodes,
435  NodesContainerType const& rNodes,
436  const RadiusArrayType & Radius,
438  {
439  KRATOS_TRY
440 
441  int MaxNumberOfNodes = rStructureNodes.size();
442 
443  NodesContainerType::ContainerType& nodes_array = const_cast<NodesContainerType::ContainerType&>(rNodes.GetContainer());
444  NodesContainerType::ContainerType& nodes_ModelPart = const_cast<NodesContainerType::ContainerType&>(rStructureNodes.GetContainer());
445 
446  NodeBinsType bins(nodes_ModelPart.begin(), nodes_ModelPart.end());
447 
448  #pragma omp parallel
449  {
450  ResultNodesContainerType localResults(MaxNumberOfNodes);
451  std::size_t NumberOfResults = 0;
452 
453  #pragma omp for
454  for (int i = 0; i < static_cast<int>(nodes_array.size()); ++i){
455  ResultNodesContainerType::iterator ResultsPointer = localResults.begin();
456 
457  NumberOfResults = bins.SearchObjectsInRadius(nodes_array[i],Radius[i],ResultsPointer,MaxNumberOfNodes);
458 
459  rResults[i].insert(rResults[i].begin(),localResults.begin(),localResults.begin()+NumberOfResults);
460  }
461  }
462 
463  KRATOS_CATCH("")
464  }
465 
467  ElementsContainerType const& rStructureElements,
468  ConditionsContainerType const& rElements,
469  const RadiusArrayType & Radius,
471  VectorDistanceType& rResultsDistance )
472  {
473  KRATOS_TRY
474 
475  int MaxNumberOfElements = rStructureElements.size();
476 
477  ElementsContainerType::ContainerType& elements_bins = const_cast<ElementsContainerType::ContainerType&> (rStructureElements.GetContainer());
478  ConditionsContainerType::ContainerType& elements_sear = const_cast<ConditionsContainerType::ContainerType&>(rElements.GetContainer());
479 
480  GeometricalObjectType::ContainerType SearElementPointerToGeometricalObjecPointerTemporalVector;
481  GeometricalObjectType::ContainerType BinsElementPointerToGeometricalObjecPointerTemporalVector;
482 
483  SearElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_sear.size());
484  BinsElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_bins.size());
485 
486  for (ElementsContainerType::ContainerType::iterator it = elements_bins.begin(); it != elements_bins.end(); it++)
487  BinsElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
488 
489  for (ConditionsContainerType::ContainerType::iterator it = elements_sear.begin(); it != elements_sear.end(); it++)
490  SearElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
491 
492  GeometricalBinsType bins(BinsElementPointerToGeometricalObjecPointerTemporalVector.begin(), BinsElementPointerToGeometricalObjecPointerTemporalVector.end());
493 
494  #pragma omp parallel
495  {
496  GeometricalObjectType::ContainerType localResults(MaxNumberOfElements);
497  DistanceType localResultsDistances(MaxNumberOfElements);
498  std::size_t NumberOfResults = 0;
499 
500  #pragma omp for
501  for (int i = 0; i < static_cast<int>(elements_sear.size()); ++i){
502  GeometricalObjectType::ContainerType::iterator ResultsPointer = localResults.begin();
503  DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
504 
505  NumberOfResults = bins.SearchObjectsInRadiusExclusive(SearElementPointerToGeometricalObjecPointerTemporalVector[i],Radius[i],ResultsPointer,ResultsDistancesPointer,MaxNumberOfElements);
506 
507  rResults[i].reserve(NumberOfResults);
508 
509  for (GeometricalObjectType::ContainerType::iterator it = localResults.begin(); it != localResults.begin() + NumberOfResults; it++)
510  {
511  Condition::Pointer elem = dynamic_pointer_cast<Condition>(*it);
512  rResults[i].push_back(elem);
513  rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
514  }
515  }
516  }
517 
518  KRATOS_CATCH("")
519  }
520 
522  ElementsContainerType const& rStructureElements,
523  ConditionsContainerType const& rElements,
524  const RadiusArrayType& Radius,
526  VectorDistanceType& rResultsDistance )
527  {
528  KRATOS_TRY
529 
530  int MaxNumberOfElements = rStructureElements.size();
531 
532  ElementsContainerType::ContainerType& elements_bins = const_cast<ElementsContainerType::ContainerType&> (rStructureElements.GetContainer());
533  ConditionsContainerType::ContainerType& elements_sear = const_cast<ConditionsContainerType::ContainerType&>(rElements.GetContainer());
534 
535  GeometricalObjectType::ContainerType SearElementPointerToGeometricalObjecPointerTemporalVector;
536  GeometricalObjectType::ContainerType BinsElementPointerToGeometricalObjecPointerTemporalVector;
537 
538  SearElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_sear.size());
539  BinsElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_bins.size());
540 
541  for (ElementsContainerType::ContainerType::iterator it = elements_bins.begin(); it != elements_bins.end(); it++)
542  BinsElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
543 
544  for (ConditionsContainerType::ContainerType::iterator it = elements_sear.begin(); it != elements_sear.end(); it++)
545  SearElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
546 
547  GeometricalBinsType bins(BinsElementPointerToGeometricalObjecPointerTemporalVector.begin(), BinsElementPointerToGeometricalObjecPointerTemporalVector.end());
548 
549  #pragma omp parallel
550  {
551  GeometricalObjectType::ContainerType localResults(MaxNumberOfElements);
552  DistanceType localResultsDistances(MaxNumberOfElements);
553  std::size_t NumberOfResults = 0;
554 
555  #pragma omp for
556  for (int i = 0; i < static_cast<int>(elements_sear.size()); ++i){
557  GeometricalObjectType::ContainerType::iterator ResultsPointer = localResults.begin();
558  DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
559 
560  NumberOfResults = bins.SearchObjectsInRadius(SearElementPointerToGeometricalObjecPointerTemporalVector[i],Radius[i],ResultsPointer,ResultsDistancesPointer,MaxNumberOfElements);
561 
562  rResults[i].reserve(NumberOfResults);
563 
564  for (GeometricalObjectType::ContainerType::iterator it = localResults.begin(); it != localResults.begin() + NumberOfResults; it++)
565  {
566  Condition::Pointer elem = dynamic_pointer_cast<Condition>(*it);
567  rResults[i].push_back(elem);
568  rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
569  }
570  }
571  }
572 
573  KRATOS_CATCH("")
574  }
575 
577  ConditionsContainerType const& rStructureElements,
578  ElementsContainerType const& rElements,
579  const RadiusArrayType & Radius,
581  VectorDistanceType& rResultsDistance )
582  {
583  KRATOS_TRY
584 
585  int MaxNumberOfElements = rStructureElements.size();
586 
587  ConditionsContainerType::ContainerType& elements_bins = const_cast<ConditionsContainerType::ContainerType&>(rStructureElements.GetContainer());
588  ElementsContainerType::ContainerType& elements_sear = const_cast<ElementsContainerType::ContainerType&> (rElements.GetContainer());
589 
590  GeometricalObjectType::ContainerType SearElementPointerToGeometricalObjecPointerTemporalVector;
591  GeometricalObjectType::ContainerType BinsElementPointerToGeometricalObjecPointerTemporalVector;
592 
593  SearElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_sear.size());
594  BinsElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_bins.size());
595 
596  for (ElementsContainerType::ContainerType::iterator it = elements_sear.begin(); it != elements_sear.end(); it++)
597  SearElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
598 
599  for (ConditionsContainerType::ContainerType::iterator it = elements_bins.begin(); it != elements_bins.end(); it++)
600  BinsElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
601 
602  GeometricalBinsType bins(BinsElementPointerToGeometricalObjecPointerTemporalVector.begin(), BinsElementPointerToGeometricalObjecPointerTemporalVector.end());
603 
604  #pragma omp parallel
605  {
606  GeometricalObjectType::ContainerType localResults(MaxNumberOfElements);
607  DistanceType localResultsDistances(MaxNumberOfElements);
608  std::size_t NumberOfResults = 0;
609 
610  #pragma omp for
611  for (int i = 0; i < static_cast<int>(elements_sear.size()); ++i){
612  GeometricalObjectType::ContainerType::iterator ResultsPointer = localResults.begin();
613  DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
614 
615  NumberOfResults = bins.SearchObjectsInRadiusExclusive(SearElementPointerToGeometricalObjecPointerTemporalVector[i],Radius[i],ResultsPointer,ResultsDistancesPointer,MaxNumberOfElements);
616 
617  rResults[i].reserve(NumberOfResults);
618 
619  for (GeometricalObjectType::ContainerType::iterator it = localResults.begin(); it != localResults.begin() + NumberOfResults; it++)
620  {
621  Element::Pointer elem = dynamic_pointer_cast<Element>(*it);
622  rResults[i].push_back(elem);
623  rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
624  }
625  }
626  }
627 
628  KRATOS_CATCH("")
629  }
630 
632  ConditionsContainerType const& rStructureElements,
633  ElementsContainerType const& rElements,
634  const RadiusArrayType& Radius,
636  VectorDistanceType& rResultsDistance )
637  {
638  KRATOS_TRY
639 
640  int MaxNumberOfElements = rStructureElements.size();
641 
642  ConditionsContainerType::ContainerType& elements_bins = const_cast<ConditionsContainerType::ContainerType&>(rStructureElements.GetContainer());
643  ElementsContainerType::ContainerType& elements_sear = const_cast<ElementsContainerType::ContainerType&> (rElements.GetContainer());
644 
645  GeometricalObjectType::ContainerType SearElementPointerToGeometricalObjecPointerTemporalVector;
646  GeometricalObjectType::ContainerType BinsElementPointerToGeometricalObjecPointerTemporalVector;
647 
648  SearElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_sear.size());
649  BinsElementPointerToGeometricalObjecPointerTemporalVector.reserve(elements_bins.size());
650 
651  for (ElementsContainerType::ContainerType::iterator it = elements_sear.begin(); it != elements_sear.end(); it++)
652  SearElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
653 
654  for (ConditionsContainerType::ContainerType::iterator it = elements_bins.begin(); it != elements_bins.end(); it++)
655  BinsElementPointerToGeometricalObjecPointerTemporalVector.push_back(*it);
656 
657  GeometricalBinsType bins(BinsElementPointerToGeometricalObjecPointerTemporalVector.begin(), BinsElementPointerToGeometricalObjecPointerTemporalVector.end());
658 
659  #pragma omp parallel
660  {
661  GeometricalObjectType::ContainerType localResults(MaxNumberOfElements);
662  DistanceType localResultsDistances(MaxNumberOfElements);
663  std::size_t NumberOfResults = 0;
664 
665  #pragma omp for
666  for (int i = 0; i < static_cast<int>(elements_sear.size()); ++i){
667  GeometricalObjectType::ContainerType::iterator ResultsPointer = localResults.begin();
668  DistanceType::iterator ResultsDistancesPointer = localResultsDistances.begin();
669 
670  NumberOfResults = bins.SearchObjectsInRadius(SearElementPointerToGeometricalObjecPointerTemporalVector[i],Radius[i],ResultsPointer,ResultsDistancesPointer,MaxNumberOfElements);
671 
672  rResults[i].reserve(NumberOfResults);
673 
674  for (GeometricalObjectType::ContainerType::iterator it = localResults.begin(); it != localResults.begin() + NumberOfResults; it++)
675  {
676  Element::Pointer elem = dynamic_pointer_cast<Element>(*it);
677  rResults[i].push_back(elem);
678  rResultsDistance[i].insert(rResultsDistance[i].begin(),localResultsDistances.begin(),localResultsDistances.begin()+NumberOfResults);
679  }
680  }
681  }
682 
683  KRATOS_CATCH("")
684  }
685 
689 
690 
694 
695 
699 
701  virtual std::string Info() const override
702  {
703  std::stringstream buffer;
704  buffer << "OpenMPDemSearch" ;
705 
706  return buffer.str();
707  }
708 
710  virtual void PrintInfo(std::ostream& rOStream) const override {rOStream << "OpenMPDemSearch";}
711 
713  virtual void PrintData(std::ostream& rOStream) const override {}
714 
715 
719 
720 
722 
723  protected:
726 
727 
731 
732 
733 
737 
738 
742 
743 
747 
751 
752 
756 
757 
759 
760  private:
763 
764 
768 
769 
773 
774 
778 
779 
783 
784 
789  BinsUniquePointerType GetBins(ElementsContainerType::ContainerType& r_model_part_container)
790  {
791  if (mDomainPeriodicity){
792  return std::unique_ptr<BinsType>(new BinsTypePeriodic(r_model_part_container.begin(), r_model_part_container.end(), this->mDomainMin, this->mDomainMax));
793  }
794 
795  else {
796  return std::unique_ptr<BinsType>(new BinsType(r_model_part_container.begin(), r_model_part_container.end()));
797  }
798  }
799 
800  NodeBinsUniquePointerType GetBins(NodesContainerType::ContainerType& r_model_part_container)
801  {
802  if (mDomainPeriodicity){
803  return std::unique_ptr<NodeBinsType>(new NodeBinsTypePeriodic(r_model_part_container.begin(), r_model_part_container.end(), this->mDomainMin, this->mDomainMax));
804  }
805 
806  else {
807  return std::unique_ptr<NodeBinsType>(new NodeBinsType(r_model_part_container.begin(), r_model_part_container.end()));
808  }
809  }
810 
814 
816  OMP_DEMSearch& operator=(OMP_DEMSearch const& rOther)
817  {
818  return *this;
819  }
820 
822  OMP_DEMSearch(OMP_DEMSearch const& rOther)
823  {
824  *this = rOther;
825  }
826 
827 
829 
830  }; // Class DEMSearch
831 
833 
836 
837 
841 
843 // inline std::istream& operator >> (std::istream& rIStream,
844 // DEMSearch& rThis){return rIStream;}
845 //
846 // /// output stream function
847 // inline std::ostream& operator << (std::ostream& rOStream,
848 // const DEMSearch& rThis)
849 // {
850 // rThis.PrintInfo(rOStream);
851 // rOStream << std::endl;
852 // rThis.PrintData(rOStream);
853 //
854 // return rOStream;
855 // }
856 
858 
860 
861 } // namespace Kratos.
862 
863 #endif // KRATOS_DEM_SEARCH_H_INCLUDED defined
864 
865 
Short class definition.
Definition: bins_dynamic_objects.h:57
SizeType SearchObjectsInRadius(PointerType &ThisObject, const double &Radius, ResultIteratorType &Results)
Definition: bins_dynamic_objects.h:301
virtual SizeType SearchObjectsInRadiusExclusive(PointerType &ThisObject, const double &Radius, ResultIteratorType &Results)
Definition: bins_dynamic_objects.h:368
Short class definition.
Definition: bins_dynamic_objects_periodic.h:49
Definition: dem_search.h:132
bool mDomainPeriodicity
Definition: dem_search.h:367
Definition: discrete_particle_configure.h:46
Definition: geometrical_object_configure.h:43
Configuration file for Nodes.
Definition: node_configure.h:56
Short class definition.
Definition: omp_dem_search.h:72
void SearchNodesInRadiusInclusiveImplementation(NodesContainerType const &rStructureNodes, NodesContainerType const &rNodes, const RadiusArrayType &Radius, VectorResultNodesContainerType &rResults, VectorDistanceType &rResultsDistance)
Definition: omp_dem_search.h:363
PointType * PtrPointType
Definition: omp_dem_search.h:80
void SearchElementsInRadiusExclusiveImplementation(ElementsContainerType const &rStructureElements, ElementsContainerType const &rElements, const RadiusArrayType &Radius, VectorResultElementsContainerType &rResults, VectorDistanceType &rResultsDistance)
Definition: omp_dem_search.h:131
void SearchGeometricalInRadiusExclusiveImplementation(ElementsContainerType const &rStructureElements, ConditionsContainerType const &rElements, const RadiusArrayType &Radius, VectorResultConditionsContainerType &rResults, VectorDistanceType &rResultsDistance)
Definition: omp_dem_search.h:466
NodeConfigure< 3 > NodeConfigureType
Definition: omp_dem_search.h:89
BinsObjectDynamic< ElementConfigureType > BinsType
Definition: omp_dem_search.h:93
double * DistanceVector
Definition: omp_dem_search.h:84
void SearchGeometricalInRadiusInclusiveImplementation(ConditionsContainerType const &rStructureElements, ElementsContainerType const &rElements, const RadiusArrayType &Radius, VectorResultElementsContainerType &rResults, VectorDistanceType &rResultsDistance)
Definition: omp_dem_search.h:631
DiscreteParticleConfigure< 3 > ElementConfigureType
Definition: omp_dem_search.h:88
void SearchGeometricalInRadiusExclusiveImplementation(ConditionsContainerType const &rStructureElements, ElementsContainerType const &rElements, const RadiusArrayType &Radius, VectorResultElementsContainerType &rResults, VectorDistanceType &rResultsDistance)
Definition: omp_dem_search.h:576
KRATOS_CLASS_POINTER_DEFINITION(OMP_DEMSearch)
Pointer definition of OMP_DEMSearch.
BinsObjectDynamic< GeometricalConfigureType > GeometricalBinsType
Definition: omp_dem_search.h:99
BinsObjectDynamicPeriodic< NodeConfigureType > NodeBinsTypePeriodic
Definition: omp_dem_search.h:97
double * DistanceIterator
Definition: omp_dem_search.h:85
GeometricalConfigure< 3 > GeometricalConfigureType
Definition: omp_dem_search.h:90
std::vector< PtrPointType >::iterator PointIterator
Definition: omp_dem_search.h:82
void SearchElementsInRadiusInclusiveImplementation(ElementsContainerType const &rStructureElements, ElementsContainerType const &rElements, const RadiusArrayType &Radius, VectorResultElementsContainerType &rResults)
Definition: omp_dem_search.h:290
virtual void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: omp_dem_search.h:710
BinsObjectDynamicPeriodic< ElementConfigureType > BinsTypePeriodic
Definition: omp_dem_search.h:94
void SearchNodesInRadiusExclusiveImplementation(NodesContainerType const &rStructureNodes, NodesContainerType const &rNodes, const RadiusArrayType &Radius, VectorResultNodesContainerType &rResults, VectorDistanceType &rResultsDistance)
Definition: omp_dem_search.h:326
virtual std::string Info() const override
Turn back information as a string.
Definition: omp_dem_search.h:701
std::unique_ptr< NodeBinsType > NodeBinsUniquePointerType
Definition: omp_dem_search.h:98
void SearchNodesInRadiusInclusiveImplementation(NodesContainerType const &rStructureNodes, NodesContainerType const &rNodes, const RadiusArrayType &Radius, VectorResultNodesContainerType &rResults)
Definition: omp_dem_search.h:433
OMP_DEMSearch(const double domain_min_x=0.0, const double domain_min_y=0.0, const double domain_min_z=0.0, const double domain_max_x=-1.0, const double domain_max_y=-1.0, const double domain_max_z=-1.0)
Default constructor.
Definition: omp_dem_search.h:111
void SearchElementsInRadiusExclusiveImplementation(ElementsContainerType const &rStructureElements, ElementsContainerType const &rElements, const RadiusArrayType &Radius, VectorResultElementsContainerType &rResults)
Definition: omp_dem_search.h:256
void SearchGeometricalInRadiusInclusiveImplementation(ElementsContainerType const &rStructureElements, ConditionsContainerType const &rElements, const RadiusArrayType &Radius, VectorResultConditionsContainerType &rResults, VectorDistanceType &rResultsDistance)
Definition: omp_dem_search.h:521
std::vector< PtrPointType > * PointVector
Definition: omp_dem_search.h:81
BinsObjectDynamic< NodeConfigureType > NodeBinsType
Definition: omp_dem_search.h:96
PointerVectorSet< GeometricalObject, IndexedObject > GeometricalObjectType
Definition: omp_dem_search.h:102
void SearchElementsInRadiusInclusiveImplementation(ElementsContainerType const &rStructureElements, ElementsContainerType const &rElements, const RadiusArrayType &Radius, VectorResultElementsContainerType &rResults, VectorDistanceType &rResultsDistance)
Definition: omp_dem_search.h:217
virtual void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: omp_dem_search.h:713
std::unique_ptr< BinsType > BinsUniquePointerType
Definition: omp_dem_search.h:95
void SearchNodesInRadiusExclusiveImplementation(NodesContainerType const &rStructureNodes, NodesContainerType const &rNodes, const RadiusArrayType &Radius, VectorResultNodesContainerType &rResults)
Definition: omp_dem_search.h:400
~OMP_DEMSearch()
Destructor.
Definition: omp_dem_search.h:118
Point class.
Definition: point.h:59
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
TContainerType ContainerType
Definition: pointer_vector_set.h:90
std::vector< ResultConditionsContainerType > VectorResultConditionsContainerType
Definition: spatial_search.h:92
std::vector< double > RadiusArrayType
Input/output types.
Definition: spatial_search.h:95
std::vector< DistanceType > VectorDistanceType
Definition: spatial_search.h:97
std::vector< ResultNodesContainerType > VectorResultNodesContainerType
Definition: spatial_search.h:82
ModelPart::NodesContainerType NodesContainerType
Nodes classes.
Definition: spatial_search.h:80
ModelPart::ElementsContainerType ElementsContainerType
Elements classes.
Definition: spatial_search.h:85
ModelPart::ConditionsContainerType ConditionsContainerType
Conditions classes.
Definition: spatial_search.h:90
NodesContainerType::ContainerType ResultNodesContainerType
Definition: spatial_search.h:81
std::vector< ResultElementsContainerType > VectorResultElementsContainerType
Definition: spatial_search.h:87
ElementsContainerType::ContainerType ResultElementsContainerType
Definition: spatial_search.h:86
std::vector< double > DistanceType
Definition: spatial_search.h:96
Definition: spheric_particle.h:31
virtual double GetSearchRadius()
Definition: spheric_particle.cpp:2201
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
float radius
Definition: mesh_to_mdpa_converter.py:18
integer i
Definition: TensorModule.f:17
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247