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.
point_point_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_POINT_POINT_SEARCH_H_INCLUDED)
10 #define KRATOS_POINT_POINT_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
20 #include "utilities/openmp_utils.h"
21 
22 // Configures
24 #include "point_configure.h"
25 // Search
28 
29 // External includes
30 
31 /* Timer defines */
32 #include "utilities/timer.h"
33 #ifdef CUSTOMTIMER
34 #define KRATOS_TIMER_START(t) Timer::Start(t);
35 #define KRATOS_TIMER_STOP(t) Timer::Stop(t);
36 #else
37 #define KRATOS_TIMER_START(t)
38 #define KRATOS_TIMER_STOP(t)
39 #endif
40 
41 namespace Kratos
42 {
43 
46 
50 
54 
58 
62 
64 
68 {
69 public:
72 
75 
77 typedef std::vector<PointPointerType>* PointVector;
78 typedef std::vector<PointPointerType>::iterator PointIterator;
79 
80 typedef double* DistanceVector;
81 typedef double* DistanceIterator;
82 
83 //Configure Types
85 //Bin Types
88 
89 
93 
96 
99 
101  NodesContainerType const& r_nodes,
102  NodesContainerType const& r_nodes_to_find,
103  RadiusArrayType const& radius,
105  VectorDistanceType& r_results_distances)
106 {
107  KRATOS_TRY
108 
109  int max_n_of_neigh_nodes = r_nodes_to_find.size();
110 
111  NodesContainerType::ContainerType& nodes = const_cast <NodesContainerType::ContainerType&> (r_nodes.GetContainer());
112  NodesContainerType::ContainerType& nodes_to_find = const_cast <NodesContainerType::ContainerType&> (r_nodes_to_find.GetContainer());
113 
114  PointSetType::ContainerType nodes_temp;
115  PointSetType::ContainerType nodes_to_find_temp;
116 
117  std::map<Point::Pointer, Node::Pointer> map_point_to_node;
118 
119  nodes_temp.reserve(nodes.size());
120 
121  for (NodesContainerType::ContainerType::iterator it = nodes.begin(); it != nodes.end(); ++it){
122  auto p_point = std::make_shared<Point>((*it)->Coordinates());
123  nodes_temp.push_back(p_point);
124  }
125 
126  nodes_to_find_temp.reserve(nodes_to_find.size());
127 
128  for (auto it = nodes_to_find.begin(); it != nodes_to_find.end(); ++it){
129  auto p_point = std::make_shared<Point>((*it)->Coordinates());
130  nodes_to_find_temp.push_back(p_point);
131  map_point_to_node[p_point] = *it; //*(it.base());
132  }
133 
134  PointBinsType bins(nodes_to_find_temp.begin(), nodes_to_find_temp.end());
135 
136  #pragma omp parallel
137  {
138  PointSetType::ContainerType local_results(max_n_of_neigh_nodes);
139  DistanceType local_results_distances(max_n_of_neigh_nodes);
140  std::size_t n_of_results = 0;
141 
142  #pragma omp for
143  for (int i = 0; i < static_cast<int>(nodes.size()); ++i){
144  PointSetType::ContainerType::iterator i_results_begin = local_results.begin();
145  DistanceType::iterator i_distances_results_begin = local_results_distances.begin();
146 
147  n_of_results = bins.SearchObjectsInRadiusExclusive(nodes_temp[i], radius[i], i_results_begin, i_distances_results_begin, max_n_of_neigh_nodes);
148 
149  r_results[i].reserve(n_of_results);
150 
151  for (PointSetType::ContainerType::iterator it = local_results.begin(); it != local_results.begin() + n_of_results; ++it){
152  r_results[i].push_back(map_point_to_node[ *it ]);
153  }
154 
155  r_results_distances[i].insert(r_results_distances[i].begin(), local_results_distances.begin(), local_results_distances.begin() + n_of_results);
156  }
157  }
158 
159  KRATOS_CATCH("")
160 }
161 
163 virtual std::string Info() const override
164 {
165 std::stringstream buffer;
166 buffer << "PointPointSearch" ;
167 
168 return buffer.str();
169 }
170 
172 virtual void PrintInfo(std::ostream& rOStream) const override {rOStream << "PointPointSearch";}
173 
175 virtual void PrintData(std::ostream& rOStream) const override {}
176 
177 
181 
182 
184 
185 protected:
188 
189 
193 
194 
195 
199 
200 
204 
205 
209 
210 
214 
215 
219 
220 
222 
223 private:
226 
227 
231 
232 
236 
237 
241 
242 
246 
247 
251 
252 
256 
258 PointPointSearch& operator=(PointPointSearch const& rOther)
259 {
260  return *this;
261 }
262 
264 PointPointSearch(PointPointSearch const& rOther)
265 {
266  *this = rOther;
267 }
268 
269 
270 }; // Class PointPointSearch
271 
272 
273 } // namespace Kratos.
274 
275 #endif // KRATOS_POINT_POINT_SEARCH_H_INCLUDED defined
276 
277 
Short class definition.
Definition: bins_dynamic_objects.h:57
virtual SizeType SearchObjectsInRadiusExclusive(PointerType &ThisObject, const double &Radius, ResultIteratorType &Results)
Definition: bins_dynamic_objects.h:368
Definition: point_configure.h:48
Point class.
Definition: point.h:59
Short class definition.
Definition: point_point_search.h:68
PointType * PointPointerType
Definition: point_point_search.h:76
double * DistanceVector
Definition: point_point_search.h:80
PointerVectorSet< Point, IndexedObject > PointSetType
Definition: point_point_search.h:87
PointPointSearch()
Default constructor.
Definition: point_point_search.h:95
~PointPointSearch()
Destructor.
Definition: point_point_search.h:98
virtual std::string Info() const override
Turn back information as a string.
Definition: point_point_search.h:163
void SearchPointsImplementation(NodesContainerType const &r_nodes, NodesContainerType const &r_nodes_to_find, RadiusArrayType const &radius, VectorResultNodesContainerType &r_results, VectorDistanceType &r_results_distances)
Definition: point_point_search.h:100
BinsObjectDynamic< PointConfigureType > PointBinsType
Definition: point_point_search.h:86
double * DistanceIterator
Definition: point_point_search.h:81
virtual void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: point_point_search.h:172
std::vector< PointPointerType >::iterator PointIterator
Definition: point_point_search.h:78
virtual void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: point_point_search.h:175
PointConfigure< 3 > PointConfigureType
Definition: point_point_search.h:84
KRATOS_CLASS_POINTER_DEFINITION(PointPointSearch)
Pointer definition of PointPointSearch.
std::vector< PointPointerType > * PointVector
Definition: point_point_search.h:77
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
This class is used to search for elements, conditions and nodes in a given model part.
Definition: spatial_search.h:50
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
std::vector< double > DistanceType
Definition: spatial_search.h:96
#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