Advertisement
Guest User

Moody chart code

a guest
Apr 19th, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | Science | 0 0
  1. THIS CODE IS BROUGHT TO YOU FROM FELLOW REDDITR BEKOSS
  2.  
  3. colebrookMoody[f_, ReD_, epsD_] :=
  4. 1/(f^(1/2)) + 2.0 Log10[(epsD)/3.7 + 2.51/(ReD f^(1/2))]
  5.  
  6. f[ReD_, epsD_] :=
  7. FindRoot[colebrookMoody[x, ReD, epsD] == 0, {x, 0.01}][[1, 2]]
  8. ReDValues = Range[10^3, 10^8, 10000];
  9. fValuesLaminar = If[# <= 2300, 64/#, Indeterminate] & /@ ReDValues;
  10. fValues = f[#, 0.000001] & /@ ReDValues;
  11. fValues2 = f[#, 0.000005] & /@ ReDValues;
  12. fValues3 = f[#, 0.00001] & /@ ReDValues;
  13. fValues4 = f[#, 0.00005] & /@ ReDValues;
  14. fValues5 = f[#, 0.0001] & /@ ReDValues;
  15. fValues6 = f[#, 0.0002] & /@ ReDValues;
  16. fValues7 = f[#, 0.0004] & /@ ReDValues;
  17. fValues8 = f[#, 0.0008] & /@ ReDValues;
  18. fValues9 = f[#, 0.001] & /@ ReDValues;
  19. fValues10 = f[#, 0.002] & /@ ReDValues;
  20. fValues11 = f[#, 0.004] & /@ ReDValues;
  21. fValues12 = f[#, 0.006] & /@ ReDValues;
  22. fValues13 = f[#, 0.008] & /@ ReDValues;
  23. fValues14 = f[#, 0.01] & /@ ReDValues;
  24. fValues15 = f[#, 0.015] & /@ ReDValues;
  25. fValues16 = f[#, 0.02] & /@ ReDValues;
  26. fValues17 = f[#, 0.03] & /@ ReDValues;
  27. fValues18 = f[#, 0.04] & /@ ReDValues;
  28. fValues19 = f[#, 0.05] & /@ ReDValues;
  29. dataLaminar = Transpose[{ReDValues, fValuesLaminar}];
  30. data = Transpose[{ReDValues, fValues}];
  31. data2 = Transpose[{ReDValues, fValues2}];
  32. data3 = Transpose[{ReDValues, fValues3}];
  33. data4 = Transpose[{ReDValues, fValues4}];
  34. data5 = Transpose[{ReDValues, fValues5}];
  35. data6 = Transpose[{ReDValues, fValues6}];
  36. data7 = Transpose[{ReDValues, fValues7}];
  37. data8 = Transpose[{ReDValues, fValues8}];
  38. data9 = Transpose[{ReDValues, fValues9}];
  39. data10 = Transpose[{ReDValues, fValues10}];
  40. data11 = Transpose[{ReDValues, fValues11}];
  41. data12 = Transpose[{ReDValues, fValues12}];
  42. data13 = Transpose[{ReDValues, fValues13}];
  43. data14 = Transpose[{ReDValues, fValues14}];
  44. data15 = Transpose[{ReDValues, fValues15}];
  45. data16 = Transpose[{ReDValues, fValues16}];
  46. data17 = Transpose[{ReDValues, fValues17}];
  47. data18 = Transpose[{ReDValues, fValues18}];
  48. data19 = Transpose[{ReDValues, fValues19}];
  49. graph0 =
  50. ListPlot[dataLaminar,
  51. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  52. PlotLabel -> "Colebrook-Moody Equation for Laminar flow case",
  53. PlotStyle -> Red, PlotLegends -> "Laminar Flow",
  54. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  55. ScalingFunctions -> {"Log", "Linear"}]
  56. graph1 =
  57. ListPlot[data,
  58. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  59. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  60. PlotStyle -> Blue, PlotLegends -> "Turbulent Flow",
  61. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  62. ScalingFunctions -> {"Log", "Linear"}]
  63. graph2 =
  64. ListPlot[data2,
  65. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  66. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  67. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  68. ScalingFunctions -> {"Log", "Linear"}]
  69. graph3 =
  70. ListPlot[data3,
  71. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  72. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  73. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  74. ScalingFunctions -> {"Log", "Linear"}]
  75. graph4 =
  76. ListPlot[data4,
  77. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  78. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  79. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  80. ScalingFunctions -> {"Log", "Linear"}]
  81. graph5 =
  82. ListPlot[data5,
  83. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  84. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  85. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  86. ScalingFunctions -> {"Log", "Linear"}]
  87. graph6 =
  88. ListPlot[data6,
  89. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  90. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  91. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  92. ScalingFunctions -> {"Log", "Linear"}]
  93. graph7 =
  94. ListPlot[data7,
  95. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  96. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  97. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  98. ScalingFunctions -> {"Log", "Linear"}]
  99. graph8 =
  100. ListPlot[data8,
  101. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  102. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  103. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  104. ScalingFunctions -> {"Log", "Linear"}]
  105. graph9 =
  106. ListPlot[data9,
  107. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  108. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  109. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  110. ScalingFunctions -> {"Log", "Linear"}]
  111. graph10 =
  112. ListPlot[data10,
  113. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  114. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  115. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  116. ScalingFunctions -> {"Log", "Linear"}]
  117. graph11 =
  118. ListPlot[data11,
  119. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  120. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  121. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  122. ScalingFunctions -> {"Log", "Linear"}]
  123. graph12 =
  124. ListPlot[data12,
  125. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  126. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  127. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  128. ScalingFunctions -> {"Log", "Linear"}]
  129. graph13 =
  130. ListPlot[data13,
  131. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  132. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  133. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  134. ScalingFunctions -> {"Log", "Linear"}]
  135. graph14 =
  136. ListPlot[data14,
  137. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  138. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  139. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  140. ScalingFunctions -> {"Log", "Linear"}]
  141. graph15 =
  142. ListPlot[data15,
  143. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  144. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  145. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  146. ScalingFunctions -> {"Log", "Linear"}]
  147. graph16 =
  148. ListPlot[data16,
  149. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  150. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  151. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  152. ScalingFunctions -> {"Log", "Linear"}]
  153. graph17 =
  154. ListPlot[data17,
  155. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  156. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  157. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  158. ScalingFunctions -> {"Log", "Linear"}]
  159. graph18 =
  160. ListPlot[data18,
  161. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  162. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  163. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  164. ScalingFunctions -> {"Log", "Linear"}]
  165. graph19 =
  166. ListPlot[data19,
  167. AxesLabel -> {"Reynolds Number", "Darcy Friction Factor"},
  168. PlotLabel -> "Colebrook-Moody Equation for epsD set",
  169. PlotRange -> {{10^3, 10^8}, {0.008, 0.1}},
  170. ScalingFunctions -> {"Log", "Linear"}]
  171. Show[graph0, graph1, graph2, graph3, graph4, graph5, graph6, graph7, \
  172. graph8, graph9, graph10, graph11, graph12, graph13, graph14, graph15, \
  173. graph16, graph17, graph18, graph19]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement