How to use the Spatial Search Algorithm

From KratosWiki
(Difference between revisions)
Jump to: navigation, search
m (Highlight headers)
(Calling the Constructor)
 
(6 intermediate revisions by one user not shown)
Line 40: Line 40:
 
Suppose that we have a set of discrete elements like a spheres.
 
Suppose that we have a set of discrete elements like a spheres.
 
The first step is to create a configuration file. The easiest way to do that is  
 
The first step is to create a configuration file. The easiest way to do that is  
copying the template found in "KRATOS_ROOT/kratos/templates/header_template.h".  
+
copying the template found in ''"KRATOS_ROOT/kratos/templates/header_template.h"''.  
In this example we are going to name the file *"example_configure_file.h"*.
+
In this example we are going to name the file ''"example_configure_file.h"''.
  
 
=== Creating the Skeleton ===
 
=== Creating the Skeleton ===
Line 60: Line 60:
 
=== Definition of the types and containers ===
 
=== Definition of the types and containers ===
  
Once our file *"example_configure_file.h"* is prepared we need to fill it with the
+
Once our file ''"example_configure_file.h"'' is prepared we need to fill it with the
 
types and operations.  
 
types and operations.  
  
Line 82: Line 82:
 
In our example, a possible definition of these types can be:
 
In our example, a possible definition of these types can be:
  
 +
<!--THIS IS THE ORIGINAL CODE:
 
   ///@}
 
   ///@}
 
   ///@name Type Definitions
 
   ///@name Type Definitions
Line 97: Line 98:
 
   typedef  ContainerContactType::iterator                  IteratorContactType;  
 
   typedef  ContainerContactType::iterator                  IteratorContactType;  
 
   typedef  ContainerContactType::value_type                PointerContactType;  
 
   typedef  ContainerContactType::value_type                PointerContactType;  
   typedef  std::vector<PointerType>::iterator              PointerTypeIterator;
+
   typedef  std::vector<PointerType>::iterator              PointerTypeIterator;-->
 
+
  <span style='color:#008000; '>///@}</span>
 +
  <span style='color:#008000; '>///@name Type Definitions</span>
 +
  <span style='color:#008000; '>///@{</span>
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  Point<span style='color:#0000ff; '>&lt;</span>Dimension<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>></span>                        PointType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  std<span style='color:#0000ff; '>::</span>vector<span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>></span><span style='color:#0000ff; '>::</span><span style='color:#0000ff; font-weight:bold; '>iterator</span>                  DistanceIteratorType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ModelPart<span style='color:#0000ff; '>::</span>ElementsContainerType<span style='color:#0000ff; '>::</span>ContainerType ContainerType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ModelPart<span style='color:#0000ff; '>::</span>ElementsContainerType<span style='color:#0000ff; '>::</span>ContainerType ResultContainerType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ContainerType<span style='color:#0000ff; '>::</span>value_type                      PointerType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ContainerType<span style='color:#0000ff; '>::</span><span style='color:#0000ff; font-weight:bold; '>iterator</span>                        IteratorType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ResultContainerType<span style='color:#0000ff; '>::</span>value_type                ResultPointerType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ResultContainerType<span style='color:#0000ff; '>::</span><span style='color:#0000ff; font-weight:bold; '>iterator</span>                  ResultIteratorType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ContactPair<span style='color:#0000ff; '>&lt;</span>PointerType<span style='color:#0000ff; '>></span>                        ContactPairType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  std<span style='color:#0000ff; '>::</span>vector<span style='color:#0000ff; '>&lt;</span>ContactPairType<span style='color:#0000ff; '>></span>                    ContainerContactType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ContainerContactType<span style='color:#0000ff; '>::</span><span style='color:#0000ff; font-weight:bold; '>iterator</span>                  IteratorContactType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  ContainerContactType<span style='color:#0000ff; '>::</span>value_type                PointerContactType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span>  std<span style='color:#0000ff; '>::</span>vector<span style='color:#0000ff; '>&lt;</span>PointerType<span style='color:#0000ff; '>></span><span style='color:#0000ff; '>::</span><span style='color:#0000ff; font-weight:bold; '>iterator</span>              PointerTypeIterator<span style='color:#0000ff; '>;</span>
  
 
{{Note|
 
{{Note|
 
Please, note that these are only suggestions and any other types and containers different to ModelPart can be used.
 
Please, note that these are only suggestions and any other types and containers different to ModelPart can be used.
 
}}
 
}}
 
  
 
=== Definition of the operations ===
 
=== Definition of the operations ===
Line 123: Line 139:
 
==== BoundingBox ====
 
==== BoundingBox ====
  
*'''<span style="color:blue">static inline void</span> CalculateBoundingBox'''(<span style="color:blue">const PointerType</span>& rObject, <span style="color:blue">PointType</span>& rLowPoint, <span style="color:blue">PointType</span>& rHighPoint):
+
*'''static inline void CalculateBoundingBox'''(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint):
 
This method is used to calculate the boundingbox of the element (rObject). Once calculated the Low and High points of the  
 
This method is used to calculate the boundingbox of the element (rObject). Once calculated the Low and High points of the  
 
boundingbox need to be stored in '''rLowPoint''' and '''rHighPoint'''
 
