Advertisement
TorutheRedFox

P60B40.mr

Sep 3rd, 2022
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.16 KB | None | 0 0
  1. // note: this is kinda janky rn
  2. import "engine_sim.mr"
  3. import "../../part-library/part_library.mr"
  4.  
  5. units units()
  6. constants constants()
  7.  
  8. label cycle(2 * 360 * units.deg)
  9. label sparkadvance(-60 * units.deg)
  10.  
  11. private node wires {
  12. output wire1: ignition_wire();
  13. output wire2: ignition_wire();
  14. output wire3: ignition_wire();
  15. output wire4: ignition_wire();
  16. output wire5: ignition_wire();
  17. output wire6: ignition_wire();
  18. output wire7: ignition_wire();
  19. output wire8: ignition_wire();
  20. }
  21.  
  22. public node P60B40_distributor {
  23. input wires;
  24. input timing_curve;
  25. input rev_limit: 8500 * units.rpm;
  26. alias output __out:
  27. ignition_module(timing_curve: timing_curve, rev_limit: rev_limit, limiter_duration: 0.01 * units.sec)
  28. .connect_wire(wires.wire1, ((0.0/4.0) * cycle) + sparkadvance)
  29. .connect_wire(wires.wire2, ((3.0/4.0) * cycle) + sparkadvance)
  30. .connect_wire(wires.wire3, ((1.0/4.0) * cycle) + sparkadvance)
  31. .connect_wire(wires.wire4, ((2.0/4.0) * cycle) + sparkadvance)
  32. .connect_wire(wires.wire5, ((0.0/4.0) * cycle) + sparkadvance)
  33. .connect_wire(wires.wire6, ((3.0/4.0) * cycle) + sparkadvance)
  34. .connect_wire(wires.wire7, ((1.0/4.0) * cycle) + sparkadvance)
  35. .connect_wire(wires.wire8, ((2.0/4.0) * cycle) + sparkadvance);
  36. }
  37.  
  38. public node P60B40_intake_lobe_profile {
  39. alias output __out:
  40. harmonic_cam_lobe(
  41. duration_at_50_thou: 210 * units.deg,
  42. gamma: 1.0,
  43. lift: 10 * units.mm,
  44. steps: 100
  45. );
  46. }
  47.  
  48. public node P60B40_exhaust_lobe_profile {
  49. alias output __out:
  50. harmonic_cam_lobe(
  51. duration_at_50_thou: 225 * units.deg,
  52. gamma: 1.0,
  53. lift: 12 * units.mm,
  54. steps: 100
  55. );
  56. }
  57.  
  58. public node P60B40_camshaft_builder {
  59. input lobe_profile: P60B40_intake_lobe_profile();
  60. input ex_lobe_profile: P60B40_exhaust_lobe_profile();
  61. input intake_lobe_profile: lobe_profile;
  62. input exhaust_lobe_profile: ex_lobe_profile;
  63. input lobe_separation: 102.0 * units.deg;
  64. input intake_lobe_center: lobe_separation;
  65. input exhaust_lobe_center: lobe_separation;
  66. input advance: -90.0 * units.deg;
  67. input base_radius: 0.6 * units.inch;
  68.  
  69. output intake_cam_0: _intake_cam_0;
  70. output exhaust_cam_0: _exhaust_cam_0;
  71.  
  72. output intake_cam_1: _intake_cam_1;
  73. output exhaust_cam_1: _exhaust_cam_1;
  74.  
  75. camshaft_parameters params(
  76. advance: advance,
  77. base_radius: base_radius
  78. )
  79.  
  80. camshaft _intake_cam_0(params, lobe_profile: intake_lobe_profile)
  81. camshaft _exhaust_cam_0(params, lobe_profile: exhaust_lobe_profile)
  82. camshaft _intake_cam_1(params, lobe_profile: intake_lobe_profile)
  83. camshaft _exhaust_cam_1(params, lobe_profile: exhaust_lobe_profile)
  84.  
  85. label rot90(90 * units.deg)
  86. label rot360(360 * units.deg)
  87.  
  88. _intake_cam_0
  89. .add_lobe(rot360 + intake_lobe_center + 0 * rot90) //0
  90. .add_lobe(rot360 + intake_lobe_center + 5 * rot90) //1
  91. .add_lobe(rot360 + intake_lobe_center + 2 * rot90) //2
  92. .add_lobe(rot360 + intake_lobe_center + 7 * rot90) //3
  93.  
  94. _intake_cam_1
  95. .add_lobe(rot360 + intake_lobe_center + 0 * rot90) //4
  96. .add_lobe(rot360 + intake_lobe_center + 5 * rot90) //5
  97. .add_lobe(rot360 + intake_lobe_center + 2 * rot90) //6
  98. .add_lobe(rot360 + intake_lobe_center + 7 * rot90) //7
  99.  
  100. _exhaust_cam_0
  101. .add_lobe(rot360 - intake_lobe_center + 0 * rot90)
  102. .add_lobe(rot360 - intake_lobe_center + 5 * rot90)
  103. .add_lobe(rot360 - intake_lobe_center + 2 * rot90)
  104. .add_lobe(rot360 - intake_lobe_center + 7 * rot90)
  105.  
  106. _exhaust_cam_1
  107. .add_lobe(rot360 - intake_lobe_center + 0 * rot90)
  108. .add_lobe(rot360 - intake_lobe_center + 5 * rot90)
  109. .add_lobe(rot360 - intake_lobe_center + 2 * rot90)
  110. .add_lobe(rot360 - intake_lobe_center + 7 * rot90)
  111. }
  112.  
  113. private node add_flow_sample {
  114. input lift;
  115. input flow;
  116. input this;
  117. alias output __out: this;
  118.  
  119. this.add_sample(lift * units.thou, k_28inH2O(flow))
  120. }
  121.  
  122. public node P60B40_head {
  123. input intake_camshaft;
  124. input exhaust_camshaft;
  125. input chamber_volume: 60.0 * units.cc;
  126. input flip_display: false;
  127. alias output __out: head;
  128.  
  129. function intake_flow(50 * units.thou)
  130. intake_flow
  131. .add_flow_sample(0, 0)
  132. .add_flow_sample(250, 225)
  133. .add_flow_sample(300, 276)
  134. .add_flow_sample(350, 300)
  135. .add_flow_sample(400, 346)
  136. .add_flow_sample(450, 375)
  137. .add_flow_sample(500, 412)
  138. .add_flow_sample(550, 430)
  139. .add_flow_sample(600, 455)
  140. .add_flow_sample(650, 475)
  141. .add_flow_sample(700, 494)
  142. .add_flow_sample(750, 500)
  143. .add_flow_sample(800, 514)
  144. .add_flow_sample(850, 514)
  145. .add_flow_sample(900, 514)
  146.  
  147. function exhaust_flow(50 * units.thou)
  148. exhaust_flow
  149. .add_flow_sample(0, 0)
  150. .add_flow_sample(250, 225)
  151. .add_flow_sample(300, 2700)
  152. .add_flow_sample(350, 300)
  153. .add_flow_sample(400, 332)
  154. .add_flow_sample(450, 340)
  155. .add_flow_sample(500, 356)
  156. .add_flow_sample(550, 370)
  157. .add_flow_sample(600, 381)
  158. .add_flow_sample(650, 391)
  159. .add_flow_sample(700, 407)
  160. .add_flow_sample(750, 414)
  161. .add_flow_sample(800, 428)
  162. .add_flow_sample(850, 428)
  163. .add_flow_sample(900, 428)
  164.  
  165. cylinder_head head(
  166. chamber_volume: chamber_volume,
  167. intake_runner_volume: 275.0 * units.cc,
  168. intake_runner_cross_section_area: 9.6123 * units.cm2,
  169.  
  170. intake_port_flow: intake_flow,
  171. exhaust_port_flow: exhaust_flow,
  172. intake_camshaft: intake_camshaft,
  173. exhaust_camshaft: exhaust_camshaft,
  174. flip_display: flip_display
  175. )
  176. }
  177.  
  178. public node P60B40 {
  179. alias output __out: engine;
  180.  
  181. engine engine(
  182. name: "P60B40",
  183. starter_torque: 200 * units.lb_ft,
  184. starter_speed: 2200 * units.rpm,
  185. redline: 8500 * units.rpm,
  186. fuel: fuel(
  187. max_turbulence_effect: 2.0,
  188. burning_efficiency_randomness: 0.2,
  189. max_burning_efficiency: 5.00
  190. )
  191. )
  192.  
  193. wires wires()
  194.  
  195. crankshaft c0(
  196. throw: 72.2 * units.mm/2,
  197. flywheel_mass: 1 * units.kg,
  198. mass: 8 * units.kg,
  199. friction_torque: 0.0 * units.lb_ft,
  200. moment_of_inertia: 0.03,
  201. position_x: 0.0,
  202. position_y: 0.0,
  203. tdc: (constants.pi / 4)
  204. )
  205.  
  206. piston_parameters piston_params(
  207. mass: 240 * units.g,
  208. compression_height: 20.51 * units.mm,
  209. wrist_pin_position: 0.0,
  210. displacement: 0 * units.cc
  211. )
  212.  
  213. connecting_rod_parameters cr_params(
  214. mass: 240.0 * units.g,
  215. moment_of_inertia: 0.0015884918028487504,
  216. center_of_mass: 0.0,
  217. length: 130.72 * units.mm
  218. )
  219.  
  220. cylinder_bank_parameters bank_params(
  221. bore: 94 * units.mm,
  222. deck_height: 205 * units.mm
  223. )
  224.  
  225. performer_rpm_intake intake(
  226. carburetor_cfm: 1200.0,
  227. idle_flow_rate_cfm: 0.002,
  228. idle_throttle_plate_position: 0.996,
  229. throttle_gamma: 1.5
  230. )
  231.  
  232. exhaust_system_parameters es_params0(
  233. outlet_flow_rate: k_carb(2200.0),
  234. primary_tube_length: 30.0 * units.inch,
  235. primary_flow_rate: k_carb(2200.0),
  236. velocity_decay: 0.0, //0.5
  237. volume: 300.0 * units.L
  238. )
  239.  
  240. exhaust_system_parameters es_params1(
  241. outlet_flow_rate: k_carb(2200.0),
  242. primary_tube_length: 40.0 * units.inch,
  243. primary_flow_rate: k_carb(2200.0),
  244. velocity_decay: 0.0, //0.5
  245. volume: 301.0 * units.L
  246. )
  247.  
  248. rod_journal rj1(angle: 0.0 * units.deg)
  249. rod_journal rj2(angle: 270.0 * units.deg)
  250.  
  251. rod_journal rj3(angle: 180.0 * units.deg)
  252. rod_journal rj4(angle: 450.0 * units.deg)
  253.  
  254. rod_journal rj5(angle: 180.0 * units.deg)
  255. rod_journal rj6(angle: 450.0 * units.deg)
  256.  
  257. rod_journal rj7(angle: 0.0 * units.deg)
  258. rod_journal rj8(angle: 270.0 * units.deg)
  259. c0
  260. .add_rod_journal(rj1)
  261. .add_rod_journal(rj2)
  262. .add_rod_journal(rj3)
  263. .add_rod_journal(rj4)
  264. .add_rod_journal(rj5)
  265. .add_rod_journal(rj6)
  266. .add_rod_journal(rj7)
  267. .add_rod_journal(rj8)
  268.  
  269. impulse_response ir0(filename: "../../sound-library/smooth/smooth_35.wav", volume: 0.001)
  270. impulse_response ir1(filename: "../../sound-library/smooth/smooth_35.wav", volume: 0.001)
  271. exhaust_system exhaust0(es_params0, audio_volume: 1.0, impulse_response: ir0)
  272. exhaust_system exhaust1(es_params1, audio_volume: 1.0, impulse_response: ir1)
  273.  
  274. cylinder_bank b0(bank_params, angle: 45 * units.deg)
  275. b0
  276. .add_cylinder(
  277. piston: piston(piston_params, blowby: k_28inH2O(0.1)),
  278. connecting_rod: connecting_rod(cr_params),
  279. rod_journal: rj1,
  280. intake: intake,
  281. exhaust_system: exhaust0,
  282. ignition_wire: wires.wire1
  283. )
  284. .add_cylinder(
  285. piston: piston(piston_params, blowby: k_28inH2O(0.1)),
  286. connecting_rod: connecting_rod(cr_params),
  287. rod_journal: rj3,
  288. intake: intake,
  289. exhaust_system: exhaust0,
  290. ignition_wire: wires.wire2
  291. )
  292. .add_cylinder(
  293. piston: piston(piston_params, blowby: k_28inH2O(0.1)),
  294. connecting_rod: connecting_rod(cr_params),
  295. rod_journal: rj5,
  296. intake: intake,
  297. exhaust_system: exhaust0,
  298. ignition_wire: wires.wire3
  299. )
  300. .add_cylinder(
  301. piston: piston(piston_params, blowby: k_28inH2O(0.1)),
  302. connecting_rod: connecting_rod(cr_params),
  303. rod_journal: rj7,
  304. intake: intake,
  305. exhaust_system: exhaust0,
  306. ignition_wire: wires.wire4
  307. )
  308.  
  309. cylinder_bank b1(bank_params, angle: -45 * units.deg)
  310. b1
  311. .add_cylinder(
  312. piston: piston(piston_params, blowby: k_28inH2O(0.1)),
  313. connecting_rod: connecting_rod(cr_params),
  314. rod_journal: rj2,
  315. intake: intake,
  316. exhaust_system: exhaust1,
  317. ignition_wire: wires.wire5
  318. )
  319. .add_cylinder(
  320. piston: piston(piston_params, blowby: k_28inH2O(0.1)),
  321. connecting_rod: connecting_rod(cr_params),
  322. rod_journal: rj4,
  323. intake: intake,
  324. exhaust_system: exhaust1,
  325. ignition_wire: wires.wire6
  326. )
  327. .add_cylinder(
  328. piston: piston(piston_params, blowby: k_28inH2O(0.1)),
  329. connecting_rod: connecting_rod(cr_params),
  330. rod_journal: rj6,
  331. intake: intake,
  332. exhaust_system: exhaust1,
  333. ignition_wire: wires.wire7
  334. )
  335. .add_cylinder(
  336. piston: piston(piston_params, blowby: k_28inH2O(0.1)),
  337. connecting_rod: connecting_rod(cr_params),
  338. rod_journal: rj8,
  339. intake: intake,
  340. exhaust_system: exhaust1,
  341. ignition_wire: wires.wire8
  342. )
  343.  
  344. engine
  345. .add_cylinder_bank(b0)
  346. .add_cylinder_bank(b1)
  347.  
  348. engine.add_crankshaft(c0)
  349.  
  350. P60B40_camshaft_builder camshaft(
  351. lobe_profile: P60B40_intake_lobe_profile(),
  352. ex_lobe_profile: P60B40_exhaust_lobe_profile()
  353. )
  354.  
  355. b0.set_cylinder_head (
  356. P60B40_head(
  357. chamber_volume: 60.0 * units.cc,
  358. intake_camshaft: camshaft.intake_cam_0,
  359. exhaust_camshaft: camshaft.exhaust_cam_0,
  360. flip_display: true
  361. )
  362. )
  363.  
  364. b1.set_cylinder_head (
  365. P60B40_head(
  366. chamber_volume: 60.0 * units.cc,
  367. intake_camshaft: camshaft.intake_cam_1,
  368. exhaust_camshaft: camshaft.exhaust_cam_1,
  369. flip_display: false
  370. )
  371. )
  372.  
  373.  
  374. function timing_curve(1000 * units.rpm)
  375. timing_curve
  376. .add_sample(0 * units.rpm, 11 * units.deg)
  377. .add_sample(1000 * units.rpm, 22 * units.deg)
  378. .add_sample(2000 * units.rpm, 22 * units.deg)
  379. .add_sample(3000 * units.rpm, 44 * units.deg)
  380. .add_sample(4000 * units.rpm, 44 * units.deg)
  381. .add_sample(5000 * units.rpm, 55 * units.deg)
  382. .add_sample(6000 * units.rpm, 55 * units.deg)
  383. .add_sample(7000 * units.rpm, 55 * units.deg)
  384. .add_sample(8000 * units.rpm, 55 * units.deg)
  385. .add_sample(9000 * units.rpm, 55 * units.deg)
  386.  
  387.  
  388.  
  389. engine.add_ignition_module(
  390. P60B40_distributor(
  391. wires: wires,
  392. timing_curve: timing_curve,
  393. rev_limit: 8500 * units.rpm
  394. ))
  395. }
  396.  
  397. public node P60B40_vehicle {
  398. alias output __out: vehicle;
  399. vehicle vehicle(
  400. mass: 1120 * units.kg,
  401. drag_coefficient: 0.0012,
  402. cross_sectional_area: (1900 * units.mm) * (1318 * units.mm),
  403. diff_ratio: 13.00,
  404. tire_radius: 22.5 * units.inch,
  405. rolling_resistance: 2000
  406. )
  407. }
  408.  
  409. public node P60B40_transmission {
  410. alias output __out: trans;
  411. transmission trans(
  412. max_clutch_torque: 2400 * units.lb_ft
  413. )
  414.  
  415. trans
  416. .add_gear(2.7)
  417. .add_gear(2.5)
  418. .add_gear(2.07)
  419. .add_gear(1.89)
  420. .add_gear(1.58)
  421. .add_gear(1.38)
  422. .add_gear(1.24)
  423. }
  424.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement