ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_coque.cpp
Revision: 328
Committed: Wed Mar 14 22:04:28 2012 UTC (13 years, 2 months ago) by gervaislavoie
File size: 5655 byte(s)
Log Message:
Ajout orientation d'une coque par id a partir d'un maillage geometrique.

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     // mg_coque.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 � 11H22
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26     #include "mg_coque.h"
27 gervaislavoie 328 #include "mg_maillage.h"
28     #include "ot_mathematique.h"
29 francois 283 //#include "message.h"
30    
31     MG_COQUE::MG_COQUE(std::string idori,unsigned long num):MG_ELEMENT_TOPOLOGIQUE(num,idori),num_materiau(-1)
32     {
33     }
34    
35     MG_COQUE::MG_COQUE(std::string idori):MG_ELEMENT_TOPOLOGIQUE(idori),num_materiau(-1)
36     {
37     }
38    
39     MG_COQUE::MG_COQUE(MG_COQUE& mdd):MG_ELEMENT_TOPOLOGIQUE(mdd),lst_coquille(mdd.lst_coquille)
40     {
41     }
42    
43     MG_COQUE::~MG_COQUE()
44     {
45     }
46    
47     void MG_COQUE::ajouter_mg_coquille(class MG_COQUILLE* mgcoq)
48     {
49     lst_coquille.insert(lst_coquille.end(),mgcoq);
50     }
51    
52     void MG_COQUE::supprimer_mg_coquille(class MG_COQUILLE* mgcoq)
53     {
54     std::vector<MG_COQUILLE*>::iterator i;
55     for (i=lst_coquille.begin();i!=lst_coquille.end();i++)
56     {
57     if ((*i)==mgcoq)
58     {
59     lst_coquille.erase(i);
60     return;
61     }
62     }
63     }
64    
65    
66     int MG_COQUE::get_nb_mg_coquille(void)
67     {
68     return lst_coquille.size();
69     }
70    
71     MG_COQUILLE* MG_COQUE::get_mg_coquille(int num)
72     {
73     return lst_coquille[num];
74     }
75    
76     int MG_COQUE::get_dimension(void)
77     {
78     return 2;
79     }
80     void MG_COQUE::get_topologie_sousjacente(TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> *lst)
81     {
82     int nbcoq=lst_coquille.size();
83     for (int i=0;i<nbcoq;i++)
84     {
85     MG_COQUILLE* coq=lst_coquille[i];
86     int nbface=coq->get_nb_mg_coface();
87     for (int j=0;j<nbface;j++)
88     {
89     MG_FACE* face=coq->get_mg_coface(j)->get_face();
90     lst->ajouter(face);
91     face->get_topologie_sousjacente(lst);
92     }
93     }
94     }
95     void MG_COQUE::enregistrer(std::ostream& o)
96     {
97     o << "%" << get_id() << "=COQUE(" << get_idoriginal() << ",(";
98     for (unsigned int i=0;i<lst_coquille.size();i++)
99     {
100     o << "$" << lst_coquille[i]->get_id();
101     if (i!=lst_coquille.size()-1) o << ",";
102     else o << ")";
103     }
104     int nb=get_nb_ccf();
105     o << "," << num_materiau << "," << nb;
106     if (nb!=0)
107     {
108     o << ",(";
109     for (int i=0;i<nb;i++)
110     {
111     char nom[3];
112     get_type_ccf(i,nom);
113     o << "(" << nom << "," << get_valeur_ccf(i) << ")";
114     if (i!=nb-1) o << "," ;
115     }
116     o << ")";
117     }
118     o << ");" << std::endl;
119     }
120    
121 gervaislavoie 328 void MG_COQUE::orienter(class MG_MAILLAGE* mai)
122     {
123     double point[3]; // Coordonnées X, Y et Z du point d'orientation
124     int nbccf=get_nb_ccf();
125     for (int k=0;k<nbccf;k++)
126     {
127     char typeccf[2];
128     get_type_ccf(k,typeccf);
129     if (typeccf[0]=='C')
130     {
131     if (typeccf[1]=='x') point[0]=get_valeur_ccf(k);
132     if (typeccf[1]=='y') point[1]=get_valeur_ccf(k);
133     if (typeccf[1]=='z') point[2]=get_valeur_ccf(k);
134     }
135     }
136     double dist_min=1e300;
137     MG_NOEUD* noeud_plus_pres;
138     LISTE_MG_NOEUD::iterator it;
139     for (MG_NOEUD* noeud_actuel=mai->get_premier_noeud(it);noeud_actuel;noeud_actuel=mai->get_suivant_noeud(it))
140     {
141     double *xyz_actuel=noeud_actuel->get_coord();
142     OT_VECTEUR_3D vec_actuel(xyz_actuel,point);
143     double distance_actuelle=vec_actuel.get_longueur();
144     if (distance_actuelle<dist_min)
145     {
146     dist_min=distance_actuelle;
147     noeud_plus_pres=noeud_actuel;
148     }
149     }
150     MG_TRIANGLE* tri=(MG_TRIANGLE*)noeud_plus_pres->get_lien_triangle()->get(0);
151     MG_NOEUD* no1;
152     MG_NOEUD* no2;
153     MG_NOEUD* no3;
154    
155     no1=tri->get_noeud1();
156     no2=tri->get_noeud2();
157     no3=tri->get_noeud3();
158    
159     MG_FACE* face=(MG_FACE*)(tri->get_lien_topologie());
160     double *xyzn1=no1->get_coord();
161     double *xyzn2=no2->get_coord();
162     double *xyzn3=no3->get_coord();
163    
164     // Pour vérifier l'ordre des vecteurs pour le calcul de la normale d'un triangle
165     double uv[2];
166     face->inverser(uv,xyzn1); // Changement de système de coordonnées
167     double normale[3];
168     face->calcul_normale_unitaire(uv,normale);
169    
170     OT_VECTEUR_3D vec1(xyzn1,xyzn3);
171     OT_VECTEUR_3D vec2(xyzn1,xyzn2);
172     OT_VECTEUR_3D norm=vec1&vec2; // Normale au triangle
173     norm.norme();
174     double ps=norm*normale;
175     double *xyz_plus_pres=noeud_plus_pres->get_coord();
176     OT_VECTEUR_3D vec_plus_pres(xyz_plus_pres,point);
177     vec_plus_pres.norme();
178     ps=norm*vec_plus_pres;
179     ps=norm*vec_plus_pres;
180    
181     if (ps<0) // Il faut inverser le signe de la coface
182     {
183     int nbcofaces=get_mg_coquille(0)->get_nb_mg_coface();
184     for (int i=0;i<nbcofaces;i++)
185     {
186     MG_COFACE* cof=get_mg_coquille(0)->get_mg_coface(i);
187     int signe=cof->get_orientation();
188     MG_FACE* f=cof->get_face();
189     cof->change(f,-1*signe);
190     }
191     }
192     }
193    
194 francois 283 void MG_COQUE::change_num_materiau(int num)
195     {
196     num_materiau=num;
197     }
198    
199     int MG_COQUE::get_num_materiau(void)
200     {
201     return num_materiau;
202     }
203    
204     VCT& MG_COQUE::get_vectorisation(void)
205     {
206     VCT *p=NULL;
207     return *p;
208     }