-- FreeFem++ v4.6 (Thu Apr 2 15:47:38 CEST 2020 - git v4.6) Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // molding.edp 2 : // 3 : // Discussion: 4 : // 5 : // Simulation of injection molding. 6 : // 7 : // Location: 8 : // 9 : // http://people.sc.fsu.edu/~jburkardt/freefem++/molding/molding.edp 10 : // 11 : // Modified: 12 : // 13 : // 20 May 2015 14 : // 15 : // Author: 16 : // 17 : // Florian De Vuyst 18 : // 19 : // Reference: 20 : // 21 : // Florian De Vuyst, 22 : // Numerical modeling of transport problems using freefem++ software - 23 : // with examples in biology, CFD, traffic flow and energy transfer, 24 : // HAL id: cel-00842234 25 : // https://cel.archives-ouvertes.fr/cel-00842234 26 : // 27 : real[int] PA(2); PA = [0, 0]; 28 : real[int] PB(2); PB = [9, 0]; 29 : real[int] PC(2); PC = [9, 9]; 30 : real[int] PD(2); PD = [8, 9]; 31 : real[int] PE(2); PE = [0, 9]; 32 : real [int ] PF(2); PF = [0, 6]; 33 : real [int ] PG(2); PG = [0,4]; 34 : real [int ] PH(2); PH = [1, 1]; 35 : real [int ] PK(2); PK = [1,8]; 36 : real [int ] PL(2); PL = [8,8]; 37 : real [int ] PM(2); PM = [8,5]; 38 : real [int ] PO(2); PO = [5,5]; 39 : real [int ] PP(2); PP = [5,4]; 40 : real [int ] PQ(2); PQ = [8,4]; 41 : real [int ] PR(2); PR = [8,1]; 42 : 43 : border c1(t=0,1) {x =(1-t)*PA[0]+t*PB[0]; y =(1-t)*PA[1]+t*PB[1];} 44 : border c2(t=0,1) {x =(1-t)*PB[0]+t*PC[0]; y =(1-t)*PB[1]+t*PC[1];} 45 : border c3(t=0,1) {x =(1-t)*PC[0]+t*PD[0]; y =(1-t)*PC[1]+t*PD[1];} 46 : border c4(t=0,1) {x =(1-t)*PD[0]+t*PE[0]; y =(1-t)*PD[1]+t*PE[1];} 47 : border c5(t=0,1) {x =(1-t)*PE[0]+t*PF[0]; y =(1-t)*PE[1]+t*PF[1];} 48 : border c6(t=0,1) {x =(1-t)*PF[0]+t*PG[0]; y =(1-t)*PF[1]+t*PG[1];} 49 : border c7(t=0,1) {x =(1-t)*PG[0]+t*PA[0]; y =(1-t)*PG[1]+t*PA[1];} 50 : // 51 : border c8(t=0,1){x=(1-t)*PH[0]+t*PK[0]; y=(1-t)*PH[1]+t*PK[1];} 52 : border c9(t=0,1){x=(1-t)*PK[0]+t*PL[0]; y=(1-t)*PK[1]+t*PL[1];} 53 : border c10(t=0,1){x=(1-t)*PL[0]+t*PM[0]; y=(1-t)*PL[1]+t*PM[1];} 54 : border c11(t=0,1){x=(1-t)*PM[0]+t*PO[0]; y=(1-t)*PM[1]+t*PO[1];} 55 : border c12(t=0,1){x=(1-t)*PO[0]+t*PP[0]; y=(1-t)*PO[1]+t*PP[1];} 56 : border c13(t=0,1){x=(1-t)*PP[0]+t*PQ[0]; y=(1-t)*PP[1]+t*PQ[1];} 57 : border c14(t=0,1){x=(1-t)*PQ[0]+t*PR[0]; y=(1-t)*PQ[1]+t*PR[1];} 58 : border c15(t=0,1){x=(1-t)*PR[0]+t*PH[0]; y=(1-t)*PR[1]+t*PH[1];} 59 : // 60 : // Define the mesh, Th. 61 : // 62 : int m = 2; 63 : 64 : mesh Th = buildmesh ( c1(80*m)+c2(50*m)+c3(10*m)+c4(40*m) 65 : + c5(30*m)+c6(10*m)+c7(30*m) 66 : + c8(80*m)+c9(40*m)+c10(25*m)+c11(20*m) 67 : + c12(5*m)+c13(20*m)+c14(25*m)+c15(30*m) ); 68 : // 69 : // Plot the mesh. 70 : // 71 : plot ( Th, ps = "molding_mesh.ps" ); 72 : // 73 : real gravity = 9.81; 74 : real rhom = 1.0; 75 : real rhop = 20.0; 76 : real num = 0.1; 77 : real nup = 10; 78 : real dt = 1.0; 79 : // 80 : // Define the finite element spaces. 81 : // 82 : fespace Uh(Th, P1b); 83 : fespace Vh(Th, P1); 84 : fespace Wh(Th, P1b); 85 : Uh u1, u2, u1old, u2old, u1h, u2h; 86 : Vh p, ph; 87 : Wh u1view, u2view; 88 : Wh rho, rhoold, rho2, mu, muold; 89 : // 90 : // Initialization 91 : // 92 : rho = rhom; 93 : mu = rhom * num; 94 : rho = rho + (rhop-rhom)*((x<0.2)*(y>PG[1])*(yPG[1])*(y