-- FreeFem++ v4.14 (mer. 06 mars 2024 16:59:04 CET - git v4.14-1-g2b2052ae) file : molding.edp Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // molding.edp 2 : // 3 : // Discussion: 4 : // 5 : // Simulation of injection molding. 6 : // 7 : // Licensing: 8 : // 9 : // This code is distributed under the MIT license. 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 : cout << "\n"; 28 : cout << "molding():\n"; 29 : cout << " FreeFem++ version\n"; 30 : cout << " Fill a hollow mold with a liquid.\n"; 31 : 32 : real[int] PA(2); PA = [0, 0]; 33 : real[int] PB(2); PB = [9, 0]; 34 : real[int] PC(2); PC = [9, 9]; 35 : real[int] PD(2); PD = [8, 9]; 36 : real[int] PE(2); PE = [0, 9]; 37 : real [int ] PF(2); PF = [0, 6]; 38 : real [int ] PG(2); PG = [0,4]; 39 : real [int ] PH(2); PH = [1, 1]; 40 : real [int ] PK(2); PK = [1,8]; 41 : real [int ] PL(2); PL = [8,8]; 42 : real [int ] PM(2); PM = [8,5]; 43 : real [int ] PO(2); PO = [5,5]; 44 : real [int ] PP(2); PP = [5,4]; 45 : real [int ] PQ(2); PQ = [8,4]; 46 : real [int ] PR(2); PR = [8,1]; 47 : 48 : border c1(t=0,1) {x =(1-t)*PA[0]+t*PB[0]; y =(1-t)*PA[1]+t*PB[1];} 49 : border c2(t=0,1) {x =(1-t)*PB[0]+t*PC[0]; y =(1-t)*PB[1]+t*PC[1];} 50 : border c3(t=0,1) {x =(1-t)*PC[0]+t*PD[0]; y =(1-t)*PC[1]+t*PD[1];} 51 : border c4(t=0,1) {x =(1-t)*PD[0]+t*PE[0]; y =(1-t)*PD[1]+t*PE[1];} 52 : border c5(t=0,1) {x =(1-t)*PE[0]+t*PF[0]; y =(1-t)*PE[1]+t*PF[1];} 53 : border c6(t=0,1) {x =(1-t)*PF[0]+t*PG[0]; y =(1-t)*PF[1]+t*PG[1];} 54 : border c7(t=0,1) {x =(1-t)*PG[0]+t*PA[0]; y =(1-t)*PG[1]+t*PA[1];} 55 : // 56 : border c8(t=0,1){x=(1-t)*PH[0]+t*PK[0]; y=(1-t)*PH[1]+t*PK[1];} 57 : border c9(t=0,1){x=(1-t)*PK[0]+t*PL[0]; y=(1-t)*PK[1]+t*PL[1];} 58 : border c10(t=0,1){x=(1-t)*PL[0]+t*PM[0]; y=(1-t)*PL[1]+t*PM[1];} 59 : border c11(t=0,1){x=(1-t)*PM[0]+t*PO[0]; y=(1-t)*PM[1]+t*PO[1];} 60 : border c12(t=0,1){x=(1-t)*PO[0]+t*PP[0]; y=(1-t)*PO[1]+t*PP[1];} 61 : border c13(t=0,1){x=(1-t)*PP[0]+t*PQ[0]; y=(1-t)*PP[1]+t*PQ[1];} 62 : border c14(t=0,1){x=(1-t)*PQ[0]+t*PR[0]; y=(1-t)*PQ[1]+t*PR[1];} 63 : border c15(t=0,1){x=(1-t)*PR[0]+t*PH[0]; y=(1-t)*PR[1]+t*PH[1];} 64 : // 65 : // Define the mesh, Th. 66 : // 67 : int m = 2; 68 : 69 : mesh Th = buildmesh ( c1(80*m)+c2(50*m)+c3(10*m)+c4(40*m) 70 : + c5(30*m)+c6(10*m)+c7(30*m) 71 : + c8(80*m)+c9(40*m)+c10(25*m)+c11(20*m) 72 : + c12(5*m)+c13(20*m)+c14(25*m)+c15(30*m) ); 73 : // 74 : // Plot the mesh. 75 : // 76 : plot ( Th, ps = "molding_mesh.ps" ); 77 : // 78 : real gravity = 9.81; 79 : real rhom = 1.0; 80 : real rhop = 20.0; 81 : real num = 0.1; 82 : real nup = 10; 83 : real dt = 1.0; 84 : // 85 : // Define the finite element spaces. 86 : // 87 : fespace Uh(Th, P1b); 88 : fespace Vh(Th, P1); 89 : fespace Wh(Th, P1b); 90 : Uh u1, u2, u1old, u2old, u1h, u2h; 91 : Vh p, ph; 92 : Wh u1view, u2view; 93 : Wh rho, rhoold, rho2, mu, muold; 94 : // 95 : // Initialization 96 : // 97 : rho = rhom; 98 : mu = rhom * num; 99 : rho = rho + (rhop-rhom)*((x<0.2)*(y>PG[1])*(yPG[1])*(y