Add machine workshop, typed logic, mechanics and sensor-driven ECUs

This commit is contained in:
max
2026-11-02 07:27:13 +01:00
parent eb2b6366c2
commit abfcce0f46
99 changed files with 28835 additions and 145 deletions

View File

@@ -35,4 +35,31 @@ inline Pipe1D make_profiled_pipe(std::span<const PipeSection> sections, float ma
}
return Pipe1D(std::move(areas), std::move(lengths));
}
// Uniform cells over the full arclength, integrating every profile section that
// a cell crosses. Route/profile knots do not force short cells; gas volume is
// still the exact sum of the piecewise frustums at any mesh density.
inline Pipe1D make_uniform_profiled_pipe(std::span<const PipeSection> sections,float maximum_cell_length=.01f){
if(!std::isfinite(maximum_cell_length)||maximum_cell_length<=0||sections.empty())throw std::invalid_argument("invalid pipe profile mesh");
double total=0;float previous=sections.front().inlet_diameter;
for(const auto& s:sections){
if(!std::isfinite(s.length)||!std::isfinite(s.inlet_diameter)||!std::isfinite(s.outlet_diameter)||s.length<=0||s.inlet_diameter<=0||s.outlet_diameter<=0||std::abs(s.inlet_diameter-previous)>1e-6f)throw std::invalid_argument("invalid/discontinuous pipe profile");
total+=s.length;previous=s.outlet_diameter;
}
const int count=profile_section_cells(float(total),maximum_cell_length);const double dx=total/count;
std::vector<float> areas;areas.reserve(count);std::vector<float> lengths(count,float(dx));
std::size_t section=0;double section_start=0,section_end=sections.front().length;
for(int i=0;i<count;++i){
double cursor=i*dx,volume=0;const double end=i+1==count?total:(i+1)*dx;
while(cursor<end){
while(section+1<sections.size()&&cursor>=section_end){section_start=section_end;section_end+=sections[++section].length;}
const auto& s=sections[section];const double stop=std::min(end,section_end);
const double d0=std::lerp(double(s.inlet_diameter),double(s.outlet_diameter),std::clamp((cursor-section_start)/s.length,0.,1.));
const double d1=std::lerp(double(s.inlet_diameter),double(s.outlet_diameter),std::clamp((stop-section_start)/s.length,0.,1.));
volume+=double(pi)/12*(stop-cursor)*(d0*d0+d0*d1+d1*d1);cursor=stop;
}
areas.push_back(float(volume/dx));
}
return Pipe1D(std::move(areas),std::move(lengths));
}
} // namespace fluidsim::port