84 lines
4.5 KiB
C++
84 lines
4.5 KiB
C++
#include "FluidSim/Scenario.hpp"
|
|
|
|
#include <iomanip>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
int main() {
|
|
using namespace fluidsim::port;
|
|
constexpr int sample_rate = 44100;
|
|
constexpr int sample_count = sample_rate;
|
|
std::vector<int> checkpoints;
|
|
checkpoints.reserve(106);
|
|
for (int step = 1; step <= 100; ++step) checkpoints.push_back(step);
|
|
checkpoints.insert(checkpoints.end(), {300, 500, 1000, 4410, 11025, 22050, 33075, 44100});
|
|
|
|
FourStrokeTwinScenario scenario(sample_rate);
|
|
scenario.set_controls(0.35f, 0.0f, 0.0f);
|
|
scenario.cylinder1.energy_variation = 0.0f;
|
|
scenario.cylinder2.energy_variation = 0.0f;
|
|
|
|
std::cout << "step,rpm,angle,cylinder1_pa,cylinder2_pa,intake_pa,exhaust_pa,speed_kmh,"
|
|
"valve1_in,valve2_in,intake_flow,exhaust_flow,pipe0_left_pa,pipe0_right_pa,"
|
|
"pipe1_left_pa,pipe1_right_pa,pipe2_left_pa,pipe2_right_pa,"
|
|
"pipe3_left_pa,pipe3_right_pa,pipe4_left_pa,pipe4_right_pa,"
|
|
"throttle_port_flow,runner1_port_flow,runner2_port_flow,"
|
|
"cyl1_intake_flow,cyl2_intake_flow,cyl1_exhaust_flow,cyl2_exhaust_flow,"
|
|
"pipe0_right_rho,pipe0_right_u,pipe1_left_rho,pipe1_left_u,pipe1_right_rho,pipe1_right_u,"
|
|
"pipe2_left_rho,pipe2_left_u,pipe2_right_rho,pipe2_right_u,"
|
|
"intake_rho,intake_temperature,pipe0_left_rho,pipe0_left_u\n";
|
|
std::cout << std::setprecision(10);
|
|
std::size_t checkpoint = 0;
|
|
for (int step = 1; step <= sample_count; ++step) {
|
|
scenario.process();
|
|
if (checkpoint < checkpoints.size() && step == checkpoints[checkpoint]) {
|
|
const auto state = scenario.snapshot();
|
|
std::cout << step << ','
|
|
<< scenario.crankshaft.omega * 60.0f / (2.0f * pi) << ','
|
|
<< scenario.crankshaft.angle << ','
|
|
<< scenario.cylinder1.pressure << ','
|
|
<< scenario.cylinder2.pressure << ','
|
|
<< scenario.intake_plenum.pressure() << ','
|
|
<< scenario.exhaust_collector.pressure() << ','
|
|
<< scenario.vehicle.speed * 3.6f << ','
|
|
<< state.valve1_intake_area << ','
|
|
<< state.valve2_intake_area << ','
|
|
<< state.intake_flow << ','
|
|
<< state.exhaust_flow << ','
|
|
<< state.pipe_states[0].front().pressure << ','
|
|
<< state.pipe_states[0].back().pressure << ','
|
|
<< state.pipe_states[1].front().pressure << ','
|
|
<< state.pipe_states[1].back().pressure << ','
|
|
<< state.pipe_states[2].front().pressure << ','
|
|
<< state.pipe_states[2].back().pressure << ','
|
|
<< state.pipe_states[3].front().pressure << ','
|
|
<< state.pipe_states[3].back().pressure << ','
|
|
<< state.pipe_states[4].front().pressure << ','
|
|
<< state.pipe_states[4].back().pressure << ','
|
|
<< scenario.intake_plenum.ports()[0]->mass_flow << ','
|
|
<< scenario.intake_plenum.ports()[1]->mass_flow << ','
|
|
<< scenario.intake_plenum.ports()[2]->mass_flow << ','
|
|
<< scenario.cylinder1.intake.mass_flow << ','
|
|
<< scenario.cylinder2.intake.mass_flow << ','
|
|
<< scenario.cylinder1.exhaust.mass_flow << ','
|
|
<< scenario.cylinder2.exhaust.mass_flow << ','
|
|
<< state.pipe_states[0].back().rho << ','
|
|
<< state.pipe_states[0].back().velocity << ','
|
|
<< state.pipe_states[1].front().rho << ','
|
|
<< state.pipe_states[1].front().velocity << ','
|
|
<< state.pipe_states[1].back().rho << ','
|
|
<< state.pipe_states[1].back().velocity << ','
|
|
<< state.pipe_states[2].front().rho << ','
|
|
<< state.pipe_states[2].front().velocity << ','
|
|
<< state.pipe_states[2].back().rho << ','
|
|
<< state.pipe_states[2].back().velocity << ','
|
|
<< scenario.intake_plenum.density() << ','
|
|
<< scenario.intake_plenum.temperature() << ','
|
|
<< state.pipe_states[0].front().rho << ','
|
|
<< state.pipe_states[0].front().velocity << '\n';
|
|
++checkpoint;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|