boundingbox need to be stored in '''rLowPoint''' and '''rHighPoint'''
  
*'''<span style="color:blue">static inline void</span> CalculateBoundingBox'''(<span style="color:blue">const PointerType</span>& rObject, <span style="color:blue">PointType</span>& rLowPoint, <span style="color:blue">PointType</span>& rHighPoint, <span style="color:blue">const double</span>& Radius):
+
*'''static inline void CalculateBoundingBox'''(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint, const double& Radius):
 
This method is used to calculate the boundingbox of the element (rObject) given an imposed radius. Once calculated the Low and High points of the  
 
This method is used to calculate the boundingbox of the element (rObject) given an imposed radius. Once calculated the Low and High points of the  
 
boundingbox need to be stored in '''rLowPoint''' and '''rHighPoint'''
 
boundingbox need to be stored in '''rLowPoint''' and '''rHighPoint'''
Line 133: Line 149:
  
 
As an example, for our spheric elements:
 
As an example, for our spheric elements:
 
+
<!--THIS IS THE ORIGINAL CODE:
 
   static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint) {
 
   static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint) {
 
      
 
      
Line 153: Line 169:
 
       rHighPoint[i] += Radius;
 
       rHighPoint[i] += Radius;
 
     }
 
     }
   }
+
   }-->
 +
 
 +
