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.
binbased_fast_point_locator.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ \.
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // license: license.txt
9 //
10 // License: BSD License
11 // Main authors: Riccardo Rossi
12 // Pablo Becker
13 // Carlos Roig
14 // Vicente Mataix Ferrandiz
15 //
16 
17 #pragma once
18 
19 // System includes
20 
21 // External includes
22 
23 // Project includes
24 #include "includes/define.h"
25 #include "includes/node.h"
26 
30 
32 
33 namespace Kratos
34 {
37 
41 
45 
49 
53 
66 template< SizeType TDim, class TConfigureType = SpatialContainersConfigure<TDim> >
68 {
69 public:
72 
74  typedef TConfigureType ConfigureType;
75 
78  typedef typename ConfigureType::EntityType EntityType;
83 
84  // The definition of the bins
88 
90  typedef Node NodeType;
91 
94 
96  typedef std::size_t SizeType;
97 
99  typedef std::size_t IndexType;
100 
103 
107 
112  explicit BinBasedFastPointLocator(ModelPart& rModelPart)
113  : mrModelPart(rModelPart)
114  {
115  }
116 
118  virtual ~BinBasedFastPointLocator() = default;
119 
122  : mrModelPart(rOther.mrModelPart)
123  {
124  auto paux = typename BinsType::Pointer(new BinsType(*rOther.mpBinsObjectDynamic));
125  paux.swap(mpBinsObjectDynamic);
126  }
127 
131 
135 
140  {
141  KRATOS_TRY
142 
143  // Copy the entities to a new container, as the list will be shuffled during the construction of the tree
144  ContainerType entities_array;
145  GetContainer(mrModelPart, entities_array);
146  IteratorType it_begin = entities_array.begin();
147  IteratorType it_end = entities_array.end();
148 
149  auto paux = typename BinsType::Pointer(new BinsType(it_begin, it_end));
150  paux.swap(mpBinsObjectDynamic);
151 
152  KRATOS_CATCH("")
153  }
154 
160  {
161  KRATOS_TRY
162 
163  // Copy the entities to a new container, as the list will be shuffled duringthe construction of the tree
164  ContainerType entities_array;
165  GetContainer(mrModelPart, entities_array);
166  IteratorType it_begin = entities_array.begin();
167  IteratorType it_end = entities_array.end();
168 
169  auto paux = typename BinsType::Pointer(new BinsType(it_begin, it_end, CellSize));
170  paux.swap(mpBinsObjectDynamic);
171 
172  KRATOS_CATCH("")
173  }
174 
189  KRATOS_DEPRECATED_MESSAGE("This is legacy version (using array instead of vector for shape function)") bool FindPointOnMesh(
191  array_1d<double, TDim + 1 >& rNShapeFunction,
192  typename EntityType::Pointer& pEntity,
195  const double Tolerance = 1.0e-5
196  )
197  {
198  // Ask to the container for the list of candidate entities
200 
201  if (results_found > 0) {
202  // Loop over the candidate entities and check if the particle falls within
203  for (IndexType i = 0; i < results_found; i++) {
204  GeometryType& r_geom = (*(ItResultBegin + i))->GetGeometry();
205 
206  // Find local position
207  array_1d<double, 3> point_local_coordinates;
208  Vector shape_function;
209  const bool is_found = LocalIsInside(r_geom, rCoordinates, point_local_coordinates, Tolerance);
210  r_geom.ShapeFunctionsValues(shape_function, point_local_coordinates);
211  noalias(rNShapeFunction) = shape_function;
212 
213  if (is_found) {
214  pEntity = (*(ItResultBegin + i));
215  return true;
216  }
217  }
218  }
219 
220  // Not found case
221  pEntity = nullptr;
222  return false;
223  }
224 
238  bool FindPointOnMesh(
241  typename EntityType::Pointer& pEntity,
243  const SizeType MaxNumberOfResults = 1000,
244  const double Tolerance = 1.0e-5
245  )
246  {
247  // Ask to the container for the list of candidate entities
248  const SizeType results_found = mpBinsObjectDynamic->SearchObjectsInCell(BinsPointType{rCoordinates}, ItResultBegin, MaxNumberOfResults);
249 
250  if (results_found > 0) {
251  // Loop over the candidate entities and check if the particle falls within
252  for (IndexType i = 0; i < static_cast<IndexType>(results_found); i++) {
253 
254  GeometryType& r_geom = (*(ItResultBegin + i))->GetGeometry();
255 
256  // Find local position
257  array_1d<double, 3> point_local_coordinates;
258  const bool is_found = LocalIsInside(r_geom, rCoordinates, point_local_coordinates, Tolerance);
259  r_geom.ShapeFunctionsValues(rNShapeFunction, point_local_coordinates);
260 
261  if (is_found) {
262  pEntity = (*(ItResultBegin + i));
263  return true;
264  }
265  }
266  }
267 
268  // Not found case
269  pEntity = nullptr;
270  return false;
271  }
272 
283  bool FindPointOnMeshSimplified(
284  const array_1d<double, 3 >& rCoordinates,
286  typename EntityType::Pointer& pEntity,
287  const SizeType MaxNumberOfResults = 1000,
288  const double Tolerance = 1.0e-5
289  )
290  {
292 
293  const bool is_found = FindPointOnMesh(rCoordinates, rNShapeFunction, pEntity, results.begin(), MaxNumberOfResults, Tolerance);
294 
295  return is_found;
296  }
297 
301 
305 
310 
311 protected:
314 
318 
322 
326 
338  virtual bool LocalIsInside(
339  const GeometryType& rGeometry,
340  const GeometryType::CoordinatesArrayType& rPointGlobalCoordinates,
342  const double Tolerance = std::numeric_limits<double>::epsilon()
343  ) const
344  {
345  return rGeometry.IsInside(rPointGlobalCoordinates, rResult, Tolerance);
346  }
347 
351 
355 
360 
361 private:
362 
368 
369  ModelPart& mrModelPart;
370 
371  typename BinsType::Pointer mpBinsObjectDynamic;
372 
376 
380 
386  static inline void GetContainer(
387  ModelPart& rModelPart,
389  )
390  {
391  rContainerArray = rModelPart.ElementsArray();
392  }
393 
399  static inline void GetContainer(
400  ModelPart& rModelPart,
402  )
403  {
404  rContainerArray = rModelPart.ConditionsArray();
405  }
406 
411 
415 
419 
423 };
424 
425 } // namespace Kratos.
This class is designed to allow the fast location of MANY points on the top of a 3D mesh.
Definition: binbased_fast_point_locator.h:68
array_1d< double, TDim+1 > EntityType::Pointer ResultIteratorType const SizeType MaxNumberOfResults
Definition: binbased_fast_point_locator.h:194
ConfigureType::ResultIteratorType ResultIteratorType
Definition: binbased_fast_point_locator.h:82
BinsObjectDynamic< ConfigureType > BinsType
Definition: binbased_fast_point_locator.h:85
Node NodeType
The definition of the node.
Definition: binbased_fast_point_locator.h:90
array_1d< double, TDim+1 > & rNShapeFunction
Definition: binbased_fast_point_locator.h:191
TConfigureType ConfigureType
The configure type.
Definition: binbased_fast_point_locator.h:74
static void GetContainer(ModelPart &rModelPart, PointerVectorSet< Element, IndexedObject >::ContainerType &rContainerArray)
This operation is defined to the the corresponding container type.
Definition: binbased_fast_point_locator.h:386
& rCoordinates
Definition: binbased_fast_point_locator.h:190
std::size_t SizeType
The size definition.
Definition: binbased_fast_point_locator.h:96
KRATOS_DEPRECATED_MESSAGE("This is legacy version (using array instead of vector for shape function)") bool FindPointOnMesh(const array_1d< double
This function should find the element into which a given node is located and return a pointer to the ...
std::size_t IndexType
The index definition.
Definition: binbased_fast_point_locator.h:99
static void GetContainer(ModelPart &rModelPart, PointerVectorSet< Condition, IndexedObject >::ContainerType &rContainerArray)
This operation is defined to the the corresponding container type.
Definition: binbased_fast_point_locator.h:399
BinsObjectDynamic< ConfigureType >::CoordinateType BinsCoordinateType
Definition: binbased_fast_point_locator.h:86
void UpdateSearchDatabaseAssignedSize(const BinsCoordinateType CellSize)
Function to construct or update the search database.
Definition: binbased_fast_point_locator.h:159
ConfigureType::EntityType EntityType
Definition: binbased_fast_point_locator.h:78
ConfigureType::PointType PointType
The definition of the different containers.
Definition: binbased_fast_point_locator.h:77
void UpdateSearchDatabase()
Function to construct or update the search database.
Definition: binbased_fast_point_locator.h:139
BinBasedFastPointLocator(BinBasedFastPointLocator const &rOther)
Copy constructor.
Definition: binbased_fast_point_locator.h:121
ConfigureType::ResultContainerType ResultContainerType
Definition: binbased_fast_point_locator.h:81
BinsObjectDynamic< ConfigureType >::PointType BinsPointType
Definition: binbased_fast_point_locator.h:87
ConfigureType::ContainerType ContainerType
Definition: binbased_fast_point_locator.h:79
array_1d< double, TDim+1 > EntityType::Pointer ResultIteratorType const SizeType const double Tolerance
Definition: binbased_fast_point_locator.h:195
BinsType::Pointer mpBinsObjectDynamic
The model part containing the mesh for the search.
Definition: binbased_fast_point_locator.h:371
virtual ~BinBasedFastPointLocator()=default
Destructor.
array_1d< double, TDim+1 > EntityType::Pointer ResultIteratorType ItResultBegin
Definition: binbased_fast_point_locator.h:193
array_1d< double, TDim+1 > EntityType::Pointer & pEntity
Definition: binbased_fast_point_locator.h:192
KRATOS_CLASS_POINTER_DEFINITION(BinBasedFastPointLocator)
Pointer definition of BinBasedFastPointLocator.
Geometry< NodeType > GeometryType
The definition of the geometry.
Definition: binbased_fast_point_locator.h:93
ConfigureType::IteratorType IteratorType
Definition: binbased_fast_point_locator.h:80
BinBasedFastPointLocator(ModelPart &rModelPart)
This is the default constructor.
Definition: binbased_fast_point_locator.h:112
Short class definition.
Definition: bins_dynamic_objects.h:57
TreeNodeType::CoordinateType CoordinateType
Definition: bins_dynamic_objects.h:75
TConfigure::PointType PointType
Definition: bins_dynamic_objects.h:65
Geometry base class.
Definition: geometry.h:71
const Matrix & ShapeFunctionsValues() const
Definition: geometry.h:3393
PointType::CoordinatesArrayType CoordinatesArrayType
Definition: geometry.h:147
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionsContainerType::ContainerType & ConditionsArray(IndexType ThisIndex=0)
Definition: model_part.h:1401
ElementsContainerType::ContainerType & ElementsArray(IndexType ThisIndex=0)
Definition: model_part.h:1209
This class defines the node.
Definition: node.h:65
TContainerType ContainerType
Definition: pointer_vector_set.h:90
Short class definition.
Definition: array_1d.h:61
BOOST_UBLAS_INLINE const_iterator begin() const
Definition: array_1d.h:606
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
REACTION_CHECK_STIFFNESS_FACTOR INNER_LOOP_ITERATION DISTANCE_THRESHOLD ACTIVE_CHECK_FACTOR AUXILIAR_COORDINATES NORMAL_GAP WEIGHTED_GAP WEIGHTED_SCALAR_RESIDUAL bool
Definition: contact_structural_mechanics_application_variables.h:93
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
tuple const
Definition: ode_solve.py:403
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31
Configure::ResultIteratorType ResultIteratorType
Definition: transfer_utility.h:252
Configure::IteratorType IteratorType
Definition: transfer_utility.h:249
Configure::PointType PointType
Definition: transfer_utility.h:245
Configure::ResultContainerType ResultContainerType
Definition: transfer_utility.h:250
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247