1 |
bechet |
105 |
#include "gestionversion.h" |
2 |
francois |
104 |
#include "toxfem.h" |
3 |
|
|
#include "MagXchange.h" |
4 |
|
|
#include "mg_file.h" |
5 |
|
|
#include "ot_mathematique.h" |
6 |
|
|
#include "tpl_map_entite.h" |
7 |
|
|
#include "tpl_octree.h" |
8 |
|
|
#include <math.h> |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
toxfem::toxfem() |
13 |
|
|
{ |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
toxfem::~toxfem() |
18 |
|
|
{ |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
int toxfem::estdansletetra(MG_TETRA *tet,double x,double y, double z) |
24 |
|
|
{ |
25 |
|
|
double* xyz1=tet->get_noeud1()->get_coord(); |
26 |
|
|
double* xyz2=tet->get_noeud2()->get_coord(); |
27 |
|
|
double* xyz3=tet->get_noeud3()->get_coord(); |
28 |
|
|
double* xyz4=tet->get_noeud4()->get_coord(); |
29 |
|
|
OT_VECTEUR_3D v1(xyz2[0]-xyz1[0],xyz2[1]-xyz1[1],xyz2[2]-xyz1[2]); |
30 |
|
|
OT_VECTEUR_3D v2(xyz3[0]-xyz1[0],xyz3[1]-xyz1[1],xyz3[2]-xyz1[2]); |
31 |
|
|
OT_VECTEUR_3D v3(xyz4[0]-xyz1[0],xyz4[1]-xyz1[1],xyz4[2]-xyz1[2]); |
32 |
|
|
OT_VECTEUR_3D v4(x-xyz1[0],y-xyz1[1],z-xyz1[2]); |
33 |
|
|
OT_MATRICE_3D mat(v1,v2,v3); |
34 |
|
|
OT_MATRICE_3D mat1(v4,v2,v3); |
35 |
|
|
OT_MATRICE_3D mat2(v1,v4,v3); |
36 |
|
|
OT_MATRICE_3D mat3(v1,v2,v4); |
37 |
|
|
double det=mat.get_determinant(); |
38 |
|
|
double xsi=mat1.get_determinant()/det; |
39 |
|
|
double eta=mat2.get_determinant()/det; |
40 |
|
|
double dseta=mat3.get_determinant()/det; |
41 |
|
|
int reponse=1; |
42 |
|
|
if (xsi<-0.000001) reponse=0; |
43 |
|
|
if (eta<-0.000001) reponse=0; |
44 |
|
|
if (dseta<-0.000001) reponse=0; |
45 |
|
|
if (xsi+eta+dseta>1.000001) reponse=0; |
46 |
|
|
return reponse; |
47 |
|
|
|
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
double toxfem::calculdist(double *n,double x,double y,double z,MG_NOEUD* noeud,MG_TETRA* tet) |
51 |
|
|
{ |
52 |
|
|
double* xyz=noeud->get_coord(); |
53 |
|
|
/*double t=(-n[0]*xyz[0]-n[1]*xyz[1]-n[2]*xyz[2]-n[3])/(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); |
54 |
|
|
double xyz1[3]; |
55 |
|
|
xyz1[0]=xyz[0]+t*n[0]; |
56 |
|
|
xyz1[1]=xyz[1]+t*n[1]; |
57 |
|
|
xyz1[2]=xyz[2]+t*n[2]; |
58 |
|
|
double dist; |
59 |
|
|
if (estdansletetra(tet,xyz1[0],xyz1[1],xyz1[2])) |
60 |
|
|
dist=sqrt((xyz[0]-xyz1[0])*(xyz[0]-xyz1[0])+(xyz[1]-xyz1[1])*(xyz[1]-xyz1[1])+(xyz[2]-xyz1[2])*(xyz[2]-xyz1[2])); |
61 |
|
|
else*/ |
62 |
|
|
double dist=sqrt((xyz[0]-x)*(xyz[0]-x)+(xyz[1]-y)*(xyz[1]-y)+(xyz[2]-z)*(xyz[2]-z)); |
63 |
|
|
OT_VECTEUR_3D vec1(n[0],n[1],n[2]); |
64 |
|
|
OT_VECTEUR_3D vec2(xyz[0]-x,xyz[1]-y,xyz[2]-z); |
65 |
|
|
double ps=vec1*vec2; |
66 |
|
|
if (ps<0.) dist=-dist; |
67 |
|
|
return dist; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
void toxfem::importer(std::string nomfichier,class MagXchange* data) |
71 |
|
|
{ |
72 |
|
|
MG_FILE gest((char*)nomfichier.c_str()); |
73 |
|
|
MG_MAILLAGE* mai=gest.get_mg_maillage(1); |
74 |
|
|
MG_GEOMETRIE* geo=gest.get_mg_geometrie(0); |
75 |
|
|
int nb_noeud=mai->get_nb_mg_noeud(); |
76 |
|
|
std::string nomfichier2=nomfichier+".sol"; |
77 |
|
|
MG_SOLUTION* solution=new MG_SOLUTION(mai,1,(char*)nomfichier.c_str(),nb_noeud,"level set"); |
78 |
|
|
solution->change_legende(0,"level_0"); |
79 |
|
|
gest.ajouter_mg_solution(solution); |
80 |
|
|
double xmin=1e300,ymin=1e300,zmin=1e308; |
81 |
|
|
double xmax=-1e300,ymax=-1e300,zmax=-1e308; |
82 |
|
|
TPL_MAP_ENTITE<MG_NOEUD*> lst_noeud; |
83 |
|
|
for (int i=0;i<nb_noeud;i++) |
84 |
|
|
{ |
85 |
|
|
MG_NOEUD* noeud=mai->get_mg_noeud(i); |
86 |
|
|
double* xyz=noeud->get_coord(); |
87 |
|
|
if (xyz[0]<xmin) xmin=xyz[0]; |
88 |
|
|
if (xyz[1]<ymin) ymin=xyz[1]; |
89 |
|
|
if (xyz[2]<zmin) zmin=xyz[2]; |
90 |
|
|
if (xyz[0]>xmax) xmax=xyz[0]; |
91 |
|
|
if (xyz[1]>ymax) ymax=xyz[1]; |
92 |
|
|
if (xyz[2]>zmax) zmax=xyz[2]; |
93 |
|
|
noeud->change_solution(1e300); |
94 |
|
|
lst_noeud.ajouter(noeud); |
95 |
|
|
} |
96 |
|
|
TPL_OCTREE<MG_TETRA*,MG_NOEUD*> octree; |
97 |
|
|
octree.initialiser(&lst_noeud,1,xmin,ymin,zmin,xmax,ymax,zmax); |
98 |
|
|
int nb_tetra=mai->get_nb_mg_tetra(); |
99 |
|
|
for (int i=0;i<nb_tetra;i++) |
100 |
|
|
{ |
101 |
|
|
MG_TETRA* tet=mai->get_mg_tetra(i); |
102 |
|
|
octree.inserer(tet); |
103 |
|
|
} |
104 |
|
|
int nbface=geo->get_nb_mg_face(); |
105 |
|
|
for (int iface=0;iface<nbface;iface++) |
106 |
|
|
{ |
107 |
|
|
MG_FACE* face=geo->get_mg_face(iface);TPL_MAP_ENTITE<MG_NOEUD*> lstnd; |
108 |
|
|
TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it; |
109 |
|
|
for (MG_ELEMENT_MAILLAGE* ele=face->get_lien_maillage()->get_premier(it);ele!=NULL;ele=face->get_lien_maillage()->get_suivant(it)) |
110 |
|
|
{ |
111 |
|
|
MG_TRIANGLE *tri=(MG_TRIANGLE*)ele; |
112 |
|
|
lstnd.ajouter(tri->get_noeud1()); |
113 |
|
|
lstnd.ajouter(tri->get_noeud2()); |
114 |
|
|
lstnd.ajouter(tri->get_noeud3()); |
115 |
|
|
} |
116 |
|
|
TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR it2; |
117 |
|
|
TPL_MAP_ENTITE<MG_TETRA*> listcoupe; |
118 |
|
|
for (MG_NOEUD* noeud=lstnd.get_premier(it2);noeud!=NULL;noeud=lstnd.get_suivant(it2)) |
119 |
|
|
{ |
120 |
|
|
double uv[2]; |
121 |
|
|
double *xyz=noeud->get_coord(); |
122 |
|
|
double normal[4]; |
123 |
|
|
face->inverser(uv,xyz); |
124 |
|
|
face->calcul_normale_unitaire(uv,normal); |
125 |
|
|
TPL_MAP_ENTITE<MG_TETRA*> liste; |
126 |
|
|
octree.rechercher(xyz[0],xyz[1],xyz[2],0.,liste); |
127 |
|
|
int nb=liste.get_nb(); |
128 |
|
|
for (int k=0;k<nb;k++) |
129 |
|
|
{ |
130 |
|
|
MG_TETRA* tet=liste.get(k); |
131 |
|
|
if ( estdansletetra(tet,xyz[0],xyz[1],xyz[2])) |
132 |
|
|
{ |
133 |
|
|
listcoupe.ajouter(tet); |
134 |
|
|
normal[3]=-normal[0]*xyz[0]-normal[1]*xyz[1]-normal[2]*xyz[2]; |
135 |
|
|
double dist=calculdist(normal,xyz[0],xyz[1],xyz[2],tet->get_noeud1(),tet); |
136 |
|
|
if (fabs(dist)<fabs(tet->get_noeud1()->get_solution())) |
137 |
|
|
tet->get_noeud1()->change_solution(dist); |
138 |
|
|
dist=calculdist(normal,xyz[0],xyz[1],xyz[2],tet->get_noeud2(),tet); |
139 |
|
|
if (fabs(dist)<fabs(tet->get_noeud2()->get_solution())) |
140 |
|
|
tet->get_noeud2()->change_solution(dist); |
141 |
|
|
dist=calculdist(normal,xyz[0],xyz[1],xyz[2],tet->get_noeud3(),tet); |
142 |
|
|
if (fabs(dist)<fabs(tet->get_noeud3()->get_solution())) |
143 |
|
|
tet->get_noeud3()->change_solution(dist); |
144 |
|
|
dist=calculdist(normal,xyz[0],xyz[1],xyz[2],tet->get_noeud4(),tet); |
145 |
|
|
if (fabs(dist)<fabs(tet->get_noeud4()->get_solution())) |
146 |
|
|
tet->get_noeud4()->change_solution(dist); |
147 |
|
|
|
148 |
|
|
} |
149 |
|
|
} |
150 |
|
|
} |
151 |
|
|
} |
152 |
|
|
for (int i=0;i<nb_noeud;i++) |
153 |
|
|
{ |
154 |
|
|
MG_NOEUD* noeud=mai->get_mg_noeud(i); |
155 |
|
|
if (i==866) noeud->change_solution(noeud->get_solution()*(-1)); |
156 |
|
|
if (i==921) noeud->change_solution(noeud->get_solution()*(-1)); |
157 |
|
|
if (i==1213) noeud->change_solution(noeud->get_solution()*(-1)); |
158 |
|
|
if (i==1158) noeud->change_solution(noeud->get_solution()*(-1)); |
159 |
|
|
solution->ecrire(i,0,noeud->get_solution()); |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
for (int i=0;i<nb_noeud;i++) |
163 |
|
|
{ |
164 |
|
|
MG_NOEUD* noeud=mai->get_mg_noeud(i); |
165 |
|
|
MagNode *xfemnode; |
166 |
|
|
if (noeud->get_solution()<1e200) |
167 |
|
|
{ |
168 |
|
|
xfemnode=new MagNode(1); |
169 |
|
|
xfemnode->values()[0]=noeud->get_solution(); |
170 |
|
|
xfemnode->idvalues()[0]=0; |
171 |
|
|
} // 1 valeur de levelset |
172 |
|
|
else |
173 |
|
|
xfemnode=new MagNode(0); // 0 valeur de levelset |
174 |
|
|
double * posxfem=xfemnode->position(); |
175 |
|
|
for (int i=0;i<3;++i) posxfem[i]=noeud->get_coord()[i]; |
176 |
|
|
xfemnode->id(noeud->get_id()); |
177 |
|
|
data->addnode(*xfemnode,true); |
178 |
|
|
delete xfemnode; |
179 |
|
|
} |
180 |
|
|
int nbtetra=mai->get_nb_mg_tetra(); |
181 |
|
|
for (int i=0;i<nbtetra;i++) |
182 |
|
|
{ |
183 |
|
|
MG_TETRA* tet=mai->get_mg_tetra(i); |
184 |
|
|
MagElement xfemele(MagElement::TETRAHEDRON); |
185 |
|
|
xfemele.nodes()[0]=tet->get_noeud1()->get_id(); |
186 |
|
|
xfemele.nodes()[1]=tet->get_noeud2()->get_id(); |
187 |
|
|
xfemele.nodes()[2]=tet->get_noeud3()->get_id(); |
188 |
|
|
xfemele.nodes()[3]=tet->get_noeud4()->get_id(); |
189 |
|
|
data->addelement(xfemele); |
190 |
|
|
} |
191 |
|
|
} |