Engine Simulatorの作法 その3

# 概要
Engine Simulatorの作法を調べてみた。
練習問題やってみた。

# 練習問題
１ローターのロータリーエンジンを作れ。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/5a1c281c-0249-1a82-4739-9977084e5599.png)


# サンプルコード

```
import "engine_sim.mr"
units units()
constants constants()
impulse_response_library ir_lib()
label cycle(3 * 360 * units.deg)

private node wires {
	output wire1: ignition_wire();
}

private node make {
	alias output __out: engine;
	wankel_engine engine(
		name: "test2",
		starter_torque: 50 * units.lb_ft,
		starter_speed: 1000 * units.rpm,
		redline: 9000 * units.rpm,
		fuel: fuel(max_burning_efficiency: 0.9, max_dilution_effect: 1.5, burning_efficiency_randomness: 1.0),
		throttle_gamma: 2.0,
		hf_gain: 0.01,
		noise: 1.0,
		jitter: 0.5,
		simulation_frequency: 4000,
		rotor_calculation_quality: 1024,
		rotor_housing_resolution: 1024
	)
	wires wires()
	label stroke(3 * units.cm)
	label radius(10 * units.cm)
	label depth(7 * units.cm)
	label intake_port_start(130 * units.deg)
	label intake_port_end(150 * units.deg)
	label exhaust_port_start(220 * units.deg)
	label exhaust_port_end(240 * units.deg)
	label rotor_mass(5000 * units.g)
	label rotor_I(disk_moment_of_inertia(mass: rotor_mass, radius: radius))
	crankshaft c0(
		throw: 0.5 * stroke,
		flywheel_mass: 5 * units.lb,
		mass: 5 * units.lb,
		friction_torque: 15.0 * units.lb_ft,
		moment_of_inertia: 0.22986844776863666 * 0.5,
		position_x: 0.0,
		position_y: 0.0,
		tdc: 0.0
	)
	rod_journal rj0(angle: 0.0 * units.deg)
	c0.add_rod_journal(rj0)
	engine.add_crankshaft(c0)
	wankel_rotor rotor0(
		mass: 5000 * units.g,
		moment_of_inertia: rotor_I,
		radius: radius,
		crown_gear_radius: 3 * 0.5 * stroke,
		angle: 60 * units.deg,
		depth: depth,
		depression_volume: 38 * units.cc
	)
	chevy_bbc_stock_intake intake(
		carburetor_cfm: 280.0,
		idle_flow_rate_cfm: 0.02,
		idle_throttle_plate_position: 0.99
	)
	exhaust_system_parameters es_params(
		outlet_flow_rate: k_carb(550.0),
		primary_tube_length: 10.0 * units.inch,
		primary_flow_rate: k_carb(500.0),
		velocity_decay: 1.0,
		length: 100.0 * units.inch
	)
	exhaust_system exhaust0(
		es_params,
		length: (180 + 72.0) * units.inch,
		audio_volume: 5.5,
		impulse_response: ir_lib.minimal_muffling_02
	)
	engine.add_rotor(
		intake,
		exhaust0,
		rotor0,
		rj0,
		wires.wire1,
		sound_attenuation: 1.0,
		primary_length: 3 * units.inch,
		intake_port: default_wankel_peripheral_port(intake_port_start, intake_port_end, k_carb(200.0)),
		exhaust_port: default_wankel_peripheral_port(exhaust_port_start, exhaust_port_end, k_carb(300.0)),
		intake_runner_cross_section_area: 4 * units.cm2,
		exhaust_cross_section_area: 4 * units.cm2,
		spark_plug_angle: 0
	)
	function timing_curve(1000 * units.rpm)
	timing_curve
		.add_sample(0000 * units.rpm, 20 * units.deg)
		.add_sample(1000 * units.rpm, 20 * units.deg)
		.add_sample(2000 * units.rpm, 30 * units.deg)
		.add_sample(3000 * units.rpm, 50 * units.deg)
		.add_sample(4000 * units.rpm, 50 * units.deg)
	engine.add_ignition_module(
		ignition_module(timing_curve: timing_curve, rev_limit: 15000 * units.rpm, limiter_duration: 0.01)
			.connect_wire(wires.wire1, (0.0 / 12.0) * cycle)
			.connect_wire(wires.wire1, (4.0 / 12.0) * cycle)
			.connect_wire(wires.wire1, (8.0 / 12.0) * cycle)
	)
}

run(engine: make())





```


以上。