1 // GetDP - Copyright (C) 1997-2021 P. Dular and C. Geuzaine, University of Liege
2 //
3 // See the LICENSE.txt file for license information. Please report all
4 // issues on https://gitlab.onelab.info/getdp/getdp/issues.
5 
6 #include <math.h>
7 #include "Gauss.h"
8 #include "Gauss_Triangle.h"
9 #include "Message.h"
10 #include "MallocUtils.h"
11 
12 /* Gauss Integration over a triangle */
13 
Gauss_Triangle(int Nbr_Points,int Num,double * u,double * v,double * w,double * wght)14 void Gauss_Triangle(int Nbr_Points, int Num,
15 		    double *u, double *v, double *w, double *wght)
16 {
17   switch (Nbr_Points) {
18   case  1 : *u= xt1 [Num] ; *v= yt1 [Num] ; *w= 0. ; *wght= pt1 [Num] ; break ;
19   case  3 : *u= xt3 [Num] ; *v= yt3 [Num] ; *w= 0. ; *wght= pt3 [Num] ; break ;
20   case  4 : *u= xt4 [Num] ; *v= yt4 [Num] ; *w= 0. ; *wght= pt4 [Num] ; break ;
21   case  6 : *u= xt6 [Num] ; *v= yt6 [Num] ; *w= 0. ; *wght= pt6 [Num] ; break ;
22   case  7 : *u= xt7 [Num] ; *v= yt7 [Num] ; *w= 0. ; *wght= pt7 [Num] ; break ;
23   case 12 : *u= xt12[Num] ; *v= yt12[Num] ; *w= 0. ; *wght= pt12[Num] ; break ;
24   case 13 : *u= xt13[Num] ; *v= yt13[Num] ; *w= 0. ; *wght= pt13[Num] ; break ;
25   case 16 : *u= xt16[Num] ; *v= yt16[Num] ; *w= 0. ; *wght= pt16[Num] ; break ;
26   default :
27     Message::Error("Wrong number of Gauss points for Triangle: "
28                    "valid choices: 1, 3, 4, 6, 7, 12, 13, 16");
29     break;
30   }
31 }
32 
33 /* Degenerate n1Xn2 Gauss-Legendre scheme to integrate over a tri */
34 
35 static int glt[MAX_LINE_POINTS] = {-1};
36 static double *glxt[MAX_LINE_POINTS], *glyt[MAX_LINE_POINTS], *glpt[MAX_LINE_POINTS];
37 
quadToTri(double xi,double eta,double * r,double * s,double * J)38 static void quadToTri(double xi,double eta,double *r, double *s, double *J)
39 {
40   double r1;
41 
42   *r = 0.5e0 * (1.0e0 + xi);
43   r1 = 1.0e0 - (*r);
44   *s = 0.5e0 * (1.0e0 + eta) * r1;
45   *J = 0.25e0 * r1;
46 }
47 
GaussLegendre_Triangle(int Nbr_Points,int Num,double * u,double * v,double * w,double * wght)48 void GaussLegendre_Triangle(int Nbr_Points, int Num,
49 			    double *u, double *v, double *w, double *wght)
50 {
51   int i,j,index=0,nb;
52   double pt1,pt2,wt1,wt2,dJ,dum;
53 
54   nb = (int)sqrt((double)Nbr_Points);
55 
56   if(nb*nb != Nbr_Points || nb > MAX_LINE_POINTS){
57     Message::Error("Number of points should be n^2 with n in [1,%d]", MAX_LINE_POINTS) ;
58     return;
59   }
60 
61   if(glt[0] < 0) for(i=0 ; i < MAX_LINE_POINTS ; i++) glt[i] = 0 ;
62 
63   if(!glt[nb - 1]){
64     Message::Info("Computing degenerate GaussLegendre %dX%d for Triangle", nb, nb);
65     glxt[nb - 1] = (double*)Malloc(Nbr_Points * sizeof(double));
66     glyt[nb - 1] = (double*)Malloc(Nbr_Points * sizeof(double));
67     glpt[nb - 1] = (double*)Malloc(Nbr_Points * sizeof(double));
68     for(i = 0; i < nb; i++) {
69       Gauss_Line(nb, i, &pt1, &dum, &dum, &wt1);
70       for(j = 0; j < nb; j++) {
71 	Gauss_Line(nb, j, &pt2, &dum, &dum, &wt2);
72 	quadToTri(pt1, pt2, &glxt[nb - 1][index], &glyt[nb - 1][index], &dJ);
73 	glpt[nb - 1][index++] = dJ * wt1 * wt2;
74       }
75     }
76     glt[nb - 1] = 1;
77   }
78 
79   *u = glxt[nb - 1][Num] ; *v = glyt[nb - 1][Num] ; *w = 0. ; *wght = glpt[nb - 1][Num] ;
80 }
81 
82 /* Gauss Integration over a triangle with a 1/R singularity over node (0,0,0) */
83 
GaussSingularR_Triangle(int Nbr_Points,int Num,double * u,double * v,double * w,double * wght)84 void GaussSingularR_Triangle(int Nbr_Points, int Num,
85 			     double *u, double *v, double *w, double *wght)
86 {
87   switch (Nbr_Points) {
88   case  1 : *u= xts1 [Num] ; *v= yts1 [Num] ; *w= 0. ; *wght= pts1 [Num] ; break ;
89   case  3 : *u= xts3 [Num] ; *v= yts3 [Num] ; *w= 0. ; *wght= pts3 [Num] ; break ;
90   case  4 : *u= xts4 [Num] ; *v= yts4 [Num] ; *w= 0. ; *wght= pts4 [Num] ; break ;
91   default :
92     Message::Error("Wrong number of (modified) Gauss points for Triangle: "
93                    "valid choices: 1, 3, 4");
94     break;
95   }
96 }
97 
98