<span style='color:#0000ff; font-weight:bold; '>static</span> <span style='color:#0000ff; font-weight:bold; '>inline</span> <span style='color:#0000ff; font-weight:bold; '>void</span> CalculateBoundingBox<span style='color:#0000ff; '>(</span><span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObject<span style='color:#0000ff; '>,</span> PointType<span style='color:#0000ff; '>&amp;</span> rLowPoint<span style='color:#0000ff; '>,</span> PointType<span style='color:#0000ff; '>&amp;</span> rHighPoint<span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>{</span>
 +
 
 +
    rHighPoint <span style='color:#0000ff; '>=</span> rLowPoint  <span style='color:#0000ff; '>=</span> rObject<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>double</span> radius <span style='color:#0000ff; '>=</span> rObject<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetSolutionStepValue<span style='color:#0000ff; '>(</span>RADIUS<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
 
 +
    <span style='color:#0000ff; font-weight:bold; '>for</span><span style='color:#0000ff; '>(</span>std<span style='color:#0000ff; '>::</span><span style='color:#0000ff; font-weight:bold; '>size_t</span> i <span style='color:#0000ff; '>=</span> <span style='color:#800000; '>0</span><span style='color:#0000ff; '>;</span> i <span style='color:#0000ff; '>&lt;</span> <span style='color:#800000; '>3</span><span style='color:#0000ff; '>;</span> i<span style='color:#0000ff; '>+</span><span style='color:#0000ff; '>+</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>{</span>
 +
      rLowPoint<span style='color:#0000ff; '>[</span>i<span style='color:#0000ff; '>]</span>  <span style='color:#0000ff; '>+</span><span style='color:#0000ff; '>=</span> <span style='color:#0000ff; '>-</span>radius<span style='color:#0000ff; '>;</span>
 +
      rHighPoint<span style='color:#0000ff; '>[</span>i<span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>+</span><span style='color:#0000ff; '>=</span> radius<span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; '>}</span>
 +
<span style='color:#0000ff; '>}</span>
 +
 
 +
<span style='color:#0000ff; font-weight:bold; '>static</span> <span style='color:#0000ff; font-weight:bold; '>inline</span> <span style='color:#0000ff; font-weight:bold; '>void</span> CalculateBoundingBox<span style='color:#0000ff; '>(</span><span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObject<span style='color:#0000ff; '>,</span> PointType<span style='color:#0000ff; '>&amp;</span> rLowPoint<span style='color:#0000ff; '>,</span> PointType<span style='color:#0000ff; '>&amp;</span> rHighPoint<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>const</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>&amp;</span> Radius<span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>{</span>
 +
   
 +
    rHighPoint <span style='color:#0000ff; '>=</span> rLowPoint  <span style='color:#0000ff; '>=</span> rObject<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>for</span><span style='color:#0000ff; '>(</span>std<span style='color:#0000ff; '>::</span><span style='color:#0000ff; font-weight:bold; '>size_t</span> i <span style='color:#0000ff; '>=</span> <span style='color:#800000; '>0</span><span style='color:#0000ff; '>;</span> i <span style='color:#0000ff; '>&lt;</span> <span style='color:#800000; '>3</span><span style='color:#0000ff; '>;</span> i<span style='color:#0000ff; '>+</span><span style='color:#0000ff; '>+</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>{</span>
 +
      rLowPoint<span style='color:#0000ff; '>[</span>i<span style='color:#0000ff; '>]</span>  <span style='color:#0000ff; '>+</span><span style='color:#0000ff; '>=</span> <span style='color:#0000ff; '>-</span>Radius<span style='color:#0000ff; '>;</span>
 +
      rHighPoint<span style='color:#0000ff; '>[</span>i<span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>+</span><span style='color:#0000ff; '>=</span> Radius<span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; '>}</span>
 +
<span style='color:#0000ff; '>}</span>
  
 
==== Object-Object Intersection ====
 
==== Object-Object Intersection ====
Line 167: Line 204:
  
 
As an example:
 
As an example:
 
+
<!--THIS IS THE ORIGINAL CODE:
 
   static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2){
 
   static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2){
 
      
 
      
Line 191: Line 228:
 
     bool intersect        = (distance_2 - radius_sum * radius_sum) <= 0;
 
     bool intersect        = (distance_2 - radius_sum * radius_sum) <= 0;
 
     return intersect;
 
     return intersect;
   }
+
   }-->
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>static</span> <span style='color:#0000ff; font-weight:bold; '>inline</span> <span style='color:#0000ff; font-weight:bold; '>bool</span> Intersection<span style='color:#0000ff; '>(</span><span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObj_1<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObj_2<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>{</span>
 +
   
 +
    array_1d<span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>,</span> <span style='color:#800000; '>3</span><span style='color:#0000ff; '>></span> rObj_2_to_rObj_1 <span style='color:#0000ff; '>=</span> rObj_1<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>-</span> rObj_2<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>double</span> distance_2 <span style='color:#0000ff; '>=</span> inner_prod<span style='color:#0000ff; '>(</span>rObj_2_to_rObj_1<span style='color:#0000ff; '>,</span> rObj_2_to_rObj_1<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>const</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>&amp;</span> radius_1 <span style='color:#0000ff; '>=</span> rObj_1<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetSolutionStepValue<span style='color:#0000ff; '>(</span>RADIUS<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>const</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>&amp;</span> radius_2 <span style='color:#0000ff; '>=</span> rObj_2<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetSolutionStepValue<span style='color:#0000ff; '>(</span>RADIUS<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>double</span> radius_sum      <span style='color:#0000ff; '>=</span> radius_1 <span style='color:#0000ff; '>+</span> radius_2<span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>bool</span> intersect        <span style='color:#0000ff; '>=</span> <span style='color:#0000ff; '>(</span>distance_2 <span style='color:#0000ff; '>-</span> radius_sum <span style='color:#0000ff; '>*</span> radius_sum<span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; '>=</span> <span style='color:#800000; '>0</span><span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>return</span> intersect<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; '>}</span>
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>static</span> <span style='color:#0000ff; font-weight:bold; '>inline</span> <span style='color:#0000ff; font-weight:bold; '>bool</span> Intersection<span style='color:#0000ff; '>(</span><span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObj_1<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObj_2<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>const</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>&amp;</span> Radius<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>{</span>
 +
   
 +
    array_1d<span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>,</span> <span style='color:#800000; '>3</span><span style='color:#0000ff; '>></span> rObj_2_to_rObj_1 <span style='color:#0000ff; '>=</span> rObj_1<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>-</span> rObj_2<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>double</span> distance_2 <span style='color:#0000ff; '>=</span> inner_prod<span style='color:#0000ff; '>(</span>rObj_2_to_rObj_1<span style='color:#0000ff; '>,</span> rObj_2_to_rObj_1<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>const</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>&amp;</span> radius_2 <span style='color:#0000ff; '>=</span> rObj_2<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetSolutionStepValue<span style='color:#0000ff; '>(</span>RADIUS<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>double</span> radius_sum      <span style='color:#0000ff; '>=</span> Radius <span style='color:#0000ff; '>+</span> radius_2<span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>bool</span> intersect        <span style='color:#0000ff; '>=</span> <span style='color:#0000ff; '>(</span>distance_2 <span style='color:#0000ff; '>-</span> radius_sum <span style='color:#0000ff; '>*</span> radius_sum<span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; '>=</span> <span style='color:#800000; '>0</span><span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>return</span> intersect<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; '>}</span>
  
 
==== Object-Cell Intersection ====
 
==== Object-Cell Intersection ====
Line 205: Line 267:
  
 
As an example:
 
As an example:
 
+
<!--THIS IS THE ORIGINAL CODE:
 
   static inline bool IntersectionBox(const PointerType& rObject,  const PointType& rLowPoint, const PointType& rHighPoint){
 
   static inline bool IntersectionBox(const PointerType& rObject,  const PointType& rLowPoint, const PointType& rHighPoint){
 
      
 
      
Line 235: Line 297:
 
      
 
      
 
     return  intersect;
 
     return  intersect;
   }
+
   }-->
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>static</span> <span style='color:#0000ff; font-weight:bold; '>inline</span> <span style='color:#0000ff; font-weight:bold; '>bool</span> IntersectionBox<span style='color:#0000ff; '>(</span><span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObject<span style='color:#0000ff; '>,</span>  <span style='color:#0000ff; font-weight:bold; '>const</span> PointType<span style='color:#0000ff; '>&amp;</span> rLowPoint<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>const</span> PointType<span style='color:#0000ff; '>&amp;</span> rHighPoint<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>{</span>
 +
   
 +
    array_1d<span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>,</span> <span style='color:#800000; '>3</span><span style='color:#0000ff; '>></span> center_of_particle <span style='color:#0000ff; '>=</span> rObject<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
    <span style='color:#0000ff; font-weight:bold; '>const</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>&amp;</span> radius <span style='color:#0000ff; '>=</span> rObject<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetSolutionStepValue<span style='color:#0000ff; '>(</span>RADIUS<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>bool</span> intersect <span style='color:#0000ff; '>=</span> <span style='color:#0000ff; '>(</span> rLowPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span>  <span style='color:#0000ff; '>-</span> radius <span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rLowPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span>  <span style='color:#0000ff; '>-</span> radius <span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rLowPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span>  <span style='color:#0000ff; '>-</span> radius <span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rHighPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>+</span> radius <span style='color:#0000ff; '>></span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rHighPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>+</span> radius <span style='color:#0000ff; '>></span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rHighPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>+</span> radius <span style='color:#0000ff; '>></span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span>
 +
                      <span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>return</span>  intersect<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; '>}</span>
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>static</span> <span style='color:#0000ff; font-weight:bold; '>inline</span> <span style='color:#0000ff; font-weight:bold; '>bool</span> IntersectionBox<span style='color:#0000ff; '>(</span><span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObject<span style='color:#0000ff; '>,</span>  <span style='color:#0000ff; font-weight:bold; '>const</span> PointType<span style='color:#0000ff; '>&amp;</span> rLowPoint<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>const</span> PointType<span style='color:#0000ff; '>&amp;</span> rHighPoint<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>const</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>&amp;</span> Radius<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>{</span>
 +
   
 +
    array_1d<span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>,</span> <span style='color:#800000; '>3</span><span style='color:#0000ff; '>></span> center_of_particle <span style='color:#0000ff; '>=</span> rObject<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>bool</span> intersect <span style='color:#0000ff; '>=</span> <span style='color:#0000ff; '>(</span> rLowPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span>  <span style='color:#0000ff; '>-</span> Radius <span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rLowPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span>  <span style='color:#0000ff; '>-</span> Radius <span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rLowPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span>  <span style='color:#0000ff; '>-</span> Radius <span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rHighPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>+</span> Radius <span style='color:#0000ff; '>></span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rHighPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>+</span> Radius <span style='color:#0000ff; '>></span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>&amp;</span><span style='color:#0000ff; '>&amp;</span>
 +
                      rHighPoint<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>+</span> Radius <span style='color:#0000ff; '>></span><span style='color:#0000ff; '>=</span> center_of_particle<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span>
 +
                      <span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    <span style='color:#0000ff; font-weight:bold; '>return</span>  intersect<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; '>}</span>
  
 
Please notice that if the object-cell function returns '''True''' the strategy will behave as a brute froce search.
 
Please notice that if the object-cell function returns '''True''' the strategy will behave as a brute froce search.
Line 244: Line 337:
 
This function returns the distance between to given elements (rObj_1, rObj_2). Result must be stored in "distance"
 
This function returns the distance between to given elements (rObj_1, rObj_2). Result must be stored in "distance"
  
For instance:
 
  
 +
For instance:
 +
<!--THIS IS THE ORIGINAL CODE:
 
   static inline void Distance(const PointerType& rObj_1, const PointerType& rObj_2, double& distance) {
 
   static inline void Distance(const PointerType& rObj_1, const PointerType& rObj_2, double& distance) {
 
      
 
      
Line 254: Line 348:
 
                     (center_of_particle1[1] - center_of_particle2[1]) * (center_of_particle1[1] - center_of_particle2[1]) +
 
                     (center_of_particle1[1] - center_of_particle2[1]) * (center_of_particle1[1] - center_of_particle2[1]) +
 
                     (center_of_particle1[2] - center_of_particle2[2]) * (center_of_particle1[2] - center_of_particle2[2]) );
 
                     (center_of_particle1[2] - center_of_particle2[2]) * (center_of_particle1[2] - center_of_particle2[2]) );
   }
+
   }-->
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>static</span> <span style='color:#0000ff; font-weight:bold; '>inline</span> <span style='color:#0000ff; font-weight:bold; '>void</span> Distance<span style='color:#0000ff; '>(</span><span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObj_1<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>const</span> PointerType<span style='color:#0000ff; '>&amp;</span> rObj_2<span style='color:#0000ff; '>,</span> <span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>&amp;</span> distance<span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>{</span>
 +
   
 +
    array_1d<span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>,</span> <span style='color:#800000; '>3</span><span style='color:#0000ff; '>></span> center_of_particle1 <span style='color:#0000ff; '>=</span> rObj_1<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
    array_1d<span style='color:#0000ff; '>&lt;</span><span style='color:#0000ff; font-weight:bold; '>double</span><span style='color:#0000ff; '>,</span> <span style='color:#800000; '>3</span><span style='color:#0000ff; '>></span> center_of_particle2 <span style='color:#0000ff; '>=</span> rObj_2<span style='color:#0000ff; '>-</span><span style='color:#0000ff; '>></span>GetGeometry<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>.</span>GetPoint<span style='color:#0000ff; '>(</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
    distance <span style='color:#0000ff; '>=</span> <span style='color:#0000ff; font-weight:bold; '>sqrt</span><span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>(</span>center_of_particle1<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>-</span> center_of_particle2<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span><span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>*</span> <span style='color:#0000ff; '>(</span>center_of_particle1<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>-</span> center_of_particle2<span style='color:#0000ff; '>[</span><span style='color:#800000; '>0</span><span style='color:#0000ff; '>]</span><span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>+</span>
 +
                    <span style='color:#0000ff; '>(</span>center_of_particle1<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>-</span> center_of_particle2<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span><span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>*</span> <span style='color:#0000ff; '>(</span>center_of_particle1<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>-</span> center_of_particle2<span style='color:#0000ff; '>[</span><span style='color:#800000; '>1</span><span style='color:#0000ff; '>]</span><span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>+</span>
 +
                    <span style='color:#0000ff; '>(</span>center_of_particle1<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>-</span> center_of_particle2<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span><span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>*</span> <span style='color:#0000ff; '>(</span>center_of_particle1<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span> <span style='color:#0000ff; '>-</span> center_of_particle2<span style='color:#0000ff; '>[</span><span style='color:#800000; '>2</span><span style='color:#0000ff; '>]</span><span style='color:#0000ff; '>)</span> <span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; '>}</span>
  
 
== Calling the Constructor ==
 
== Calling the Constructor ==
Line 274: Line 378:
  
 
For our example we are going to select "bins_dinamyc_objects.h". Hence our file will have to include:
 
For our example we are going to select "bins_dinamyc_objects.h". Hence our file will have to include:
 
+
<!--THIS IS THE ORIGINAL CODE:
   #include "spatial_containers/bins_dinamyc_objects.h"
+
   #include "spatial_containers/bins_dinamyc_objects.h"-->
 +
  <span style='color:#004a43; '>#</span><span style='color:#004a43; '>include </span><span style='color:#0000e6; '>"</span><span style='color:#40015a; '>spatial_containers/bins_dinamyc_objects.h</span><span style='color:#0000e6; '>"</span>
  
 
And define:
 
And define:
 
+
<!--THIS IS THE ORIGINAL CODE:
 
   static const std::size_t space_dim = 2;
 
   static const std::size_t space_dim = 2;
 
    
 
    
Line 298: Line 403:
 
   typedef Configure::ContainerContactType          ContainerContactPair;   
 
   typedef Configure::ContainerContactType          ContainerContactPair;   
 
   typedef Configure::IteratorContactType            IteratorContainerContactPair;   
 
   typedef Configure::IteratorContactType            IteratorContainerContactPair;   
   typedef Configure::PointerContactType            PointerContainerContactPair;
+
   typedef Configure::PointerContactType            PointerContainerContactPair;-->
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>static</span> <span style='color:#0000ff; font-weight:bold; '>const</span> std<span style='color:#0000ff; '>::</span><span style='color:#0000ff; font-weight:bold; '>size_t</span> space_dim <span style='color:#0000ff; '>=</span> <span style='color:#800000; '>2</span><span style='color:#0000ff; '>;</span>
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> ExampleConfigure<span style='color:#0000ff; '>&lt;</span>space_dim<span style='color:#0000ff; '>></span>              Configure<span style='color:#0000ff; '>;</span> 
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>PointType                      PointType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> PointType<span style='color:#0000ff; '>::</span>CoordinatesArrayType          CoordinatesArrayType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>ContainerType                  ContainerType<span style='color:#0000ff; '>;</span> 
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>PointerType                    PointerType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>IteratorType                  IteratorType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>ResultContainerType            ResultContainerType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>ResultPointerType              ResultPointerType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>ResultIteratorType            ResultIteratorType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>ContactPairType                ContactPairType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>ContainerContactType          ContainerContactType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>IteratorContactType            IteratorContactType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>PointerContactType            PointerContactType<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>PointerTypeIterator            PointerTypeIterator<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>ContainerContactType          ContainerContactPair<span style='color:#0000ff; '>;</span> 
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>IteratorContactType            IteratorContainerContactPair<span style='color:#0000ff; '>;</span> 
 +
  <span style='color:#0000ff; font-weight:bold; '>typedef</span> Configure<span style='color:#0000ff; '>::</span>PointerContactType            PointerContainerContactPair<span style='color:#0000ff; '>;</span>
  
 
After that we can create the search strategy itself.
 
After that we can create the search strategy itself.
 
In order to create our search strategy we will need to pass all the elements in our domain:
 
In order to create our search strategy we will need to pass all the elements in our domain:
   
+
<!--THIS IS THE ORIGINAL CODE:   
   IteratorType it_begin     =  mElements.begin();
+
   IteratorType it_begin =  mElements.begin();
   IteratorType it_end       =  mElements.end();
+
   IteratorType it_end =  mElements.end();
 
    
 
    
   BinsObjectDynamic<Configure>  rBinsObjectDynamic(it_begin, it_end);   
+
   BinsObjectDynamic<Configure>  rBinsObjectDynamic(it_begin, it_end);-->
 +
  IteratorType it_begin <span style='color:#0000ff; '>=</span> mElements<span style='color:#0000ff; '>.</span>begin<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
  IteratorType it_end  <span style='color:#0000ff; '>=</span> mElements<span style='color:#0000ff; '>.</span>end<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
 +
   
 +
  BinsObjectDynamic<span style='color:#0000ff; '>&lt;</span>Configure<span style='color:#0000ff; '>></span> rBinsObjectDynamic<span style='color:#0000ff; '>(</span>it_begin<span style='color:#0000ff; '>,</span> it_end<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>
  
 
Finally we call the search. For example if we want to search the neighbours of our elements in a Radius N:
 
Finally we call the search. For example if we want to search the neighbours of our elements in a Radius N:
 
+
<!--THIS IS THE ORIGINAL CODE:
 
   ContainerType SearchElements;
 
   ContainerType SearchElements;
 
   double * Radius;
 
   double * Radius;
Line 318: Line 448:
 
    
 
    
 
   ...
 
   ...
   rBins.SearchObjectsInRadiusExclusive(SearElementPointerToGeometricalObjecPointerTemporalVector,Radius[i],Results.begin(),ResultsDistances.begin(),MaxNumberOfElements);
+
    
 +
rBins.SearchObjectsInRadiusExclusive(SearElementPointerToGeometricalObjecPointerTemporalVector,Radius[i],Results.begin(),ResultsDistances.begin(),MaxNumberOfElements);-->
 +
 
 +
  ContainerType SearchElements<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>double</span> <span style='color:#0000ff; '>*</span> Radius<span style='color:#0000ff; '>;</span>
 +
  ResultContainerType Results<span style='color:#0000ff; '>;</span>
 +
  <span style='color:#0000ff; font-weight:bold; '>double</span> <span style='color:#0000ff; '>*</span> ResultDistance<span style='color:#0000ff; '>;</span>
 +
 
 +
  <span style='color:#0000ff; font-weight:bold; '>int</span> MaxNumberOfElements <span style='color:#0000ff; '>=</span> MAX_RES<span style='color:#0000ff; '>;</span>
 +
 
 +
  <span style='color:#008000; '>// Extra code can go here...</span>
 +
 
 +
  rBins<span style='color:#0000ff; '>.</span>SearchObjectsInRadiusExclusive<span style='color:#0000ff; '>(</span>SearElementPointerToGeometricalObjecPointerTemporalVector<span style='color:#0000ff; '>,</span>Radius<span style='color:#0000ff; '>[</span>i<span style='color:#0000ff; '>]</span><span style='color:#0000ff; '>,</span>Results<span style='color:#0000ff; '>.</span>begin<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>,</span>ResultsDistances<span style='color:#0000ff; '>.</span>begin<span style='color:#0000ff; '>(</span><span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>,</span>MaxNumberOfElements<span style='color:#0000ff; '>)</span><span style='color:#0000ff; '>;</span>

Latest revision as of 08:55, 17 July 2015

Contents

The Spatial Search Algorithm

Large-scale in Finite Element Methods, Discrete Element Method and Combined Finite-Discrete Element Method simulations involve contact of a large number of separate bodies. Processing contact interaction for all possible contacts would involve a total number of operations proportional to N^2, where N is the total number of separates bodies comprising the problem.

This would be very CPU intensive, and would limit the overall performance of the application. To reduce CPU requirements of processing contact interaction, it is necessary to eliminate couples of discrete elements that are far from each other and are not in contact. A set procedures designed to detect bodies that are close to each other is usually called a contact detection algorithm, or sometimes a contact search algorithm.

With this purpose a set contact search algorithms based on spatial decomposition are provided in Kratos, so they can be used for any application. Therefore it requires a contact search algorithm having the following characteristics:

  • Robust,
  • CPU efficient,
  • RAM efficient

Usage

Kratos search algorithm is presented in several variants but all of them follow a common structure that needs to be followed in order to make a correct use of the algorithms. All the search algorithms are composed of two parts, the *user configuration file* and the *strategy*

The User Configure File

The configuration file is an user-made file where the specific characteristics of the problem. In simple terms, it can be considered as a small template class that the user needs to fill with the types, operations and containers necessary for the strategy to search the contacts.

This file is divided of four parts:

  • Definition of the types and their containers.
  • Function that calculates bounding box
  • Function of intersection between objects
  • Function of intercession between the object and cells.

An Example Configure File

Suppose that we have a set of discrete elements like a spheres. The first step is to create a configuration file. The easiest way to do that is copying the template found in "KRATOS_ROOT/kratos/templates/header_template.h". In this example we are going to name the file "example_configure_file.h".

Creating the Skeleton

The first thing we have to do is changing the default names and directives of the file. This normal implies changing two tokens that appear repeatedly across the file:

 KRATOS_FILENAME_H_INCLUDED
 
 ClassName

that in our case would become:

 KRATOS_EXAMPLE_CONFIGURE_INCLUDED
 
 ExampleConfigure

Definition of the types and containers

Once our file "example_configure_file.h" is prepared we need to fill it with the types and operations.

The proper place to define the files is under the "Type Definitions" section and the list of types that need to be defined is the following:

  • PointType: Type of the points that form our element.
  • DistanceIteratorType: Type of the iterator for the distances between contacts.
  • ContainerType: Type of the elements container.
  • ResultContainerType: Type of the elements container for the results. This is normally the same as ContainerType but it can vary in case our results are different elements. For example if we want to search all the tetrahedrons in a X distance from a set of triangles.
  • PointerType: Type of the pointer to our elements
  • IteratorType: Type of the iterator to our elements
  • ResultPointerType: Type of the pointer to our result elements
  • ResultIteratorType: Type of the iterator to our result elements
  • ContactPairType: Type of the contact pair
  • ContainerContactType:
  • IteratorContactType:
  • PointerContactType:
  • PointerTypeIterator: Type of the pointer iterator

In our example, a possible definition of these types can be:

 ///@}
 ///@name Type Definitions
 ///@{
 
 typedef  Point<Dimension, double>                        PointType;
 typedef  std::vector<double>::iterator                   DistanceIteratorType;
 typedef  ModelPart::ElementsContainerType::ContainerType ContainerType;
 typedef  ModelPart::ElementsContainerType::ContainerType ResultContainerType;
 typedef  ContainerType::value_type                       PointerType;
 typedef  ContainerType::iterator                         IteratorType; 
 typedef  ResultContainerType::value_type                 ResultPointerType;
 typedef  ResultContainerType::iterator                   ResultIteratorType; 
 typedef  ContactPair<PointerType>                        ContactPairType;
 typedef  std::vector<ContactPairType>                    ContainerContactType; 
 typedef  ContainerContactType::iterator                  IteratorContactType; 
 typedef  ContainerContactType::value_type                PointerContactType; 
 typedef  std::vector<PointerType>::iterator              PointerTypeIterator;

Warn_icon.gif Note:

Please, note that these are only suggestions and any other types and containers different to ModelPart can be used.

Definition of the operations

Along with the definition of the types of the previous section one also needs to define a set of basic operations that will be used by the strategy. This operations involve mainly interaction between objects which have to be defined apart as they are bound to the characteristics of the elements.

The list of functions to be defined are:

  • Computing the bounding box.
  • The Intersection function between objects.
  • Intersection cell and objects.
  • Distance function between two objects.

Please note that the signature of all functions is mandatory as the strategy will only be able to use them if they appear exactly as described.

BoundingBox

  • static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint):

This method is used to calculate the boundingbox of the element (rObject). Once calculated the Low and High points of the boundingbox need to be stored in rLowPoint and rHighPoint

  • static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint, const double& Radius):

This method is used to calculate the boundingbox of the element (rObject) given an imposed radius. Once calculated the Low and High points of the boundingbox need to be stored in rLowPoint and rHighPoint


As an example, for our spheric elements:

static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint) {
  
   rHighPoint = rLowPoint  = rObject->GetGeometry().GetPoint(0);
   double radius = rObject->GetGeometry()(0)->GetSolutionStepValue(RADIUS);
  
   for(std::size_t i = 0; i < 3; i++){
     rLowPoint[i]  += -radius;
     rHighPoint[i] += radius;
   }
}
static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint, const double& Radius) {
   
   rHighPoint = rLowPoint  = rObject->GetGeometry().GetPoint(0);
    
   for(std::size_t i = 0; i < 3; i++){
     rLowPoint[i]  += -Radius;
     rHighPoint[i] += Radius;
   }
}

Object-Object Intersection

  • static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2):

This method is used to test if two given elements (rObj_1, rObj_2) intersect with each other. If the intersection is not defined the default return value must be True.

  • static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2, const double& Radius):

This method is used to test if elements rObj_2 intersect with rObj_1 in a radius (Radius) . If the intersection is not defined the default return value must be True.


As an example:

 static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2){
   
   array_1d<double, 3> rObj_2_to_rObj_1 = rObj_1->GetGeometry().GetPoint(0) - rObj_2->GetGeometry().GetPoint(0);
   double distance_2 = inner_prod(rObj_2_to_rObj_1, rObj_2_to_rObj_1);
   
   const double& radius_1 = rObj_1->GetGeometry()(0)->GetSolutionStepValue(RADIUS);
   const double& radius_2 = rObj_2->GetGeometry()(0)->GetSolutionStepValue(RADIUS);
   
   double radius_sum      = radius_1 + radius_2;
   bool intersect         = (distance_2 - radius_sum * radius_sum) <= 0;
   return intersect;
 }
 static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2, const double& Radius){
   
   array_1d<double, 3> rObj_2_to_rObj_1 = rObj_1->GetGeometry().GetPoint(0) - rObj_2->GetGeometry().GetPoint(0);
   double distance_2 = inner_prod(rObj_2_to_rObj_1, rObj_2_to_rObj_1);
   
   const double& radius_2 = rObj_2->GetGeometry()(0)->GetSolutionStepValue(RADIUS);
   
   double radius_sum      = Radius + radius_2;
   bool intersect         = (distance_2 - radius_sum * radius_sum) <= 0;
   return intersect;
 }

Object-Cell Intersection

  • static inline bool IntersectionBox(const PointerType& rObject, const PointType& rLowPoint, const PointType& rHighPoint):

This method is used to test if a given element (rObject) intersect with a cell defined by rLowPoint and rHighPoint. If the intersection is not defined the default return value must be True.

  • static inline bool IntersectionBox(const PointerType& rObject, const PointType& rLowPoint, const PointType& rHighPoint, const double& Radius):

This method is used to test if a given element (rObject) intersect with a cell defined by rLowPoint and rHighPoint in a radius (Radius). If the intersection is not defined the default return value must be True.


As an example:

 static inline bool IntersectionBox(const PointerType& rObject,  const PointType& rLowPoint, const PointType& rHighPoint){
   
   array_1d<double, 3> center_of_particle = rObject->GetGeometry().GetPoint(0);
   const double& radius = rObject->GetGeometry()(0)->GetSolutionStepValue(RADIUS);
   
   bool intersect = ( rLowPoint[0]  - radius <= center_of_particle[0] && 
                      rLowPoint[1]  - radius <= center_of_particle[1] &&
                      rLowPoint[2]  - radius <= center_of_particle[2] &&
                      rHighPoint[0] + radius >= center_of_particle[0] && 
                      rHighPoint[1] + radius >= center_of_particle[1] && 
                      rHighPoint[2] + radius >= center_of_particle[2]
                     );
   
   return  intersect;
 }
 static inline bool IntersectionBox(const PointerType& rObject,  const PointType& rLowPoint, const PointType& rHighPoint, const double& Radius){
   
   array_1d<double, 3> center_of_particle = rObject->GetGeometry().GetPoint(0);
   
   bool intersect = ( rLowPoint[0]  - Radius <= center_of_particle[0] && 
                      rLowPoint[1]  - Radius <= center_of_particle[1] &&
                      rLowPoint[2]  - Radius <= center_of_particle[2] &&
                      rHighPoint[0] + Radius >= center_of_particle[0] && 
                      rHighPoint[1] + Radius >= center_of_particle[1] && 
                      rHighPoint[2] + Radius >= center_of_particle[2]
                     );
   
   return  intersect;
 }

Please notice that if the object-cell function returns True the strategy will behave as a brute froce search.

Distance function

  • static inline void Distance(const PointerType& rObj_1, const PointerType& rObj_2, double& distance):

This function returns the distance between to given elements (rObj_1, rObj_2). Result must be stored in "distance"


For instance:

 static inline void Distance(const PointerType& rObj_1, const PointerType& rObj_2, double& distance) {
   
   array_1d<double, 3> center_of_particle1 = rObj_1->GetGeometry().GetPoint(0);
   array_1d<double, 3> center_of_particle2 = rObj_2->GetGeometry().GetPoint(0);
   
   distance = sqrt((center_of_particle1[0] - center_of_particle2[0]) * (center_of_particle1[0] - center_of_particle2[0]) +
                   (center_of_particle1[1] - center_of_particle2[1]) * (center_of_particle1[1] - center_of_particle2[1]) +
                   (center_of_particle1[2] - center_of_particle2[2]) * (center_of_particle1[2] - center_of_particle2[2]) );
 }

Calling the Constructor

Once the configure file is finished, we are able to use Contact Search Algorithm, based in a domain decomposition.

In the file where our search is going to be called we will need to include our configuration file along with the desired strategy. The available strategies can be found in "KRATOS_ROOT/kratos/spatial_containers" and basically are:

  • Bins_static
  • Bins_static_objects
  • Bins_dynamic
  • Bins_dynamic_objects

Typically dynamic strategies are slower but are not bound to a specific amount of memory. Static strategies are faster but we need to anticipate the memory requirements.

For our example we are going to select "bins_dinamyc_objects.h". Hence our file will have to include:

 #include "spatial_containers/bins_dinamyc_objects.h"

And define:

 static const std::size_t space_dim = 2;
 
 typedef ExampleConfigure<space_dim>               Configure;  
 
 typedef Configure::PointType                      PointType; 
 typedef PointType::CoordinatesArrayType           CoordinatesArrayType;
 typedef Configure::ContainerType                  ContainerType;   
 typedef Configure::PointerType                    PointerType;
 typedef Configure::IteratorType                   IteratorType; 
 typedef Configure::ResultContainerType            ResultContainerType;
 typedef Configure::ResultPointerType              ResultPointerType;
 typedef Configure::ResultIteratorType             ResultIteratorType; 
 typedef Configure::ContactPairType                ContactPairType;
 typedef Configure::ContainerContactType           ContainerContactType; 
 typedef Configure::IteratorContactType            IteratorContactType; 
 typedef Configure::PointerContactType             PointerContactType; 
 typedef Configure::PointerTypeIterator            PointerTypeIterator;
 typedef Configure::ContainerContactType           ContainerContactPair;   
 typedef Configure::IteratorContactType            IteratorContainerContactPair;  
 typedef Configure::PointerContactType             PointerContainerContactPair;

After that we can create the search strategy itself. In order to create our search strategy we will need to pass all the elements in our domain:

 IteratorType it_begin = mElements.begin();
 IteratorType it_end   = mElements.end();
   
 BinsObjectDynamic<Configure>  rBinsObjectDynamic(it_begin, it_end);

Finally we call the search. For example if we want to search the neighbours of our elements in a Radius N:

 ContainerType SearchElements;
 double * Radius;
 ResultContainerType Results;
 double * ResultDistance;
 
 int MaxNumberOfElements = MAX_RES;
 
 // Extra code can go here...
 
 rBins.SearchObjectsInRadiusExclusive(SearElementPointerToGeometricalObjecPointerTemporalVector,Radius[i],Results.begin(),ResultsDistances.begin(),MaxNumberOfElements);
Personal tools
Categories