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.
triangle_3d_3.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: Riccardo Rossi
11 // Janosch Stascheit
12 // Felix Nagel
13 // Contributors: Hoang Giang Bui
14 // Josep Maria Carbonell
15 // Vicente Mataix Ferrandiz
16 //
17 
18 #pragma once
19 
20 // System includes
21 #include <iomanip>
22 
23 // External includes
24 
25 // Project includes
26 #include "geometries/plane_3d.h"
27 #include "geometries/line_3d_2.h"
30 #include "utilities/geometry_utilities.h"
33 
34 namespace Kratos
35 {
38 
42 
46 
50 
54 
75 template<class TPointType> class Triangle3D3
76  : public Geometry<TPointType>
77 {
78 public:
82 
87 
89 
94 
99 
104 
109 
115 
119  typedef TPointType PointType;
120 
127  typedef typename BaseType::IndexType IndexType;
128 
134  typedef typename BaseType::SizeType SizeType;
135 
141 
146 
152 
161 
168 
174 
180 
187 
194 
202 
210 
215 
219 
220 // Triangle3D3( const PointType& FirstPoint,
221 // const PointType& SecondPoint,
222 // const PointType& ThirdPoint )
223 // : BaseType( PointsArrayType(), &msGeometryData )
224 // {
225 // this->Points().push_back( typename PointType::Pointer( new PointType( FirstPoint ) ) );
226 // this->Points().push_back( typename PointType::Pointer( new PointType( SecondPoint ) ) );
227 // this->Points().push_back( typename PointType::Pointer( new PointType( ThirdPoint ) ) );
228 // }
229 
230  Triangle3D3( typename PointType::Pointer pFirstPoint,
231  typename PointType::Pointer pSecondPoint,
232  typename PointType::Pointer pThirdPoint )
233  : BaseType( PointsArrayType(), &msGeometryData )
234  {
235  this->Points().push_back( pFirstPoint );
236  this->Points().push_back( pSecondPoint );
237  this->Points().push_back( pThirdPoint );
238  }
239 
240  explicit Triangle3D3( const PointsArrayType& ThisPoints )
241  : BaseType( ThisPoints, &msGeometryData )
242  {
243  KRATOS_ERROR_IF(this->PointsNumber() != 3) << "Invalid points number. Expected 3, given " << this->PointsNumber() << std::endl;
244  }
245 
247  explicit Triangle3D3(
248  const IndexType GeometryId,
249  const PointsArrayType& rThisPoints
250  ) : BaseType(GeometryId, rThisPoints, &msGeometryData)
251  {
252  KRATOS_ERROR_IF(this->PointsNumber() != 3) << "Invalid points number. Expected 3, given " << this->PointsNumber() << std::endl;
253  }
254 
256  explicit Triangle3D3(
257  const std::string& rGeometryName,
258  const PointsArrayType& rThisPoints
259  ) : BaseType(rGeometryName, rThisPoints, &msGeometryData)
260  {
261  KRATOS_ERROR_IF(this->PointsNumber() != 3) << "Invalid points number. Expected 3, given " << this->PointsNumber() << std::endl;
262  }
263 
273  Triangle3D3( Triangle3D3 const& rOther )
274  : BaseType( rOther )
275  {
276  }
277 
290  template<class TOtherPointType> explicit Triangle3D3( Triangle3D3<TOtherPointType> const& rOther )
291  : BaseType( rOther )
292  {
293  }
294 
298  ~Triangle3D3() override {}
299 
301  {
303  }
304 
306  {
308  }
309 
313 
326  {
327  BaseType::operator=( rOther );
328  return *this;
329  }
330 
342  template<class TOtherPointType>
344  {
345  BaseType::operator=( rOther );
346  return *this;
347  }
348 
352 
358  typename BaseType::Pointer Create(
359  PointsArrayType const& rThisPoints
360  ) const override
361  {
362  return typename BaseType::Pointer( new Triangle3D3( rThisPoints ) );
363  }
364 
371  typename BaseType::Pointer Create(
372  const IndexType NewGeometryId,
373  PointsArrayType const& rThisPoints
374  ) const override
375  {
376  return typename BaseType::Pointer( new Triangle3D3( NewGeometryId, rThisPoints ) );
377  }
378 
384  typename BaseType::Pointer Create(
385  const BaseType& rGeometry
386  ) const override
387  {
388  auto p_geometry = typename BaseType::Pointer( new Triangle3D3( rGeometry.Points() ) );
389  p_geometry->SetData(rGeometry.GetData());
390  return p_geometry;
391  }
392 
399  typename BaseType::Pointer Create(
400  const IndexType NewGeometryId,
401  const BaseType& rGeometry
402  ) const override
403  {
404  auto p_geometry = typename BaseType::Pointer( new Triangle3D3( NewGeometryId, rGeometry.Points() ) );
405  p_geometry->SetData(rGeometry.GetData());
406  return p_geometry;
407  }
408 
414  Matrix& PointsLocalCoordinates( Matrix& rResult ) const override
415  {
416  rResult.resize( 3, 2 ,false);
417  noalias( rResult ) = ZeroMatrix( 3, 2 );
418  rResult( 0, 0 ) = 0.0;
419  rResult( 0, 1 ) = 0.0;
420  rResult( 1, 0 ) = 1.0;
421  rResult( 1, 1 ) = 0.0;
422  rResult( 2, 0 ) = 0.0;
423  rResult( 2, 1 ) = 1.0;
424  return rResult;
425  }
426 
436  Vector& rResult,
437  const typename BaseType::LumpingMethods LumpingMethod = BaseType::LumpingMethods::ROW_SUM
438  ) const override
439  {
440  rResult.resize( 3, false );
441  std::fill( rResult.begin(), rResult.end(), 1.00 / 3.00 );
442  return rResult;
443  }
444 
448 
468  double Length() const override
469  {
470  return std::sqrt(2.0 * Area());
471  }
472 
482  double Area() const override
483  {
484  const double a = MathUtils<double>::Norm3(this->GetPoint(0)-this->GetPoint(1));
485  const double b = MathUtils<double>::Norm3(this->GetPoint(1)-this->GetPoint(2));
486  const double c = MathUtils<double>::Norm3(this->GetPoint(2)-this->GetPoint(0));
487 
488  const double s = (a+b+c) / 2.0;
489 
490  return std::sqrt(s*(s-a)*(s-b)*(s-c));
491  }
492 
493  // TODO: Code activated in June 2023
494  // /**
495  // * @brief This method calculates and returns the volume of this geometry.
496  // * @return Error, the volume of a 2D geometry is not defined
497  // * @see Length()
498  // * @see Area()
499  // * @see Volume()
500  // */
501  // double Volume() const override
502  // {
503  // KRATOS_ERROR << "Triangle3D3:: Method not well defined. Replace with DomainSize() instead" << std::endl;
504  // return 0.0;
505  // }
506 
515  double DomainSize() const override
516  {
517  return Area();
518  }
519 
521 
530  double MinEdgeLength() const override
531  {
532  const array_1d<double, 3> a = this->GetPoint(0) - this->GetPoint(1);
533  const array_1d<double, 3> b = this->GetPoint(1) - this->GetPoint(2);
534  const array_1d<double, 3> c = this->GetPoint(2) - this->GetPoint(0);
535 
536  const double sa = (a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2]);
537  const double sb = (b[0]*b[0])+(b[1]*b[1])+(b[2]*b[2]);
538  const double sc = (c[0]*c[0])+(c[1]*c[1])+(c[2]*c[2]);
539 
540  return CalculateMinEdgeLength(sa, sb, sc);
541  }
542 
551  double MaxEdgeLength() const override
552  {
553  const array_1d<double, 3> a = this->GetPoint(0) - this->GetPoint(1);
554  const array_1d<double, 3> b = this->GetPoint(1) - this->GetPoint(2);
555  const array_1d<double, 3> c = this->GetPoint(2) - this->GetPoint(0);
556 
557  const double sa = (a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2]);
558  const double sb = (b[0]*b[0])+(b[1]*b[1])+(b[2]*b[2]);
559  const double sc = (c[0]*c[0])+(c[1]*c[1])+(c[2]*c[2]);
560 
561  return CalculateMaxEdgeLength(sa, sb, sc);
562  }
563 
572  double AverageEdgeLength() const override
573  {
574  return CalculateAvgEdgeLength(
575  MathUtils<double>::Norm3(this->GetPoint(0)-this->GetPoint(1)),
576  MathUtils<double>::Norm3(this->GetPoint(1)-this->GetPoint(2)),
577  MathUtils<double>::Norm3(this->GetPoint(2)-this->GetPoint(0))
578  );
579  }
580 
588  double Circumradius() const override
589  {
590  return CalculateCircumradius(
591  MathUtils<double>::Norm3(this->GetPoint(0)-this->GetPoint(1)),
592  MathUtils<double>::Norm3(this->GetPoint(1)-this->GetPoint(2)),
593  MathUtils<double>::Norm3(this->GetPoint(2)-this->GetPoint(0))
594  );
595  }
596 
604  double Inradius() const override
605  {
606  return CalculateInradius(
607  MathUtils<double>::Norm3(this->GetPoint(0)-this->GetPoint(1)),
608  MathUtils<double>::Norm3(this->GetPoint(1)-this->GetPoint(2)),
609  MathUtils<double>::Norm3(this->GetPoint(2)-this->GetPoint(0))
610  );
611  }
612 
613 
614  bool AllSameSide(array_1d<double, 3> const& Distances) const
615  {
616  constexpr double epsilon = std::numeric_limits<double>::epsilon();
617 
618  // put U0,U1,U2 into plane equation 1 to compute signed distances to the plane//
619  double du0 = Distances[0];
620  double du1 = Distances[1];
621  double du2 = Distances[2];
622 
623  // coplanarity robustness check //
624  if (std::abs(du0)<epsilon) du0 = 0.0;
625  if (std::abs(du1)<epsilon) du1 = 0.0;
626  if (std::abs(du2)<epsilon) du2 = 0.0;
627 
628  const double du0du1 = du0*du1;
629  const double du0du2 = du0*du2;
630 
631  if (du0du1>0.00 && du0du2>0.00)// same sign on all of them + not equal 0 ? //
632  return true; // no intersection occurs //
633 
634  return false;
635 
636  }
637 
639  {
640  int index = static_cast<int>(std::abs(V[0]) < std::abs(V[1]));
641  return (std::abs(V[index]) > std::abs(V[2])) ? index : 2;
642  }
643 
649  bool HasIntersection(const GeometryType& rThisGeometry) const override
650  {
651  const auto geometry_type = rThisGeometry.GetGeometryType();
652 
654  return LineTriangleOverlap(rThisGeometry[0], rThisGeometry[1]);
655  }
656  else if(geometry_type == GeometryData::KratosGeometryType::Kratos_Triangle3D3) {
657  return TriangleTriangleOverlap(rThisGeometry[0], rThisGeometry[1], rThisGeometry[2]);
658  }
660  if ( TriangleTriangleOverlap(rThisGeometry[0], rThisGeometry[1], rThisGeometry[2]) ) return true;
661  else if ( TriangleTriangleOverlap(rThisGeometry[2], rThisGeometry[3], rThisGeometry[0]) ) return true;
662  else return false;
663  }
664  else {
665  KRATOS_ERROR << "Triangle3D3::HasIntersection : Geometry cannot be identified, please, check the intersecting geometry type." << std::endl;
666  }
667  }
668 
680  bool HasIntersection( const Point& rLowPoint, const Point& rHighPoint) const override
681  {
682  Point box_center;
683  Point box_half_size;
684 
685  box_center[0] = 0.5 * (rLowPoint[0] + rHighPoint[0]);
686  box_center[1] = 0.5 * (rLowPoint[1] + rHighPoint[1]);
687  box_center[2] = 0.5 * (rLowPoint[2] + rHighPoint[2]);
688 
689  box_half_size[0] = 0.5 * std::abs(rHighPoint[0] - rLowPoint[0]);
690  box_half_size[1] = 0.5 * std::abs(rHighPoint[1] - rLowPoint[1]);
691  box_half_size[2] = 0.5 * std::abs(rHighPoint[2] - rLowPoint[2]);
692 
693  return TriBoxOverlap(box_center, box_half_size);
694  }
695 
697 
708  double InradiusToCircumradiusQuality() const override
709  {
710  constexpr double normFactor = 1.0;
711 
712  const double a = MathUtils<double>::Norm3(this->GetPoint(0)-this->GetPoint(1));
713  const double b = MathUtils<double>::Norm3(this->GetPoint(1)-this->GetPoint(2));
714  const double c = MathUtils<double>::Norm3(this->GetPoint(2)-this->GetPoint(0));
715 
716  return normFactor * CalculateInradius(a,b,c) / CalculateCircumradius(a,b,c);
717  };
718 
729  double InradiusToLongestEdgeQuality() const override
730  {
731  constexpr double normFactor = 1.0; // TODO: This normalization coeficient is not correct.
732 
733  const array_1d<double, 3> a = this->GetPoint(0) - this->GetPoint(1);
734  const array_1d<double, 3> b = this->GetPoint(1) - this->GetPoint(2);
735  const array_1d<double, 3> c = this->GetPoint(2) - this->GetPoint(0);
736 
737  const double sa = (a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2]);
738  const double sb = (b[0]*b[0])+(b[1]*b[1])+(b[2]*b[2]);
739  const double sc = (c[0]*c[0])+(c[1]*c[1])+(c[2]*c[2]);
740 
741  return normFactor * CalculateInradius(std::sqrt(sa),std::sqrt(sb),std::sqrt(sc)) / CalculateMaxEdgeLength(sa,sb,sc);
742  }
743 
755  double AreaToEdgeLengthRatio() const override
756  {
757  constexpr double normFactor = 1.0;
758 
759  const array_1d<double, 3> a = this->GetPoint(0) - this->GetPoint(1);
760  const array_1d<double, 3> b = this->GetPoint(1) - this->GetPoint(2);
761  const array_1d<double, 3> c = this->GetPoint(2) - this->GetPoint(0);
762 
763  const double sa = (a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2]);
764  const double sb = (b[0]*b[0])+(b[1]*b[1])+(b[2]*b[2]);
765  const double sc = (c[0]*c[0])+(c[1]*c[1])+(c[2]*c[2]);
766 
767  return normFactor * Area() / (sa+sb+sc);
768  }
769 
781  double ShortestAltitudeToEdgeLengthRatio() const override {
782  constexpr double normFactor = 1.0;
783 
784  const array_1d<double, 3> a = this->GetPoint(0) - this->GetPoint(1);
785  const array_1d<double, 3> b = this->GetPoint(1) - this->GetPoint(2);
786  const array_1d<double, 3> c = this->GetPoint(2) - this->GetPoint(0);
787 
788  const double sa = (a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2]);
789  const double sb = (b[0]*b[0])+(b[1]*b[1])+(b[2]*b[2]);
790  const double sc = (c[0]*c[0])+(c[1]*c[1])+(c[2]*c[2]);
791 
792  // Shortest altitude is the one intersecting the largest base.
793  double base = CalculateMaxEdgeLength(sa,sb,sc);
794 
795  return normFactor * (Area() * 2 / base ) / std::sqrt(sa+sb+sc);
796  }
797 
809  virtual double AreaToEdgeLengthSquareRatio() const {
810  constexpr double normFactor = 1.0;
811 
812  const double a = MathUtils<double>::Norm3(this->GetPoint(0)-this->GetPoint(1));
813  const double b = MathUtils<double>::Norm3(this->GetPoint(1)-this->GetPoint(2));
814  const double c = MathUtils<double>::Norm3(this->GetPoint(2)-this->GetPoint(0));
815 
816  return normFactor * Area() / std::pow(a+b+c, 2);
817  }
818 
830  virtual double ShortestAltitudeToLongestEdge() const
831  {
832  constexpr double normFactor = 1.0;
833 
834  const array_1d<double, 3> a = this->GetPoint(0) - this->GetPoint(1);
835  const array_1d<double, 3> b = this->GetPoint(1) - this->GetPoint(2);
836  const array_1d<double, 3> c = this->GetPoint(2) - this->GetPoint(0);
837 
838  const double sa = (a[0]*a[0])+(a[1]*a[1])+(a[2]*a[2]);
839  const double sb = (b[0]*b[0])+(b[1]*b[1])+(b[2]*b[2]);
840  const double sc = (c[0]*c[0])+(c[1]*c[1])+(c[2]*c[2]);
841 
842  // Shortest altitude is the one intersecting the largest base (or edge).
843  const double base = CalculateMaxEdgeLength(sa,sb,sc);
844 
845  return normFactor * (Area() * 2 / base ) / base;
846  }
847 
853  array_1d<double, 3> Normal(const CoordinatesArrayType& rPointLocalCoordinates) const override
854  {
855  const array_1d<double, 3> tangent_xi = this->GetPoint(1) - this->GetPoint(0);
856  const array_1d<double, 3> tangent_eta = this->GetPoint(2) - this->GetPoint(0);
857 
858  array_1d<double, 3> normal;
859  MathUtils<double>::CrossProduct(normal, tangent_xi, tangent_eta);
860 
861  return 0.5 * normal;
862  }
863 
871  bool IsInside(
872  const CoordinatesArrayType& rPoint,
873  CoordinatesArrayType& rResult,
874  const double Tolerance = std::numeric_limits<double>::epsilon()
875  ) const override
876  {
877  // We compute the normal to check the normal distances between the point and the triangles, so we can discard that is on the triangle
878  const auto center = this->Center();
879  const array_1d<double, 3> normal = this->UnitNormal(center);
880 
881  // We compute the distance, if it is not in the plane we project
882  const Point point_to_project(rPoint);
883  double distance;
884  CoordinatesArrayType point_projected;
885  point_projected = GeometricalProjectionUtilities::FastProject( center, point_to_project, normal, distance);
886 
887  // We check if we are on the plane
888  if (std::abs(distance) > std::numeric_limits<double>::epsilon()) {
889  if (std::abs(distance) > 1.0e-6 * Length()) {
890  KRATOS_WARNING_FIRST_N("Triangle3D3", 10) << "The " << rPoint << " is in a distance: " << std::abs(distance) << std::endl;
891  return false;
892  }
893 
894  // Not in the plane, but allowing certain distance, projecting
895  noalias(point_projected) = rPoint - normal * distance;
896  }
897 
898  PointLocalCoordinates( rResult, point_projected );
899 
900  if ( (rResult[0] >= (0.0-Tolerance)) && (rResult[0] <= (1.0+Tolerance)) ) {
901  if ( (rResult[1] >= (0.0-Tolerance)) && (rResult[1] <= (1.0+Tolerance)) ) {
902  if ( (rResult[0] + rResult[1]) <= (1.0+Tolerance) ) {
903  return true;
904  }
905  }
906  }
907 
908  return false;
909  }
910 
918  CoordinatesArrayType& rResult,
919  const CoordinatesArrayType& rPoint
920  ) const override
921  {
922  // Initialize
923  noalias(rResult) = ZeroVector(3);
924 
925  // Tangent vectors
926  array_1d<double, 3> tangent_xi = this->GetPoint(1) - this->GetPoint(0);
927  tangent_xi /= norm_2(tangent_xi);
928  array_1d<double, 3> tangent_eta = this->GetPoint(2) - this->GetPoint(0);
929  tangent_eta /= norm_2(tangent_eta);
930 
931  // The center of the geometry
932  const auto center = this->Center();
933 
934  // Computation of the rotation matrix
935  BoundedMatrix<double, 3, 3> rotation_matrix = ZeroMatrix(3, 3);
936  for (IndexType i = 0; i < 3; ++i) {
937  rotation_matrix(0, i) = tangent_xi[i];
938  rotation_matrix(1, i) = tangent_eta[i];
939  }
940 
941  // Destination point rotated
942  CoordinatesArrayType aux_point_to_rotate, destination_point_rotated;
943  noalias(aux_point_to_rotate) = rPoint - center.Coordinates();
944  noalias(destination_point_rotated) = prod(rotation_matrix, aux_point_to_rotate) + center.Coordinates();
945 
946  // Points of the geometry
947  array_1d<CoordinatesArrayType, 3> points_rotated;
948  for (IndexType i = 0; i < 3; ++i) {
949  noalias(aux_point_to_rotate) = this->GetPoint(i).Coordinates() - center.Coordinates();
950  noalias(points_rotated[i]) = prod(rotation_matrix, aux_point_to_rotate) + center.Coordinates();
951  }
952 
953  // Compute the Jacobian matrix and its determinant
955  J(0,0) = points_rotated[1][0] - points_rotated[0][0];
956  J(0,1) = points_rotated[2][0] - points_rotated[0][0];
957  J(1,0) = points_rotated[1][1] - points_rotated[0][1];
958  J(1,1) = points_rotated[2][1] - points_rotated[0][1];
959  const double det_J = J(0,0)*J(1,1) - J(0,1)*J(1,0);
960 
961  // Compute eta and xi
962  const double eta = (J(1,0)*(points_rotated[0][0] - destination_point_rotated[0]) +
963  J(0,0)*(destination_point_rotated[1] - points_rotated[0][1])) / det_J;
964  const double xi = (J(1,1)*(destination_point_rotated[0] - points_rotated[0][0]) +
965  J(0,1)*(points_rotated[0][1] - destination_point_rotated[1])) / det_J;
966 
967  rResult(0) = xi;
968  rResult(1) = eta;
969 
970  return rResult;
971  }
972 
976 
990  const CoordinatesArrayType& rPointGlobalCoordinates,
991  const double Tolerance = std::numeric_limits<double>::epsilon()
992  ) const override
993  {
994  const Point point(rPointGlobalCoordinates);
995  return GeometryUtils::PointDistanceToTriangle3D(this->GetPoint(0), this->GetPoint(1), this->GetPoint(2), point);
996  }
997 
1001 
1020  IntegrationMethod ThisMethod ) const override
1021  {
1022  Matrix jacobian( 3, 2 );
1023  jacobian( 0, 0 ) = -( BaseType::GetPoint( 0 ).X() ) + ( BaseType::GetPoint( 1 ).X() ); //on the Gauss points (J is constant at each element)
1024  jacobian( 1, 0 ) = -( BaseType::GetPoint( 0 ).Y() ) + ( BaseType::GetPoint( 1 ).Y() );
1025  jacobian( 2, 0 ) = -( BaseType::GetPoint( 0 ).Z() ) + ( BaseType::GetPoint( 1 ).Z() );
1026  jacobian( 0, 1 ) = -( BaseType::GetPoint( 0 ).X() ) + ( BaseType::GetPoint( 2 ).X() );
1027  jacobian( 1, 1 ) = -( BaseType::GetPoint( 0 ).Y() ) + ( BaseType::GetPoint( 2 ).Y() );
1028  jacobian( 2, 1 ) = -( BaseType::GetPoint( 0 ).Z() ) + ( BaseType::GetPoint( 2 ).Z() );
1029 
1030  if ( rResult.size() != this->IntegrationPointsNumber( ThisMethod ) )
1031  {
1032  // KLUDGE: While there is a bug in ublas vector resize, I have to put this beside resizing!!
1033  JacobiansType temp( this->IntegrationPointsNumber( ThisMethod ) );
1034  rResult.swap( temp );
1035  }
1036 
1037  std::fill( rResult.begin(), rResult.end(), jacobian );
1038 
1039  return rResult;
1040  }
1041 
1061  IntegrationMethod ThisMethod,
1062  Matrix & DeltaPosition ) const override
1063  {
1064  Matrix jacobian( 3, 2 );
1065  jacobian( 0, 0 ) = -( BaseType::GetPoint( 0 ).X() - DeltaPosition(0,0) ) + ( BaseType::GetPoint( 1 ).X() - DeltaPosition(1,0) ); //on the Gauss points (J is constant at each element)
1066  jacobian( 1, 0 ) = -( BaseType::GetPoint( 0 ).Y() - DeltaPosition(0,1) ) + ( BaseType::GetPoint( 1 ).Y() - DeltaPosition(1,1) );
1067  jacobian( 2, 0 ) = -( BaseType::GetPoint( 0 ).Z() - DeltaPosition(0,2) ) + ( BaseType::GetPoint( 1 ).Z() - DeltaPosition(1,2) );
1068  jacobian( 0, 1 ) = -( BaseType::GetPoint( 0 ).X() - DeltaPosition(0,0) ) + ( BaseType::GetPoint( 2 ).X() - DeltaPosition(2,0) );
1069  jacobian( 1, 1 ) = -( BaseType::GetPoint( 0 ).Y() - DeltaPosition(0,1) ) + ( BaseType::GetPoint( 2 ).Y() - DeltaPosition(2,1) );
1070  jacobian( 2, 1 ) = -( BaseType::GetPoint( 0 ).Z() - DeltaPosition(0,2) ) + ( BaseType::GetPoint( 2 ).Z() - DeltaPosition(2,2) );
1071 
1072  if ( rResult.size() != this->IntegrationPointsNumber( ThisMethod ) )
1073  {
1074  // KLUDGE: While there is a bug in ublas vector resize, I have to put this beside resizing!!
1075  JacobiansType temp( this->IntegrationPointsNumber( ThisMethod ) );
1076  rResult.swap( temp );
1077  }
1078 
1079  std::fill( rResult.begin(), rResult.end(), jacobian );
1080 
1081  return rResult;
1082  }
1083 
1105  Matrix& Jacobian( Matrix& rResult,
1106  IndexType IntegrationPointIndex,
1107  IntegrationMethod ThisMethod ) const override
1108  {
1109  rResult.resize( 3, 2,false );
1110  rResult( 0, 0 ) = -( BaseType::GetPoint( 0 ).X() ) + ( BaseType::GetPoint( 1 ).X() ); //on the Gauss points (J is constant at each element)
1111  rResult( 1, 0 ) = -( BaseType::GetPoint( 0 ).Y() ) + ( BaseType::GetPoint( 1 ).Y() );
1112  rResult( 2, 0 ) = -( BaseType::GetPoint( 0 ).Z() ) + ( BaseType::GetPoint( 1 ).Z() );
1113  rResult( 0, 1 ) = -( BaseType::GetPoint( 0 ).X() ) + ( BaseType::GetPoint( 2 ).X() );
1114  rResult( 1, 1 ) = -( BaseType::GetPoint( 0 ).Y() ) + ( BaseType::GetPoint( 2 ).Y() );
1115  rResult( 2, 1 ) = -( BaseType::GetPoint( 0 ).Z() ) + ( BaseType::GetPoint( 2 ).Z() );
1116  return rResult;
1117  }
1118 
1134  Matrix& Jacobian( Matrix& rResult, const CoordinatesArrayType& rPoint ) const override
1135  {
1136  rResult.resize( 3, 2 ,false);
1137  rResult( 0, 0 ) = -( BaseType::GetPoint( 0 ).X() ) + ( BaseType::GetPoint( 1 ).X() );
1138  rResult( 1, 0 ) = -( BaseType::GetPoint( 0 ).Y() ) + ( BaseType::GetPoint( 1 ).Y() );
1139  rResult( 2, 0 ) = -( BaseType::GetPoint( 0 ).Z() ) + ( BaseType::GetPoint( 1 ).Z() );
1140  rResult( 0, 1 ) = -( BaseType::GetPoint( 0 ).X() ) + ( BaseType::GetPoint( 2 ).X() );
1141  rResult( 1, 1 ) = -( BaseType::GetPoint( 0 ).Y() ) + ( BaseType::GetPoint( 2 ).Y() );
1142  rResult( 2, 1 ) = -( BaseType::GetPoint( 0 ).Z() ) + ( BaseType::GetPoint( 2 ).Z() );
1143  return rResult;
1144  }
1145 
1158  Vector& DeterminantOfJacobian( Vector& rResult, IntegrationMethod ThisMethod ) const override
1159  {
1160  const unsigned int integration_points_number = msGeometryData.IntegrationPointsNumber( ThisMethod );
1161  if(rResult.size() != integration_points_number)
1162  {
1163  rResult.resize(integration_points_number,false);
1164  }
1165 
1166  const double detJ = 2.0*(this->Area());
1167 
1168  for ( unsigned int pnt = 0; pnt < integration_points_number; pnt++ )
1169  {
1170  rResult[pnt] = detJ;
1171  }
1172  return rResult;
1173  }
1174 
1195  IntegrationMethod ThisMethod ) const override
1196  {
1197  return 2.0*(this->Area());
1198  }
1199 
1213  double DeterminantOfJacobian( const CoordinatesArrayType& rPoint ) const override
1214  {
1215  return 2.0*(this->Area());
1216  }
1217 
1221 
1233  SizeType EdgesNumber() const override
1234  {
1235  return 3;
1236  }
1237 
1247  {
1249  edges.push_back( Kratos::make_shared<EdgeType>( this->pGetPoint( 1 ), this->pGetPoint( 2 ) ) );
1250  edges.push_back( Kratos::make_shared<EdgeType>( this->pGetPoint( 2 ), this->pGetPoint( 0 ) ) );
1251  edges.push_back( Kratos::make_shared<EdgeType>( this->pGetPoint( 0 ), this->pGetPoint( 1 ) ) );
1252  return edges;
1253  }
1254 
1258 
1266  SizeType FacesNumber() const override
1267  {
1268  return 1;
1269  }
1270 
1280  {
1282 
1283  faces.push_back( Kratos::make_shared<FaceType>( this->pGetPoint( 0 ), this->pGetPoint( 1 ), this->pGetPoint( 2 )) );
1284  return faces;
1285  }
1286 
1287  //Connectivities of faces required
1289  {
1290  if(NumberNodesInFaces.size() != 3 )
1291  NumberNodesInFaces.resize(3,false);
1292  // Linear Triangles have elements of 2 nodes as faces
1293  NumberNodesInFaces[0]=2;
1294  NumberNodesInFaces[1]=2;
1295  NumberNodesInFaces[2]=2;
1296 
1297  }
1298 
1300  {
1301  // faces in columns
1302  if(NodesInFaces.size1() != 3 || NodesInFaces.size2() != 3)
1303  NodesInFaces.resize(3,3,false);
1304 
1305  //face 1
1306  NodesInFaces(0,0)=0;//contrary node to the face
1307  NodesInFaces(1,0)=1;
1308  NodesInFaces(2,0)=2;
1309  //face 2
1310  NodesInFaces(0,1)=1;//contrary node to the face
1311  NodesInFaces(1,1)=2;
1312  NodesInFaces(2,1)=0;
1313  //face 3
1314  NodesInFaces(0,2)=2;//contrary node to the face
1315  NodesInFaces(1,2)=0;
1316  NodesInFaces(2,2)=1;
1317 
1318  }
1319 
1320 
1329  GeometriesArrayType Faces( void ) override
1330  {
1331  return GeometriesArrayType();
1332  }
1333 
1334 
1338 
1348  double ShapeFunctionValue( IndexType ShapeFunctionIndex,
1349  const CoordinatesArrayType& rPoint ) const override
1350  {
1351  switch ( ShapeFunctionIndex )
1352  {
1353  case 0:
1354  return( 1.0 -rPoint[0] - rPoint[1] );
1355  case 1:
1356  return( rPoint[0] );
1357  case 2:
1358  return( rPoint[1] );
1359  default:
1360  KRATOS_ERROR << "Wrong index of shape function!" << *this << std::endl;
1361  }
1362 
1363  return 0;
1364  }
1365 
1378  Vector& ShapeFunctionsValues (Vector &rResult, const CoordinatesArrayType& rCoordinates) const override
1379  {
1380  if(rResult.size() != 3)
1381  {
1382  rResult.resize(3,false);
1383  }
1384 
1385  rResult[0] = 1.0 -rCoordinates[0] - rCoordinates[1];
1386  rResult[1] = rCoordinates[0] ;
1387  rResult[2] = rCoordinates[1] ;
1388 
1389  return rResult;
1390  }
1391 
1395 
1403  std::string Info() const override
1404  {
1405  return "2 dimensional triangle with three nodes in 3D space";
1406  }
1407 
1414  void PrintInfo( std::ostream& rOStream ) const override
1415  {
1416  rOStream << "2 dimensional triangle with three nodes in 3D space";
1417  }
1418 
1433  void PrintData( std::ostream& rOStream ) const override
1434  {
1435  // Base Geometry class PrintData call
1436  BaseType::PrintData( rOStream );
1437  std::cout << std::endl;
1438 
1439  // If the geometry has valid points, calculate and output its data
1440  if (this->AllPointsAreValid()) {
1441  Matrix jacobian;
1442  this->Jacobian( jacobian, PointType() );
1443  rOStream << " Jacobian in the origin\t : " << jacobian;
1444  }
1445  }
1446 
1452  IntegrationMethod ThisMethod )
1453  {
1454  ShapeFunctionsGradientsType localGradients
1455  = CalculateShapeFunctionsIntegrationPointsLocalGradients( ThisMethod );
1456  const int integration_points_number
1457  = msGeometryData.IntegrationPointsNumber( ThisMethod );
1458  ShapeFunctionsGradientsType Result( integration_points_number );
1459 
1460  for ( int pnt = 0; pnt < integration_points_number; pnt++ )
1461  {
1462  Result[pnt] = localGradients[pnt];
1463  }
1464 
1465  return Result;
1466  }
1467 
1473  {
1474  IntegrationMethod ThisMethod = msGeometryData.DefaultIntegrationMethod();
1475  ShapeFunctionsGradientsType localGradients
1476  = CalculateShapeFunctionsIntegrationPointsLocalGradients( ThisMethod );
1477  const int integration_points_number
1478  = msGeometryData.IntegrationPointsNumber( ThisMethod );
1479  ShapeFunctionsGradientsType Result( integration_points_number );
1480 
1481  for ( int pnt = 0; pnt < integration_points_number; pnt++ )
1482  {
1483  Result[pnt] = localGradients[pnt];
1484  }
1485 
1486  return Result;
1487  }
1488 
1499  const CoordinatesArrayType& rPoint ) const override
1500  {
1501  rResult.resize( 3, 2 ,false);
1502  noalias( rResult ) = ZeroMatrix( 3, 2 );
1503  rResult( 0, 0 ) = -1.0;
1504  rResult( 0, 1 ) = -1.0;
1505  rResult( 1, 0 ) = 1.0;
1506  rResult( 1, 1 ) = 0.0;
1507  rResult( 2, 0 ) = 0.0;
1508  rResult( 2, 1 ) = 1.0;
1509  return rResult;
1510  }
1511 
1512 
1513 
1523  virtual Matrix& ShapeFunctionsGradients( Matrix& rResult, PointType& rPoint )
1524  {
1525  rResult.resize( 3, 2,false );
1526  noalias( rResult ) = ZeroMatrix( 3, 2 );
1527  rResult( 0, 0 ) = -1.0;
1528  rResult( 0, 1 ) = -1.0;
1529  rResult( 1, 0 ) = 1.0;
1530  rResult( 1, 1 ) = 0.0;
1531  rResult( 2, 0 ) = 0.0;
1532  rResult( 2, 1 ) = 1.0;
1533  return rResult;
1534  }
1535 
1543  {
1544  if ( rResult.size() != this->PointsNumber() )
1545  {
1546  // KLUDGE: While there is a bug in
1547  // ublas vector resize, I have to put this beside resizing!!
1549  rResult.swap( temp );
1550  }
1551 
1552  rResult[0].resize( 2, 2 ,false);
1553 
1554  rResult[1].resize( 2, 2 ,false);
1555  rResult[2].resize( 2, 2 ,false);
1556  rResult[0]( 0, 0 ) = 0.0;
1557  rResult[0]( 0, 1 ) = 0.0;
1558  rResult[0]( 1, 0 ) = 0.0;
1559  rResult[0]( 1, 1 ) = 0.0;
1560  rResult[1]( 0, 0 ) = 0.0;
1561  rResult[1]( 0, 1 ) = 0.0;
1562  rResult[1]( 1, 0 ) = 0.0;
1563  rResult[1]( 1, 1 ) = 0.0;
1564  rResult[2]( 0, 0 ) = 0.0;
1565  rResult[2]( 0, 1 ) = 0.0;
1566  rResult[2]( 1, 0 ) = 0.0;
1567  rResult[2]( 1, 1 ) = 0.0;
1568  return rResult;
1569  }
1570 
1578  {
1579  if ( rResult.size() != this->PointsNumber() )
1580  {
1581  // KLUDGE: While there is a bug in
1582  // ublas vector resize, I have to put this beside resizing!!
1583 // ShapeFunctionsGradientsType
1585  rResult.swap( temp );
1586  }
1587 
1588  for ( IndexType i = 0; i < rResult.size(); i++ )
1589  {
1591  rResult[i].swap( temp );
1592  }
1593 
1594  rResult[0][0].resize( 2, 2 ,false);
1595 
1596  rResult[0][1].resize( 2, 2 ,false);
1597  rResult[1][0].resize( 2, 2 ,false);
1598  rResult[1][1].resize( 2, 2 ,false);
1599  rResult[2][0].resize( 2, 2 ,false);
1600  rResult[2][1].resize( 2, 2 ,false);
1601 
1602  for ( int i = 0; i < 3; i++ )
1603  {
1604  rResult[i][0]( 0, 0 ) = 0.0;
1605  rResult[i][0]( 0, 1 ) = 0.0;
1606  rResult[i][0]( 1, 0 ) = 0.0;
1607  rResult[i][0]( 1, 1 ) = 0.0;
1608  rResult[i][1]( 0, 0 ) = 0.0;
1609  rResult[i][1]( 0, 1 ) = 0.0;
1610  rResult[i][1]( 1, 0 ) = 0.0;
1611  rResult[i][1]( 1, 1 ) = 0.0;
1612  }
1613 
1614  return rResult;
1615  }
1616 
1620 
1650  KRATOS_DEPRECATED_MESSAGE("This method is deprecated. Use either \'ProjectionPointLocalToLocalSpace\' or \'ProjectionPointGlobalToLocalSpace\' instead.")
1652  const CoordinatesArrayType& rPointGlobalCoordinates,
1653  CoordinatesArrayType& rProjectedPointGlobalCoordinates,
1654  CoordinatesArrayType& rProjectedPointLocalCoordinates,
1655  const double Tolerance = std::numeric_limits<double>::epsilon()
1656  ) const override
1657  {
1658  KRATOS_WARNING("ProjectionPoint") << "This method is deprecated. Use either \'ProjectionPointLocalToLocalSpace\' or \'ProjectionPointGlobalToLocalSpace\' instead." << std::endl;
1659 
1660  ProjectionPointGlobalToLocalSpace(rPointGlobalCoordinates, rProjectedPointLocalCoordinates, Tolerance);
1661 
1662  this->GlobalCoordinates(rProjectedPointGlobalCoordinates, rProjectedPointLocalCoordinates);
1663 
1664  return 1;
1665  }
1666 
1668  const CoordinatesArrayType& rPointLocalCoordinates,
1669  CoordinatesArrayType& rProjectionPointLocalCoordinates,
1670  const double Tolerance = std::numeric_limits<double>::epsilon()
1671  ) const override
1672  {
1673  for (std::size_t i = 0; i < 3; ++i) {
1674  rProjectionPointLocalCoordinates[i] = (rPointLocalCoordinates[i] < 0.0) ? 0.0 : rPointLocalCoordinates[i];
1675  rProjectionPointLocalCoordinates[i] = (rPointLocalCoordinates[i] > 1.0) ? 1.0 : rPointLocalCoordinates[i];
1676  }
1677 
1678  return 1;
1679  }
1680 
1682  const CoordinatesArrayType& rPointGlobalCoordinates,
1683  CoordinatesArrayType& rProjectionPointLocalCoordinates,
1684  const double Tolerance = std::numeric_limits<double>::epsilon()
1685  ) const override
1686  {
1687  // Calculate the point of interest global coordinates
1688  // Note that rProjectionPointLocalCoordinates is used as initial guess
1689  PointLocalCoordinates(rProjectionPointLocalCoordinates, rPointGlobalCoordinates);
1690 
1691  // Calculate the projection point local coordinates from the input point local coordinates
1692  CoordinatesArrayType point_local_coordinates(rProjectionPointLocalCoordinates);
1693  return ProjectionPointLocalToLocalSpace(point_local_coordinates, rProjectionPointLocalCoordinates);
1694  }
1695 
1699 
1701 
1702 protected:
1707 private:
1710 
1711  static const GeometryData msGeometryData;
1712 
1713  static const GeometryDimension msGeometryDimension;
1714 
1718 
1719  friend class Serializer;
1720 
1721  void save( Serializer& rSerializer ) const override
1722  {
1724  }
1725 
1726  void load( Serializer& rSerializer ) override
1727  {
1729  }
1730 
1731  Triangle3D3(): BaseType( PointsArrayType(), &msGeometryData ) {}
1732 
1736 
1737 
1741 
1742 
1746 
1754  static Matrix CalculateShapeFunctionsIntegrationPointsValues(
1755  typename BaseType::IntegrationMethod ThisMethod )
1756  {
1757  IntegrationPointsContainerType all_integration_points =
1758  AllIntegrationPoints();
1759  IntegrationPointsArrayType integration_points = all_integration_points[static_cast<int>(ThisMethod)];
1760  //number of integration points
1761  const int integration_points_number = integration_points.size();
1762  //number of nodes in current geometry
1763  const int points_number = 3;
1764  //setting up return matrix
1765  Matrix shape_function_values( integration_points_number, points_number );
1766  //loop over all integration points
1767 
1768  for ( int pnt = 0; pnt < integration_points_number; pnt++ )
1769  {
1770  row( shape_function_values, pnt )[0] = 1.0
1771  - integration_points[pnt].X()
1772  - integration_points[pnt].Y();
1773  row( shape_function_values, pnt )[1] = integration_points[pnt].X();
1774  row( shape_function_values, pnt )[2] = integration_points[pnt].Y();
1775  }
1776 
1777  return shape_function_values;
1778  }
1779 
1790  CalculateShapeFunctionsIntegrationPointsLocalGradients(
1791  typename BaseType::IntegrationMethod ThisMethod )
1792  {
1793  IntegrationPointsContainerType all_integration_points =
1794  AllIntegrationPoints();
1795  IntegrationPointsArrayType integration_points = all_integration_points[static_cast<int>(ThisMethod)];
1796  //number of integration points
1797  const int integration_points_number = integration_points.size();
1798  ShapeFunctionsGradientsType d_shape_f_values( integration_points_number );
1799  //initialising container
1800  //std::fill(d_shape_f_values.begin(), d_shape_f_values.end(), Matrix(4,2));
1801  //loop over all integration points
1802 
1803  for ( int pnt = 0; pnt < integration_points_number; pnt++ )
1804  {
1805  Matrix result( 3, 2 );
1806  result( 0, 0 ) = -1.0;
1807  result( 0, 1 ) = -1.0;
1808  result( 1, 0 ) = 1.0;
1809  result( 1, 1 ) = 0.0;
1810  result( 2, 0 ) = 0.0;
1811  result( 2, 1 ) = 1.0;
1812  d_shape_f_values[pnt] = result;
1813  }
1814 
1815  return d_shape_f_values;
1816  }
1817 
1821  static const IntegrationPointsContainerType AllIntegrationPoints()
1822  {
1823  IntegrationPointsContainerType integration_points =
1824  {
1825  {
1826  Quadrature<TriangleGaussLegendreIntegrationPoints1, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1827  Quadrature<TriangleGaussLegendreIntegrationPoints2, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1828  Quadrature<TriangleGaussLegendreIntegrationPoints3, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1829  Quadrature<TriangleGaussLegendreIntegrationPoints4, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1830  Quadrature<TriangleGaussLegendreIntegrationPoints5, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1831  Quadrature<TriangleCollocationIntegrationPoints1, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1832  Quadrature<TriangleCollocationIntegrationPoints2, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1833  Quadrature<TriangleCollocationIntegrationPoints3, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1834  Quadrature<TriangleCollocationIntegrationPoints4, 2, IntegrationPoint<3> >::GenerateIntegrationPoints(),
1835  Quadrature<TriangleCollocationIntegrationPoints5, 2, IntegrationPoint<3> >::GenerateIntegrationPoints()
1836  }
1837  };
1838  return integration_points;
1839  }
1840 
1844  static const ShapeFunctionsValuesContainerType AllShapeFunctionsValues()
1845  {
1846  ShapeFunctionsValuesContainerType shape_functions_values =
1847  {
1848  {
1849  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1851  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1853  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1855  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1857  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1859  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1861  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1863  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1865  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1867  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsValues(
1869  }
1870  };
1871  return shape_functions_values;
1872  }
1873 
1878  AllShapeFunctionsLocalGradients()
1879  {
1880  ShapeFunctionsLocalGradientsContainerType shape_functions_local_gradients =
1881  {
1882  {
1883  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_GAUSS_1 ),
1884  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_GAUSS_2 ),
1885  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_GAUSS_3 ),
1886  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_GAUSS_4 ),
1887  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_GAUSS_5 ),
1888  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_EXTENDED_GAUSS_1 ),
1889  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_EXTENDED_GAUSS_2 ),
1890  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_EXTENDED_GAUSS_3 ),
1891  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_EXTENDED_GAUSS_4 ),
1892  Triangle3D3<TPointType>::CalculateShapeFunctionsIntegrationPointsLocalGradients( GeometryData::IntegrationMethod::GI_EXTENDED_GAUSS_5 )
1893  }
1894  };
1895  return shape_functions_local_gradients;
1896  }
1897 
1907  inline double CalculateMinEdgeLength(const double a, const double b, const double c) const {
1908  return std::sqrt(std::min({a, b, c}));
1909  }
1910 
1920  inline double CalculateMaxEdgeLength(const double a, const double b, const double c) const {
1921  return std::sqrt(std::max({a, b, c}));
1922  }
1923 
1933  inline double CalculateAvgEdgeLength(const double a, const double b, const double c) const {
1934  constexpr double onethird = 1.0 / 3.0;
1935  return (a+b+c) * onethird;
1936  }
1937 
1947  inline double CalculateCircumradius(const double a, const double b, const double c) const {
1948  return (a*b*c) / std::sqrt((a+b+c) * (b+c-a) * (c+a-b) * (a+b-c));
1949  }
1950 
1960  inline double CalculateInradius(const double a, const double b, const double c) const {
1961  return 0.5 * std::sqrt((b+c-a) * (c+a-b) * (a+b-c) / (a+b+c));
1962  }
1963 
1964  bool LineTriangleOverlap(
1965  const Point& rPoint1,
1966  const Point& rPoint2) const
1967  {
1968  array_1d<double,3> intersection_point;
1969  const int result = IntersectionUtilities::ComputeTriangleLineIntersection(*this, rPoint1, rPoint2, intersection_point);
1970  return result == 1 ? true : false;
1971  }
1972 
1973  bool TriangleTriangleOverlap(
1974  const Point& rPoint1,
1975  const Point& rPoint2,
1976  const Point& rPoint3) const
1977  {
1978  // Based on code develop by Moller: http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/opttritri.txt
1979  // and the article "A Fast Triangle-Triangle Intersection Test", Journal of Graphics Tools, 2(2), 1997:
1980  // http://web.stanford.edu/class/cs277/resources/papers/Moller1997b.pdf
1981 
1982  Plane3D plane_1(this->GetPoint(0), this->GetPoint(1), this->GetPoint(2));
1983  array_1d<double, 3> distances_1;
1984  distances_1[0] = plane_1.CalculateSignedDistance(rPoint1);
1985  distances_1[1] = plane_1.CalculateSignedDistance(rPoint2);
1986  distances_1[2] = plane_1.CalculateSignedDistance(rPoint3);
1987  if (AllSameSide(distances_1))
1988  return false;
1989 
1990  Plane3D plane_2(rPoint1, rPoint2, rPoint3);
1991  array_1d<double, 3> distances_2;
1992  for (int i = 0; i < 3; ++i)
1993  distances_2[i] = plane_2.CalculateSignedDistance(this->GetPoint(i));
1994  if (AllSameSide(distances_2))
1995  return false;
1996 
1997  // compute direction of intersection line //
1998  array_1d<double, 3> intersection_direction;
1999  MathUtils<double>::CrossProduct(intersection_direction, plane_1.GetNormal(), plane_2.GetNormal());
2000 
2001  int index = GetMajorAxis(intersection_direction);
2002 
2003  // this is the simplified projection onto L//
2004  double vp0 = this->GetPoint(0)[index];
2005  double vp1 = this->GetPoint(1)[index];
2006  double vp2 = this->GetPoint(2)[index];
2007 
2008  double up0 = rPoint1[index];
2009  double up1 = rPoint2[index];
2010  double up2 = rPoint3[index];
2011 
2012  // compute interval for triangle 1 //
2013  double a, b, c, x0, x1;
2014  if (ComputeIntervals(vp0, vp1, vp2, distances_2[0], distances_2[1], distances_2[2], a, b, c, x0, x1))
2015  {
2016  return CoplanarIntersectionCheck(plane_1.GetNormal(), rPoint1, rPoint2, rPoint3);
2017  }
2018 
2019  // compute interval for triangle 2 //
2020  double d, e, f, y0, y1;
2021  if (ComputeIntervals(up0, up1, up2, distances_1[0], distances_1[1], distances_1[2], d, e, f, y0, y1))
2022 
2023  {
2024  return CoplanarIntersectionCheck(plane_1.GetNormal(), rPoint1, rPoint2, rPoint3);
2025  }
2026 
2027  double xx, yy, xxyy, tmp;
2028  xx = x0*x1;
2029  yy = y0*y1;
2030  xxyy = xx*yy;
2031 
2032  array_1d<double, 2> isect1, isect2;
2033 
2034  tmp = a*xxyy;
2035  isect1[0] = tmp + b*x1*yy;
2036  isect1[1] = tmp + c*x0*yy;
2037 
2038  tmp = d*xxyy;
2039  isect2[0] = tmp + e*xx*y1;
2040  isect2[1] = tmp + f*xx*y0;
2041 
2042  if (isect1[0] > isect1[1]) {
2043  isect1[1] = isect1[0] + isect1[1];
2044  isect1[0] = isect1[1] - isect1[0];
2045  isect1[1] = isect1[1] - isect1[0];
2046  }
2047 
2048  if (isect2[0] > isect2[1]) {
2049  isect2[1] = isect2[0] + isect2[1];
2050  isect2[0] = isect2[1] - isect2[0];
2051  isect2[1] = isect2[1] - isect2[0];
2052  }
2053 
2054  return (isect1[1]<isect2[0] || isect2[1]<isect1[0]) ? false : true;
2055  }
2056 
2057  bool ComputeIntervals(
2058  double& VV0,
2059  double& VV1,
2060  double& VV2,
2061  double& D0,
2062  double& D1,
2063  double& D2,
2064  double& A,
2065  double& B,
2066  double& C,
2067  double& X0,
2068  double& X1
2069  ) const
2070  {
2071  double D0D1 = D0 * D1;
2072  double D0D2 = D0 * D2;
2073 
2074  if (D0D1 > 0.0) {
2075  // here we know that D0D2<=0.0 //
2076  // that is D0, D1 are on the same side, D2 on the other or on the plane //
2077  A = VV2;
2078  B = (VV0 - VV2)*D2;
2079  C = (VV1 - VV2)*D2;
2080  X0 = D2 - D0;
2081  X1 = D2 - D1;
2082  }
2083  else if (D0D2 > 0.0) {
2084  // here we know that d0d1<=0.0 //
2085  A = VV1;
2086  B = (VV0 - VV1)*D1;
2087  C = (VV2 - VV1)*D1;
2088  X0 = D1 - D0;
2089  X1 = D1 - D2;
2090  }
2091  else if (D1 * D2 > 0.00 || D0 != 0.00) {
2092  // here we know that d0d1<=0.0 or that D0!=0.0 //
2093  A = VV0;
2094  B = (VV1 - VV0)*D0;
2095  C = (VV2 - VV0)*D0;
2096  X0 = D0 - D1;
2097  X1 = D0 - D2;
2098  }
2099  else if (D1 != 0.00) {
2100  A = VV1;
2101  B = (VV0 - VV1)*D1;
2102  C = (VV2 - VV1)*D1;
2103  X0 = D1 - D0;
2104  X1 = D1 - D2;
2105  }
2106  else if (D2 != 0.00) {
2107  A = VV2;
2108  B = (VV0 - VV2)*D2;
2109  C = (VV1 - VV2)*D2;
2110  X0 = D2 - D0;
2111  X1 = D2 - D1;
2112  }
2113  else { // Triangles are coplanar
2114  return true;
2115  }
2116  return false;
2117  }
2118 
2119  bool CoplanarIntersectionCheck(
2120  const array_1d<double,3>& N,
2121  const Point& rPoint1,
2122  const Point& rPoint2,
2123  const Point& rPoint3) const
2124  {
2125  array_1d<double, 3 > A;
2126  int i0, i1;
2127 
2128  // first project onto an axis-aligned plane, that maximizes the area //
2129  // of the triangles, compute indices: i0,i1. //
2130  A[0] = std::abs(N[0]);
2131  A[1] = std::abs(N[1]);
2132  A[2] = std::abs(N[2]);
2133  if (A[0] > A[1]) {
2134  if (A[0] > A[2]) {
2135  i0 = 1; // A[0] is greatest //
2136  i1 = 2;
2137  } else {
2138  i0 = 0; // A[2] is greatest //
2139  i1 = 1;
2140  }
2141  } else { // A[0] <= A[1] //
2142  if (A[2] > A[1]) {
2143  i0 = 0; // A[2] is greatest //
2144  i1 = 1;
2145  } else {
2146  i0 = 0; // A[1] is greatest //
2147  i1 = 2;
2148  }
2149  }
2150 
2151  // test all edges of triangle 1 against the edges of triangle 2 //
2152  if (EdgeToTriangleEdgesCheck(i0, i1, this->GetPoint(0), this->GetPoint(1), rPoint1, rPoint2, rPoint3)) return true;
2153  if (EdgeToTriangleEdgesCheck(i0, i1, this->GetPoint(1), this->GetPoint(2), rPoint1, rPoint2, rPoint3)) return true;
2154  if (EdgeToTriangleEdgesCheck(i0, i1, this->GetPoint(2), this->GetPoint(0), rPoint1, rPoint2, rPoint3)) return true;
2155 
2156 
2157  // finally, test if tri1 is totally contained in tri2 or vice versa //
2158  if (PointInTriangle(i0, i1, this->GetPoint(0), rPoint1, rPoint2, rPoint3)) return true;
2159  else if (PointInTriangle(i0, i1, rPoint1, this->GetPoint(0), this->GetPoint(1), this->GetPoint(2))) return true;
2160 
2161  return false;
2162  }
2163 
2164  bool EdgeToTriangleEdgesCheck(
2165  const int& i0,
2166  const int& i1,
2167  const Point& V0,
2168  const Point& V1,
2169  const Point&U0,
2170  const Point&U1,
2171  const Point&U2) const
2172  {
2173  double Ax, Ay, Bx, By, Cx, Cy, e, d, f;
2174  Ax = V1[i0] - V0[i0];
2175  Ay = V1[i1] - V0[i1];
2176 
2177  // test edge U0,U1 against V0,V1 //
2178  if (EdgeToEdgeIntersectionCheck(Ax, Ay, Bx, By, Cx, Cy, e, d, f, i0, i1, V0, U0, U1) == true) return true;
2179 
2180  // test edge U1,U2 against V0,V1 //
2181  if (EdgeToEdgeIntersectionCheck(Ax, Ay, Bx, By, Cx, Cy, e, d, f, i0, i1, V0, U1, U2) == true) return true;
2182 
2183  // test edge U2,U1 against V0,V1 //
2184  if (EdgeToEdgeIntersectionCheck(Ax, Ay, Bx, By, Cx, Cy, e, d, f, i0, i1, V0, U2, U0) == true) return true;
2185 
2186  return false;
2187  }
2188 
2189  // this edge to edge test is based on Franlin Antonio's gem:
2190  // "Faster Line Segment Intersection", in Graphics Gems III,
2191  // pp. 199-202
2192  bool EdgeToEdgeIntersectionCheck(
2193  double& Ax,
2194  double& Ay,
2195  double& Bx,
2196  double& By,
2197  double& Cx,
2198  double& Cy,
2199  double& e,
2200  double& d,
2201  double& f,
2202  const int& i0,
2203  const int& i1,
2204  const Point& V0,
2205  const Point& U0,
2206  const Point& U1) const
2207  {
2208  Bx = U0[i0] - U1[i0];
2209  By = U0[i1] - U1[i1];
2210  Cx = V0[i0] - U0[i0];
2211  Cy = V0[i1] - U0[i1];
2212  f = Ay*Bx - Ax*By;
2213  d = By*Cx - Bx*Cy;
2214 
2215  if (std::abs(f) < 1E-10) f = 0.00;
2216  if (std::abs(d) < 1E-10) d = 0.00;
2217 
2218  if ((f>0.00 && d >= 0.00 && d <= f) || (f<0.00 && d <= 0.00 && d >= f)) {
2219  e = Ax*Cy - Ay*Cx;
2220 
2221  if (f > 0.0) {
2222  if (e >= 0.0 && e <= f) return true;
2223  } else {
2224  if (e <= 0.0 && e >= f) return true;
2225  }
2226  }
2227  return false;
2228  }
2229 
2230  bool PointInTriangle(
2231  int i0,
2232  int i1,
2233  const Point& V0,
2234  const Point& U0,
2235  const Point& U1,
2236  const Point& U2) const
2237  {
2238  double a,b,c,d0,d1,d2;
2239  /* is T1 completely inside T2? */
2240  /* check if V0 is inside tri(U0,U1,U2) */
2241  a = U1[i1] - U0[i1];
2242  b = -(U1[i0] - U0[i0]);
2243  c = -a * U0[i0] -b * U0[i1];
2244  d0= a * V0[i0] +b * V0[i1] + c;
2245 
2246  a = U2[i1] - U1[i1];
2247  b = -(U2[i0] - U1[i0]);
2248  c = -a * U1[i0] -b * U1[i1];
2249  d1= a * V0[i0] +b * V0[i1] + c;
2250 
2251  a = U0[i1] - U2[i1];
2252  b = -(U0[i0] - U2[i0]);
2253  c = -a * U2[i0] - b * U2[i1];
2254  d2 = a * V0[i0] + b * V0[i1] + c;
2255 
2256  if (d0 * d1 > 0.0){
2257  if (d0 * d2 > 0.0) return true;
2258  }
2259  return false;
2260  }
2261 
2270  inline bool TriBoxOverlap(Point& rBoxCenter, Point& rBoxHalfSize) const
2271  {
2272  double abs_ex, abs_ey, abs_ez, distance;
2273  array_1d<double,3 > vert0, vert1, vert2;
2274  array_1d<double,3 > edge0, edge1, edge2, normal;
2275  std::pair<double, double> min_max;
2276 
2277  // move everything so that the boxcenter is in (0,0,0)
2278  noalias(vert0) = this->GetPoint(0) - rBoxCenter;
2279  noalias(vert1) = this->GetPoint(1) - rBoxCenter;
2280  noalias(vert2) = this->GetPoint(2) - rBoxCenter;
2281 
2282  // compute triangle edges
2283  noalias(edge0) = vert1 - vert0;
2284  noalias(edge1) = vert2 - vert1;
2285  noalias(edge2) = vert0 - vert2;
2286 
2287  // Bullet 3:
2288  // test the 9 tests first (this was faster)
2289  abs_ex = std::abs(edge0[0]);
2290  abs_ey = std::abs(edge0[1]);
2291  abs_ez = std::abs(edge0[2]);
2292  if (AxisTestX(edge0[1],edge0[2],abs_ey,abs_ez,vert0,vert2,rBoxHalfSize)) return false;
2293  if (AxisTestY(edge0[0],edge0[2],abs_ex,abs_ez,vert0,vert2,rBoxHalfSize)) return false;
2294  if (AxisTestZ(edge0[0],edge0[1],abs_ex,abs_ey,vert0,vert2,rBoxHalfSize)) return false;
2295 
2296  abs_ex = std::abs(edge1[0]);
2297  abs_ey = std::abs(edge1[1]);
2298  abs_ez = std::abs(edge1[2]);
2299  if (AxisTestX(edge1[1],edge1[2],abs_ey,abs_ez,vert1,vert0,rBoxHalfSize)) return false;
2300  if (AxisTestY(edge1[0],edge1[2],abs_ex,abs_ez,vert1,vert0,rBoxHalfSize)) return false;
2301  if (AxisTestZ(edge1[0],edge1[1],abs_ex,abs_ey,vert1,vert0,rBoxHalfSize)) return false;
2302 
2303  abs_ex = std::abs(edge2[0]);
2304  abs_ey = std::abs(edge2[1]);
2305  abs_ez = std::abs(edge2[2]);
2306  if (AxisTestX(edge2[1],edge2[2],abs_ey,abs_ez,vert2,vert1,rBoxHalfSize)) return false;
2307  if (AxisTestY(edge2[0],edge2[2],abs_ex,abs_ez,vert2,vert1,rBoxHalfSize)) return false;
2308  if (AxisTestZ(edge2[0],edge2[1],abs_ex,abs_ey,vert2,vert1,rBoxHalfSize)) return false;
2309 
2310  // Bullet 1:
2311  // first test overlap in the {x,y,z}-directions
2312  // find min, max of the triangle for each direction, and test for
2313  // overlap in that direction -- this is equivalent to testing a minimal
2314  // AABB around the triangle against the AABB
2315 
2316  // test in X-direction
2317  min_max = std::minmax({vert0[0], vert1[0], vert2[0]});
2318  if(min_max.first>rBoxHalfSize[0] || min_max.second<-rBoxHalfSize[0]) return false;
2319 
2320  // test in Y-direction
2321  min_max = std::minmax({vert0[1], vert1[1], vert2[1]});
2322  if(min_max.first>rBoxHalfSize[1] || min_max.second<-rBoxHalfSize[1]) return false;
2323 
2324  // test in Z-direction
2325  min_max = std::minmax({vert0[2], vert1[2], vert2[2]});
2326  if(min_max.first>rBoxHalfSize[2] || min_max.second<-rBoxHalfSize[2]) return false;
2327 
2328  // Bullet 2:
2329  // test if the box intersects the plane of the triangle
2330  // compute plane equation of triangle: normal*x+distance=0
2331  MathUtils<double>::CrossProduct(normal, edge0, edge1);
2332  distance = -inner_prod(normal, vert0);
2333  if(!PlaneBoxOverlap(normal, distance, rBoxHalfSize)) return false;
2334 
2335  return true; // box and triangle overlaps
2336  }
2337 
2349  bool PlaneBoxOverlap(const array_1d<double,3>& rNormal, const double& rDist, const array_1d<double,3>& rMaxBox) const
2350  {
2351  array_1d<double,3> vmin, vmax;
2352  for(int q = 0; q < 3; q++)
2353  {
2354  if(rNormal[q] > 0.00)
2355  {
2356  vmin[q] = -rMaxBox[q];
2357  vmax[q] = rMaxBox[q];
2358  }
2359  else
2360  {
2361  vmin[q] = rMaxBox[q];
2362  vmax[q] = -rMaxBox[q];
2363  }
2364  }
2365  if(inner_prod(rNormal, vmin) + rDist > 0.00) return false;
2366  if(inner_prod(rNormal, vmax) + rDist >= 0.00) return true;
2367 
2368  return false;
2369  }
2370 
2381  bool AxisTestX(double& rEdgeY, double& rEdgeZ,
2382  double& rAbsEdgeY, double& rAbsEdgeZ,
2383  array_1d<double,3>& rVertA,
2384  array_1d<double,3>& rVertC,
2385  Point& rBoxHalfSize) const
2386  {
2387  double proj_a, proj_c, rad;
2388  proj_a = rEdgeY*rVertA[2] - rEdgeZ*rVertA[1];
2389  proj_c = rEdgeY*rVertC[2] - rEdgeZ*rVertC[1];
2390  std::pair<double, double> min_max = std::minmax(proj_a, proj_c);
2391 
2392  rad = rAbsEdgeZ*rBoxHalfSize[1] + rAbsEdgeY*rBoxHalfSize[2];
2393 
2394  if(min_max.first>rad || min_max.second<-rad) return true;
2395  else return false;
2396  }
2397 
2408  bool AxisTestY(double& rEdgeX, double& rEdgeZ,
2409  double& rAbsEdgeX, double& rAbsEdgeZ,
2410  array_1d<double,3>& rVertA,
2411  array_1d<double,3>& rVertC,
2412  Point& rBoxHalfSize) const
2413  {
2414  double proj_a, proj_c, rad;
2415  proj_a = rEdgeZ*rVertA[0] - rEdgeX*rVertA[2];
2416  proj_c = rEdgeZ*rVertC[0] - rEdgeX*rVertC[2];
2417  std::pair<double, double> min_max = std::minmax(proj_a, proj_c);
2418 
2419  rad = rAbsEdgeZ*rBoxHalfSize[0] + rAbsEdgeX*rBoxHalfSize[2];
2420 
2421  if(min_max.first>rad || min_max.second<-rad) return true;
2422  else return false;
2423  }
2424 
2435  bool AxisTestZ(double& rEdgeX, double& rEdgeY,
2436  double& rAbsEdgeX, double& rAbsEdgeY,
2437  array_1d<double,3>& rVertA,
2438  array_1d<double,3>& rVertC,
2439  Point& rBoxHalfSize) const
2440  {
2441  double proj_a, proj_c, rad;
2442  proj_a = rEdgeX*rVertA[1] - rEdgeY*rVertA[0];
2443  proj_c = rEdgeX*rVertC[1] - rEdgeY*rVertC[0];
2444  std::pair<double, double> min_max = std::minmax(proj_a, proj_c);
2445 
2446  rad = rAbsEdgeY*rBoxHalfSize[0] + rAbsEdgeX*rBoxHalfSize[1];
2447 
2448  if(min_max.first>rad || min_max.second<-rad) return true;
2449  else return false;
2450  }
2451 
2455 
2456 
2460 
2461 
2465 
2466  template<class TOtherPointType> friend class Triangle3D3;
2467 
2471 
2472 
2473 
2475 }; // Class Geometry
2476 
2480 
2481 
2485 
2488 template<class TPointType> inline std::istream& operator >> (
2489  std::istream& rIStream,
2490  Triangle3D3<TPointType>& rThis );
2494 template<class TPointType> inline std::ostream& operator << (
2495  std::ostream& rOStream,
2496  const Triangle3D3<TPointType>& rThis )
2497 {
2498  rThis.PrintInfo( rOStream );
2499  rOStream << std::endl;
2500  rThis.PrintData( rOStream );
2501  return rOStream;
2502 }
2503 
2505 
2506 template<class TPointType> const
2507 GeometryData Triangle3D3<TPointType>::msGeometryData(
2510  Triangle3D3<TPointType>::AllIntegrationPoints(),
2511  Triangle3D3<TPointType>::AllShapeFunctionsValues(),
2512  AllShapeFunctionsLocalGradients()
2513 );
2514 
2515 template<class TPointType>
2516 const GeometryDimension Triangle3D3<TPointType>::msGeometryDimension(3, 2);
2517 
2518 }// 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
Definition: geometry_data.h:60
KratosGeometryType
Definition: geometry_data.h:110
SizeType IntegrationPointsNumber() const
Definition: geometry_data.h:430
IntegrationMethod
Definition: geometry_data.h:76
KratosGeometryFamily
Definition: geometry_data.h:91
IntegrationMethod DefaultIntegrationMethod() const
Definition: geometry_data.h:425
Definition: geometry_dimension.h:42
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: geometry.h:3834
Geometry & operator=(const Geometry &rOther)
Definition: geometry.h:400
virtual CoordinatesArrayType & GlobalCoordinates(CoordinatesArrayType &rResult, CoordinatesArrayType const &LocalCoordinates) const
Definition: geometry.h:2377
std::vector< IntegrationPointType > IntegrationPointsArrayType
Definition: geometry.h:161
DataValueContainer & GetData()
Definition: geometry.h:591
KRATOS_DEPRECATED_MESSAGE("This is legacy version (use GenerateEdges instead)") virtual GeometriesArrayType Edges(void)
This method gives you all edges of this geometry.
Definition: geometry.h:2106
std::size_t SizeType
Definition: geometry.h:144
virtual array_1d< double, 3 > UnitNormal(const CoordinatesArrayType &rPointLocalCoordinates) const
It computes the unit normal of the geometry in the given local point.
Definition: geometry.h:1639
const TPointType::Pointer pGetPoint(const int Index) const
Definition: geometry.h:1790
std::size_t IndexType
Definition: geometry.h:137
std::array< Matrix, static_cast< int >GeometryData::IntegrationMethod::NumberOfIntegrationMethods)> ShapeFunctionsValuesContainerType
Definition: geometry.h:172
const PointsArrayType & Points() const
Definition: geometry.h:1768
bool AllPointsAreValid() const
Checks if the geometry points are valid Checks if the geometry points are valid from the pointer valu...
Definition: geometry.h:4093
std::array< IntegrationPointsArrayType, static_cast< int >GeometryData::IntegrationMethod::NumberOfIntegrationMethods)> IntegrationPointsContainerType
Definition: geometry.h:167
LumpingMethods
This defines the different methods to compute the lumping methods.
Definition: geometry.h:109
virtual GeometryData::KratosGeometryType GetGeometryType() const
Definition: geometry.h:381
virtual Point Center() const
Definition: geometry.h:1514
TPointType const & GetPoint(const int Index) const
Definition: geometry.h:1816
GeometryData::ShapeFunctionsLocalGradientsContainerType ShapeFunctionsLocalGradientsContainerType
Definition: geometry.h:177
SizeType IntegrationPointsNumber() const
Definition: geometry.h:2257
GeometryData::IntegrationMethod IntegrationMethod
Definition: geometry.h:122
static double PointDistanceToTriangle3D(const Point &rTrianglePoint1, const Point &rTrianglePoint2, const Point &rTrianglePoint3, const Point &rPoint)
This function calculates the distance of a 3D point to a 3D triangle.
Definition: geometry_utilities.cpp:172
Short class definition.
Definition: integration_point.h:52
Definition: amatrix_interface.h:41
void swap(Matrix &Other)
Definition: amatrix_interface.h:289
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
iterator end()
Definition: amatrix_interface.h:243
iterator begin()
Definition: amatrix_interface.h:241
static int ComputeTriangleLineIntersection(const TGeometryType &rTriangleGeometry, const array_1d< double, 3 > &rLinePoint1, const array_1d< double, 3 > &rLinePoint2, array_1d< double, 3 > &rIntersectionPoint, const double epsilon=1e-12)
Definition: intersection_utilities.h:101
An two node 3D line geometry with linear shape functions.
Definition: line_3d_2.h:64
Various mathematical utilitiy functions.
Definition: math_utils.h:62
static double Norm3(const TVectorType &a)
Calculates the norm of vector "a" which is assumed to be of size 3.
Definition: math_utils.h:691
static T CrossProduct(const T &a, const T &b)
Performs the vector product of the two input vectors a,b.
Definition: math_utils.h:762
This class defines the node.
Definition: node.h:65
Point class.
Definition: point.h:59
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
void push_back(const TPointerType &x)
Definition: pointer_vector.h:270
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
A three node 3D triangle geometry with linear shape functions.
Definition: triangle_3d_3.h:77
GeometryData::IntegrationMethod IntegrationMethod
Definition: triangle_3d_3.h:108
ShapeFunctionsSecondDerivativesType & ShapeFunctionsSecondDerivatives(ShapeFunctionsSecondDerivativesType &rResult, const CoordinatesArrayType &rPoint) const override
Definition: triangle_3d_3.h:1542
double DomainSize() const override
This method calculates and returns length, area or volume of this geometry depending to it's dimensio...
Definition: triangle_3d_3.h:515
GeometriesArrayType GenerateFaces() const override
Returns all faces of the current geometry.
Definition: triangle_3d_3.h:1279
BaseType::IntegrationPointType IntegrationPointType
Definition: triangle_3d_3.h:151
Triangle3D3(const std::string &rGeometryName, const PointsArrayType &rThisPoints)
Constructor with Geometry Name.
Definition: triangle_3d_3.h:256
virtual double ShortestAltitudeToLongestEdge() const
Definition: triangle_3d_3.h:830
Geometry< TPointType > GeometryType
Definition: triangle_3d_3.h:88
Matrix & Jacobian(Matrix &rResult, const CoordinatesArrayType &rPoint) const override
Definition: triangle_3d_3.h:1134
double Circumradius() const override
Definition: triangle_3d_3.h:588
double InradiusToCircumradiusQuality() const override
Quality functions.
Definition: triangle_3d_3.h:708
BaseType::JacobiansType JacobiansType
Definition: triangle_3d_3.h:186
Matrix & PointsLocalCoordinates(Matrix &rResult) const override
Definition: triangle_3d_3.h:414
double AverageEdgeLength() const override
Definition: triangle_3d_3.h:572
KRATOS_CLASS_POINTER_DEFINITION(Triangle3D3)
virtual Matrix & ShapeFunctionsGradients(Matrix &rResult, PointType &rPoint)
Definition: triangle_3d_3.h:1523
double MaxEdgeLength() const override
Definition: triangle_3d_3.h:551
double ShapeFunctionValue(IndexType ShapeFunctionIndex, const CoordinatesArrayType &rPoint) const override
Definition: triangle_3d_3.h:1348
BaseType::SizeType SizeType
Definition: triangle_3d_3.h:134
int GetMajorAxis(array_1d< double, 3 > const &V) const
Definition: triangle_3d_3.h:638
~Triangle3D3() override
Definition: triangle_3d_3.h:298
Vector & ShapeFunctionsValues(Vector &rResult, const CoordinatesArrayType &rCoordinates) const override
Definition: triangle_3d_3.h:1378
Geometry< TPointType > BaseType
Definition: triangle_3d_3.h:86
Triangle3D3(Triangle3D3 const &rOther)
Definition: triangle_3d_3.h:273
BaseType::Pointer Create(const IndexType NewGeometryId, PointsArrayType const &rThisPoints) const override
Creates a new geometry pointer.
Definition: triangle_3d_3.h:371
friend class Triangle3D3
Definition: triangle_3d_3.h:2466
double DeterminantOfJacobian(IndexType IntegrationPoint, IntegrationMethod ThisMethod) const override
Definition: triangle_3d_3.h:1194
Triangle3D3 & operator=(const Triangle3D3 &rOther)
Definition: triangle_3d_3.h:325
BaseType::IntegrationPointsArrayType IntegrationPointsArrayType
Definition: triangle_3d_3.h:160
CoordinatesArrayType & PointLocalCoordinates(CoordinatesArrayType &rResult, const CoordinatesArrayType &rPoint) const override
Returns the local coordinates of a given arbitrary point.
Definition: triangle_3d_3.h:917
BaseType::GeometriesArrayType GeometriesArrayType
Definition: triangle_3d_3.h:114
BaseType::ShapeFunctionsValuesContainerType ShapeFunctionsValuesContainerType
Definition: triangle_3d_3.h:173
BaseType::PointsArrayType PointsArrayType
Definition: triangle_3d_3.h:140
double ShortestAltitudeToEdgeLengthRatio() const override
Definition: triangle_3d_3.h:781
SizeType EdgesNumber() const override
This method gives you number of all edges of this geometry.
Definition: triangle_3d_3.h:1233
TPointType PointType
Definition: triangle_3d_3.h:119
void PrintData(std::ostream &rOStream) const override
Definition: triangle_3d_3.h:1433
BaseType::CoordinatesArrayType CoordinatesArrayType
Definition: triangle_3d_3.h:145
Triangle3D3(const PointsArrayType &ThisPoints)
Definition: triangle_3d_3.h:240
double CalculateDistance(const CoordinatesArrayType &rPointGlobalCoordinates, const double Tolerance=std::numeric_limits< double >::epsilon()) const override
Computes the distance between an point in global coordinates and the closest point of this geometry....
Definition: triangle_3d_3.h:989
Triangle3D3(Triangle3D3< TOtherPointType > const &rOther)
Definition: triangle_3d_3.h:290
void PrintInfo(std::ostream &rOStream) const override
Definition: triangle_3d_3.h:1414
GeometriesArrayType GenerateEdges() const override
This method gives you all edges of this geometry.
Definition: triangle_3d_3.h:1246
double InradiusToLongestEdgeQuality() const override
Definition: triangle_3d_3.h:729
bool AllSameSide(array_1d< double, 3 > const &Distances) const
Definition: triangle_3d_3.h:614
std::string Info() const override
Definition: triangle_3d_3.h:1403
double DeterminantOfJacobian(const CoordinatesArrayType &rPoint) const override
Definition: triangle_3d_3.h:1213
ShapeFunctionsThirdDerivativesType & ShapeFunctionsThirdDerivatives(ShapeFunctionsThirdDerivativesType &rResult, const CoordinatesArrayType &rPoint) const override
Definition: triangle_3d_3.h:1577
Vector & LumpingFactors(Vector &rResult, const typename BaseType::LumpingMethods LumpingMethod=BaseType::LumpingMethods::ROW_SUM) const override
Lumping factors for the calculation of the lumped mass matrix.
Definition: triangle_3d_3.h:435
virtual double AreaToEdgeLengthSquareRatio() const
Definition: triangle_3d_3.h:809
SizeType FacesNumber() const override
Returns the number of faces of the current geometry.
Definition: triangle_3d_3.h:1266
BaseType::Pointer Create(PointsArrayType const &rThisPoints) const override
Creates a new geometry pointer.
Definition: triangle_3d_3.h:358
BaseType::IndexType IndexType
Definition: triangle_3d_3.h:127
double Area() const override
This method calculates and returns area or surface area of this geometry depending to it's dimension.
Definition: triangle_3d_3.h:482
Matrix & Jacobian(Matrix &rResult, IndexType IntegrationPointIndex, IntegrationMethod ThisMethod) const override
Definition: triangle_3d_3.h:1105
BaseType::ShapeFunctionsThirdDerivativesType ShapeFunctionsThirdDerivativesType
Definition: triangle_3d_3.h:209
BaseType::Pointer Create(const IndexType NewGeometryId, const BaseType &rGeometry) const override
Creates a new geometry pointer.
Definition: triangle_3d_3.h:399
Triangle3D3< TPointType > FaceType
Definition: triangle_3d_3.h:98
BaseType::Pointer Create(const BaseType &rGeometry) const override
Creates a new geometry pointer.
Definition: triangle_3d_3.h:384
Triangle3D3(const IndexType GeometryId, const PointsArrayType &rThisPoints)
Constructor with Geometry Id.
Definition: triangle_3d_3.h:247
virtual ShapeFunctionsGradientsType ShapeFunctionsLocalGradients(IntegrationMethod ThisMethod)
Definition: triangle_3d_3.h:1451
GeometryData::KratosGeometryFamily GetGeometryFamily() const override
Definition: triangle_3d_3.h:300
Matrix & ShapeFunctionsLocalGradients(Matrix &rResult, const CoordinatesArrayType &rPoint) const override
Definition: triangle_3d_3.h:1498
int ProjectionPointLocalToLocalSpace(const CoordinatesArrayType &rPointLocalCoordinates, CoordinatesArrayType &rProjectionPointLocalCoordinates, const double Tolerance=std::numeric_limits< double >::epsilon()) const override
Projects a point onto the geometry Projects a certain point on the geometry, or finds the closest poi...
Definition: triangle_3d_3.h:1667
Line3D2< TPointType > EdgeType
Definition: triangle_3d_3.h:93
bool HasIntersection(const Point &rLowPoint, const Point &rHighPoint) const override
Definition: triangle_3d_3.h:680
Vector & DeterminantOfJacobian(Vector &rResult, IntegrationMethod ThisMethod) const override
Definition: triangle_3d_3.h:1158
void NumberNodesInFaces(DenseVector< unsigned int > &NumberNodesInFaces) const override
Definition: triangle_3d_3.h:1288
double Length() const override
Definition: triangle_3d_3.h:468
BaseType::ShapeFunctionsGradientsType ShapeFunctionsGradientsType
Definition: triangle_3d_3.h:193
Triangle3D3 & operator=(Triangle3D3< TOtherPointType > const &rOther)
Definition: triangle_3d_3.h:343
JacobiansType & Jacobian(JacobiansType &rResult, IntegrationMethod ThisMethod) const override
Definition: triangle_3d_3.h:1019
double AreaToEdgeLengthRatio() const override
Definition: triangle_3d_3.h:755
void NodesInFaces(DenseMatrix< unsigned int > &NodesInFaces) const override
Definition: triangle_3d_3.h:1299
int ProjectionPoint(const CoordinatesArrayType &rPointGlobalCoordinates, CoordinatesArrayType &rProjectedPointGlobalCoordinates, CoordinatesArrayType &rProjectedPointLocalCoordinates, const double Tolerance=std::numeric_limits< double >::epsilon()) const override
Projects a certain point on the geometry, or finds the closest point, depending on the provided initi...
Definition: triangle_3d_3.h:1651
double Inradius() const override
Definition: triangle_3d_3.h:604
Triangle3D3(typename PointType::Pointer pFirstPoint, typename PointType::Pointer pSecondPoint, typename PointType::Pointer pThirdPoint)
Definition: triangle_3d_3.h:230
int ProjectionPointGlobalToLocalSpace(const CoordinatesArrayType &rPointGlobalCoordinates, CoordinatesArrayType &rProjectionPointLocalCoordinates, const double Tolerance=std::numeric_limits< double >::epsilon()) const override
Projects a point onto the geometry Projects a certain point on the geometry, or finds the closest poi...
Definition: triangle_3d_3.h:1681
double MinEdgeLength() const override
Class Interface.
Definition: triangle_3d_3.h:530
GeometryData::KratosGeometryType GetGeometryType() const override
Definition: triangle_3d_3.h:305
bool IsInside(const CoordinatesArrayType &rPoint, CoordinatesArrayType &rResult, const double Tolerance=std::numeric_limits< double >::epsilon()) const override
Returns whether given arbitrary point is inside the Geometry and the respective local point for the g...
Definition: triangle_3d_3.h:871
BaseType::ShapeFunctionsLocalGradientsContainerType ShapeFunctionsLocalGradientsContainerType
Definition: triangle_3d_3.h:179
BaseType::NormalType NormalType
Definition: triangle_3d_3.h:214
BaseType::IntegrationPointsContainerType IntegrationPointsContainerType
Definition: triangle_3d_3.h:167
BaseType::ShapeFunctionsSecondDerivativesType ShapeFunctionsSecondDerivativesType
Definition: triangle_3d_3.h:201
JacobiansType & Jacobian(JacobiansType &rResult, IntegrationMethod ThisMethod, Matrix &DeltaPosition) const override
Definition: triangle_3d_3.h:1060
bool HasIntersection(const GeometryType &rThisGeometry) const override
Test the intersection with another geometry.
Definition: triangle_3d_3.h:649
GeometriesArrayType Faces(void) override
Definition: triangle_3d_3.h:1329
array_1d< double, 3 > Normal(const CoordinatesArrayType &rPointLocalCoordinates) const override
It returns a vector that is normal to its corresponding geometry in the given local point.
Definition: triangle_3d_3.h:853
virtual ShapeFunctionsGradientsType ShapeFunctionsLocalGradients()
Definition: triangle_3d_3.h:1472
Short class definition.
Definition: array_1d.h:61
#define KRATOS_SERIALIZE_SAVE_BASE_CLASS(Serializer, BaseType)
Definition: define.h:812
#define KRATOS_SERIALIZE_LOAD_BASE_CLASS(Serializer, BaseType)
Definition: define.h:815
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_WARNING(label)
Definition: logger.h:265
#define KRATOS_WARNING_FIRST_N(label, logger_count)
Definition: logger.h:272
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
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
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
const GeometryData BrepCurve< TContainerPointType, TContainerPointEmbeddedType >::msGeometryData & msGeometryDimension
Definition: brep_curve.h:483
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
const GeometryData Triangle3D3< TPointType >::msGeometryData & msGeometryDimension(), Triangle3D3< TPointType >::AllShapeFunctionsValues(), AllShapeFunctionsLocalGradients()
Definition: brep_curve.h:483
q
Definition: generate_convection_diffusion_explicit_element.py:109
f
Definition: generate_convection_diffusion_explicit_element.py:112
V
Definition: generate_droplet_dynamics.py:256
x1
Definition: generate_frictional_mortar_condition.py:121
X1
Definition: generate_frictional_mortar_condition.py:119
E
Definition: generate_hyper_elastic_simo_taylor_neo_hookean.py:26
int C
Definition: generate_hyper_elastic_simo_taylor_neo_hookean.py:27
a
Definition: generate_stokes_twofluid_element.py:77
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
def load(f)
Definition: ode_solve.py:307
tuple const
Definition: ode_solve.py:403
int d
Definition: ode_solve.py:397
float temp
Definition: rotating_cone.py:85
J
Definition: sensitivityMatrix.py:58
A
Definition: sensitivityMatrix.py:70
N
Definition: sensitivityMatrix.py:29
det_J
Definition: sensitivityMatrix.py:67
B
Definition: sensitivityMatrix.py:76
namespace
Definition: array_1d.h:793
integer i
Definition: TensorModule.f:17
subroutine d1(DSTRAN, D, dtime, NDI, NSHR, NTENS)
Definition: TensorModule.f:594
e
Definition: run_cpp_mpi_tests.py:31