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.
nearest_point_utilities.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <string>
17 #include <iostream>
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
23 #include "geometries/geometry.h"
25 #include "geometries/line_3d_2.h"
26 
27 namespace Kratos {
28 
31 
34 
38 
47 {
48 public:
51 
54 
58 
61 
64 
68 
71 
75 
86  template<class TPointType, class TGeometryType>
88  const TPointType& rPoint,
89  const TGeometryType& rLine
90  )
91  {
92  KRATOS_DEBUG_ERROR_IF_NOT(rLine.size() == 2) << "This function only accepts Line2D2 as input" << std::endl;
93  Point result;
94  const Point line_projected_point = GeometricalProjectionUtilities::FastProjectOnLine(rLine, rPoint, result);
95  array_1d<double,3> projected_local;
96  if(rLine.IsInside(result.Coordinates(), projected_local))
97  return result;
98 
99  const double distance1 = norm_2(rLine[0] - result);
100  const double distance2 = norm_2(rLine[1] - result);
101 
102  result = (distance1 < distance2) ? rLine[0] : rLine[1];
103  return result;
104  }
105 
106 
133  template<class TPointType, class TGeometryType>
135  const TPointType& rPoint,
136  const TGeometryType& rTriangle
137  )
138  {
139  constexpr double Tolerance = 1e-12;
140  Point result;
141  array_1d<double,3> local_coordinates = ZeroVector(3);
142  const Point center = rTriangle.Center();
143  const array_1d<double, 3> normal = rTriangle.UnitNormal(local_coordinates);
144  double distance = 0.0;
145  const Point point_projected = GeometricalProjectionUtilities::FastProject( center, rPoint, normal, distance);
146  rTriangle.PointLocalCoordinates(local_coordinates, point_projected);
147  using line_point_type= typename TGeometryType::PointType;
148 
149  if(local_coordinates[0] < -Tolerance) { // case 2,5,6
150  if(local_coordinates[1] < -Tolerance) { // case 5
151  result = rTriangle[0];
152  } else if ((local_coordinates[0] + local_coordinates[1]) > (1.0+Tolerance)) { // case 6
153  result = rTriangle[2];
154  } else {
155  result = LineNearestPoint(rPoint, Line3D2<line_point_type>(rTriangle.pGetPoint(0), rTriangle.pGetPoint(2)));
156  }
157  } else if(local_coordinates[1] < -Tolerance) { // case 4,7 (case 5 is already covered in previous if)
158  if ((local_coordinates[0] + local_coordinates[1]) > (1.0+Tolerance)) { // case 7
159  result = rTriangle[1];
160  } else { // case 4
161  result = LineNearestPoint(rPoint, Line3D2<line_point_type>(rTriangle.pGetPoint(0), rTriangle.pGetPoint(1)));
162  }
163  } else if ((local_coordinates[0] + local_coordinates[1]) > (1.0+Tolerance)) { // case 3
164  result = LineNearestPoint(rPoint, Line3D2<line_point_type>(rTriangle.pGetPoint(1), rTriangle.pGetPoint(2)));
165  } else { // inside
166  result = point_projected;
167  }
168 
169  return result;
170  }
171 
173 private:
176 
177 
181 
182 
186 
187 
191 
192 
196 
197 
201 
202 
204 
205 }; // Class NearestPointUtilities
206 
208 
211 
213 
215 
216 } // namespace Kratos
static TPointClass3 FastProject(const TPointClass1 &rPointOrigin, const TPointClass2 &rPointToProject, const array_1d< double, 3 > &rNormal, double &rDistance)
Project a point over a plane (avoiding some steps)
Definition: geometrical_projection_utilities.h:135
static double FastProjectOnLine(const TGeometryType &rGeometry, const PointType &rPointToProject, PointType &rPointProjected)
Project a point over a line (2D or 3D)
Definition: geometrical_projection_utilities.h:192
An two node 3D line geometry with linear shape functions.
Definition: line_3d_2.h:64
Tools to calculate the nearest point in different geometries.
Definition: nearest_point_utilities.h:47
NearestPointUtilities & operator=(NearestPointUtilities const &rOther)=delete
Assignment operator.
static Point TriangleNearestPoint(const TPointType &rPoint, const TGeometryType &rTriangle)
Finds the nearest point to the given point on a trianlge.
Definition: nearest_point_utilities.h:134
NearestPointUtilities(NearestPointUtilities const &rOther)=delete
Copy constructor.
static Point LineNearestPoint(const TPointType &rPoint, const TGeometryType &rLine)
Finds the nearest point to the given point on a line segment.
Definition: nearest_point_utilities.h:87
NearestPointUtilities()=delete
Default constructor.
KRATOS_CLASS_POINTER_DEFINITION(NearestPointUtilities)
Pointer definition of NearestPointUtilities.
Point class.
Definition: point.h:59
CoordinatesArrayType const & Coordinates() const
Definition: point.h:215
#define KRATOS_DEBUG_ERROR_IF_NOT(conditional)
Definition: exception.h:172
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
e
Definition: run_cpp_mpi_tests.py:31
Configure::PointType PointType
Definition: transfer_utility.h:245