You are on page 1of 41
14 Computer Codes Different computer codes used inthe book are presented. The cross-references to the sections, examples, and exercises are provided 14.1. Mathematica Codes ‘Mathematica is used to compute solution of the matrix equation KU = F and in some cases to draw the graphs. Inthe cases of solving the above matrix equation, the Mathematica command is LinearSolve m,®) which gives the vector x as the solution of the matrix equation mx = b. The commands Plot, ListPlot, and InplicitPlot are generally used to generate graphs of functions or data. In this section we provide Mathematica codes for some representative examples solved in previous chapters. Most ofthe examples and exercises can be similarly solved EXAMPLE 3.3. In[l]: m={ {892200, -356800 44600}, {~356800,712600, ~356800}, {44600 -356800,312200} }; Inj2]: b = 8333.3{1, 4, 1}; In[3}: LinearSolve(m, b] Out(3}: 0.865988, 0.227477, 0.274294 Injd]: Qt = ~8.8*105 + 0.086598 Outi]: -80227.3 352 14, COMPUTER CODES EXERCISE 3.2. FourNopeCuaic ( 4enode cubic element Determine the stiffness matrix and the force vector. Write xe and x{e + 1} as a and b, respectively. Note b - a= L7(e), where ve write lover case el as L. ‘Then ve have xbar = (L/2)(1 + xi), or xi = 2xbar/L - 1. We vill write xbar as x +) Inf]: sabe) ~(9/36)+ (1 = 2 x/L = 19)404/9 - @ x/L - 1972); phi2be] = (27/16)*(1 = (2 x/L ~ 1)72)¥(1/3 = (2 x/L - 1); phil] i= ( 27/16)+(1 - (2 x/L - 1)°2)4(4/3 + (2 x/L - 1)); phigtx] := -(9/16)* (1 + (2 x/L - 1))#(1/9 = (2 x/L ~ 1972); i = Diphitld, 25 42 = Diphi2tx), x; 43 = Diphi3ixd, x); 44 = D[phidte), x; kil = Integratelae(dt)"2, x, 0, LI + Integrate[cephit[xJ~2, x, 0, L] x12 = Integratela+(a1) (42), x, 0, LI + Integrate[cephit [x]+phi2ix], x, 0, L] 13 = Integratelar(4t) (43), x, 0, L) + Integrate (c+phit (x]*phi3{x), x, 0, L] Kid = IntegrateLae(at) (44), x, 0, L] + Integrate[cephit [x]+phid{x), x, 0, L] X22 = Integratela+(d2)~2, x, 0, LI + Integrateleephi2[xJ~2, x, 0, LI 23 = Integrate [ar (a2) (43), x, 0, L) + Integrate[cephi2(x]*phi3{x), x, 0, L] X24 = Integratelae(a2) (44), x, 0, L] + Integrate[cephi2(x]+phiatx], x, 0, L] x33 = Integrate[ar(43)~2, x, 0, L] + Integrate[cephiS(xJ~2, x, 0, LI x34 = Integrate [ar (43) (44), x, 0, L) + Integrate[eephi3[x]*phiax], x, 0, L] k4d = Integrate[ar(d4)"2, x, 0, L) + Integrate(cephi4(xJ"2, x, 0, L) £1 = Integratelfephit[x], x, 0, L) £2 = Integrate[fephi2(x], x, 0, L) £3 = Integrate[fephi3[x], x, 0, 1] £4 = Integrate[fephid[x], x, 0, L] MM. MATHEMATICA CODES 353 Out{t]: ‘The Mathematica output is suppressed: but it yields the answer given on page 66, EXAMPLE 4.3. (# 3-Element Mesh, keeping EI with Ui +) nfl]: a = (2/512)4{ (6, -24, -6, -24}, {-24, 128, 24, 64}, {-6, 24, 6, 24}, {-24, 64, 24, 128} }; x2 = (2/64)4{ {6, -12, ~6, -12}, {-12, 32, 12, 16}, {-6, 12, 6, 12}, (-12, 16, 12, 32} }; k3 = 2; Ke { (RCCL, 19], KACCt, 200, RLECt, 30], KACC4, 417, 0, 0, 0,0}, {ki (C2, 107, KLC(2, 20, KAC(2, 32], KAC(2, 421, 0, 0, 0, 0), {ei (C3, 10], K1C(3, 201, w1CC3, 39] + K2ECi, 12), RaCls, 4] + w2CL1, 20) ,k2CC4, 31], K2CCt, 41], 0, 0}, {eil4, 10], e1CC4, 20), KACC4, 3]] + Kaela, 2), KiCl4, 4)) + w2C(2, 213, katl2, 31, ¥20l2, 41], 0, 0}, fo, 0, 2C(3, 11], K2UC3, 21], w20(3, 3} + K9CCt, 13), KaCl3, 4)] + x3CCt, 20], x3(C4, 3], KSCLL, 421}, {0, 0, KaCC4, 19], K2CC4, 201, x20C4, 30] + K3tl2, 11), w2Ul4, 4}) + x3E(2, 21], K9C(2, 3}J, KSEL2, 41]}, {0, 0, 0, 0, KSCC3, 1], KS{(3, 21}, KSCC3, 3], K3E(3, 41]}, {0, 0, 0, 0, KA{(4, 11, KBE(4, 20), Kata, 901, Kata, 413} } ans) a1" Infa]: = ~(600%8/12)+{6, -8, 6, 8} Out[2}: {-2400, 3200, -2400, -3200} (# We solve for EI Uj,i=2,3,4,5,6,8+) Infg]: m= { {1/2, 3/32, 1/4, 0, 0, 0}, (8/32, 27/128, -9/32, -3/16, -3/8, 0}, {4/4, -9/92, 3/2, 3/8, 1/2, 0}, {0, -3/16, 3/8, 3/8, 0, -3/8), (0, -3/8, 1/2, 0, 2, 1/2}, {0, 0, 0, -3/8, 1/2, 1} }; a4 1M. COMPUTER CODES b = (8200, -2400, -3200, 2500, 0, 9000}/185000000; (+ b= F/EI, with EI = 18.5 x10" +) LinearSolve(m, b) // Out(3}: {0.000316787, -0.0013982, -0.00004, -0.000867027, -0.000208189, =0.000171892) Injd}: 11 = (-3/32)+(0.000316757) + (-3/128)+(-0.0013982) + (- 3/32) (-0.00004) + 2400/185000000 Out[4]: 0.0000197973 (+ Now we solve for the 2 - element mesh. The matrix K is Eleki, and f1 is the same as f above. Compute £2 for the element 2: +) Info]: phit(e) := 1 - 36x72/64 + 24x°3/512 phi2tx} = -x¥(4 x/8)72 phiSle] := Sex" 2/64 - 26x73/512 phid(x] := ~xa(x" 2/64 - x/8) £12 = phit[4); £22 = phi2(a) £23 = phis(4]; £24 = phia(4); £2 = -25008{f12, £22, £23, £24} Out{5]: {-1250, 2500, -1250, -2500} In[6]: fvector = {-2400, 3200, -2400, -3200, 0, 0} + {0, 0, -1250, 2600, -1250, -2500 + 9000} Out{6]: {-2400, 3200, -3660, -700, 1250, 6500} Inj7]: m = (2/512)+{ (128, 24, 64, 0}, (24, 12, 0, -24}, {64, 0, 256, 64}, {0, -24, 64, 128} }; b = {3200, -3650, -700, 6500}/185000000; LinearSolve(m, b) // ut{7}: {0.000316757, -0.0013982, -0.0000, -0.000171892} Infg}: Qtitwo = (2/512)4( -244(0.000316757) + (-6)*(-0.0013982) + (-24)*(-0.00004)) + 2400/185000000 utfs}:0.0000197973 Inf9}: QB2two = (2/512)4( (-6)*(-0.0013982) + (24)+(-0.00004) + 24e(-0.000171892)) + 1250/185000000 141. MATHEMATICA CODES 355, Out{g]: 0.0000196622 EXERCISE 6.20. (= use (6.15), with a= 5, b= 6, and Kre = Ht + #722; also take fo =2. Since all 4 elements are similar, wwe compute K” 1, denoted by matkl, and fl *) Int]: watkt = (1/5)*{ {2, -2, -1, A}, {-2, 2, 4, -1}, (1, 1,2, -2}, (1, “ts -2, 2) + (5/16)*{ (2, 1, -1, -2}, (1, 2, -2, -1}, {-t, -2, 2, 1}, {-2, “1, 1, 2h} Out{t]: { (41/40, ~7/80, -41/80, -17/40), {-7/80, 41/40, -17/40, 41/80}, {-41/80, -17/40, 41/40, -7/80}, {-17/40, 41/80, ~7/80, 41/40} } In[2}: £1 = (245+6)/4{1, 1, 1, 1} Outf2]: (18, 15, 15, 18} (+ Denote the assenbled stiffness matrix related to Us and Ug by m, and the force vector by b +) Infg}: m= ({mavki((3, 3]] + mavki[{4, 4] + matkt((2, 21] + matki[(1, 1]], matki([4, 9]] + matki[(1, 21), matki((3, 40] matki + natki((2, 11], ((3, 3]) + matkt(t2, 21]}} Out[3]: { {41/10, -7/40}, {-7/40, 41/20} } Infa}: b= {£4 0C3)) + £40040) + f1C(2)) + £10000) - ( matki((2, 4]] + 46¢(matki ((2, 3] + matki((1, 4]]) + sotematki (1, 31]), £1((9)) + £10020) - (46ematki([2, 4]] +191matki (C2, 31) } Outi]: {395/2, $39/4} Inf5]: LinearSolvela, b] // N Out(g]: {81.1628, 70.0993} EXAMPLE 7.1 (+ Heat transfer without convection; Rectangle size 4a x 2a; 16 Linear triangular elenents *) Inf]: k1{ {2,-1,0,0,-1,0,0,0},{-1,4,-1,0,0,-2,0,0}, {0,-1,4,-1,0,0,-2,0},{0,0,-1,4,0,0,0,-2} {-1,0,0,0,4,-2,0,0},{0,-2,0,0,-2,8,-2,0} {0,0,-2,0,0,-2,8,-2},{0,0,0,-2,0,0,-2,8}}; 386 M4, COMPUTER CODES f1= (0, 0, 0, 0, T, 2#T+Cos[n/8], 24T'«Cos|n/4], 2eT*Cos|3x/8] }; LinearSolve [kt ,£1)//M Out[lj: {0.759838 T, 0.701999 T, 0.637286 T, 0.290777 T, 0.817677 T, 0.755435 T, 0.578185 T, 0.312911 T} ( Heat At node 5 is given by Fs = Qs = ~(k/2)Ti +) Inj2]: FS = ~(x/2)*(0.290777 1) Out/2]: -0.145389 k T (@ Sane problem with 8 rectangular @ Ina]: k2 = { {4, -1, 0, 0, (1,8, 1,0, ~ {0, -1, 8, -1, 0, {0, 0, -1, 8, 0, 0, {-1, -2, 0, 0, 8 -2, 0, 0}, {-2, -2, -2, 0, -2, 16, -2, O}, {0, -2, -2, -2, 0, -2, 16, -2}, {0, 0, -2, -2, 0, 0, -2, 16} }; £2 = {0, 0, 0, 0, T+ 2 Te Cosln/3],27 + 2+ Cos[x/3] + IF » Cos|n/4],2T x Cos(x/8| + 2T + Cos[x/4] + 2F » Cos|3x/8], 2E + Cos|{Pil/4 + 20 » Cos|3 Pi/8) }s LinearSolve(k2, £2) // " Out{s]+ {0.749839 7, 0.692761 T, 0.530216 T, 0.286951 T, 0.809968 7, 0.748313 T, 0.572734 7, 0.309961 T} (+ Heat at nodeS is given by Qs+) Ina] = Q5 = —(KT/6) « (0.286951 + 2 + 0.309961) Out[4]: -0.151146 & T (* Exact Solution *) TLx,y = T'+ (Cosh|(ry)/(8a)] Cos{(wx) /(8a)}) /Cosh|r/4}// Table(T (x, y), {,0,4a, a}, {y,0,2a, a} | Out[a) { {0.75494 T, 0.813902 T, T}, {0.697473 T, 0.751948 T, (0.92368 T), {0.533828 T, 0.575516 T, 0.707107 T}, {0.288903 T, 0.311467 T, 0.382683 T}, {0., 0., 0.) } EXAMPLE 7.2. (+ Heat transfer with convection; Tx, = 0+) M41. MATHEMATICA CODES aT Injt] { (40.8, -9.8, 0, 0, ~4.9, -10, 0, 0}, {-4.9, 81.6, ~4.9, 0, -10, -9.8, 10, 0}, {0, -9.8, 81.6, -9.8, 0, -10, -9.8, -10}, {0, 0, -9.8, 81.6, 0, 0, -10, -9.8}, {-4.9, -10, 0, 0, 20.4, -4.9, 0, O},. {-10,'-9.8, 10, 0,-4.9, 40.8, -4.9, 0}, 0,-9.8, ~10, 0, -4.9, 40.8, 4.9}, , “10, “9.8, 0, 0, -4.9, 40.8} b = {1500, 1000, 1000, 3020, 1250, 500, 500, 1990}; LinearSolvelm, b] // Out/t]: {87.138, 56.6033, 57.095, 63.6882, 130.62, 86.0481, 76.2619, 87.2249 } (# Now with Ta = 20 each element of the right side vector c is +) In{Q] : cl = (107 +0.019)/2 + (0.01 + 2+ 10°)/2 + 2 60 0.01 + 20 10" ¥ 0.01? + 4 60 + 200.01; 107 + 0.01? + 4 60 + 200.01; cf = 10" + 0.012 + 4 + 60 «20 + 0.01 + 20.4» 100; 107 + 0.012)/4 + (0.01 + 2+ 10°)/2 + 60 + 20 + 0.01; 107 + 0.012)/2 + 2+ 60+20+0.01; (107 + 0.012)/2 + 2+ 60+20+0.01; (107 +0.012)/2 + 2+ 6020+ 0.01 + (15 ~ 10+ 0.01) + 100; 12,03, 04 05, 6,07, 8 Out(g]: {1824., 1048., 1048., 3088., 1262., 524., 524., 2014.} In3]: LinearSolvelm, ¢) // N Out(3]: (89.0275, 58.2868, 58.8475, 65.2117, 133.077, 88.5034, 78.5511, 88.8896} EXAMPLE 7.3. (* Torsion of a unit square bar +) Inf]: m= 0.81, ~1, 0, -1, 4, 2, 0, -2, 4 b = 29.0888208741, 3, 3; LinearSolve(m, b] Out{l]: 94.8387, 36.361, 61.8137 Info]: _g = 810%;0 = 0.01 « 7/180; A = 1/3; 2a gO A/S Out{2]: 29.0888, (+ Computation of shear stresses *) (@ For elesente 1, 2, 3:4) 358 MM. COMPUTER CODES Inj}: gradient = 16e{{-1/4, 1/4, 0}, (0, -1/4, 1/4)}. (94.8387, 36.361, 61.8137} Out{3]: {-232.711, 101.811} Injd]: gradient? = 166{{1/4, 0, -1/4}, {-1/4, 1/4, 0}).{94.5387, 36.361, 61.8137} Outfd]: (130.9, -232.711) Info]: gradient3 = 16+{{0, -1/4, 1/4}, (1/4, 0, ~1/4}}. (94.8387, 36.361, 61.8137} Out{p]: 101.811, 130.9 (+gradionté = gradientt +) { (4, -1, “1, -2, 0, 0}, (-4, 8, -2, -2, 0, O}, ~2, 8, ~ ~2}, {-2, -2, -2, 16, -2, -2}, {0, 0, -1, -2, 4, -1}, {0, 0, -2, -2, -1, 8} + (/1s)*{ {4 1, 4, 0, 0, 0}, 1, 8, 0, 2, 0, 0}, {1, 0, 8, 1, 1, O}, {0, 2, 1, 16, 0, 2}, {0, 0, 1, 0, 4, 4, 0,0, 0, 2, 1, B}}; b= 1000e{1, 2, 2, 4, 1, 1} +16e{1, 2,2, 4 1, th + (41/200){300000, 0, 300000, 0, 300000, 0} + {0, 5#400, 0, 5+500, 0, +300}; LinearSolve[m, 6] // ¥ Out{t]: {450.857, 326.768, 416.402, 311.457, 441.355, 288.786 } EXERCISE 7.8 (+ Element 4 +) Inf) 45 yt = 0.885618083; x2 = 0; y2 = 1; x3 = aft] = 22+ 3 — 23 + 92; al2| = 23 «yl — 21 +43; (3) = 21+ y2—22+ yl; List{a(1}, [2], «{3]] Out{l]: 0, 0, 1 Inf]: & = aft] +2] + 0[3] Out[2]: 4 MM. MATHEMATICA CODES 359 Inf]: = v2 Ws Bl2| = y3— yl; 83) = yl — 92; afi] = 23 — 22; 92] = 21-23; [3] = 22 - 21; List{6|1}, 812}, 8(3)} List{y{1},712),713]) Out(g]: (1, -0.885618, -0.114382); i{0, 1, -t} Inf]: wt = (tr? + 7109)/(4A), 12 = (5{1] + B[2] + alt] * v12))/(4A)s 13 = (5{1] + 13] + aIl] v13))/(44); 422 = (5)2)? + 912)°)/(4A); 23 = (8l2] « nf3] + v12] + a13))/(44); #33 = (613)? + 713}*)/(4A)s kal = k12; kS1 = k13; 32 = 23; rmatkd = {{le11, k12, K13}, (R21, K22, k23}, {K31, k32, k33}} // NV Out[d]: {{0.25, -0.221405, -0.0285955}, 221405, 0.44608, -0.224675}, {-0.0285955, -0.224675, 0.253271} } Info]: £4 = (2/3)*{1, 4, 1} Out[s}: (2/3, 2/3, 2/3) (e Remaining Elenents 1, 2, 3, 5, 6, 7. 8 Notation : m denotes the stiffness matrix K for the elenent @;fe denotes the force vector for the elenent e +) Info): markt = 0.5¢{{2, 1, -t}, (1, 1, 0}, (1, 0, t}}; 4 = 0.55269207«(1, 1, 1}; atk? = matkt; 12= £1; matk3 = 0,564577451+{{1.784319988, -0.784319388, -1}, {-0.784319388, 0.784319388, 0}, {-1, 0, 1}}; £3 = 0.295206027+{1, 1, 1}; matkS = 0.312876192+{{3.659847573, -1, -2.853847573}, {-1, 1, 0}, {-2.853847573, 0, 2.553847573) }; £5 = 0.53269207{1, 1, 1}; matk6 = matk5; 16 = £5; 360 14, COMPUTER CODES matk7 = 0.353285686+({3.338166961, -0.784319388, -2.553847573}, {-0.764319888, 0.784319368, 0}, {-2.553847573, 0, 2.553647573} }; 47 = 0.4717617294(1, 1, 1}; matk8 = 1,244016935+{{1.161542732, -1, -0.161542732}, {-1, 1, 0}, {-0.161842732, 0, 0.161542782} };, £8 = 0.133974596+{1, 1, 1}; ( Assembly : The assembled stiffness matrix is denoted by m; the assombled force vector is denoted by b :*) m= {{matkt ((1, 19] + matk2{(3, SJ], matki([1, 21], 0, matk2((3, 2)], matki({t, 3}] + matk2((3, 13), matki(lt, 21], matki[(2, 2]] + matkS{(1, t]) + matk6((3, 31], matkS{[1, 21], 0, matki[(2, 3] + matk6((3, 2)], 0, matk5{(t, 21), matk5((2, 2]] + matk@((3, 21], 0, 0, matk2((3, 2]], 0, 0, matk2((2, 2)] + matk3{{1, 1}] + matka((3, 3)), matk2((2, 1] + matka{(t, 23}, matki{{1, 3]] + mate2tts, 111, matki[(2, 3]] + matk6((3, 21], 0, matk2((2, 1)] + matk3{(1, 21), matki[(3, 3)) + matk2((t, 1)) + matk3[(2, 2)) + matk7(l2, 21) Outf6]: {{1.5,-0.5, 0,0,-1.}, {-05, 2.41095, -0.312876, 0,0}, {0,-0.312876, 0.312876, 0,0}, {0, 0, 0, 1.76066, -0.942809}, {1,0 0, -0.942809, 2.2199} } Inf7}s b= {FU(CN + P2UL3T), A1LL2T + ASU + £61031), £5((2)) + (81(2]}, (C2) + BIC) + USI), U({3)) + f21(1)) + €3U021) + f6L02N + £71121) } Out{7]: {1.06538, 1.59808, 0.666667, 1.49456, 2.36504 } In[8}: LinearSolvem, b} Out/8): 4.32553, 2.11027, 4.24104, 3.1875, 4.36778 (* Exact Solution *) Tn9]: lx y_] = (72/13)(1 ~ x2/9 = y?/A)//N List{u[0, 0], u(t, 0], ul0, 1]) Out{9]:{5.53846, 4.92308, 4.15385} EXERCISE 8.7 Injl]: = { {0.045, -0.015, 0, 0, -0.03, 0}, {-0.015, 0.12, -0.015, -0.03, -0.03, -0.03}, {0, -0.015, 0.12, 0, -0.03, -0.03}, {0, -0.03, 0, 0.045, -0.015, 0}, 14.1, MATHEMATICA CODES 01 {-0.03, -0.03, -0.03, -0.015, 0.12, -0.015),, {0, -0.08, -0.03, 0, -0.015, 0.12} }; £ = (0.1847, 0.54 + 7,0.54 «7 + 100(0.015 + 0.03),0.18 + x, 0.54 10.54 x F + 100(0.03 + 0.015) }; LinearSolve(k, £) Out{t]: {250.796, 238.23, 187.965, 250.796, 238.23, 187.965} EXAMPLE 10. Infl]: FindRoot (x"3 + 9x ~ Out[t]: (& -> 0.221023} Inf2]: FindRoot[x"3 + 9x - 2 == 0, (x, 0.5}) Out[2]: (x -> 0.221023} Inf3}: FindRoot(x"3 + 9x Out[3}: {x -> 0.221023} Infdj: FindRoot(x"3 + 9x - 2 == 0, {x, 2} Out[d]: {x ~> 0.221023} 0, {x, 0}) 0, {x, 1}) EXAMPLE 10.2. Infi]: FimdRoot [{x" 2 - y°2 + 6 x - 4 {x, 0.2}, {y, 0.1}] Out{t]: (x => 0.65125, y -> 0.875873} (+ For Example 5.1, we compute x; by taking xo = 0.54) In]: tix) v3 +9%- 2; £[0.81; In]: tx] e349 x- Dittd, Out2]: 2.625 Inf]: f(x] i= x3 +9 x - 25 g+ 3x2 In[3]: tprime[o.6] = 9 + 3 (0.5)2; Inf]: 0x] s= x73 + 9x - 2; xi = 0.5 - £[0.5]/tprine[0.5] Out[3]: 0.230769 Inf]: relativepitt = (xt - 0.221023)/0.221023, 62 14, COMPUTER CODES Outi]: 0.044095, EXAMPLE 10.4 (+ First, simplify the two equations *) Int} feqnt = Simplity(2¥5.0265+10~ (-6)+x ~ 5.0265+10~ (-5)+y + 2.198410 ~ (-14)«((5. 1958010 ~ (7)/15)ex + (1.3924610'5)/10) «22 +(24373.16/18)4x°3 + x74/3 + 2x73 y/IS + x72 y"2/10+ x y7 3/18 + y74/30) = 1.8756010* (-2) - (4.1459¢10~ (-2))/30] Outft]: .128010-1 x4 + x¥ (1.06303 +10- + 2.2812e10-% y. 0,000050265 y + 7.128 + 10-16 y*+ x? (2.9750816* 10-10 + 2.1386 10" y2+-2 (0,000100604) + 1.4256 + 10-15 y® == 0.017374 Inf2]: eqn? = Simplity(-5.0265+10 7 (-5)4x + 2 +6.0265+107 (-5)+y + 2.13840107 (-14)4(x" 4/30 + x73 y/15 + x72 y72/10 + 2ex y73/18 + y7 4/6) == 1.0697#107 (-13)¥(y~4 ~ 5.566810 ~9)) ut[2]: 0.000898481 ~ 0.000050265x + 7.12610 x4 + 0,00010083 + 1.425610"! xy + 2.1384K107 11 x2y + 2.851210" xy? + 3.564107! y! == 1.0697e10713y! Inf3]: FinaRoot C{eqnt, eqn2}, x, Random{]}, {y, Randomt]}1 Out{3]: (x -> 225.687, y -> 106.974) Infa]: FinaRoot ({eqnt, eqn2}, {x, 0-5, 50}}, {ys {1, 100}}1 Outfa]: {x -> 225.633, y -> 106.973) 142, ANSYS CODES 63 14.2. Ansys Code 14.2.1, EXAMPLE 9.5. For the 16-element mesh, shown in Fig, 9:3, the ‘Ansys code is as follows: PLANETS AXISYNMETRIC-HARMONIC THERMAL SOLID /#ilnane fin Punits, si Tpxep? antyp, trans et 1,75 np xx, 1,237 mp, dens, 1,2702 mp,c,1,803 mp, hf, 1,150 mp, kyy,1,237 rectng,0,0.002,0,0.04 lesize,1,,,2 lesize,2,,.8 eshape,2 anesh, 1 eplot. /solu outres, ,all outpr, ,last sfa,1,2,conv, 150,25 sfa,1,3,conv,0,25 veunit 25 4,1, temp, 85 4,2, temp, 85 4,3, temp, 85 autots,on time,0.01 time,8k! 8 5 subst 802! process 80 steps solve finish /post26 nsol,2,1,temp, ,t1 nsol,3,17,temp, ,t2 nsol,4,12,temp, ,t3 Jaxiab,y, tempet plvar,2,3,4 finish M4, COMPUTER CODES Output Listings 14.2.1 and 14.2.2 LoaD sTEP= 0 suBsTeP= 0 | LOAD STEP=0 SUBSTEP= 0 TIME* 1.0000 LOAD cASE= 0 | TIME 2.0000 LOAD CASE 0 Node Tex 1 85.000 2 88.000 3 85.000 eee too a eee | 2 88.000 5 66.610 | 3 85.000 6 51.448 4 30.919 7 40.664 | 5 71.836 8 33.786 | 6 59.905 ° 29.764 | 7 50.013 10 27.859 | 8 42.430 wep otto 2 26.196 | . i 31.847 - poe | 12 30.919 ee 26.508 | 13 30.919 18 27.559 14 31.547 16 29.751 | 15 33.510 17 33.786 | 16 37.032 18 40.664 17 42.430 19, 81.448 18 50.013, aa fates | 19 59.905 ee es be era | m2 59.908 eS eoreee | 23 50.013 24 33.786 | 24 42.430 25 29.784 | 28 37.032 26 27.859 26 33.510 ar 26.505 | a7 31.847 MAXIMUM ABSOLUTE VALUES MAXIMUM ABSOLUTE. VALUES ove. 1 NODE VALUE 85,000 VALUE 85.000 142. ANSYS CODES Output Listings 14.2.3 and 14.2.4 LOAD STEP= 0 SUBSTEP= 0 | LOAD STEP= 0 SUBSTEP= 0 TIME* 3.0000 LOAD CASE 0 | TIME= 4.0000 LOAD CASE= 0 Node Top | 1 85.000 | e eae | Node TEMP P 5.000 fT g5:000 4 20.919 | 3 B.000 5 71.836 3 85.000 6 se.s08 aces 8 42.430 | 6 67-864 9 37.032 | 7 60.367 10 33.510 | 8 53.977 11 31.547 | 9 48,912 2 aa | Saat 13 30.919 | no oe 4 suse | 3 Alaa 5 wsio | tg ase 6 soz, | ts asst 7 42.430 | 16 48.912 18 50,013 | 17 53.977 19 59.905 | 18 60.387 S nese freee at 71.836 | 20 76.208 zs sess | are x» mo | be sore = o7.082 2 48.912 2 ss.si0 mas. 281 2 31.547 | 27 43.064 waxnMn ABSOLUTE VALUES vaxaoom ABSOLUTE VALIES toot toot VALUE 85.000 VALUE 85.000 14, COMPUTER CODES Output Listings 14.2.5 and 14.2.6 LOAD STEP= 0 SUBSTEP= 0 LOAD STEP= 0 SUBSTEP= 0 BY oe onol note TIME 6.0000 LOAD CASI Node Tee | 1 88.000 2 85.000 | 3 28.000 oe 4 47.613 | 3 R008 5 77.508 | 3 85.000 6 70.345 | 4 52.356 7 63.822 | 5 78.645 8 8.192 | 6 72.387 9 53.646 | 7 66.688 10 50.319 | 8 61.755 “ rasta | 9 7.740 12 47.613, | Qf Sm 18 47.613 | ih Se ges 4 a3 | hat ase 15 50.319 | 14 52.966 16 53.646 | 15 84.779 17 8.192 | 16 7.740 18 63.822 | 17 61.755 19 70.345 | 18 66.688 a eieoe | 19 72.367 a ae | 22 pee 22 72.387 ee ese eaal 23 66.688 24 58.192 | 24 61.755, 25 53.646 | 25 87.740 26 50.319 | 26 Sa.779 27 48.293 | a7 852.966 MAXIHOM ABSOLUTE VALUES MAXIHQM ABSOLUTE VALUES NODE 1 NODE VALUE 85.000 VALUE 85.000 Output Listings 14.2.7 and 14.2.8 LOAD STEP= 0 TIME= 7.0000 MAXIMUM ABSOLUTE VALUES NODE VALUE SUBSTEP= 0 LOAD CASE= 0 142, ANSYS CODES TEP 85 85. 85 56. 79. 74, 69. 6a, 61. 58. 57 56. 56. 87 58 61 64 69 4 79 79 " 69 64. 6. 58 87. 4 000 000 000 602 424 ont 150 883 339 738 140 602 602 140 738 339 853 150 ont 424 424 ova 150 853 339 738 140 85.000 | Loan step= 0 | TmME+ 8.0000 367 SUBSTEP= 0 LOAD CASE= 0 85. 85. 85. 56 73 74 69 64 61 58. 87 56 56. 87 58 61 64 69 000 ‘000 ‘000 602 424 ont 150 853 339 738 140 602 602 140 738 339 853 150 74.071 79. 79. 74. 69, 64. 61 58 87 424 428 ova 150 253 339 738 140 MAXIMUM ABSOLUTE VALUES NODE VALUE 1 85.000 368, MM, COMPUTER CODES 14.3. Matlab Codes 14.3.1. EXAMPLE 12.4. The listing of the Matlab code for the unit cavity problem follows. Main function: Cavity-flow(Wl,x,nu, epsilon) 4M: number division on each side of the unit square in: power-law index nu: viscosity of the fluid 4% epsilon : penalty paraneter Yrenti=1.6, 2.0, 3.0 function Cavityflow(l,x,epsilon) i initialization ket; fx=ty=0.0; eros ((N+1)* 2,2); U.V((W+1)#(Ne1) 4K, 191/25 end ww. conv-tolerance=10* (-2); pitezeros(2« (W+1)* 2,1); =zeros(2s (W#1)* 2,1); fied"); “get _dlduv(ULV,k,g,r epsilon); errorsgradient_i’sgradient i; Af error < conv-tolerance uw error (success?) ; break; end 14.3, MATLAB CODES 369 error if 0 gradient i-gradiont it; otal i=(gradient.ieyit)/(pit’ryit); beta2-iv(gradiont-i gradient D/(pi-1+y-4.1)5 beta_i-max(0,min(betati,beta2i)); end p-is-gradient itbeta.iep. the line-search schene predict.U.V+UV; for ppet:(M1)"2 predict.U.V(pp,1)=predict UV(pp,1)+2" (-k) * p-i(2epp-1); predict U.V(pp,2)=predict ULV(pp,2)+2" (-k)* p.i(2¢pp) 5 end predict f=get_Ie (predict.ULV,k,g,r,epsilon,N) ; current {=get_1e(U.V,k,g,r,epsilon,N); if predict-f < current. break; end end for pp=t: it)" 2 U.V(pp,1)=U.V(pp,1)42° (-kD* p-i(2epp-1) U.V(pp,2)=UV(pp,2)42" (-K)* p-4(2*pp) 5 end it(predict.t <5) break; end Xe0:1/N: 45 Y=0:4/0: 4; for ieNeL:-1:1 U=U.V((-1) (N41) +1226 (e193 Ve [UV(Ci-1) (wet )#4:44 Met) ,2)°3¥0; end u v quiver(K,¥,U,V); hold off; 310 1M, COMPUTER CODES load first-part first.part; load penalty penalty; first_part penalty save UV UV; ‘The following are the subfunctions used in the main function, function result=get.dIduv(wv,k,g.r epsilon, N) A, connect) =get.connect.matrix(W) ; (A1,B1,Ct,A2,B2,C2, A3,B3,C3)=got-abc(W); areasi/li72; for i=1:NeNe2 number=connect (1, :); utsuy(nunber(1) ,1); vieuv (number (1) ,2); u2euv (number (2) 1); v2euv (number (2) ,2); u3=uv (number (3) ,1) ; veuv (number (3) ,2); ateat (i); bisBiG3); et-01(4); a2=A2(3); b2-B2(4); 200264 343 3=B3(4); €3+03(4); Af mumber(1)(W+t)=W Te.du(i, 1) else si=(ul¥bitu2eb2+u3+b3) ~ 2; si=siti/2e(uiecl +udec2+u3ecd+viebl +v29b2+v3"b3)~ 2; si+(viscl+v24c2+v3eC3)* 2; sitesi” (x/2-1); 8252+ (ulsb1+ud*b2+u3¥b3) ¥b1 +atect+udc2tudecdtvLebity2eb2+v3eb3) #c1; Lf 0(N+1) +N Te.du(i,2)= else si=(uleb1+u29b2+u3eb3)” 2; ssi+1/2+(ul+ct+u2*c2+udsc+visbity2+b2+v34b3)* 2; st=sit(vitct+v2¥c2+v34c3)" 2; siest* (x/2-1); 52=2+ (ut+b1+u2+b2+u3+b3)*b2 +(utect +udec2+uecdtviebL+v2eb2+v3eb3)#e2; Lf 0<=((uL¥b1tu2*d2+ud4b3) + (vieci+v2ec2+v3¥C3)) 53=((ut*bi+ud+b2+u+b3)+ (vitcitv2+c2+v3ec3))* (x-1) #2; else 53*- (abs ((ui#b1+u2+b2+u3eb3) + (vict+v2ac2+v3eC3)))* (x-1)#b2; end To.du(i,2)=k/2tareatsivs2+1/epsiloneareats3; 82=2¢ (viecl+v2ec2+v¥e3) ¥c2 +(ulscl+ud*c2+usec3tviebL+v2rb2+v34b3) #02; Lf 0<=((ul¥b1tu¥d2+us+b3) + (viel +v24e24v3¥e3)) 83=((ul*b1+u24b2+u3eb3)+ (viecL+v2c2+v3ee3))” (e-1)*e2; else 53=- (abs ((uisb1+u2*b2+u3eb3)+(vitct+v24c2+v3ee3)))~ (x-1) 462; end Te.dv(i,2)=k/2+areatsi+s2+1/epsilontarears3+geareati/3; end if mumber(3)<=N+1 | mod (number (3) N+ { mod (number (3) ,N+1)==0 | number (3)>(N+1)4N Te.du(i,3)=0; else st=(ul¥biru2*d2+udeb3)~2; s1=81+1/2« (uleci+udec2+uecS+viebl+v29b2+v3eb3)~ 2; si=si+(viscttv2ec2+v3*c3)" 2; sizst” (r/2-1); 22504 (a1 wht #u2eb24n3¥n3) #3 ana MM, COMPUTER CODES + (atect+udrc2+udec3tvi¥b1+v24b2+v3eb3) #3; Af 0

You might also like