15 #if !defined(KRATOS_DISCONTINUOUS_2D_UTILITIES_INCLUDED )
16 #define KRATOS_DISCONTINUOUS_2D_UTILITIES_INCLUDED
96 template<
class TMatrixType,
class TVectorType,
class TGradientType>
98 TVectorType rDistances, TVectorType& rVolumes, TMatrixType& rGPShapeFunctionValues,
99 TVectorType& rPartitionsSign, std::vector<TMatrixType>& rGradientsValue, TMatrixType& Nenriched,
100 TVectorType& face_gauss_N, TVectorType& face_gauss_Nenriched,
double& face_Area, TVectorType& face_n ,
unsigned int& type_of_cut)
108 const double one_third=1.0/3.0;
115 rGPShapeFunctionValues(0,0)=one_third; rGPShapeFunctionValues(0,1)=one_third; rGPShapeFunctionValues(0,2)=one_third;
116 Area = CalculateVolume2D( rPoints );
122 if( (rDistances(0)*rDistances(1))>0.0 && (rDistances(0)*rDistances(2))>0.0 )
125 rGPShapeFunctionValues(0,0)=one_third; rGPShapeFunctionValues(0,1)=one_third; rGPShapeFunctionValues(0,2)=one_third;
126 Nenriched(0,0) = 0.0;
128 for (
int j = 0;
j < 3;
j++)
129 rGradientsValue[0](0,
j) = 0.0;
130 if (rDistances(0) < 0.0) rPartitionsSign[0] = -1.0;
131 else rPartitionsSign[0] = 1.0;
142 if ((rDistances(0)*rDistances(1))<0.0)
146 if ((rDistances(1)*rDistances(2))<0.0)
150 if ((rDistances(2)*rDistances(0))<0.0)
159 const double unsigned_distance0=fabs(rDistances(0));
160 const double unsigned_distance1=fabs(rDistances(1));
161 const double unsigned_distance2=fabs(rDistances(2));
163 double longest_distance=fabs(unsigned_distance0);
164 if (unsigned_distance1>longest_distance)
165 longest_distance=unsigned_distance1;
166 if (unsigned_distance2>longest_distance)
167 longest_distance=unsigned_distance2;
169 const double tolerable_distance =longest_distance*0.001;
171 if (unsigned_distance0<tolerable_distance)
172 rDistances[0]=tolerable_distance*(rDistances[0]/fabs(rDistances[0]));
173 if (unsigned_distance1<tolerable_distance)
174 rDistances[1]=tolerable_distance*(rDistances[1]/fabs(rDistances[1]));
175 if (unsigned_distance2<tolerable_distance)
176 rDistances[2]=tolerable_distance*(rDistances[2]/fabs(rDistances[2]));
182 for (
unsigned int i=0;
i<3;
i++)
184 int edge_begin_node=
i;
185 int edge_end_node=
i+1;
186 if (edge_end_node==3) edge_end_node=0;
188 if(cut_edges(
i)==
true)
190 aux_nodes_relative_locations(
i)=fabs(rDistances(edge_end_node)/(rDistances(edge_end_node)-rDistances(edge_begin_node) ) ) ;
191 aux_nodes_father_nodes(
i,0)=edge_begin_node;
192 aux_nodes_father_nodes(
i,1)=edge_end_node;
196 if(fabs(rDistances(edge_end_node))>fabs(rDistances(edge_begin_node)))
198 aux_nodes_relative_locations(
i)=0.0;
199 aux_nodes_father_nodes(
i,0)=edge_end_node;
200 aux_nodes_father_nodes(
i,1)=edge_end_node;
204 aux_nodes_relative_locations(
i)=1.0;
205 aux_nodes_father_nodes(
i,0)=edge_begin_node;
206 aux_nodes_father_nodes(
i,1)=edge_begin_node;
211 for (
unsigned int j=0;
j<2;
j++)
212 aux_points(
i,
j)= rPoints(edge_begin_node,
j) * aux_nodes_relative_locations(
i) + rPoints(edge_end_node,
j) * (1.0- aux_nodes_relative_locations(
i));
226 unsigned int partition_number=0;
229 for (
unsigned int i=0;
i<4;
i++)
231 unsigned int j_aux =
i + 2;
232 if (j_aux>2) j_aux -= 3;
237 partition_father_nodes(0,0)=
i;
238 partition_father_nodes(0,1)=
i;
239 partition_father_nodes(1,0)=aux_nodes_father_nodes(
i,0);
240 partition_father_nodes(1,1)=aux_nodes_father_nodes(
i,1);
241 partition_father_nodes(2,0)=aux_nodes_father_nodes(j_aux,0);
242 partition_father_nodes(2,1)=aux_nodes_father_nodes(j_aux,1);
244 coord_subdomain(0,0)=rPoints(
i,0);
245 coord_subdomain(0,1)=rPoints(
i,1);
246 coord_subdomain(1,0)=aux_points(
i,0);
247 coord_subdomain(1,1)=aux_points(
i,1);
248 coord_subdomain(2,0)=aux_points(j_aux,0);
249 coord_subdomain(2,1)=aux_points(j_aux,1);
254 partition_father_nodes=aux_nodes_father_nodes;
255 coord_subdomain=aux_points;
259 CalculateGeometryData(coord_subdomain, DN_DX_subdomain, temp_area);
260 if (temp_area > 1.0e-20)
262 rVolumes(partition_number)=temp_area;
264 double x_GP_partition = one_third * ( coord_subdomain(0,0) + coord_subdomain(1,0) + coord_subdomain(2,0) );
265 double y_GP_partition = one_third * ( coord_subdomain(0,1) + coord_subdomain(1,1) + coord_subdomain(2,1) );
266 double z_GP_partition = 0.0;
268 coord_subdomain = rPoints;
270 bool is_found = CalculatePosition ( coord_subdomain , x_GP_partition ,y_GP_partition ,z_GP_partition ,
N);
272 const double partition_sign = (
N(0)*rDistances(0) +
N(1)*rDistances(1) +
N(2)*rDistances(2))/fabs(
N(0)*rDistances(0) +
N(1)*rDistances(1) +
N(2)*rDistances(2));
273 rPartitionsSign(partition_number)=partition_sign;
275 for (
unsigned int j=0;
j<3;
j++)
277 if((partition_sign*rDistances(
j))>0)
280 for (
unsigned int k=0;
k<3;
k++)
281 if (partition_father_nodes(
k,0)==
j || partition_father_nodes(
k,1)==
j )
283 Nenriched(partition_number,
j)+=one_third;
284 rGradientsValue[partition_number](
j,0)+=DN_DX_subdomain(
k,0);
285 rGradientsValue[partition_number](
j,1)+=DN_DX_subdomain(
k,1);
292 rGPShapeFunctionValues(partition_number,0)=
N(0);
293 rGPShapeFunctionValues(partition_number,1)=
N(1);
294 rGPShapeFunctionValues(partition_number,2)=
N(2);
311 template<
class TMatrixType,
class TVectorType,
class TGradientType>
313 TVectorType rDistances, TVectorType& rVolumes, TMatrixType& rGPShapeFunctionValues,
314 TVectorType& rPartitionsSign, std::vector<TMatrixType>& rGradientsValue, TMatrixType& NEnriched,
315 TVectorType& face_gauss_N, TVectorType& face_gauss_Nenriched,
double& face_Area, TVectorType& face_n ,
unsigned int& type_of_cut)
320 unsigned int i_aux,j_aux,k_aux;
322 const double one_third=1.0/3.0;
326 rGPShapeFunctionValues(0,0)=one_third; rGPShapeFunctionValues(0,1)=one_third; rGPShapeFunctionValues(0,2)=one_third;
327 Area = CalculateVolume2D( rPoints );
331 if( (rDistances(0)*rDistances(1))>0.0 && (rDistances(0)*rDistances(2))>0.0 )
334 rGPShapeFunctionValues(0,0)=one_third; rGPShapeFunctionValues(0,1)=one_third; rGPShapeFunctionValues(0,2)=one_third;
335 NEnriched(0,0) = 0.0;
337 for (
int j = 0;
j < 3;
j++)
338 rGradientsValue[0](0,
j) = 0.0;
339 if (rDistances(0) < 0.0) rPartitionsSign[0] = -1.0;
340 else rPartitionsSign[0] = 1.0;
351 if ((rDistances(0)*rDistances(1))<0.0)
353 if ((rDistances(0)*rDistances(2))<0.0)
395 if (rDistances(i_aux) < 0.0)
397 rPartitionsSign[0] = -1.0;
398 rPartitionsSign[1] = 1.0;
399 rPartitionsSign[2] = 1.0;
403 rPartitionsSign[0] = 1.0;
404 rPartitionsSign[1] = -1.0;
405 rPartitionsSign[2] = -1.0;
411 const double unsigned_distance0=fabs(rDistances(0));
412 const double unsigned_distance1=fabs(rDistances(1));
413 const double unsigned_distance2=fabs(rDistances(2));
415 double longest_distance=fabs(unsigned_distance0);
416 if (unsigned_distance1>longest_distance)
417 longest_distance=unsigned_distance1;
418 if (unsigned_distance2>longest_distance)
419 longest_distance=unsigned_distance2;
421 const double tolerable_distance =longest_distance*0.01;
424 if (unsigned_distance0<tolerable_distance)
425 rDistances[0]=tolerable_distance*(rDistances[0]/fabs(rDistances[0]));
426 if (unsigned_distance1<tolerable_distance)
427 rDistances[1]=tolerable_distance*(rDistances[1]/fabs(rDistances[1]));
428 if (unsigned_distance2<tolerable_distance)
429 rDistances[2]=tolerable_distance*(rDistances[2]/fabs(rDistances[2]));
437 const double node4_relative_position=fabs(rDistances(j_aux)/(rDistances(i_aux)-rDistances(j_aux) ) ) ;
438 const double node5_relative_position=fabs(rDistances(k_aux)/(rDistances(i_aux)-rDistances(k_aux) ) ) ;
443 const double Ni_aux_node4 = node4_relative_position;
444 const double Nj_aux_node4 = (1.0-node4_relative_position);
446 const double Ni_aux_node5 = node5_relative_position;
448 const double Nk_aux_node5 = (1.0-node5_relative_position);
451 const double x_midpoint=((rPoints(i_aux,0)*Ni_aux_node4+rPoints(j_aux,0)*Nj_aux_node4)+
452 (rPoints(i_aux,0)*Ni_aux_node5+rPoints(k_aux,0)*Nk_aux_node5))*0.5;
453 const double y_midpoint=((rPoints(i_aux,1)*Ni_aux_node4+rPoints(j_aux,1)*Nj_aux_node4)+
454 (rPoints(i_aux,1)*Ni_aux_node5+rPoints(k_aux,1)*Nk_aux_node5))*0.5;
455 const double z_midpoint=0.0;
458 coord_subdomain = rPoints;
460 bool is_found = CalculatePosition ( coord_subdomain , x_midpoint,y_midpoint,z_midpoint,
N);
464 const double adim_Nenriched_i_aux = 1.0 /(face_gauss_N(i_aux));
466 const double adim_Nenriched_j_aux = adim_Nenriched_i_aux * Ni_aux_node4 / Nj_aux_node4 ;
467 const double adim_Nenriched_k_aux = adim_Nenriched_i_aux * Ni_aux_node5 / Nk_aux_node5 ;
470 const double adim_Nenriched_j_aux_b = (2.0 - node4_relative_position * adim_Nenriched_i_aux) / Nj_aux_node4;
471 const double adim_Nenriched_k_aux_b = (2.0 - node5_relative_position * adim_Nenriched_i_aux) / Nk_aux_node5;
475 face_gauss_Nenriched(i_aux)= 1.0;
476 face_gauss_Nenriched(j_aux)= 0.0;
480 coord_subdomain(0,0)=rPoints(i_aux,0);
481 coord_subdomain(0,1)=rPoints(i_aux,1);
482 coord_subdomain(1,0)=rPoints(i_aux,0)*Ni_aux_node4+rPoints(j_aux,0)*Nj_aux_node4;
483 coord_subdomain(1,1)=rPoints(i_aux,1)*Ni_aux_node4+rPoints(j_aux,1)*Nj_aux_node4;
484 coord_subdomain(2,0)=rPoints(i_aux,0)*Ni_aux_node5+rPoints(k_aux,0)*Nk_aux_node5;
485 coord_subdomain(2,1)=rPoints(i_aux,1)*Ni_aux_node5+rPoints(k_aux,1)*Nk_aux_node5;
488 CalculateGeometryData(coord_subdomain, DN_DX_subdomain, rVolumes(0));
491 rGradientsValue[0](i_aux,0)=DN_DX_subdomain(0,0);
492 rGradientsValue[0](i_aux,1)=DN_DX_subdomain(0,1);
496 double x_GP_partition = one_third * ( coord_subdomain(0,0) + coord_subdomain(1,0) + coord_subdomain(2,0) );
497 double y_GP_partition = one_third * ( coord_subdomain(0,1) + coord_subdomain(1,1) + coord_subdomain(2,1) );
498 double z_GP_partition = 0.0;
500 coord_subdomain = rPoints;
502 is_found = CalculatePosition ( coord_subdomain , x_GP_partition ,y_GP_partition ,z_GP_partition ,
N);
503 rGPShapeFunctionValues(0,0)=
N(0);
504 rGPShapeFunctionValues(0,1)=
N(1);
505 rGPShapeFunctionValues(0,2)=
N(2);
507 NEnriched(0,i_aux)=one_third;
516 face_Area=sqrt(pow((coord_subdomain(2,0)-coord_subdomain(1,0)),2)+pow((coord_subdomain(2,1)-coord_subdomain(1,1)),2));
518 face_n(0)=(coord_subdomain(2,1)-coord_subdomain(1,1))/face_Area;
519 face_n(1)=-(coord_subdomain(2,0)-coord_subdomain(1,0))/face_Area;
542 coord_subdomain(0,0) = rPoints(j_aux,0);
543 coord_subdomain(0,1) = rPoints(j_aux,1);
544 coord_subdomain(1,0) = rPoints(k_aux,0);
545 coord_subdomain(1,1) = rPoints(k_aux,1);
546 coord_subdomain(2,0) = rPoints(i_aux,0)*Ni_aux_node5+rPoints(k_aux,0)*Nk_aux_node5;
547 coord_subdomain(2,1) = rPoints(i_aux,1)*Ni_aux_node5+rPoints(k_aux,1)*Nk_aux_node5;
550 CalculateGeometryData(coord_subdomain, DN_DX_subdomain, rVolumes(1));
554 rGradientsValue[1](j_aux,0)=DN_DX_subdomain(0,0);
555 rGradientsValue[1](j_aux,1)=DN_DX_subdomain(0,1);
556 rGradientsValue[1](k_aux,0)= DN_DX_subdomain(1,0);
557 rGradientsValue[1](k_aux,1)= DN_DX_subdomain(1,1);
562 x_GP_partition = one_third * ( coord_subdomain(0,0) + coord_subdomain(1,0) + coord_subdomain(2,0) );
563 y_GP_partition = one_third * ( coord_subdomain(0,1) + coord_subdomain(1,1) + coord_subdomain(2,1) );
564 z_GP_partition = 0.0;
566 coord_subdomain = rPoints;
568 is_found = CalculatePosition ( coord_subdomain , x_GP_partition ,y_GP_partition ,z_GP_partition ,
N);
569 rGPShapeFunctionValues(1,0)=
N(0);
570 rGPShapeFunctionValues(1,1)=
N(1);
571 rGPShapeFunctionValues(1,2)=
N(2);
574 NEnriched(1,j_aux) = one_third;
575 NEnriched(1,k_aux) = one_third;
593 coord_subdomain(2,0) = rPoints(i_aux,0)*Ni_aux_node4+rPoints(j_aux,0)*Nj_aux_node4;
594 coord_subdomain(2,1) = rPoints(i_aux,1)*Ni_aux_node4+rPoints(j_aux,1)*Nj_aux_node4;
595 rVolumes(3)=CalculateVolume2D(coord_subdomain);
599 coord_subdomain(0,0) = rPoints(j_aux,0);
600 coord_subdomain(0,1) = rPoints(j_aux,1);
601 coord_subdomain(1,0)=rPoints(i_aux,0)*Ni_aux_node5+rPoints(k_aux,0)*Nk_aux_node5;
602 coord_subdomain(1,1)=rPoints(i_aux,1)*Ni_aux_node5+rPoints(k_aux,1)*Nk_aux_node5;
603 coord_subdomain(2,0)=rPoints(i_aux,0)*Ni_aux_node4+rPoints(j_aux,0)*Nj_aux_node4;
604 coord_subdomain(2,1)=rPoints(i_aux,1)*Ni_aux_node4+rPoints(j_aux,1)*Nj_aux_node4;
606 CalculateGeometryData(coord_subdomain, DN_DX_subdomain, rVolumes(2));
609 rGradientsValue[2](j_aux,0)= DN_DX_subdomain(0,0);
610 rGradientsValue[2](j_aux,1)= DN_DX_subdomain(0,1);
614 NEnriched(2,j_aux) = one_third;
617 x_GP_partition = one_third * ( coord_subdomain(0,0) + coord_subdomain(1,0) + coord_subdomain(2,0) );
618 y_GP_partition = one_third * ( coord_subdomain(0,1) + coord_subdomain(1,1) + coord_subdomain(2,1) );
619 z_GP_partition = 0.0;
620 coord_subdomain = rPoints;
621 is_found = CalculatePosition ( coord_subdomain , x_GP_partition ,y_GP_partition ,z_GP_partition ,
N);
622 rGPShapeFunctionValues(2,0)=
N(0);
623 rGPShapeFunctionValues(2,1)=
N(1);
624 rGPShapeFunctionValues(2,2)=
N(2);
671 static inline void CalculateGeometryData(
676 double x10 = coordinates(1,0) - coordinates(0,0);
677 double y10 = coordinates(1,1) - coordinates(0,1);
679 double x20 = coordinates(2,0) - coordinates(0,0);
680 double y20 = coordinates(2,1) - coordinates (0,1);
688 double detJ = x10 * y20-y10 * x20;
690 DN_DX(0,0) = -y20 + y10;
691 DN_DX(0,1) = x20 - x10;
703 static inline double CalculateVolume2D(
704 const BoundedMatrix<double, 3, 3 > & coordinates)
706 double x10 = coordinates(1,0) - coordinates(0,0);
707 double y10 = coordinates(1,1) - coordinates(0,1);
709 double x20 = coordinates(2,0) - coordinates(0,0);
710 double y20 = coordinates(2,1) - coordinates (0,1);
711 double detJ = x10 * y20-y10 * x20;
715 static inline bool CalculatePosition(
const BoundedMatrix<double, 3, 3 > & coordinates,
716 const double xc,
const double yc,
const double zc,
717 array_1d<double, 3 > &
N
720 double x0 = coordinates(0,0);
721 double y0 = coordinates(0,1);
722 double x1 = coordinates(1,0);
723 double y1 = coordinates(1,1);
724 double x2 = coordinates(2,0);
725 double y2 = coordinates(2,1);
727 double area = CalculateVol(x0, y0,
x1, y1,
x2, y2);
728 double inv_area = 0.0;
734 inv_area = 1.0 / area;
738 N[0] = CalculateVol(
x1, y1,
x2, y2,
xc,
yc) * inv_area;
739 N[1] = CalculateVol(
x2, y2, x0, y0,
xc,
yc) * inv_area;
740 N[2] = CalculateVol(x0, y0,
x1, y1,
xc,
yc) * inv_area;
743 if (
N[0] >= 0.0 &&
N[1] >= 0.0 &&
N[2] >= 0.0 &&
N[0] <= 1.0 &&
N[1] <= 1.0 &&
N[2] <= 1.0)
749 static inline double CalculateVol(
const double x0,
const double y0,
750 const double x1,
const double y1,
751 const double x2,
const double y2
754 return 0.5 * ((
x1 - x0)*(y2 - y0)- (y1 - y0)*(
x2 - x0));
This utility can be used to calculate the enriched shape function for tetrahedra element.
Definition: discont_2d.h:41
static int CalculateTriangleDiscontinuousShapeFunctions_ZeroInBoundary(TMatrixType const &rPoints, TGradientType const &DN_DX, TVectorType rDistances, TVectorType &rVolumes, TMatrixType &rGPShapeFunctionValues, TVectorType &rPartitionsSign, std::vector< TMatrixType > &rGradientsValue, TMatrixType &NEnriched, TVectorType &face_gauss_N, TVectorType &face_gauss_Nenriched, double &face_Area, TVectorType &face_n, unsigned int &type_of_cut)
Definition: discont_2d.h:312
static int CalculateTriangleDiscontinuousShapeFunctions(TMatrixType const &rPoints, TGradientType const &DN_DX, TVectorType rDistances, TVectorType &rVolumes, TMatrixType &rGPShapeFunctionValues, TVectorType &rPartitionsSign, std::vector< TMatrixType > &rGradientsValue, TMatrixType &Nenriched, TVectorType &face_gauss_N, TVectorType &face_gauss_Nenriched, double &face_Area, TVectorType &face_n, unsigned int &type_of_cut)
The method to calculate the enriched shape functions for given triangle.
Definition: discont_2d.h:97
Definition: amatrix_interface.h:41
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
float xc
Definition: rotating_cone.py:77
float yc
Definition: rotating_cone.py:78
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17