#pragma once #include #include #include namespace fluidsim::port { inline int mesh_cell_count(float length,float cells_per_meter) { if(!std::isfinite(cells_per_meter) || cells_per_meter<1 || cells_per_meter>500 || !std::isfinite(length) || length<=0) throw std::invalid_argument("cells_per_meter must be in 1..500 with positive pipe length"); const double count=double(length)*cells_per_meter; if(count>4096.001) throw std::invalid_argument("pipe mesh exceeds 4096 cells"); return std::max(1,int(std::ceil(count-1e-6*std::max(1.,count)))); } }