ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/fem_triangle3.cpp
Revision: 382
Committed: Wed Dec 19 22:18:06 2012 UTC (12 years, 4 months ago) by gervaislavoie
File size: 15410 byte(s)
Log Message:
Methode du mouvement normale  et jacobien 3D dans fem_triangle3

File Contents

# User Rev Content
1 francois 283 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuilli�re et Vincent FRANCOIS
5     // D�partement de G�nie M�canique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du d�partement
8     // de g�nie m�canique de l'Universit� du Qu�bec �
9     // Trois Rivi�res
10     // Les librairies ne peuvent �tre utilis�es sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // fem_triangle3.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 � 11H22
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26     #include "fem_triangle3.h"
27     #include "fem_maillage.h"
28     #include "fem_noeud.h"
29     #include "mg_element_maillage.h"
30 gervaislavoie 382 #include "math.h"
31 francois 283
32    
33 francois 309 FEM_TRIANGLE3::FEM_TRIANGLE3(unsigned long num,class MG_ELEMENT_MAILLAGE* mai,class FEM_NOEUD** tabnoeud):FEM_ELEMENT2(num,mai),FEM_TEMPLATE_ELEMENT<3>(tabnoeud)
34 francois 283 {
35     if (liaison_topologique!=NULL) if (liaison_topologique->get_dimension()==2) liaison_topologique->get_lien_fem_maillage()->ajouter(this);
36 francois 309 tab[0]->get_lien_element2()->ajouter(this);
37     tab[1]->get_lien_element2()->ajouter(this);
38     tab[2]->get_lien_element2()->ajouter(this);
39     get_fem_noeudpetitid()->get_lien_petit_element2()->ajouter(this);
40 francois 283 }
41    
42 francois 309 FEM_TRIANGLE3::FEM_TRIANGLE3(class MG_ELEMENT_MAILLAGE* mai,FEM_NOEUD** tabnoeud):FEM_ELEMENT2(mai),FEM_TEMPLATE_ELEMENT<3>(tabnoeud)
43 francois 283 {
44     if (liaison_topologique!=NULL) if (liaison_topologique->get_dimension()==2) liaison_topologique->get_lien_fem_maillage()->ajouter(this);
45 francois 309 tab[0]->get_lien_element2()->ajouter(this);
46     tab[1]->get_lien_element2()->ajouter(this);
47     tab[2]->get_lien_element2()->ajouter(this);
48     get_fem_noeudpetitid()->get_lien_petit_element2()->ajouter(this);
49 francois 283 }
50 francois 378 FEM_TRIANGLE3::FEM_TRIANGLE3(unsigned long num,class MG_ELEMENT_TOPOLOGIQUE* topo,class FEM_NOEUD** tabnoeud):FEM_ELEMENT2(num,topo),FEM_TEMPLATE_ELEMENT<3>(tabnoeud)
51     {
52     if (liaison_topologique!=NULL) if (liaison_topologique->get_dimension()==2) liaison_topologique->get_lien_fem_maillage()->ajouter(this);
53     tab[0]->get_lien_element2()->ajouter(this);
54     tab[1]->get_lien_element2()->ajouter(this);
55     tab[2]->get_lien_element2()->ajouter(this);
56     get_fem_noeudpetitid()->get_lien_petit_element2()->ajouter(this);
57     }
58 francois 283
59 francois 378 FEM_TRIANGLE3::FEM_TRIANGLE3(class MG_ELEMENT_TOPOLOGIQUE* topo,FEM_NOEUD** tabnoeud):FEM_ELEMENT2(topo),FEM_TEMPLATE_ELEMENT<3>(tabnoeud)
60     {
61     if (liaison_topologique!=NULL) if (liaison_topologique->get_dimension()==2) liaison_topologique->get_lien_fem_maillage()->ajouter(this);
62     tab[0]->get_lien_element2()->ajouter(this);
63     tab[1]->get_lien_element2()->ajouter(this);
64     tab[2]->get_lien_element2()->ajouter(this);
65     get_fem_noeudpetitid()->get_lien_petit_element2()->ajouter(this);
66     }
67     FEM_TRIANGLE3::FEM_TRIANGLE3(unsigned long num,class MG_ELEMENT_TOPOLOGIQUE* topo,class MG_ELEMENT_MAILLAGE* mai,class FEM_NOEUD** tabnoeud):FEM_ELEMENT2(num,topo,mai),FEM_TEMPLATE_ELEMENT<3>(tabnoeud)
68     {
69     if (liaison_topologique!=NULL) if (liaison_topologique->get_dimension()==2) liaison_topologique->get_lien_fem_maillage()->ajouter(this);
70     tab[0]->get_lien_element2()->ajouter(this);
71     tab[1]->get_lien_element2()->ajouter(this);
72     tab[2]->get_lien_element2()->ajouter(this);
73     get_fem_noeudpetitid()->get_lien_petit_element2()->ajouter(this);
74     }
75    
76     FEM_TRIANGLE3::FEM_TRIANGLE3(class MG_ELEMENT_TOPOLOGIQUE* topo,class MG_ELEMENT_MAILLAGE* mai,FEM_NOEUD** tabnoeud):FEM_ELEMENT2(topo,mai),FEM_TEMPLATE_ELEMENT<3>(tabnoeud)
77     {
78     if (liaison_topologique!=NULL) if (liaison_topologique->get_dimension()==2) liaison_topologique->get_lien_fem_maillage()->ajouter(this);
79     tab[0]->get_lien_element2()->ajouter(this);
80     tab[1]->get_lien_element2()->ajouter(this);
81     tab[2]->get_lien_element2()->ajouter(this);
82     get_fem_noeudpetitid()->get_lien_petit_element2()->ajouter(this);
83     }
84 francois 309 FEM_TRIANGLE3::FEM_TRIANGLE3(FEM_TRIANGLE3& mdd):FEM_ELEMENT2(mdd),FEM_TEMPLATE_ELEMENT<3>(mdd)
85 francois 283 {
86     if (liaison_topologique!=NULL) if (liaison_topologique->get_dimension()==2) liaison_topologique->get_lien_fem_maillage()->ajouter(this);
87 francois 309 tab[0]->get_lien_element2()->ajouter(this);
88     tab[1]->get_lien_element2()->ajouter(this);
89     tab[2]->get_lien_element2()->ajouter(this);
90     get_fem_noeudpetitid()->get_lien_petit_element2()->ajouter(this);
91 francois 283 }
92     FEM_TRIANGLE3::~FEM_TRIANGLE3()
93     {
94     if (liaison_topologique==NULL) return;
95     if (liaison_topologique->get_dimension()==0) liaison_topologique->get_lien_fem_maillage()->supprimer(this);
96 francois 309 tab[0]->get_lien_element2()->supprimer(this);
97     tab[1]->get_lien_element2()->supprimer(this);
98     tab[2]->get_lien_element2()->supprimer(this);
99     get_fem_noeudpetitid()->get_lien_petit_element2()->supprimer(this);
100 francois 283 }
101    
102    
103     FEM_ELEMENT_MAILLAGE* FEM_TRIANGLE3::dupliquer(FEM_MAILLAGE *femmai,long decalage)
104     {
105     FEM_NOEUD* tabnoeud[3];
106     tabnoeud[0]=femmai->get_fem_noeudid(tab[0]->get_id()+decalage);
107     tabnoeud[1]=femmai->get_fem_noeudid(tab[1]->get_id()+decalage);
108     tabnoeud[2]=femmai->get_fem_noeudid(tab[2]->get_id()+decalage);
109     FEM_TRIANGLE3* tri=new FEM_TRIANGLE3(get_id()+decalage,maillage,tabnoeud);
110 francois 309 femmai->ajouter_fem_element2(tri);
111 francois 283 return tri;
112     }
113    
114    
115    
116    
117    
118     int FEM_TRIANGLE3::get_type_entite(void)
119     {
120     return IDFEM_TRIANGLE3;
121     }
122    
123     int FEM_TRIANGLE3::get_dimension(void)
124     {
125     return 2;
126     }
127    
128    
129    
130     int FEM_TRIANGLE3::get_nb_fem_noeud(void)
131     {
132     return FEM_TEMPLATE_ELEMENT<3>::get_nb_fem_noeud();
133     }
134    
135     FEM_NOEUD* FEM_TRIANGLE3::get_fem_noeud(int num)
136     {
137     return FEM_TEMPLATE_ELEMENT<3>::get_fem_noeud(num);
138     }
139    
140     void FEM_TRIANGLE3::change_noeud(int num,FEM_NOEUD* noeud)
141     {
142     FEM_TEMPLATE_ELEMENT<3>::change_noeud(num,noeud);
143     }
144    
145     BOITE_3D& FEM_TRIANGLE3::get_boite_3D(void)
146     {
147     return FEM_TEMPLATE_ELEMENT<3>::get_boite_3D();
148     }
149    
150    
151     void FEM_TRIANGLE3::enregistrer(std::ostream& o)
152     {
153 francois 378 if (maillage!=NULL)
154     if (get_lien_topologie()!=NULL) o << "%" << get_id() << "=FEM_TRIANGLE3($"<< get_lien_topologie()->get_id() << ",$" << maillage->get_id() << ",$" << tab[0]->get_id() << ",$" << tab[1]->get_id() << ",$" << tab[2]->get_id()<< ");" << std::endl;
155     else o << "%" << get_id() << "=FEM_TRIANGLE3(NULL,$" << maillage->get_id() << ",$" << tab[0]->get_id() << ",$" << tab[1]->get_id() << ",$" << tab[2]->get_id()<< ");" << std::endl;
156     else
157     if (get_lien_topologie()!=NULL) o << "%" << get_id() << "=FEM_TRIANGLE3($"<< get_lien_topologie()->get_id() << ",NULL,$" << tab[0]->get_id() << ",$" << tab[1]->get_id() << ",$" << tab[2]->get_id()<< ");" << std::endl;
158     else o << "%" << get_id() << "=FEM_TRIANGLE3(NULL,NULL,$" << tab[0]->get_id() << ",$" << tab[1]->get_id() << ",$" << tab[2]->get_id()<< ");" << std::endl;
159    
160     }
161 francois 310
162     int FEM_TRIANGLE3::nb_fonction_interpolation(void)
163     {
164     return 3;
165     }
166    
167     double FEM_TRIANGLE3::get_fonction_interpolation(int num,double *uv)
168     {
169     double val;
170     switch (num)
171     {
172     case 1:
173     val=1-uv[0]-uv[1];
174     break;
175     case 2:
176     val=uv[0];
177     break;
178     case 3:
179     val=uv[1];
180     break;
181    
182     }
183     return val;
184     }
185    
186     double FEM_TRIANGLE3::get_fonction_derive_interpolation(int num,int num_variable,double *uv)
187     {
188     double val;
189    
190     switch (num)
191     {
192     case 1:
193     switch (num_variable)
194     {
195     case 1:
196     val=-1;
197     break;
198     case 2:
199     val=-1;
200     break;
201     } break;
202     case 2:
203     switch (num_variable)
204     {
205     case 1:
206     val=1;
207     break;
208     case 2:
209     val=0.;
210     break;
211     }break;
212     case 3:
213     switch (num_variable)
214     {
215     case 1:
216     val=0.;
217     break;
218     case 2:
219     val=1.;
220     break;
221     }break;
222    
223     }
224     return val;
225     }
226    
227     double FEM_TRIANGLE3::get_jacobien(double* jac,double *uv,int& li,int& col,double unite)
228 gervaislavoie 382 {
229     // Il faut exprimer les coordonnées x,y,z du repère 3D initial Ri dans un repère 2D final Rf de coordonnées
230     // x',y',z' où z'est nul afin de pouvoir utiliser les fonctions d'interpolation de l'élément de référence
231     FEM_NOEUD* n1=get_fem_noeud(0);
232     FEM_NOEUD* n2=get_fem_noeud(1);
233     FEM_NOEUD* n3=get_fem_noeud(2);
234    
235     double *xyzn1=n1->get_coord();
236     double *xyzn2=n2->get_coord();
237     double *xyzn3=n3->get_coord();
238    
239     // Le nouveau repère est défini par les vecteurs vec1 et vec2 et son origine est le noeud n1
240     OT_VECTEUR_3D vec1(xyzn1,xyzn2);
241     OT_VECTEUR_3D vec3(xyzn1,xyzn3);
242     vec1.norme();
243     OT_VECTEUR_3D n=vec1&vec3; // Normale au triangle au noeud n1
244     n.norme();
245     OT_VECTEUR_3D vec2=n&vec1; // Vecteur normal à vec1 dans le plan du triangle
246     vec2.norme();
247     OT_MATRICE_3D pif(vec1,vec2,n); // Matrice de passage du repère Ri au repère Rf
248    
249     // Position initiale (0) des noeuds dans le repère initial (i)
250     OT_VECTEUR_3D n1_0i(n1->get_dx(),n1->get_dy(),n1->get_dz());
251     OT_VECTEUR_3D n2_0i(n2->get_dx(),n2->get_dy(),n2->get_dz());
252     OT_VECTEUR_3D n3_0i(n3->get_dx(),n3->get_dy(),n3->get_dz());
253     OT_MATRICE_3D pos_0i(n1_0i,n2_0i,n3_0i);
254    
255     // Position initiale (0) des noeuds dans le repère final (f)
256     //OT_MATRICE_3D pos_0f=pos_0i*pif;
257     OT_MATRICE_3D pif_inverse=pif.inverse();
258     OT_MATRICE_3D pos_0f=pif_inverse*pos_0i;
259     OT_VECTEUR_3D vecn1_0=pos_0f.get_vecteur1();
260     pos_0f.change_vecteur1(pos_0f.get_vecteur1()-vecn1_0); // Étant donné que le noeud 1 est l'origine du repère final, on soustrait ses coordonnées à chaque noeud
261     pos_0f.change_vecteur2(pos_0f.get_vecteur2()-vecn1_0);
262     pos_0f.change_vecteur3(pos_0f.get_vecteur3()-vecn1_0);
263    
264     // Position actuelle (t) des noeuds dans le repère initial (i)
265     OT_VECTEUR_3D n1_ti(xyzn1);
266     OT_VECTEUR_3D n2_ti(xyzn2);
267     OT_VECTEUR_3D n3_ti(xyzn3);
268     OT_MATRICE_3D pos_ti(n1_ti,n2_ti,n3_ti);
269    
270     // Position actuelle (t) des noeuds dans le repère final (f)
271     //OT_MATRICE_3D pos_tf=pos_ti*pif;
272     OT_MATRICE_3D pos_tf=pif_inverse*pos_ti;
273     OT_VECTEUR_3D vecn1_t=pos_tf.get_vecteur1();
274     pos_tf.change_vecteur1(pos_tf.get_vecteur1()-vecn1_t);
275     pos_tf.change_vecteur2(pos_tf.get_vecteur2()-vecn1_t);
276     pos_tf.change_vecteur3(pos_tf.get_vecteur3()-vecn1_t);
277    
278     // Gestion des erreurs numériques
279     /*for (int c=0;c<3;c++)
280     for (int l=0;l<3;l++)
281     {
282     if (fabs(pos_tf(l,c))<1e-10)
283     pos_tf(l,c)=0.;
284     }*/
285    
286     // Calcul du Jacobien dans le repère initial
287     OT_VECTEUR_3D col1_Jf(pos_tf(0,1)-pos_tf(0,0),pos_tf(0,2)-pos_tf(0,0),0.);
288     OT_VECTEUR_3D col2_Jf(pos_tf(1,1)-pos_tf(1,0),pos_tf(1,2)-pos_tf(1,0),0.);
289     OT_VECTEUR_3D col3_Jf(0.,0.,0.);
290     //OT_VECTEUR_3D col1_jf(x2'-x1',x3'-x1'); // Compréhension
291     //OT_VECTEUR_3D col2_jf(y2'-y1',y3'-y1');
292    
293     OT_MATRICE_3D J_f(col1_Jf,col2_Jf,col3_Jf); // Jacobien dans le repère final
294    
295     OT_MATRICE_3D J_i=pif*J_f; // Jacobien dans le repère initial
296    
297     jac[0]=J_i(0,0);
298     jac[1]=J_i(1,0);
299     jac[2]=J_i(2,0);
300    
301     jac[3]=J_i(0,1);
302     jac[4]=J_i(1,1);
303     jac[5]=J_i(2,1);
304    
305     jac[6]=0.;
306     jac[7]=0.;
307     jac[8]=0.;
308    
309     //Temporaire
310    
311     double det_Jf=J_f(0,0)*J_f(1,1)-J_f(0,1)*J_f(1,0);
312     OT_VECTEUR_3D n_f=pif_inverse*n;
313     double aire_f=n_f.get_longueur()/2.;
314     double aire_i=n.get_longueur()/2.;
315     int test=1;
316 francois 310 }
317    
318     void FEM_TRIANGLE3::get_inverse_jacob(double* j,double *uv,double unite)
319     {
320 gervaislavoie 382 // Il faut exprimer les coordonnées x,y,z du repère 3D initial Ri dans un repère 2D final Rf de coordonnées
321     // x',y',z' où z'est nul afin de pouvoir utiliser les fonctions d'interpolation de l'élément de référence
322     FEM_NOEUD* n1=get_fem_noeud(0);
323     FEM_NOEUD* n2=get_fem_noeud(1);
324     FEM_NOEUD* n3=get_fem_noeud(2);
325    
326     double *xyzn1=n1->get_coord();
327     double *xyzn2=n2->get_coord();
328     double *xyzn3=n3->get_coord();
329    
330     //Temporaire
331     /*xyzn1[0]=5;
332     xyzn1[1]=5;
333     xyzn1[2]=5;
334    
335     xyzn2[0]=10;
336     xyzn2[1]=10;
337     xyzn2[2]=5;
338    
339     xyzn3[0]=5;
340     xyzn3[1]=10;
341     xyzn3[2]=5;*/
342     //
343    
344     OT_VECTEUR_3D vec1(xyzn1,xyzn2);
345     OT_VECTEUR_3D vec3(xyzn1,xyzn3);
346     vec1.norme();
347     OT_VECTEUR_3D n=vec1&vec3; // Normale au triangle au noeud n1
348     n.norme();
349     OT_VECTEUR_3D vec2=n&vec1; // Vecteur normal à vec1 dans le plan du triangle
350     vec2.norme();
351     OT_MATRICE_3D pif(vec1,vec2,n); // Matrice de passage du repère Ri au repère Rf
352    
353     // Position initiale (0) des noeuds dans le repère initial (i)
354     OT_VECTEUR_3D n1_0i(n1->get_dx(),n1->get_dy(),n1->get_dz());
355     OT_VECTEUR_3D n2_0i(n2->get_dx(),n2->get_dy(),n2->get_dz());
356     OT_VECTEUR_3D n3_0i(n3->get_dx(),n3->get_dy(),n3->get_dz());
357     OT_MATRICE_3D pos_0i(n1_0i,n2_0i,n3_0i);
358    
359     // Position initiale (0) des noeuds dans le repère final (f)
360     //OT_MATRICE_3D pos_0f=pos_0i*pif;
361     OT_MATRICE_3D pif_inverse=pif.inverse();
362     OT_MATRICE_3D pos_0f=pif_inverse*pos_0i;
363     OT_VECTEUR_3D vecn1_0=pos_0f.get_vecteur1();
364     pos_0f.change_vecteur1(pos_0f.get_vecteur1()-vecn1_0); // Étant donné que le noeud 1 est l'origine du repère final, on soustrait ses coordonnées à chaque noeud
365     pos_0f.change_vecteur2(pos_0f.get_vecteur2()-vecn1_0);
366     pos_0f.change_vecteur3(pos_0f.get_vecteur3()-vecn1_0);
367    
368     // Position actuelle (t) des noeuds dans le repère initial (i)
369     OT_VECTEUR_3D n1_ti(xyzn1);
370     OT_VECTEUR_3D n2_ti(xyzn2);
371     OT_VECTEUR_3D n3_ti(xyzn3);
372     OT_MATRICE_3D pos_ti(n1_ti,n2_ti,n3_ti);
373    
374     // Position actuelle (t) des noeuds dans le repère final (f)
375     //OT_MATRICE_3D pos_tf=pos_ti*pif;
376     OT_MATRICE_3D pos_tf=pif_inverse*pos_ti;
377     OT_VECTEUR_3D vecn1_t=pos_tf.get_vecteur1();
378     pos_tf.change_vecteur1(pos_tf.get_vecteur1()-vecn1_t);
379     pos_tf.change_vecteur2(pos_tf.get_vecteur2()-vecn1_t);
380     pos_tf.change_vecteur3(pos_tf.get_vecteur3()-vecn1_t);
381    
382     // Gestion des erreurs numériques
383     for (int c=0;c<3;c++)
384     for (int l=0;l<3;l++)
385     {
386     if (fabs(pos_tf(l,c))<1e-10 & fabs(pos_tf(l,c))!=0)
387     pos_tf(l,c)=0.;
388     }
389    
390     // Calcul du déterminant du Jacobien 2D dans le repère final
391     // det[J]=(x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)
392     double J11=pos_tf(0,1)-pos_tf(0,0);
393     double J21=pos_tf(0,2)-pos_tf(0,0);
394     double J12=pos_tf(1,1)-pos_tf(1,0);
395     double J22=pos_tf(1,2)-pos_tf(1,0);
396     double det_J=J11*J22-J12*J21;
397     //double det_J=((pos_tf(0,1)-pos_tf(0,0))*(pos_tf(1,2)-pos_tf(1,0))-((pos_tf(0,2)-pos_tf(0,0))*(pos_tf(1,1)-pos_tf(1,0))));
398    
399     OT_VECTEUR_3D col1_jf_3d(J22/det_J,-J21/det_J,0.);
400     OT_VECTEUR_3D col2_jf_3d(-J12/det_J,J11/det_J,0.);
401     OT_VECTEUR_3D col3_jf_3d(0.,0.,0.);
402    
403     OT_MATRICE_3D j_f_3d(col1_jf_3d,col2_jf_3d,col3_jf_3d); // Jacobien inverse 3D dans le repère final
404    
405     OT_MATRICE_3D j_i=pif*j_f_3d; // Jacobien inverse dans le repère initial
406    
407     j[0]=j_i(0,0);
408     j[1]=j_i(1,0);
409     j[2]=j_i(2,0);
410    
411     j[3]=j_i(0,1);
412     j[4]=j_i(1,1);
413     j[5]=j_i(2,1);
414    
415     j[6]=j_i(0,2);
416     j[7]=j_i(1,2);
417     j[8]=j_i(2,2);
418    
419     int test=1;
420 francois 310 }