|
| 1 | +// calcul du couplage entre deux domaines de section rectangulaire Ex*Ey |
| 2 | +// a une distance dist |
| 3 | +// en contact avec une résistance de contact 1/c |
| 4 | +// |
| 5 | +// La face opposee de chaque rectangle est a temperature imposee T1 resp T2 |
| 6 | +// Le couplage est intégré directement dans le système d'équation |
| 7 | +// |
| 8 | +// version avec les espaces composite |
| 9 | + |
| 10 | +real x0=0,x2=4; |
| 11 | +real y0=0,y1=1; |
| 12 | +real L= x2-x0; |
| 13 | +real k1=1; |
| 14 | +real k2=1; |
| 15 | + |
| 16 | +real c=1; |
| 17 | + |
| 18 | +real T0=100.0, T1=00.0; |
| 19 | + |
| 20 | + |
| 21 | +// mesh construction. |
| 22 | + |
| 23 | +// the curve in y . |
| 24 | + func F = 2+0.5*sin(2*pi*(y)); |
| 25 | + func dF= -1*0.5*pi*2*cos(2*pi*(y)); |
| 26 | + func dux = (T1-T0)/(L+ (k1/c)/sqrt(1.+0*square(dF))); // |
| 27 | + |
| 28 | + // k du/dn = c[u] |
| 29 | +// if we neglect the du/dy |
| 30 | +// the solution |
| 31 | +// du/dx is constant in x and |
| 32 | +// du/dx*L + [u] = T1-T0 |
| 33 | +// du/dx*L + N.x k/c du/dx = T1-T0 |
| 34 | +// => |
| 35 | +// du/dx = (T1-T0) /(L+nx*k/c) |
| 36 | + |
| 37 | + // t ->( F,t ) t' = ( dF, 1) n = (-1, dF) / sqrt( 1+ dF^2) |
| 38 | + // N.x = 1 / sqrt( 1+ dF^2) |
| 39 | + |
| 40 | + func Te1= T0+x*dux; |
| 41 | + func Te2= T1+(x-L)*dux; |
| 42 | + |
| 43 | +real xb1= F(0,0); |
| 44 | +real xu1= F(0,1); |
| 45 | + |
| 46 | +border left(t=y1,y0) {x=x0; y=t;label=3;} |
| 47 | +border right(t=y0,y1) {x=x2; y=t;label=4;} |
| 48 | +border bot1(t=x0,xb1) {y=y0; x=t;label=2;} |
| 49 | +border bot2(t=xb1,x2) {y=y0; x=t;label=2;} |
| 50 | +border up1(t=x2,xu1) {y=y1; x=t;label=2;} |
| 51 | +border up2(t=xu1,x0) {y=y1; x=t;label=2;} |
| 52 | +border curve(t=0,1) {y=t;x=F(0,t) ; label=10;} |
| 53 | + |
| 54 | + |
| 55 | +// Maillages coincidents |
| 56 | +int n=30; |
| 57 | +int ny=n*(y1-y0); |
| 58 | +func Bord = left(ny)+right(ny)+curve(ny*2) |
| 59 | + +bot1(n*(xb1-x0))+bot2(n*(x2-xb1)) |
| 60 | + +up1(n*(x2-xu1))+up2(n*(x2-xu1)); |
| 61 | +plot(Bord,wait=1); |
| 62 | +mesh Th= buildmesh( Bord ); |
| 63 | +// get region numbion to buid 2 meshes: |
| 64 | +int rg1=Th(x0+0.1,y0+0.1).region; |
| 65 | +int rg2=Th(x2-0.1,y1-0.1).region; |
| 66 | +// 2 meshes conform. |
| 67 | +mesh Th1=trunc(Th,region==rg1); |
| 68 | +mesh Th2=trunc(Th,region==rg2); |
| 69 | +// now the 2 meshes are not conform. |
| 70 | +//Th2 = adaptmesh(Th2,0.05,IsMetric=1,nbvx=1000000); |
| 71 | +//Th1 = adaptmesh(Th1,0.03,IsMetric=1,nbvx=1000000); |
| 72 | + |
| 73 | + |
| 74 | +plot(Th1,Th2,wait=1); |
| 75 | + |
| 76 | +fespace Vh1(Th1,P1); //Vh1 u1=T0, v1,Vh1x=x,Vh1y=y,Vh1lab=label; |
| 77 | +fespace Vh2(Th2,P1); |
| 78 | + |
| 79 | +// two good approximation of the exact solution. |
| 80 | +Vh1 ue1=Te1; |
| 81 | +Vh2 ue2=Te2; |
| 82 | +plot(ue1,ue2,wait=1,cmm="analytic approximation"); |
| 83 | + |
| 84 | +varf V11(u,v) = int2d(Th1)(k1*dx(u)*dx(v) + k1*dy(u)*dy(v)) + int1d(Th1,10,mortar=1)(c*u*v) + on(3,u=T0); |
| 85 | +varf V12(u,v) = int1d(Th1,10,mortar=1)(-c*u*v); |
| 86 | +varf V21(u,v) = int1d(Th2,10,mortar=1)(-c*u*v); |
| 87 | +varf V22(u,v) = int2d(Th2)(k2*dx(u)*dx(v) + k2*dy(u)*dy(v)) + int1d(Th2,10,mortar=1)(c*u*v) + on(4,u=T1); |
| 88 | + |
| 89 | +matrix A11 = V11(Vh1,Vh1); |
| 90 | +matrix A12 = V12(Vh2,Vh1); |
| 91 | +matrix A21 = V21(Vh1,Vh2); |
| 92 | +matrix A22 = V22(Vh2,Vh2); |
| 93 | +// test the integrale of on curve line. |
| 94 | + |
| 95 | +{ // verification of matrix A12 and A21... |
| 96 | + |
| 97 | +macro verif1(A,vv) { |
| 98 | + real[int] b(A.m); |
| 99 | + b=1.; |
| 100 | + vv[]=A*b; |
| 101 | + cout << " sum = " << vv[].sum << "== " << int1d(Th1,10)(-c) << " == " << int1d(Th2,10)(-c) <<endl; |
| 102 | + assert ( abs(vv[].sum-int1d(Th1,10)(-c) ) < 1e-3); |
| 103 | +}// |
| 104 | + |
| 105 | +Vh1 v1; |
| 106 | +Vh2 v2; |
| 107 | +verif1(A12,v1); |
| 108 | +verif1(A21,v2); |
| 109 | +} // end of verification .. |
| 110 | + |
| 111 | +//matrix A = [[A11, A12],[A12', A22]]; // valable dans le cas conforme uniquement (autrement A12' different de A21) |
| 112 | +matrix A = [[A11, A12],[A21, A22]]; |
| 113 | + |
| 114 | +// rhs compuation |
| 115 | +real[int] B1= V11(0,Vh1); |
| 116 | +real[int] B2 = V22(0,Vh2); |
| 117 | +real[int] B = [B1,B2]; |
| 118 | + |
| 119 | +Vh1 u1; |
| 120 | +Vh2 u2; |
| 121 | +set(A, solver=UMFPACK); |
| 122 | +real[int] T = A^-1*B; |
| 123 | +[u1[],u2[]]=T; // dispatch the solution. |
| 124 | + |
| 125 | +plot(u1,u2,value=1,fill=1,wait=1,nbiso=100); |
| 126 | +plot(u1,ue1,value=1,fill=0,wait=1); |
| 127 | +plot(u2,ue2,value=1,fill=0,wait=1); |
| 128 | +cout << " T1=" << int1d(Th1,10)(u1)/int1d(Th1,10)(1.0) << " T2=" << int1d(Th2,10)(u2)/int1d(Th2,10)(1.0) << endl; |
| 129 | + |
| 130 | +// composite version |
| 131 | +fespace cVh(<Vh1,Vh2>); |
| 132 | + |
| 133 | +varf compositeVall([u1,u2],[v1,v2]) = |
| 134 | + int2d(Th1)(k1*dx(u1)*dx(v1) + k1*dy(u1)*dy(v1)) |
| 135 | ++ int2d(Th2)(k2*dx(u2)*dx(v2) + k2*dy(u2)*dy(v2)) |
| 136 | ++ int1d(Th1,10,mortar=1)(c*(u1-u2)*(v1-v2) ) |
| 137 | ++ on(3,u1=T0) |
| 138 | ++ on(4,u2=T1); |
| 139 | +//+ int1d(Th1,10,mortar=1)(-c*u2*v1) |
| 140 | +//+ int1d(Th2,10,mortar=1)(-c*u1*v2) |
| 141 | +//+ int1d(Th2,10,mortar=1)(c*u2*v2) |
| 142 | + |
| 143 | +real[int] cB = compositeVall(0,cVh); |
| 144 | +matrix cA = compositeVall(cVh,cVh); |
| 145 | +set(cA, solver=UMFPACK); |
| 146 | + |
| 147 | +real[int] cT = cA^-1*cB; |
| 148 | + |
| 149 | +Vh1 uc1; |
| 150 | +Vh2 uc2; |
| 151 | +[uc1[],uc2[]]=cT; // dispatch the solution. |
| 152 | + |
| 153 | +Vh1 u1diff; |
| 154 | +u1diff[] = uc1[]-u1[]; |
| 155 | +Vh2 u2diff; |
| 156 | +u2diff[] = uc2[]-u2[]; |
| 157 | + |
| 158 | +plot(uc1,uc2,value=1,fill=1,wait=1,nbiso=100); |
| 159 | +plot(uc1,ue1,value=1,fill=0,wait=1); |
| 160 | +plot(uc2,ue2,value=1,fill=0,wait=1); |
| 161 | +plot(u1diff,u2diff,value=1,fill=1,wait=1,nbiso=100); |
| 162 | +cout << " T1=" << int1d(Th1,10)(u1)/int1d(Th1,10)(1.0) << " T2=" << int1d(Th2,10)(u2)/int1d(Th2,10)(1.0) << endl; |
| 163 | + |
| 164 | +matrix D=A -cA; |
| 165 | +cout << "D.linfty=" << D.linfty << endl; |
| 166 | +real[int] db(B.n); |
| 167 | +db=B-cB; |
| 168 | +cout << "db.linfty=" << db.linfty << endl; |
| 169 | +end; |
| 170 | + |
| 171 | +/// FIN DU PROGRAMME |
0 commit comments