all of the changes
This commit is contained in:
@@ -2,12 +2,31 @@
|
||||
#include "FluidSim/TwoStrokeScenario.hpp"
|
||||
#include "FluidSim/HelmholtzScenario.hpp"
|
||||
#include "FluidSim/PulseTestScenario.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace fluidsim::port;
|
||||
static void set_uniform_pipe_resolution(std::vector<Pipe1D>& pipes, int cells_per_meter) {
|
||||
if (cells_per_meter <= 0) throw std::invalid_argument("cells per meter must be positive");
|
||||
for (auto& pipe : pipes) {
|
||||
const float length = std::accumulate(pipe.cell_lengths.begin(), pipe.cell_lengths.end(), 0.0f);
|
||||
const float damping = pipe.damping_multiplier;
|
||||
const float relaxation = pipe.energy_relaxation_rate;
|
||||
const float ambient = pipe.ambient_pressure;
|
||||
const int count = std::max(1, static_cast<int>(std::ceil(length * cells_per_meter)));
|
||||
pipe = Pipe1D(pipe.area, length, count);
|
||||
pipe.damping_multiplier = damping;
|
||||
pipe.energy_relaxation_rate = relaxation;
|
||||
pipe.ambient_pressure = ambient;
|
||||
}
|
||||
}
|
||||
template<class S, class Control> void run(const char* name, S& s, int seconds, Control control) {
|
||||
double checksum = 0;
|
||||
std::uint64_t previous_iterations = 0;
|
||||
@@ -30,6 +49,10 @@ template<class S, class Control> void run(const char* name, S& s, int seconds, C
|
||||
std::cout << name << ',' << second+1 << ',' << elapsed << ',' << checksum << std::endl;
|
||||
if constexpr (requires { s.pipes; }) {
|
||||
unsigned tiny = 0;
|
||||
std::uint64_t repairs=0, fallbacks=0;
|
||||
for(const auto& pipe:s.pipes) { repairs+=pipe.positivity_repairs; fallbacks+=pipe.hllc_fallbacks; }
|
||||
if(repairs) throw std::runtime_error("benchmark required pipe positivity repairs");
|
||||
std::cerr<<name<<" repairs="<<repairs<<" hllc_fallbacks="<<fallbacks<<" peak="<<peak<<"\n";
|
||||
for (const auto& pipe : s.pipes)
|
||||
for (const auto& cell : pipe.cells)
|
||||
for (float value : {cell.rho, cell.momentum, cell.energy, cell.air})
|
||||
@@ -49,10 +72,10 @@ template<class S, class Control> void run(const char* name, S& s, int seconds, C
|
||||
std::cerr << name << " substeps_per_frame=" << (state.solver_substeps-previous_substeps)/44100.0
|
||||
<< " limiting_pipe=" << limiting_pipe << " cfl_us=" << stable_dt*1e6f << '\n';
|
||||
previous_substeps = state.solver_substeps;
|
||||
unsigned long long repairs = 0;
|
||||
for (const auto& pipe : s.pipes) repairs += pipe.positivity_repairs;
|
||||
unsigned long long repairs = 0, fallbacks = 0;
|
||||
for (const auto& pipe : s.pipes) { repairs += pipe.positivity_repairs; fallbacks += pipe.hllc_fallbacks; }
|
||||
std::cerr << name << " rpm=" << state.rpm << " power_kW=" << state.average_power/1000
|
||||
<< " peak=" << peak << " pipe_repairs=" << repairs << '\n';
|
||||
<< " peak=" << peak << " hllc_fallbacks=" << fallbacks << " pipe_repairs=" << repairs << '\n';
|
||||
previous_iterations = state.boundary_iterations;
|
||||
}
|
||||
}
|
||||
@@ -61,20 +84,27 @@ int main(int argc, char** argv) {
|
||||
const int seconds = argc > 1 ? std::stoi(argv[1]) : 6;
|
||||
const std::string mode = argc > 2 ? argv[2] : "pedal";
|
||||
const std::string only = argc > 3 ? argv[3] : "all";
|
||||
const int uniform_v8_cells_per_meter = argc > 4 ? std::stoi(argv[4]) : 0;
|
||||
const auto selected_solver=argc>5 ? parse_pipe_solver(argv[5]) : PipeSolver::Rusanov;
|
||||
std::cerr << "solver=" << pipe_solver_name(selected_solver) << "\n";
|
||||
auto pedal = [&](int second) {
|
||||
return mode == "idle" ? 0.0f : mode == "coast" ? (second >= 1 && second < 5 ? .7f : 0.f) :
|
||||
mode == "transient" && (second == 0 || second >= seconds-2) ? 0.0f : .7f;
|
||||
};
|
||||
std::cout << "scenario,second,wall_seconds,checksum\n";
|
||||
for (auto name : {"twin", "turbo", "b205", "b205-gt17", "v8"}) {
|
||||
for (auto name : {"twin", "b205", "v8"}) {
|
||||
if (only != "all" && only != name) continue;
|
||||
auto s = std::make_unique<FourStrokeScenario>(44100,
|
||||
std::string(name)=="v8" ? FourStrokePreset::AmericanV8 : std::string(name).starts_with("b205") ? FourStrokePreset::SaabB205 : FourStrokePreset::Twin,
|
||||
std::string(name)=="turbo" || std::string(name)=="b205-gt17");
|
||||
std::string(name)=="v8" ? FourStrokePreset::AmericanV8 : std::string(name)=="b205" ? FourStrokePreset::SaabB205 : FourStrokePreset::Twin);
|
||||
if (std::string(name) == "v8" && uniform_v8_cells_per_meter > 0) {
|
||||
set_uniform_pipe_resolution(s->pipes, uniform_v8_cells_per_meter);
|
||||
std::cerr << "v8 uniform_cells_per_meter=" << uniform_v8_cells_per_meter << '\n';
|
||||
}
|
||||
s->set_pipe_solver(selected_solver);
|
||||
s->throttle = .7f;
|
||||
run(name, *s, seconds, [&](int second) {
|
||||
s->throttle = pedal(second);
|
||||
if (mode == "loaded") s->crankshaft.omega = (std::string(name)=="v8" ? 4500 : std::string(name)=="b205-gt17" ? 5500 : 7000) * 2*pi/60;
|
||||
if (mode == "loaded") s->crankshaft.omega = (std::string(name)=="v8" ? 4500 : 7000) * 2*pi/60;
|
||||
});
|
||||
}
|
||||
for (bool racing : {true, false}) {
|
||||
@@ -82,6 +112,7 @@ int main(int argc, char** argv) {
|
||||
TwoStrokeConfig config;
|
||||
config.exhaust = racing ? TwoStrokeExhaust::Racing : TwoStrokeExhaust::Straight;
|
||||
TwoStrokeScenario s(44100, config);
|
||||
s.set_pipe_solver(selected_solver);
|
||||
s.set_throttle(.7f);
|
||||
run(racing ? "two-stroke-racing" : "two-stroke-straight", s, seconds, [&](int second) {
|
||||
s.set_throttle(pedal(second));
|
||||
|
||||
Reference in New Issue
Block a user