Files
FluidSimCpp/include/FluidSim/TwoStrokeCylinder.hpp

48 lines
1.9 KiB
C++

#pragma once
#include "FluidSim/Crankcase.hpp"
#include <cstdint>
namespace fluidsim::port {
class Carburetor;
// Two-stroke variant of the reciprocating cylinder model. The shared four-
// stroke implementation supplies geometry, state balance, and combustion
// parameters; cycle events and pumping torque are specialized here.
class TwoStrokeCylinder final : public EngineCylinder {
public:
TwoStrokeCylinder(float bore, float stroke, float connecting_rod_length,
float compression_ratio, float transfer_duration_degrees,
float exhaust_duration_degrees);
float transfer_open() const { return 180.0f - transfer_duration_ * 0.5f; }
float transfer_close() const { return 180.0f + transfer_duration_ * 0.5f; }
float exhaust_open() const { return 180.0f - exhaust_duration_ * 0.5f; }
float exhaust_close() const { return 180.0f + exhaust_duration_ * 0.5f; }
void set_crankcase(Crankcase& crankcase) { crankcase_ = &crankcase; }
void set_carburetor(Carburetor& carburetor) { carburetor_ = &carburetor; }
float transfer_width{.050f}, exhaust_width{.036f};
// Retained as two-stroke compatibility metadata; port areas come from the
// transfer and exhaust geometry above rather than poppet valve motion.
float intake_valve_lift{}, exhaust_valve_lift{};
float minimum_burn_seconds{.0008f};
std::uint64_t combustion_count() const { return combustion_count_; }
float valve_area(float cycle_degrees, bool inlet) const override;
void pre_step(Crankshaft& crank, float dt, float throttle) override;
private:
float transfer_duration_{}, exhaust_duration_{};
Crankcase* crankcase_{};
Carburetor* carburetor_{};
float active_burn_duration_{60};
float current_rpm_{};
float active_spark_angle_{};
std::uint64_t combustion_count_{};
void handle_cycle_events(float previous_degrees, float current_degrees);
};
} // namespace fluidsim::port