load "medit" load "mmg" // 2 basic functions to build surface mesh /* Usage: meshS SurfaceHex(N,B,L,orient); -- build the surface mesh of a 3d box where: for example: int[int] N=[nx,ny,nz]; // the number of seg in the 3 direction real [int,int] B=[[xmin,xmax],[ymin,ymax],[zmin,zmax]]; // bounding bax int [int,int] L=[[1,2],[3,4],[5,6]]; // the label of the 6 face left,right, front, back, down, right orient the global orientation of the surface 1 extern (-1 intern) func meshS Sphere(real R,real h,int L,int orient); -- build a surface mesh of a sphere with 1 mapping (spheriale coordinate) where R is the raduis, h is the mesh size of the shpere L is the label the the sphere orient the global orientation of the surface 1 extern (-1 intern func meshS Icosahedron (int orientation) -- build a Icosahedron meshS with given orientation. with a region number go from 1 to 20 corresponding to the 20 faces func meshS Sphere20(real R,int N,int orient); -- build a sphere mesh form a Isocaedron with each traingle subdivide by N^2 with a region number go from 1 to 20 corresponding to the 20 faces orient the global orientation of the surface 1 extern (-1 intern */ func meshS SurfaceHex(int[int] & N,real[int,int] &B ,int[int,int] & L,int orientation) { real x0=B(0,0),x1=B(0,1); real y0=B(1,0),y1=B(1,1); real z0=B(2,0),z1=B(2,1); int nx=N[0],ny=N[1],nz=N[2]; mesh Thx = square(ny,nz,[y0+(y1-y0)*x,z0+(z1-z0)*y]); mesh Thy = square(nx,nz,[x0+(x1-x0)*x,z0+(z1-z0)*y]); mesh Thz = square(nx,ny,[x0+(x1-x0)*x,y0+(y1-y0)*y]); int[int] refx=[0,L(0,0)],refX=[0,L(0,1)]; // Xmin, Ymax faces labels renumbering int[int] refy=[0,L(1,0)],refY=[0,L(1,1)]; // Ymin, Ymax faces labesl renumbering int[int] refz=[0,L(2,0)],refZ=[0,L(2,1)]; // Zmin, Zmax faces labels renumbering meshS Thx0 = movemesh23(Thx,transfo=[x0,x,y],orientation=-orientation,region=refx); meshS Thx1 = movemesh23(Thx,transfo=[x1,x,y],orientation=+orientation,region=refX); meshS Thy0 = movemesh23(Thy,transfo=[x,y0,y],orientation=+orientation,region=refy); meshS Thy1 = movemesh23(Thy,transfo=[x,y1,y],orientation=-orientation,region=refY); meshS Thz0 = movemesh23(Thz,transfo=[x,y,z0],orientation=-orientation,region=refz); meshS Thz1 = movemesh23(Thz,transfo=[x,y,z1],orientation=+orientation,region=refZ); meshS Th= Thx0+Thx1+Thy0+Thy1+Thz0+Thz1; return Th; } func meshS Ellipsoide (real RX,real RY,real RZ,real h,int L,real Ox,real Oy,real Oz,int orientation) { mesh Th=square(10,20,[x*pi-pi/2,2*y*pi]); // $]\frac{-pi}{2},frac{-pi}{2}[\times]0,2\pi[ $ // a parametrization of a sphere func f1 =RX*cos(x)*cos(y)+Ox; func f2 =RY*cos(x)*sin(y)+Oy; func f3 =RZ*sin(x)+Oz; // partiel derivative func f1x= -RX*sin(x)*cos(y); func f1y= -RX*cos(x)*sin(y); func f2x= -RY*sin(x)*sin(y); func f2y= +RY*cos(x)*cos(y); func f3x=-RZ*cos(x); func f3y=0; // the metric on the sphere $ M = DF^t DF $ func m11=f1x^2+f2x^2+f3x^2; func m21=f1x*f1y+f2x*f2y+f3x*f3y; func m22=f1y^2+f2y^2+f3y^2; func perio=[[4,y],[2,y],[1,x],[3,x]]; // to store the periodic condition real hh=h;// hh mesh size on unite sphere real vv= 1/square(hh); Th=adaptmesh(Th,m11*vv,m21*vv,m22*vv,IsMetric=1,periodic=perio); Th=adaptmesh(Th,m11*vv,m21*vv,m22*vv,IsMetric=1,periodic=perio); Th=adaptmesh(Th,m11*vv,m21*vv,m22*vv,IsMetric=1,periodic=perio); Th=adaptmesh(Th,m11*vv,m21*vv,m22*vv,IsMetric=1,periodic=perio); int[int] ref=[0,L]; meshS ThS= movemesh23(Th,transfo=[f1,f2,f3],orientation=orientation,reftri=ref); ThS=mmgs(ThS,hmin=h,hmax=h,hgrad=2.); return ThS; } func meshS Ellipsoide (real RX,real RY,real RZ,real h,int L,int orientation) { return Ellipsoide (RX,RY,RZ,h,L,0.,0.,0.,orientation); } func meshS Sphere(real R,real h,int L,int orientation) { return Ellipsoide(R,R,R,h,L,orientation); } func meshS Sphere(real R,real h,int L,real Ox,real Oy,real Oz,int orientation) { return Ellipsoide(R,R,R,h,L,Ox,Oy,Oz,orientation); } func meshS Icosahedron (int orientation,int wplot) { //=================================================================================== //Angles utiles //=================================================================================== real tan3pi10 = sqrt(25.+10.*sqrt(5.))/5.;//3pi/10 angle entre deux aretes du pentagone real sin3pi10 = (sqrt(5)+1)/4;//3pi/10 angle entre deux aretes du pentagone real cos3pi10 = sqrt(10-2*sqrt(5))/4;//3pi/10 angle entre deux aretes du pentagone real cosdiedre = sqrt(5)/3; //angle diedre de l'icosaedre -pi/2 real sindiedre = 2./3; //angle diedre de l'icosaedre -pi/2 real cosico = tan3pi10/sqrt(3); //angle entre une face de la pyramide pentagonale par rapport à l'horizontale real sinico = sqrt(1-square(cosico)); //angle entre une face de la pyramide pentagonale par rapport à l'horizontale real sin2pi5 = sqrt(10+2*sqrt(5))/4; //2pi/5 angle pour la rotation des aretes du pentagone real cos2pi5 = (sqrt(5)-1)/4; //2pi/5 angle pour la rotation des aretes du pentagone real cosicod = cosdiedre*cosico+sindiedre*sinico;//angle diedre -pi/2 - ico real sinicod = sindiedre*cosico-cosdiedre*sinico;//angle diedre -pi/2 - ico real sinpi3 = sqrt(3)/2; //angle du triangle equilateral int n = 1; real sinpi5 = cos3pi10;//pi/5 angle de décalage entre deux demi icosaedre real cospi5 = sin3pi10;//pi/5 angle de décalage entre deux demi icosaedre real tanpi10 = sqrt(25.-10.*sqrt(5.))/5.;//pi/10 real h = 0.5*sqrt(3-square(tanpi10));//hauteur du prisme d'ordre 5; //================================================================================= //Construction du triangle equilateral en 2D //================================================================================= border a(t=0,1){x=t; y=0; label =1;}; border b(t=1,0.5){x=t; y=sqrt(3)*(1-t); label =2;}; border c(t=0.5,0){x=t; y=sqrt(3)*(t); label =3;}; mesh Triangle= buildmesh(a(n)+b(n)+c(n)); //traingle equilateral if(wplot>2) plot (cmm="Triangle",Triangle,wait=1); func f = 1; meshS Triangle3 = movemesh23(Triangle,transfo=[x,0,y]);//trianglesup if(wplot>2) plot (cmm="Triangle3",Triangle3,wait=1); meshS TriangleS = change(fregion=1,movemeshS(Triangle3,transfo=[x,sinico*y+cosico*z,-cosico*y+sinico*z]));//rotation de -(pi - diedre) par rapport à l'axe des x pour former une face de la pyramide pentagonale if(wplot>2) plot (cmm="TriangleS",TriangleS,wait=1); //medit("face pyramide pentagonale",TriangleS); meshS TriangleI = change(fregion=2,movemeshS(TriangleS,transfo=[x,-cosdiedre*y+sindiedre*z,-sindiedre*y-cosdiedre*z],orientation=-1));//triangle inf rotation de l'angle diedre par rapport au triangle sup if(wplot>2) plot (cmm="TriangleI",TriangleI,wait=1); meshS Triangles = TriangleI+TriangleS; if(wplot>1) plot (cmm="Triangles",Triangles,wait=1); //medit("face pyramide pentagonale + face antiprisme d'ordre 5",Triangles); meshS T1 = change(movemeshS(Triangles,transfo=[x-0.5,y-sinpi3*cosico,z],orientation=1),fregion = region);//translation pour que la figure soit sur le bord du pentagone meshS T2 = change(movemeshS(T1,transfo=[cos2pi5*x-sin2pi5*y,sin2pi5*x+cos2pi5*y,z],orientation=1),fregion = region+2);; meshS T3 = change(movemeshS(T2,transfo=[cos2pi5*x-sin2pi5*y,sin2pi5*x+cos2pi5*y,z]),fregion = region+2);; meshS T4 = change(movemeshS(T3,transfo=[cos2pi5*x-sin2pi5*y,sin2pi5*x+cos2pi5*y,z]),fregion = region+2);; meshS T5 = change(movemeshS(T4,transfo=[cos2pi5*x-sin2pi5*y,sin2pi5*x+cos2pi5*y,z]),fregion = region+2);; meshS Tdemi= T1+T2+T3+T4+T5;//moitié de l'icosaedre meshS Tdemi0 = movemeshS(Tdemi,transfo=[x,y,z+0.5*h]);//moitié supérieure meshS Tdemi1 = movemeshS(Tdemi0,transfo=[x,y,-z]);//moitié inférieure meshS Tdemi1rot = change(movemeshS(Tdemi1,transfo=[cospi5*x-sinpi5*y,sinpi5*x+cospi5*y,z],orientation=-1),fregion = region+10);//rotation de la moitié inférieure pour les emboiter meshS Ticosaedre = Tdemi0+Tdemi1rot; //Ticosaedre=trunc(Ticosaedre,1,split=5); if(wplot) plot(Ticosaedre,wait=1); //cout << regions(Ticosaedre) << endl; return Ticosaedre; } func meshS Icosahedron (int orientation) { return Icosahedron(orientation,0); } func meshS Sphere20 (real R,int N,int orientation,int wplot) {// Isocaedre regulier !!!! Thank G. Vergez .. meshS Ticosaedre = Icosahedron(orientation,wplot); Ticosaedre=trunc(Ticosaedre,1,split=N); if(wplot) plot(cmm="Icosaedre",Ticosaedre,wait=1); //================================================================================= //Construction de la sphere 3D //================================================================================= func metric =dist(x,y,z)/R; meshS Th = movemeshS(Ticosaedre,transfo=[x/metric,y/metric,z/metric]); if(wplot) plot (cmm="Th",Th,wait=1); return Th; } func meshS Sphere20 (real R,int N,int orientation) { return Sphere20(R,N,orientation,0); } /* test: load "tetgen" { real hs = 0.1; // mesh size on sphere int[int] N=[20,20,20]; real [int,int] B=[[-1,1],[-1,1],[-1,1]]; int [int,int] L=[[1,2],[3,4],[5,6]]; //////////////////////////////// meshS ThH = (N,B,L,1); meshS ThS =Sphere(0.5,hs,7,1); // "gluing" surface meshs to tolat boundary meshes cout << " xxxx" << ThH.nv << " " << ThS.nv << endl; meshS ThHS=ThH+ThS; savemesh(ThHS,"Hex-Sphere.mesh"); exec("ffmedit Hex-Sphere.mesh;rm Hex-Sphere.mesh"); real voltet=(hs^3)/6.; cout << " voltet = " << voltet << endl; real[int] domaine = [0,0,0,1,voltet,0,0,0.7,2,voltet]; mesh3 Th = tetg(ThHS,switch="pqaAAYYQ",nbofregions=2,regionlist=domaine); medit("Cube-With-Ball",Th); } */