diff --git a/CMakeLists.txt b/CMakeLists.txt index b61119128..1210bc4ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,6 +212,10 @@ set(SOURCES "application/editormodeconnectioncurve.cpp" "application/editormodedigitize.cpp" "editor/editorSpeed.cpp" +"editor/norms/normsTables.cpp" +"editor/norms/normsLimits.cpp" +"editor/norms/normsEngine.cpp" +"editor/norms/normsLine.cpp" "editor/editorProfile.cpp" "editor/editorGauge.cpp" "editor/editorInfra.cpp" diff --git a/editor/norms/norms.hpp b/editor/norms/norms.hpp new file mode 100644 index 000000000..64b5ab983 --- /dev/null +++ b/editor/norms/norms.hpp @@ -0,0 +1,307 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +// The norms of the geometry of the tracks: the profiles of the limits as tables, each value with the document and the table or the +// paragraph it comes from, and one engine checking a line described as elements against any of them. It stands on its own, with no +// scene, no tracks and no user interface (editor-tracks-domain.md §3 and §6); the texts of what it finds are made by its users. +// +// Three tiers (§6.2): PREFER, the values the editor would choose itself (PLK P0); WARN, beyond the normal limits, allowed with a +// message (beyond P1); BLOCK, beyond the extended limits capped by the TSI (beyond P2), which no operation may reach. The global hard +// limits of §6.3 hold in every profile. A value the tables mark unconfirmed can warn, never block. +namespace norms +{ + +enum class profile_id +{ + plk, // PKP PLK ST-T1-A6 v1.0 (2017): P0 PREFER, P1 WARN, P2 BLOCK + tsi, // TSI INF, Reg. (EU) 1299/2014 as amended to 2023/1694: the legal minimum, BLOCK only + en13803, // EN 13803-1:2010: normal WARN, exceptional BLOCK + ch, // Swiss AB-EBV, AB 17 (standard gauge, 1.7.2024): Grenzwert im Normalfall WARN, maximaler Grenzwert BLOCK + count +}; + +enum class tier +{ + none, + prefer, // beyond the value the editor would choose + warn, + block +}; + +enum class parameter +{ + cant_deficiency, // I at the highest speed, mm + cant_excess, // E at the speed of the slow trains, mm + deficiency_jump, // ΔI at an abrupt change of the curvature or of the cant, mm + cant_gradient, // dD/ds of a ramp, mm/m + cant_rate, // dD/dt along a ramp, mm/s + deficiency_rate, // dI/dt along a transition or a ramp, mm/s + element_length, // of a straight or an arc, m, at least + transition_length, // m, at least + transition_shift, // of the arc moved in by its transition, m, at least + radius, // m, at least + cant, // mm, at most + cant_min, // mm: a cant given at all is at least this + vertical_radius, // m, at least; a break of the grade with no vertical curve is 0 + grade, // per mille, at most + intermediate_length, // m: abrupt changes of the cant deficiency further apart are taken one by one (ST-T1-A6 tab. 9.16) + profile_boundary, // an arc running across the boundary of two profiles: to be settled (§6.4) + count +}; + +// the limit is a least value, not a greatest one +bool minimum(parameter const What); + +enum class traffic +{ + passenger, + mixed, + freight +}; + +enum class track_kind +{ + main, // running lines and main tracks of the stations (tory szlakowe, główne zasadnicze i dodatkowe; Zuggleise) + side // sidings (tory boczne; Rangiergleise) +}; + +// what the element is part of or what the query is about, flags +namespace feature +{ +inline constexpr unsigned switch_track{1u << 0}; // a switch or a crossing: a connection of tracks (połączenie torów) +inline constexpr unsigned movable_frog{1u << 1}; +inline constexpr unsigned curved_switch{1u << 2}; // a switch bent into a curve (rozjazd łukowy) +inline constexpr unsigned crossing{1u << 3}; // a crossing or a slip: double, twofold and threefold frogs +inline constexpr unsigned expansion{1u << 4}; // a rail expansion device (przyrząd wyrównawczy) +inline constexpr unsigned diverging{1u << 5}; // the diverging track of a switch +inline constexpr unsigned platform{1u << 6}; // a track at a platform +inline constexpr unsigned station{1u << 7}; // the useful length of a station track +inline constexpr unsigned ballastless{1u << 8}; +inline constexpr unsigned suburban{1u << 9}; // passengers may stand (ST-T1-A6 tab. 10.2) +inline constexpr unsigned tilting{1u << 10}; // the trains tilt: the cant deficiency is theirs, not the TSI's +// set by the engine for a query +inline constexpr unsigned crest{1u << 11}; +inline constexpr unsigned sag{1u << 12}; +inline constexpr unsigned short_stretch{1u << 13}; // a grade held for less than 500 m (ST-T1-A6 tab. 10.1 footnote 2) +inline constexpr unsigned low_deficiency{1u << 14}; // I ≤ 75 mm on both sides of the abrupt change (TSI 4.2.4.4(2)) +inline constexpr unsigned abrupt{1u << 15}; // an arc with no transition curve at an end (AB-EBV AB 17 5.2.2) +} // namespace feature + +// the class of the line (§2): the highest speed, the slow trains, the traffic, main or side track, and what holds along all of it +struct line_class +{ + double vmax{100.0}; // km/h, where the tracks have no speed of their own + double vmin{0.0}; // km/h of the slow trains; 0: by ST-T1-A6 tab. 8.1 for the traffic and the highest speed + traffic kind{traffic::mixed}; + track_kind track{track_kind::main}; + double load{5.0}; // Tg a year, for the cant excess (ST-T1-A6 tab. 9.8) + unsigned features{0}; // platform, station, ballastless, suburban, tilting +}; + +// the speed of the slow trains of a line of the traffic and the highest speed given: the line type of ST-T1-A6 tab. 8.1 with the +// lowest highest speed not below it (P passenger, M mixed, T freight), no faster than Vmax +double slow_speed(traffic const Kind, double const Vmax); + +// what a limit is asked for +struct query +{ + double speed{0.0}; // km/h + double radius{0.0}; // m, 0 on a straight + double load{5.0}; // Tg a year + traffic kind{traffic::mixed}; + track_kind track{track_kind::main}; + unsigned features{0}; +}; + +struct source +{ + std::string_view document; // ST-T1-A6, TSI INF, EN 13803-1, AB-EBV + std::string_view place; // the table, the formula or the paragraph +}; + +struct bound +{ + double value{0.0}; + source from; + bool confirmed{true}; +}; + +struct thresholds +{ + std::optional prefer; + std::optional warn; + std::optional block; +}; + +// a profile: its tables of limits +struct profile +{ + profile_id id{profile_id::plk}; + std::string_view name; // "PLK ST-T1-A6" + std::string_view label; // "PLK", as in a message + std::string_view document; // "ST-T1-A6", the one its tables come from +}; +profile const &profile_of(profile_id const Id); + +// the limits of the profile for the parameter where the query says, the strictest of the rows which apply; empty tiers where the +// profile sets none +thresholds limits(profile_id const Profile, parameter const What, query const &Where); +// the global hard limits of §6.3 kept in every profile: the TSI, and the cant gradient of EN 13803-1 (track twist) +thresholds hard_limits(parameter const What, query const &Where); + +// the tier of the value against the limits of the profile and the hard ones: beyond a confirmed block bound or a hard one, block; beyond +// an unconfirmed block bound or the warn one, warn; beyond the prefer one, prefer. The bound passed is returned in Passed +struct assessment +{ + tier level{tier::none}; + bound passed; + bool hard{false}; // the hard limit decided +}; +// Precision: the share of a limit the value is known within, a value no further beyond it isn't beyond it +assessment assess(parameter const What, double const Value, thresholds const &Profile, thresholds const &Hard, double const Precision = 0.0); + +// the formulas of ST-T1-A6 9.3 - 9.5 (and EN 13803-1 5.2): speeds km/h, radii m, cant mm +double equilibrium_cant(double const Speed, double const Radius); // Deq = 11.8 V^2 / R (9.7) +double regular_cant(double const Speed, double const Radius); // Dreg = 6.5 V^2 / R (9.6) +double cant_deficiency(double const Speed, double const Radius, double const Cant); // I = Deq - D (9.9) +double cant_excess(double const Speed, double const Radius, double const Cant); // E = D - Deq(Vmin) (9.10) +double least_cant(double const Speed, double const Radius, double const Deficiency); // Dmin (9.4) +double greatest_cant(double const Speed, double const Radius, double const Excess); // Dmax (9.5) +double least_radius(double const Speed, double const Cant, double const Deficiency); // Rmin (9.1) +double greatest_speed(double const Radius, double const Cant, double const Deficiency); // V at which I reaches the deficiency +// the highest speed through an arc keeping I at the fast trains and I at the slow ones as given (ST-T1-A6 załącznik 1) +double speed_for_deficiencies(double const Radius, double const Fast, double const Slow, double const Vmin); + +// a plan point, x and z of the scenery +struct plan_point +{ + double x{0.0}; + double z{0.0}; +}; + +enum class element_kind +{ + straight, + transition, + arc +}; + +// an element of the line in the plan: the curvature changes evenly along it from its start to its end, signed, positive turning left +struct element +{ + element_kind kind{element_kind::straight}; + double start{0.0}; // m, chainage + double length{0.0}; + double curvature_start{0.0}; // 1/m + double curvature_end{0.0}; + double speed{0.0}; // km/h, the highest on it; 0: the one of the line class + unsigned features{0}; // switch_track, movable_frog, curved_switch, crossing, expansion, diverging, platform, station + // the element is cut by the end of the line or by a switch: its length isn't its own + bool open_start{false}; + bool open_end{false}; + plan_point from; + plan_point to; + + double end() const { return start + length; } +}; + +// the cant along the line, mm, signed: above 0 leaning into a turn to the left; changing evenly between the points, two points at one +// chainage being a step +struct cant_point +{ + double chainage{0.0}; + double cant{0.0}; +}; + +// the grade line: along each element the grade changes evenly, a vertical curve where it does, a break between two elements whose +// grades differ; grades as ratios, above 0 rising onward +struct grade_element +{ + double start{0.0}; + double length{0.0}; + double grade_start{0.0}; + double grade_end{0.0}; +}; + +struct line +{ + std::string name; + std::vector elements; + std::vector cant; + std::vector grades; + // the share of a value measured on the line it is known within: a line read from the curves of the tracks (an arc of a Bezier curve + // isn't quite one, its roll is written to a few decimals) isn't taken beyond a limit it reaches within that + double precision{0.0}; +}; + +// what the line is read from: points along it, a few metres apart, two at a joint, the end of the one path and the start of the next +struct sample +{ + double chainage{0.0}; + plan_point at; + double grade{0.0}; + double curvature{0.0}; // 1/m, signed, positive turning left + double cant{0.0}; // mm, signed, above 0 leaning left + double speed{0.0}; // km/h, 0: none set + unsigned features{0}; +}; + +// the line described as elements: straights, transitions and arcs where the curvature keeps still or changes evenly, the cant as its +// points, the grade line as its elements +line describe(std::vector const &Samples, std::string Name = {}); + +// the profiles in force by place (§6.4): the default of the scenery, areas outlined in the plan, lines by name; a line's own wins +struct area +{ + std::string name; + profile_id profile{profile_id::plk}; + std::vector outline; +}; +struct area_map +{ + profile_id scenery{profile_id::plk}; + std::vector areas; + std::vector> lines; + + profile_id at(plan_point const &Point, std::string_view Line) const; +}; + +struct finding +{ + parameter what{parameter::count}; + tier level{tier::none}; + double value{0.0}; + double limit{0.0}; + profile_id profile{profile_id::plk}; // the profile checked, the one whose limit was passed unless hard + source from; + bool confirmed{true}; + bool hard{false}; // a global hard limit of §6.3 + double chainage{0.0}; + double length{0.0}; // m along the line it holds over, 0 at a point + std::size_t element{0}; + double speed{0.0}; // km/h the value was found for + profile_id other{profile_id::plk}; // profile_boundary: the second profile +}; + +// the line checked at the line class, each element against the profile of its place, the stricter one of the two at its ends +// on a boundary; the findings in the order of the line: of the parameters checked over an element one each, the worst; of the jumps, +// the ramps and the vertical curves one each +std::vector evaluate(line const &Line, line_class const &Class, area_map const &Areas); + +} // namespace norms diff --git a/editor/norms/normsEngine.cpp b/editor/norms/normsEngine.cpp new file mode 100644 index 000000000..df571a502 --- /dev/null +++ b/editor/norms/normsEngine.cpp @@ -0,0 +1,566 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#include "stdafx.h" +#include "editor/norms/norms.hpp" + +#include +#include +#include + +// the engine: one for all the profiles (editor-tracks-domain.md §6.3). Along the line it finds the cant deficiency at the highest speed +// and the cant excess at the speed of the slow trains, the abrupt changes of the cant deficiency at every jump of the curvature or of +// the cant, taken together over elements shorter than the profile lets them be taken apart, the gradient and the rate of change of +// the cant along the ramps, the rate of change of the cant deficiency along the transitions and the ramps, the lengths of the +// elements, the radii, the cant, the vertical curves and the grades +namespace norms +{ + +namespace +{ + +double constexpr kC{11.8}; +double constexpr kSame{1e-6}; // m: points closer along the line are one +double constexpr kCurve{1.0 / 50000.0}; // 1/m: a curve, not a straight +double constexpr kJumpCurvature{1e-6}; // 1/m +double constexpr kStep{0.5}; // mm: a smaller step of the cant isn't one +double constexpr kTwistBase{5.0}; // m: a step of the cant felt over the base of the twist, ST-T1-A6 tab. 9.12 +double constexpr kBreak{0.002}; // a change of the grade up to 2 per mille needn't be rounded (ST-T1-A6 10.2 pkt 2, AB 17 7.1.3) + +double sign(double const Value) +{ + if (Value > 0.0) + return 1.0; + return Value < 0.0 ? -1.0 : 0.0; +} + +// the lateral acceleration in the track plane as mm of cant, signed with the curvature: 11.8 V^2 K - D +double lateral(double const Speed, double const Curvature, double const Cant) +{ + return kC * Speed * Speed * Curvature - Cant; +} + +// I: above 0 the cant falls short of the curve +double deficiency(double const Speed, double const Curvature, double const Cant) +{ + if (std::abs(Curvature) < kCurve) + return -std::abs(Cant); + return sign(Curvature) * lateral(Speed, Curvature, Cant); +} + +// E: above 0 the cant is more than the curve asks for at the speed; on a straight all of the cant +double excess(double const Speed, double const Curvature, double const Cant) +{ + if (std::abs(Curvature) < kCurve) + return std::abs(Cant); + return sign(Curvature) * Cant - kC * Speed * Speed * std::abs(Curvature); +} + +// the cant at the chainage, before a step there or after it +double cant_at(std::vector const &Points, double const Chainage, bool const After) +{ + if (Points.empty()) + return 0.0; + auto const first{std::ranges::lower_bound(Points, Chainage - kSame, {}, &cant_point::chainage)}; + auto const last{std::ranges::upper_bound(Points, Chainage + kSame, {}, &cant_point::chainage)}; + if (first != last) + return After ? std::prev(last)->cant : first->cant; + if (last == Points.begin()) + return Points.front().cant; + if (first == Points.end()) + return Points.back().cant; + auto const &before{*std::prev(first)}; + auto const &next{*first}; + auto const run{next.chainage - before.chainage}; + return run > kSame ? std::lerp(before.cant, next.cant, (Chainage - before.chainage) / run) : next.cant; +} + +double curvature_at(element const &Element, double const Chainage) +{ + if (Element.length <= kSame) + return Element.curvature_end; + return std::lerp(Element.curvature_start, Element.curvature_end, std::clamp((Chainage - Element.start) / Element.length, 0.0, 1.0)); +} + +// a point inside an element where the curvature and the cant are known from inside it +struct station +{ + double chainage; + double curvature; + double cant; +}; + +class checker +{ + public: + checker(line const &Line, line_class const &Class, area_map const &Areas) : m_line{Line}, m_class{Class}, m_areas{Areas} {} + + std::vector run() + { + for (std::size_t i = 0; i < m_line.elements.size(); ++i) + check_element(i); + check_jumps(); + check_ramps(); + check_grades(); + return ordered(); + } + + private: + line const &m_line; + line_class const &m_class; + area_map const &m_areas; + std::vector m_found; + + double speed(element const &Element) const { return Element.speed > 0.0 ? Element.speed : m_class.vmax; } + double slow(double const Speed) const + { + auto const vmin{m_class.vmin > 0.0 ? m_class.vmin : slow_speed(m_class.kind, m_class.vmax)}; + return std::min(vmin, Speed); + } + + std::vector profiles(element const &Element) const + { + std::vector result{m_areas.at(Element.from, m_line.name)}; + if (auto const other{m_areas.at(Element.to, m_line.name)}; other != result.front()) + result.push_back(other); + return result; + } + + query where(element const &Element, double const Speed, double const Radius, unsigned const Extra = 0) const + { + query result; + result.speed = Speed; + result.radius = Radius; + result.load = m_class.load; + result.kind = m_class.kind; + result.track = m_class.track; + result.features = m_class.features | Element.features | Extra; + return result; + } + + // the element the chainage lies on, the one starting there at a joint + std::size_t element_at(double const Chainage) const + { + auto const next{std::ranges::upper_bound(m_line.elements, Chainage + kSame, {}, &element::start)}; + return next == m_line.elements.begin() ? 0 : static_cast(std::distance(m_line.elements.begin(), next) - 1); + } + + // the value checked against each of the profiles, the worst kept + void check(parameter const What, double const Value, std::size_t const Index, query const &Where, double const Chainage, double const Length = 0.0) + { + auto const &element{m_line.elements[Index]}; + std::optional worst; + for (auto const profile : profiles(element)) + { + auto const verdict{assess(What, Value, limits(profile, What, Where), hard_limits(What, Where), m_line.precision)}; + if (verdict.level == tier::none || (worst.has_value() && verdict.level <= worst->level)) + continue; + finding found; + found.what = What; + found.level = verdict.level; + found.value = Value; + found.limit = verdict.passed.value; + found.profile = profile; + found.from = verdict.passed.from; + found.confirmed = verdict.passed.confirmed; + found.hard = verdict.hard; + found.chainage = Chainage; + found.length = Length; + found.element = Index; + found.speed = Where.speed; + worst = found; + } + if (worst.has_value()) + m_found.push_back(*worst); + } + + std::vector stations(element const &Element) const + { + std::vector result; + auto const end{Element.end()}; + result.push_back({Element.start, Element.curvature_start, cant_at(m_line.cant, Element.start, true)}); + for (auto const &point : m_line.cant) + { + if (point.chainage <= Element.start + kSame || point.chainage >= end - kSame) + continue; + result.push_back({point.chainage, curvature_at(Element, point.chainage), point.cant}); + } + result.push_back({end, Element.curvature_end, cant_at(m_line.cant, end, false)}); + return result; + } + + // an arc meeting another curvature with no transition at one of its ends + bool abrupt(std::size_t const Index) const + { + auto const &element{m_line.elements[Index]}; + if (element.kind != element_kind::arc) + return false; + auto const jump_before{Index > 0 && std::abs(m_line.elements[Index - 1].curvature_end - element.curvature_start) > kCurve}; + auto const jump_after{Index + 1 < m_line.elements.size() && std::abs(m_line.elements[Index + 1].curvature_start - element.curvature_end) > kCurve}; + return jump_before || jump_after; + } + + // the greatest of a value along an element, and where + struct peak + { + double value{0.0}; + double chainage{0.0}; + double length{0.0}; + + void take(double const Value, double const Chainage, double const Length = 0.0) + { + if (Value <= value) + return; + value = Value; + chainage = Chainage; + length = Length; + } + }; + + // a transition next to an arc reaches its radius and its cant deficiency only where the arc begins: the arc has them checked + bool beside_arc(std::size_t const Index) const + { + auto const arc_at = [this](std::size_t const At) { return At < m_line.elements.size() && m_line.elements[At].kind == element_kind::arc; }; + return m_line.elements[Index].kind == element_kind::transition && ((Index > 0 && arc_at(Index - 1)) || arc_at(Index + 1)); + } + + void check_element(std::size_t const Index) + { + auto const &element{m_line.elements[Index]}; + auto const fast{speed(element)}; + auto const sharpest{std::max(std::abs(element.curvature_start), std::abs(element.curvature_end))}; + auto const radius{sharpest >= kCurve ? 1.0 / sharpest : 0.0}; + auto const here{where(element, fast, radius, abrupt(Index) ? feature::abrupt : 0u)}; + auto const points{stations(element)}; + auto const vmin{slow(fast)}; + peak cant; + peak most_deficiency; + peak most_excess; + peak fastest_change; + for (std::size_t i = 0; i < points.size(); ++i) + { + auto const &point{points[i]}; + cant.take(std::abs(point.cant), point.chainage); + most_deficiency.take(deficiency(fast, point.curvature, point.cant), point.chainage); + most_excess.take(excess(vmin, point.curvature, point.cant), point.chainage); + if (i == 0) + continue; + // along the piece between two points the curvature and the cant change evenly, and so does the cant deficiency + auto const &previous{points[i - 1]}; + auto const run{point.chainage - previous.chainage}; + if (run < 0.5) + continue; + auto const change{std::abs(lateral(fast, point.curvature, point.cant) - lateral(fast, previous.curvature, previous.cant))}; + fastest_change.take(change * fast / (3.6 * run), previous.chainage, run); + } + auto const own_curve{false == beside_arc(Index)}; + if (radius > 0.0 && own_curve) + check(parameter::radius, radius, Index, here, element.start, element.length); + if (cant.value > kStep) + check(parameter::cant, cant.value, Index, here, cant.chainage); + if (element.kind == element_kind::arc && cant.value > kStep) + check(parameter::cant_min, cant.value, Index, here, element.start, element.length); + if (most_deficiency.value > 0.0 && own_curve) + check(parameter::cant_deficiency, most_deficiency.value, Index, here, most_deficiency.chainage); + if (most_excess.value > 0.0 && own_curve) + { + // the limits by the speed band of the element, the excess at the speed of the slow trains + auto const before{m_found.size()}; + check(parameter::cant_excess, most_excess.value, Index, here, most_excess.chainage); + if (m_found.size() > before) + m_found.back().speed = vmin; + } + if (fastest_change.value > 0.0) + check(parameter::deficiency_rate, fastest_change.value, Index, here, fastest_change.chainage, fastest_change.length); + check_lengths(Index, here); + check_boundary(Index); + } + + void check_lengths(std::size_t const Index, query const &Here) + { + auto const &element{m_line.elements[Index]}; + if (element.open_start || element.open_end) + return; + if (element.kind == element_kind::transition) + { + check(parameter::transition_length, element.length, Index, Here, element.start, element.length); + // the arc moved in by a cubic parabola or a clothoid: L^2 / 24 times the change of the curvature (ST-T1-A6 tab. 9.11) + auto const shift{element.length * element.length * std::abs(element.curvature_end - element.curvature_start) / 24.0}; + check(parameter::transition_shift, shift, Index, Here, element.start, element.length); + return; + } + check(parameter::element_length, element.length, Index, Here, element.start, element.length); + } + + void check_boundary(std::size_t const Index) + { + auto const &element{m_line.elements[Index]}; + auto const both{profiles(element)}; + if (element.kind != element_kind::arc || both.size() < 2) + return; + finding found; + found.what = parameter::profile_boundary; + found.level = tier::warn; + found.profile = both[0]; + found.other = both[1]; + found.chainage = element.start; + found.length = element.length; + found.element = Index; + found.speed = speed(element); + m_found.push_back(found); + } + + // an abrupt change of the curvature or the cant at a chainage + struct jump + { + double chainage{0.0}; + std::size_t element{0}; // the one after it + double curvature_before{0.0}; + double curvature_after{0.0}; + double cant_before{0.0}; + double cant_after{0.0}; + double speed{0.0}; + unsigned features{0}; + }; + + // the jump at a joint of two elements or at a step of the cant, none where the curvature and the cant go on there + std::optional jump_at(double const Chainage) const + { + auto const index{element_at(Chainage)}; + auto const &after{m_line.elements[index]}; + jump step; + step.chainage = Chainage; + step.element = index; + step.curvature_after = curvature_at(after, Chainage); + step.curvature_before = step.curvature_after; + step.speed = speed(after); + step.features = after.features; + if (index > 0 && std::abs(after.start - Chainage) < kSame) + { + // a train passes the joint no faster than either of the limits there + auto const &before{m_line.elements[index - 1]}; + step.curvature_before = before.curvature_end; + step.speed = std::min(step.speed, speed(before)); + step.features |= before.features & feature::switch_track; + } + step.cant_before = cant_at(m_line.cant, Chainage, false); + step.cant_after = cant_at(m_line.cant, Chainage, true); + if (std::abs(step.curvature_after - step.curvature_before) <= kJumpCurvature && std::abs(step.cant_after - step.cant_before) <= kStep) + return std::nullopt; + return step; + } + + std::vector jumps() const + { + std::vector places; + for (std::size_t i = 1; i < m_line.elements.size(); ++i) + places.push_back(m_line.elements[i].start); + for (std::size_t i = 1; i < m_line.cant.size(); ++i) + if (m_line.cant[i].chainage - m_line.cant[i - 1].chainage < kSame) + places.push_back(m_line.cant[i].chainage); + std::ranges::sort(places); + auto const repeated{std::ranges::unique(places, [](double const A, double const B) { return B - A < kSame; })}; + places.erase(repeated.begin(), repeated.end()); + std::vector result; + for (auto const place : places) + if (auto const step{jump_at(place)}) + result.push_back(*step); + return result; + } + + // the shortest element between two jumps for them to be taken apart: the longest the profiles of the element between them ask for + double intermediate(std::size_t const Index, double const Speed) const + { + auto const &element{m_line.elements[Index]}; + double result{0.0}; + for (auto const profile : profiles(element)) + if (auto const bound{limits(profile, parameter::intermediate_length, where(element, Speed, 0.0)).block}) + result = std::max(result, bound->value); + return result; + } + + // ST-T1-A6 9.11 pkt 8 - 13: the jumps closer than the intermediate length, changing the cant deficiency the same way, are taken + // together, from the deficiency before the first to the one after the last; otherwise one by one + void check_jumps() + { + auto const all{jumps()}; + std::size_t first{0}; + while (first < all.size()) + { + auto last{first}; + auto fast{all[first].speed}; + auto features{all[first].features}; + auto const way{sign(lateral(fast, all[first].curvature_after, all[first].cant_after) - lateral(fast, all[first].curvature_before, all[first].cant_before))}; + while (last + 1 < all.size()) + { + auto const &next{all[last + 1]}; + auto const speed_there{std::max(fast, next.speed)}; + auto const gap{next.chainage - all[last].chainage}; + auto const step{lateral(speed_there, next.curvature_after, next.cant_after) - lateral(speed_there, next.curvature_before, next.cant_before)}; + auto const between{lateral(speed_there, next.curvature_before, next.cant_before) - lateral(speed_there, all[last].curvature_after, all[last].cant_after)}; + auto const along{sign(between) == 0.0 || sign(between) == way}; + if (gap >= intermediate(element_at(all[last].chainage + gap * 0.5), speed_there) || sign(step) != way || false == along) + break; + fast = speed_there; + features |= next.features; + ++last; + } + auto const before{lateral(fast, all[first].curvature_before, all[first].cant_before)}; + auto const after{lateral(fast, all[last].curvature_after, all[last].cant_after)}; + auto const extra{std::abs(before) <= 75.0 && std::abs(after) <= 75.0 ? feature::low_deficiency : 0u}; + auto const &element{m_line.elements[all[first].element]}; + query here{where(element, fast, 0.0, extra)}; + here.features = (here.features & ~feature::switch_track) | (features & feature::switch_track); + check(parameter::deficiency_jump, std::abs(after - before), all[first].element, here, all[first].chainage, all[last].chainage - all[first].chainage); + first = last + 1; + } + } + + // the speed of the fastest element over the stretch, and the element its middle lies on + std::pair over(double const From, double const To) const + { + double fastest{0.0}; + for (auto const &element : m_line.elements) + if (element.end() > From + kSame && element.start < To - kSame) + fastest = std::max(fastest, speed(element)); + auto const index{element_at((From + To) * 0.5)}; + if (fastest <= 0.0) + fastest = speed(m_line.elements[index]); + return {fastest, index}; + } + + // the ramps: between two points of the cant the gradient and the rate of change (ST-T1-A6 9.16, 9.18); a step of the cant as the + // twist it makes over the base of 5 m + void check_ramps() + { + if (m_line.elements.empty()) + return; + for (std::size_t i = 1; i < m_line.cant.size(); ++i) + { + auto const &from{m_line.cant[i - 1]}; + auto const &to{m_line.cant[i]}; + auto const change{std::abs(to.cant - from.cant)}; + auto const run{to.chainage - from.chainage}; + if (change <= 1e-6) + continue; + auto const [fast, index]{over(from.chainage, std::max(to.chainage, from.chainage + kTwistBase))}; + auto const here{where(m_line.elements[index], fast, 0.0)}; + if (run < kSame) + { + if (change > kStep) + check(parameter::cant_gradient, change / kTwistBase, index, here, from.chainage); + continue; + } + auto const gradient{change / run}; + check(parameter::cant_gradient, gradient, index, here, from.chainage, run); + check(parameter::cant_rate, gradient * fast / 3.6, index, here, from.chainage, run); + } + } + + // the grade line: the vertical curves, the breaks of the grade over 2 per mille with no curve, the grades + void check_grades() + { + if (m_line.elements.empty()) + return; + auto const &grades{m_line.grades}; + std::size_t i{0}; + while (i < grades.size()) + { + auto const &piece{grades[i]}; + auto const [fast, index]{over(piece.start, piece.start + std::max(piece.length, kSame))}; + auto const held{piece.grade_start == piece.grade_end}; + // the grades held; a vertical curve goes between the ones on its sides + if (held && piece.grade_start != 0.0) + check(parameter::grade, std::abs(piece.grade_start) * 1000.0, index, where(m_line.elements[index], fast, 0.0, piece.length < 500.0 ? feature::short_stretch : 0u), piece.start, piece.length); + if (i > 0) + { + auto const &previous{grades[i - 1]}; + auto const change{piece.grade_start - previous.grade_end}; + if (std::abs(change) > kBreak) + { + auto const at{element_at(piece.start)}; + check(parameter::vertical_radius, 0.0, at, where(m_line.elements[at], fast, 0.0, change < 0.0 ? feature::crest : feature::sag), piece.start); + } + } + if (held) + { + ++i; + continue; + } + // a vertical curve, of the pieces in a row bending the same way with no break between them + auto last{i}; + auto const way{sign(piece.grade_end - piece.grade_start)}; + auto sharpest{piece.length / std::abs(piece.grade_end - piece.grade_start)}; + while (last + 1 < grades.size()) + { + auto const &next{grades[last + 1]}; + if (next.grade_start == next.grade_end || sign(next.grade_end - next.grade_start) != way || std::abs(next.grade_start - grades[last].grade_end) > 1e-9) + break; + sharpest = std::min(sharpest, next.length / std::abs(next.grade_end - next.grade_start)); + ++last; + } + auto const total{grades[last].grade_end - piece.grade_start}; + auto const end{grades[last].start + grades[last].length}; + if (std::abs(total) > kBreak) + { + auto const [curve_speed, curve_index]{over(piece.start, end)}; + check(parameter::vertical_radius, sharpest, curve_index, where(m_line.elements[curve_index], curve_speed, 0.0, way < 0.0 ? feature::crest : feature::sag), piece.start, end - piece.start); + } + i = last + 1; + } + } + + // in the order of the line; each element has one finding of a parameter checked over it, the jumps, the ramps and the breaks of the + // grade one each + std::vector ordered() const + { + auto result{m_found}; + std::ranges::stable_sort(result, [](finding const &A, finding const &B) { return std::tie(A.chainage, A.what) < std::tie(B.chainage, B.what); }); + return result; + } +}; + +// the point within the outline: a ray from it crosses its sides an odd number of times +bool inside(std::vector const &Outline, plan_point const &Point) +{ + bool result{false}; + auto previous{Outline.size() - 1}; + for (std::size_t i = 0; i < Outline.size(); ++i) + { + auto const &a{Outline[i]}; + auto const &b{Outline[previous]}; + if ((a.z > Point.z) != (b.z > Point.z) && Point.x < (b.x - a.x) * (Point.z - a.z) / (b.z - a.z) + a.x) + result = !result; + previous = i; + } + return result; +} + +} // namespace + +profile_id area_map::at(plan_point const &Point, std::string_view const Line) const +{ + if (false == Line.empty()) + for (auto const &[name, profile] : lines) + if (name == Line) + return profile; + for (auto const &area : areas) + if (area.outline.size() >= 3 && inside(area.outline, Point)) + return area.profile; + return scenery; +} + +std::vector evaluate(line const &Line, line_class const &Class, area_map const &Areas) +{ + if (Line.elements.empty()) + return {}; + return checker{Line, Class, Areas}.run(); +} + +} // namespace norms diff --git a/editor/norms/normsLimits.cpp b/editor/norms/normsLimits.cpp new file mode 100644 index 000000000..1fb019bf3 --- /dev/null +++ b/editor/norms/normsLimits.cpp @@ -0,0 +1,226 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#include "stdafx.h" +#include "editor/norms/norms.hpp" +#include "editor/norms/normsTables.hpp" + +#include +#include +#include + +// the limits of the profiles from their tables, the tier of a value against them, the formulas of the cant +namespace norms +{ + +namespace +{ + +double constexpr kC{11.8}; // mm m h^2 / km^2: the cant balancing a curve, 11.8 V^2 / R (ST-T1-A6 9.7, EN 13803-1 5.2.1) + +// the strictest of the limits of one tier where several rows hold: the lowest of the greatest values, the highest of the least +// ones; at the same value a confirmed one +void stricter(std::optional &Kept, bound const &Candidate, bool const Minimum) +{ + if (false == Kept.has_value()) + { + Kept = Candidate; + return; + } + auto const better{Minimum ? Candidate.value > Kept->value : Candidate.value < Kept->value}; + if (better || (Candidate.value == Kept->value && Candidate.confirmed && false == Kept->confirmed)) + Kept = Candidate; +} + +thresholds gathered(std::span const Rows, std::string_view const Document, parameter const What, query const &Where) +{ + thresholds result; + auto const least{minimum(What)}; + for (auto const &row : Rows) + { + if (row.what != What || false == tables::applies(row, Where)) + continue; + source const from{row.document.empty() ? Document : row.document, row.place}; + auto const take = [&Where, &from, least](tables::cell const &Cell, std::optional &Kept) { + if (Cell.present) + stricter(Kept, {tables::value(Cell.limit, Where.speed, Where.radius), from, Cell.confirmed}, least); + }; + take(row.prefer, result.prefer); + take(row.warn, result.warn); + take(row.block, result.block); + } + return result; +} + +bool beyond(parameter const What, double const Value, bound const &Bound, double const Precision) +{ + auto const margin{std::max(1e-9 * std::max(1.0, std::abs(Bound.value)), Precision * std::abs(Bound.value))}; + return minimum(What) ? Value < Bound.value - margin : Value > Bound.value + margin; +} + +} // namespace + +bool minimum(parameter const What) +{ + switch (What) + { + case parameter::element_length: + case parameter::transition_length: + case parameter::transition_shift: + case parameter::radius: + case parameter::cant_min: + case parameter::vertical_radius: + case parameter::intermediate_length: return true; + default: return false; + } +} + +profile const &profile_of(profile_id const Id) +{ + static std::array(profile_id::count)> const profiles{{ + {profile_id::plk, "PLK ST-T1-A6", "PLK", "ST-T1-A6"}, + {profile_id::tsi, "TSI INF", "TSI INF", "TSI INF"}, + {profile_id::en13803, "EN 13803", "EN 13803", "EN 13803-1"}, + {profile_id::ch, "CH AB-EBV", "AB-EBV", "AB-EBV"}, + }}; + return profiles[std::min(static_cast(Id), profiles.size() - 1)]; +} + +double slow_speed(traffic const Kind, double const Vmax) +{ + struct line_type + { + traffic kind; + double vmax; + double vmin; + }; + // ST-T1-A6 tab. 8.1: P250 P200 M200 P160 M160 P120 M120 T120 P80 M80 T80 T40 + static std::array constexpr types{{ + {traffic::passenger, 80, 60}, + {traffic::passenger, 120, 80}, + {traffic::passenger, 160, 120}, + {traffic::passenger, 200, 120}, + {traffic::passenger, 250, 120}, + {traffic::mixed, 80, 40}, + {traffic::mixed, 120, 60}, + {traffic::mixed, 160, 80}, + {traffic::mixed, 200, 80}, + {traffic::freight, 40, 40}, + {traffic::freight, 80, 40}, + {traffic::freight, 120, 60}, + }}; + double result{-1.0}; + double fastest{-1.0}; + for (auto const &type : types) + { + if (type.kind != Kind) + continue; + if (type.vmax >= Vmax - 1e-9) + { + result = type.vmin; + break; + } + fastest = type.vmin; + } + if (result < 0.0) + result = fastest; + return std::min(result, Vmax); +} + +thresholds limits(profile_id const Profile, parameter const What, query const &Where) +{ + return gathered(tables::rows(Profile), profile_of(Profile).document, What, Where); +} + +thresholds hard_limits(parameter const What, query const &Where) +{ + return gathered(tables::hard_rows(), profile_of(profile_id::tsi).document, What, Where); +} + +assessment assess(parameter const What, double const Value, thresholds const &Profile, thresholds const &Hard, double const Precision) +{ + assessment result; + auto const passed = [What, Value, Precision](std::optional const &Bound) { return Bound.has_value() && beyond(What, Value, *Bound, Precision); }; + // the extended limit of the profile when confirmed, the hard one in any case + auto const profile_block{passed(Profile.block) && Profile.block->confirmed}; + auto const hard_block{passed(Hard.block)}; + if (profile_block || hard_block) + { + result.level = tier::block; + result.passed = profile_block ? *Profile.block : *Hard.block; + result.hard = hard_block && false == profile_block; + return result; + } + // an extended limit not confirmed only warns + if (passed(Profile.block)) + { + result.level = tier::warn; + result.passed = *Profile.block; + return result; + } + if (passed(Profile.warn)) + { + result.level = tier::warn; + result.passed = *Profile.warn; + return result; + } + if (passed(Profile.prefer)) + { + result.level = tier::prefer; + result.passed = *Profile.prefer; + } + return result; +} + +double equilibrium_cant(double const Speed, double const Radius) +{ + return Radius > 0.0 ? kC * Speed * Speed / Radius : 0.0; +} + +double regular_cant(double const Speed, double const Radius) +{ + return Radius > 0.0 ? 6.5 * Speed * Speed / Radius : 0.0; +} + +double cant_deficiency(double const Speed, double const Radius, double const Cant) +{ + return equilibrium_cant(Speed, Radius) - Cant; +} + +double cant_excess(double const Speed, double const Radius, double const Cant) +{ + return Cant - equilibrium_cant(Speed, Radius); +} + +double least_cant(double const Speed, double const Radius, double const Deficiency) +{ + return equilibrium_cant(Speed, Radius) - Deficiency; +} + +double greatest_cant(double const Speed, double const Radius, double const Excess) +{ + return equilibrium_cant(Speed, Radius) + Excess; +} + +double least_radius(double const Speed, double const Cant, double const Deficiency) +{ + return Cant + Deficiency > 0.0 ? kC * Speed * Speed / (Cant + Deficiency) : 0.0; +} + +double greatest_speed(double const Radius, double const Cant, double const Deficiency) +{ + return std::sqrt(std::max(0.0, (Cant + Deficiency) * Radius / kC)); +} + +double speed_for_deficiencies(double const Radius, double const Fast, double const Slow, double const Vmin) +{ + return std::sqrt(std::max(0.0, (Fast - Slow) * Radius / kC + Vmin * Vmin)); +} + +} // namespace norms diff --git a/editor/norms/normsLine.cpp b/editor/norms/normsLine.cpp new file mode 100644 index 000000000..381f588cb --- /dev/null +++ b/editor/norms/normsLine.cpp @@ -0,0 +1,333 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#include "stdafx.h" +#include "editor/norms/norms.hpp" + +#include +#include +#include + +// a line read from its samples as elements: where the curvature keeps still an arc or a straight, where it changes evenly a +// transition, a jump at a joint where it changes at once. The pieces are found by keeping the samples a straight line between two kept +// ones misses by more than a tolerance (Douglas and Peucker), the same for the cant and for the grade +namespace norms +{ + +namespace +{ + +double constexpr kSame{1e-6}; // m +double constexpr kJumpCurvature{2e-5}; // 1/m: a smaller change at a joint, about R 50 km, is taken for the curves meeting not quite +double constexpr kStraight{1.0 / 30000.0}; // 1/m: flatter is a straight +double constexpr kCurvatureTolerance{1e-5}; // 1/m, and 3 % of the curvature +double constexpr kCurvatureShare{0.03}; +double constexpr kJumpCant{1.0}; // mm +double constexpr kCantTolerance{0.5}; // mm +double constexpr kJumpGrade{0.0005}; +double constexpr kGradeTolerance{0.0002}; +double constexpr kPrecision{0.002}; // of the values measured on a line read from its samples + +using value_of = double (*)(sample const &); + +double curvature_of(sample const &Sample) +{ + return Sample.curvature; +} + +double cant_of(sample const &Sample) +{ + return Sample.cant; +} + +double grade_of(sample const &Sample) +{ + return Sample.grade; +} + +// the runs of samples with no jump between them: [first, last] each +std::vector> runs(std::vector const &Samples, value_of const Value, double const Jump, bool const Features) +{ + std::vector> result; + std::size_t first{0}; + for (std::size_t i = 1; i < Samples.size(); ++i) + { + auto const &before{Samples[i - 1]}; + auto const &after{Samples[i]}; + if (after.chainage - before.chainage > kSame) + continue; + if (auto const jump{std::abs(Value(after) - Value(before)) > Jump || (Features && after.features != before.features)}; false == jump) + continue; + result.emplace_back(first, i - 1); + first = i; + } + result.emplace_back(first, Samples.size() - 1); + return result; +} + +// the samples kept of the run: the ones the line between the kept ones would miss by more than the tolerance +std::vector simplified(std::vector const &Samples, std::pair const Run, value_of const Value, double const Tolerance) +{ + std::vector kept{Run.first, Run.second}; + std::vector> pending{Run}; + while (false == pending.empty()) + { + auto const [first, last]{pending.back()}; + pending.pop_back(); + if (last <= first + 1) + continue; + auto const &a{Samples[first]}; + auto const &b{Samples[last]}; + auto const run{b.chainage - a.chainage}; + double furthest{0.0}; + std::size_t at{first}; + for (auto i = first + 1; i < last; ++i) + { + auto const share{run > kSame ? (Samples[i].chainage - a.chainage) / run : 0.5}; + auto const miss{std::abs(Value(Samples[i]) - std::lerp(Value(a), Value(b), share))}; + if (miss > furthest) + { + furthest = miss; + at = i; + } + } + if (furthest <= Tolerance) + continue; + kept.push_back(at); + pending.emplace_back(first, at); + pending.emplace_back(at, last); + } + std::ranges::sort(kept); + auto const repeated{std::ranges::unique(kept)}; + kept.erase(repeated.begin(), repeated.end()); + return kept; +} + +// the mean of the value over the samples, weighted by the length +double mean(std::vector const &Samples, std::size_t const First, std::size_t const Last, value_of const Value) +{ + double sum{0.0}; + double length{0.0}; + for (auto i = First + 1; i <= Last; ++i) + { + auto const run{Samples[i].chainage - Samples[i - 1].chainage}; + sum += (Value(Samples[i]) + Value(Samples[i - 1])) * 0.5 * run; + length += run; + } + return length > kSame ? sum / length : Value(Samples[First]); +} + +struct piece +{ + std::size_t first; + std::size_t last; + std::size_t run; +}; + +element element_of(std::vector const &Samples, piece const &Piece) +{ + auto const &a{Samples[Piece.first]}; + auto const &b{Samples[Piece.last]}; + element result; + result.start = a.chainage; + result.length = b.chainage - a.chainage; + result.from = a.at; + result.to = b.at; + result.features = a.features; + double sharpest{0.0}; + for (auto i = Piece.first; i <= Piece.last; ++i) + { + sharpest = std::max(sharpest, std::abs(Samples[i].curvature)); + result.speed = std::max(result.speed, Samples[i].speed); + } + auto const tolerance{std::max(kCurvatureTolerance, kCurvatureShare * std::max(std::abs(a.curvature), std::abs(b.curvature)))}; + if (sharpest < kStraight) + result.kind = element_kind::straight; + else if (std::abs(b.curvature - a.curvature) <= tolerance && a.curvature * b.curvature > 0.0) + { + result.kind = element_kind::arc; + result.curvature_start = mean(Samples, Piece.first, Piece.last, &curvature_of); + result.curvature_end = result.curvature_start; + } + else + { + result.kind = element_kind::transition; + result.curvature_start = std::abs(a.curvature) < kStraight ? 0.0 : a.curvature; + result.curvature_end = std::abs(b.curvature) < kStraight ? 0.0 : b.curvature; + } + return result; +} + +// the neighbours alike made one: straights, and arcs of about one curvature +bool alike(element const &A, element const &B) +{ + if (A.kind != B.kind || A.features != B.features) + return false; + if (A.kind == element_kind::straight) + return true; + if (A.kind != element_kind::arc) + return false; + return A.curvature_end * B.curvature_start > 0.0 && std::abs(A.curvature_end - B.curvature_start) <= kCurvatureShare * std::max(std::abs(A.curvature_end), std::abs(B.curvature_start)); +} + +void merge(element &Into, element const &Next) +{ + if (Into.kind == element_kind::arc) + { + auto const total{Into.length + Next.length}; + auto const curvature{total > kSame ? (Into.curvature_start * Into.length + Next.curvature_start * Next.length) / total : Into.curvature_start}; + Into.curvature_start = curvature; + Into.curvature_end = curvature; + } + Into.length = Next.end() - Into.start; + Into.to = Next.to; + Into.speed = std::max(Into.speed, Next.speed); +} + +// where two elements meet with no jump the curvature goes on: the transition ends at the curvature of the arc or the straight +void join(element &Before, element &After) +{ + if (Before.kind == element_kind::transition && After.kind != element_kind::transition) + Before.curvature_end = After.curvature_start; + else if (After.kind == element_kind::transition && Before.kind != element_kind::transition) + After.curvature_start = Before.curvature_end; + else if (Before.kind == element_kind::transition) + { + auto const middle{(Before.curvature_end + After.curvature_start) * 0.5}; + Before.curvature_end = middle; + After.curvature_start = middle; + } +} + +std::vector plan(std::vector const &Samples) +{ + std::vector result; + std::vector run_of; + auto const all{runs(Samples, &curvature_of, kJumpCurvature, true)}; + for (std::size_t r = 0; r < all.size(); ++r) + { + double sharpest{0.0}; + for (auto i = all[r].first; i <= all[r].second; ++i) + sharpest = std::max(sharpest, std::abs(Samples[i].curvature)); + auto const kept{simplified(Samples, all[r], &curvature_of, std::max(kCurvatureTolerance, kCurvatureShare * sharpest))}; + for (std::size_t k = 1; k < kept.size(); ++k) + { + if (Samples[kept[k]].chainage - Samples[kept[k - 1]].chainage <= kSame) + continue; + auto next{element_of(Samples, {kept[k - 1], kept[k], r})}; + if (false == result.empty() && run_of.back() == r && alike(result.back(), next)) + { + merge(result.back(), next); + continue; + } + result.push_back(next); + run_of.push_back(r); + } + } + for (std::size_t i = 1; i < result.size(); ++i) + if (run_of[i] == run_of[i - 1]) + join(result[i - 1], result[i]); + // the length of an element cut by the end of the line or by a switch isn't its own + if (false == result.empty()) + { + result.front().open_start = true; + result.back().open_end = true; + } + for (std::size_t i = 1; i < result.size(); ++i) + if ((result[i].features & feature::switch_track) != (result[i - 1].features & feature::switch_track)) + { + result[i - 1].open_end = true; + result[i].open_start = true; + } + return result; +} + +std::vector cant(std::vector const &Samples) +{ + std::vector result; + for (auto const &run : runs(Samples, &cant_of, kJumpCant, false)) + for (auto const index : simplified(Samples, run, &cant_of, kCantTolerance)) + result.push_back({Samples[index].chainage, Samples[index].cant}); + return result; +} + +std::vector grades(std::vector const &Samples) +{ + std::vector result; + for (auto const &run : runs(Samples, &grade_of, kJumpGrade, false)) + { + auto const kept{simplified(Samples, run, &grade_of, kGradeTolerance)}; + for (std::size_t k = 1; k < kept.size(); ++k) + { + auto const &a{Samples[kept[k - 1]]}; + auto const &b{Samples[kept[k]]}; + if (b.chainage - a.chainage <= kSame) + continue; + grade_element next{a.chainage, b.chainage - a.chainage, a.grade, b.grade}; + if (std::abs(b.grade - a.grade) <= kGradeTolerance) + { + auto const held{mean(Samples, kept[k - 1], kept[k], &grade_of)}; + next.grade_start = held; + next.grade_end = held; + } + // a held grade going on in the same run as the one before it + if (auto const continued{false == result.empty() && k > 1 && result.back().grade_start == result.back().grade_end && next.grade_start == next.grade_end && + std::abs(result.back().grade_end - next.grade_start) <= kGradeTolerance}; + continued) + { + auto &last{result.back()}; + auto const total{last.length + next.length}; + auto const held{(last.grade_start * last.length + next.grade_start * next.length) / total}; + last.length = total; + last.grade_start = held; + last.grade_end = held; + continue; + } + result.push_back(next); + } + } + // within a run the grade goes on from one piece to the next: a held grade sets the end of a curve next to it + for (std::size_t i = 1; i < result.size(); ++i) + { + auto &before{result[i - 1]}; + auto &after{result[i]}; + auto const before_held{before.grade_start == before.grade_end}; + auto const after_held{after.grade_start == after.grade_end}; + if (std::abs(after.start - before.start - before.length) > kSame || std::abs(after.grade_start - before.grade_end) > kJumpGrade || (before_held && after_held)) + continue; + if (after_held) + before.grade_end = after.grade_start; + else if (before_held) + after.grade_start = before.grade_end; + else + { + auto const middle{(before.grade_end + after.grade_start) * 0.5}; + before.grade_end = middle; + after.grade_start = middle; + } + } + return result; +} + +} // namespace + +line describe(std::vector const &Samples, std::string Name) +{ + line result; + result.name = std::move(Name); + if (Samples.size() < 2) + return result; + result.precision = kPrecision; + result.elements = plan(Samples); + result.cant = cant(Samples); + result.grades = grades(Samples); + return result; +} + +} // namespace norms diff --git a/editor/norms/normsTables.cpp b/editor/norms/normsTables.cpp new file mode 100644 index 000000000..362883484 --- /dev/null +++ b/editor/norms/normsTables.cpp @@ -0,0 +1,342 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#include "stdafx.h" +#include "editor/norms/normsTables.hpp" + +#include +#include + +// The tables of the profiles. Each row names the table or the paragraph of its document. The sources, as read for this module: +// +// PLK: Standardy Techniczne ... ST-T1-A6 "Układy geometryczne torów", v1.0, PKP PLK 2017 (uchwała 1086/2017), chapters 8 - 10. The +// cells spanning two or three columns of the tables (9.1, 9.6, 9.7, 9.13 - 9.15, 10.1, 10.2) were read on the pages of the PDF +// (editor-tracks-domain.md §6.5 pkt 4). Two rows stand out of line with the rows around them as printed and are kept unconfirmed: +// tab. 9.8, 5 < q <= 10, P0 95 mm (above the P0 of q <= 5), and tab. 9.7, movable frog 230 < V <= 250, P2 110 mm (above its P1). +// Table 9.4 (the straight between reverse curves without transitions) is a picture with no text and isn't here. +// TSI: Commission Regulation (EU) No 1299/2014 (TSI INF), consolidated text of 28.9.2023 (amendments 2019/776 and 2023/1694), 4.2.3 +// and 4.2.4. The cant deficiency of 153 mm spans both columns up to 300 km/h in table 8 (§6.5 pkt 3: not 100 mm above 160 km/h). +// EN 13803: EN 13803-1:2010, 5.2.1 - 5.2.5 (the part of the standard published as its preview: radius, cant, cant deficiency, cant +// excess, cant gradient). Its rate of change of the cant and of the cant deficiency, its element lengths and its vertical curves +// aren't in that part and aren't here. The plain line values of the abrupt change of the cant deficiency are EN 13803-2:2006+A1:2009 +// 7.1.3, read from a preview whose table is garbled, so unconfirmed. +// CH: AB-EBV (Ausführungsbestimmungen zur Eisenbahnverordnung, SR 742.141.11) as of 1.7.2024, AB 17 "Trassierungselemente", +// Normalspur, VR <= 250 km/h. It has no limit of the grade of a line, nor of the cant below which none is given. +// DB (Ril 800.0110) isn't here: it isn't published, and its values are known only from secondary sources. +namespace norms::tables +{ + +double value(formula const &Formula, double const Speed, double const Radius) +{ + return std::max(Formula.floor, Formula.constant + Formula.per_speed * Speed + Formula.per_speed2 * Speed * Speed + Formula.per_radius * Radius); +} + +bool applies(row const &Row, query const &Where) +{ + auto const track{Where.track == track_kind::main ? main_track : side_track}; + auto traffic_bit{mixed}; + if (Where.kind == traffic::passenger) + traffic_bit = passenger; + else if (Where.kind == traffic::freight) + traffic_bit = freight; + return (Where.features & Row.needs) == Row.needs && (Where.features & Row.excludes) == 0 && (Row.tracks & track) != 0 && (Row.traffics & traffic_bit) != 0 && Where.speed > Row.speed_above && + Where.speed <= Row.speed_to && Where.radius > Row.radius_above && Where.radius <= Row.radius_to && Where.load > Row.load_above && Where.load <= Row.load_to; +} + +namespace +{ + +using namespace norms::feature; + +constexpr cell at(double const Value) +{ + cell result; + result.limit.constant = Value; + result.present = true; + return result; +} + +constexpr cell linear(double const Constant, double const PerSpeed) +{ + auto result{at(Constant)}; + result.limit.per_speed = PerSpeed; + return result; +} + +// PerSpeed V, not below Floor +constexpr cell share(double const PerSpeed, double const Floor = -1e300) +{ + auto result{at(0.0)}; + result.limit.per_speed = PerSpeed; + result.limit.floor = Floor; + return result; +} + +// PerSpeed2 V^2, not below Floor +constexpr cell square(double const PerSpeed2, double const Floor) +{ + auto result{at(0.0)}; + result.limit.per_speed2 = PerSpeed2; + result.limit.floor = Floor; + return result; +} + +// the length run in the time at the speed +constexpr cell travel(double const Seconds) +{ + return share(Seconds / 3.6); +} + +// (R - 50) / 1.5: the cant of the small radii, for the stiff freight wagons +constexpr cell small_radius() +{ + auto result{at(-50.0 / 1.5)}; + result.limit.per_radius = 1.0 / 1.5; + return result; +} + +constexpr cell unconfirmed(cell Cell) +{ + Cell.confirmed = false; + return Cell; +} + +constexpr cell none{}; + +using enum parameter; + +// clang-format off +constexpr std::array plk{ + // tab. 9.7, the cant deficiency; footnote 2 of P2: 150 mm for selected passenger vehicles only + row{.what = cant_deficiency, .prefer = at(110), .warn = at(130), .block = at(150), .place = "tab. 9.7", .excludes = switch_track | expansion, .tracks = main_track}, + row{.what = cant_deficiency, .prefer = at(80), .warn = at(100), .block = at(100), .place = "tab. 9.7", .excludes = switch_track | expansion, .tracks = side_track}, + row{.what = cant_deficiency, .prefer = at(80), .warn = at(100), .block = at(100), .place = "tab. 9.7", .excludes = switch_track | expansion, .radius_above = 200, .radius_to = 250}, + row{.what = cant_deficiency, .prefer = at(50), .warn = at(70), .block = at(70), .place = "tab. 9.7", .excludes = switch_track | expansion, .radius_above = 0, .radius_to = 200}, + row{.what = cant_deficiency, .prefer = at(90), .warn = at(110), .block = at(110), .place = "tab. 9.7", .needs = switch_track, .excludes = movable_frog | crossing, .speed_to = 160}, + row{.what = cant_deficiency, .prefer = at(60), .warn = at(90), .block = at(90), .place = "tab. 9.7", .needs = switch_track, .excludes = movable_frog | crossing, .speed_above = 160, .speed_to = 200}, + row{.what = cant_deficiency, .prefer = at(100), .warn = at(130), .block = at(130), .place = "tab. 9.7", .needs = switch_track | movable_frog, .excludes = crossing, .speed_to = 230}, + row{.what = cant_deficiency, .prefer = at(80), .warn = at(80), .block = unconfirmed(at(110)), .place = "tab. 9.7", .needs = switch_track | movable_frog, .excludes = crossing, .speed_above = 230, .speed_to = 250}, + row{.what = cant_deficiency, .prefer = at(0), .warn = at(0), .block = at(80), .place = "tab. 9.7", .needs = crossing, .speed_to = 120}, + row{.what = cant_deficiency, .prefer = at(80), .warn = at(100), .block = at(100), .place = "tab. 9.7", .needs = expansion, .speed_to = 160}, + row{.what = cant_deficiency, .prefer = at(0), .warn = at(80), .block = at(80), .place = "tab. 9.7", .needs = expansion, .speed_above = 160, .speed_to = 200}, + row{.what = cant_deficiency, .prefer = at(0), .warn = at(60), .block = at(60), .place = "tab. 9.7", .needs = expansion, .speed_above = 200, .speed_to = 250}, + // tab. 9.8, the cant excess by the load of the track; in switches, crossings and expansion devices also their row of tab. 9.7 (9.5 pkt 4) + row{.what = cant_excess, .prefer = at(90), .warn = at(110), .block = at(110), .place = "tab. 9.8", .load_to = 5}, + row{.what = cant_excess, .prefer = unconfirmed(at(95)), .warn = at(95), .block = at(110), .place = "tab. 9.8", .load_above = 5, .load_to = 10}, + row{.what = cant_excess, .prefer = at(80), .warn = at(95), .block = at(110), .place = "tab. 9.8", .load_above = 10, .load_to = 15}, + row{.what = cant_excess, .prefer = at(65), .warn = at(80), .block = at(110), .place = "tab. 9.8", .load_above = 15, .load_to = 20}, + row{.what = cant_excess, .prefer = at(50), .warn = at(80), .block = at(110), .place = "tab. 9.8", .load_above = 20}, + row{.what = cant_excess, .prefer = at(90), .warn = at(110), .block = at(110), .place = "9.5 pkt 4, tab. 9.7", .needs = switch_track, .excludes = movable_frog | crossing, .speed_to = 160}, + row{.what = cant_excess, .prefer = at(60), .warn = at(90), .block = at(90), .place = "9.5 pkt 4, tab. 9.7", .needs = switch_track, .excludes = movable_frog | crossing, .speed_above = 160, .speed_to = 200}, + row{.what = cant_excess, .prefer = at(100), .warn = at(130), .block = at(130), .place = "9.5 pkt 4, tab. 9.7", .needs = switch_track | movable_frog, .excludes = crossing, .speed_to = 230}, + row{.what = cant_excess, .prefer = at(80), .warn = at(80), .block = unconfirmed(at(110)), .place = "9.5 pkt 4, tab. 9.7", .needs = switch_track | movable_frog, .excludes = crossing, .speed_above = 230, .speed_to = 250}, + row{.what = cant_excess, .prefer = at(0), .warn = at(0), .block = at(80), .place = "9.5 pkt 4, tab. 9.7", .needs = crossing, .speed_to = 120}, + row{.what = cant_excess, .prefer = at(80), .warn = at(100), .block = at(100), .place = "9.5 pkt 4, tab. 9.7", .needs = expansion, .speed_to = 160}, + row{.what = cant_excess, .prefer = at(0), .warn = at(80), .block = at(80), .place = "9.5 pkt 4, tab. 9.7", .needs = expansion, .speed_above = 160, .speed_to = 200}, + row{.what = cant_excess, .prefer = at(0), .warn = at(60), .block = at(60), .place = "9.5 pkt 4, tab. 9.7", .needs = expansion, .speed_above = 200, .speed_to = 250}, + // tab. 9.15, the abrupt change of the cant deficiency: connections of tracks, running lines and main tracks, sidings + row{.what = deficiency_jump, .prefer = at(130), .warn = at(130), .block = at(130), .place = "tab. 9.15", .needs = switch_track, .speed_to = 60}, + row{.what = deficiency_jump, .prefer = at(100), .warn = at(100), .block = at(125), .place = "tab. 9.15", .needs = switch_track, .speed_above = 60, .speed_to = 100}, + row{.what = deficiency_jump, .prefer = at(80), .warn = at(80), .block = linear(160, -0.35), .place = "tab. 9.15", .needs = switch_track, .speed_above = 100, .speed_to = 160}, + row{.what = deficiency_jump, .prefer = at(60), .warn = at(60), .block = linear(160, -0.35), .place = "tab. 9.15", .needs = switch_track, .speed_above = 160, .speed_to = 200}, + row{.what = deficiency_jump, .prefer = at(50), .warn = at(50), .block = at(60), .place = "tab. 9.15", .excludes = switch_track, .tracks = main_track, .speed_to = 70}, + row{.what = deficiency_jump, .prefer = at(0), .warn = linear(64, -0.2), .block = at(50), .place = "tab. 9.15", .excludes = switch_track, .tracks = main_track, .speed_above = 70, .speed_to = 160}, + row{.what = deficiency_jump, .prefer = at(0), .warn = at(30), .block = at(50), .place = "tab. 9.15", .excludes = switch_track, .tracks = main_track, .speed_above = 160, .speed_to = 200}, + row{.what = deficiency_jump, .prefer = at(0), .warn = at(25), .block = at(25), .place = "tab. 9.15", .excludes = switch_track, .tracks = main_track, .speed_above = 200, .speed_to = 250}, + row{.what = deficiency_jump, .prefer = at(50), .warn = at(100), .block = at(100), .place = "tab. 9.15", .excludes = switch_track, .tracks = side_track, .speed_to = 40}, + // tab. 9.12 the gradient of a cant ramp (twist 8 / 10 / 12.5 mm on a base of 5 m), tab. 9.13 the rate of change of the cant and tab. 9.14 + // that of the cant deficiency, straight ramps + row{.what = cant_gradient, .prefer = at(1.6), .warn = at(2.0), .block = at(2.5), .place = "tab. 9.12", .speed_to = 250}, + row{.what = cant_rate, .prefer = at(35), .warn = at(50), .block = at(60), .place = "tab. 9.13"}, + row{.what = deficiency_rate, .prefer = at(55), .warn = at(70), .block = at(80), .place = "tab. 9.14", .speed_to = 200}, + row{.what = deficiency_rate, .prefer = at(55), .warn = at(55), .block = at(70), .place = "tab. 9.14", .speed_above = 200, .speed_to = 250}, + // tab. 9.1, the shortest straights and arcs of the running lines and main tracks, outside the connections of tracks + row{.what = element_length, .prefer = share(0.35, 30), .warn = share(0.35, 30), .block = share(0.25, 20), .place = "tab. 9.1", .excludes = switch_track, .tracks = main_track, .speed_to = 120}, + row{.what = element_length, .prefer = share(0.40), .warn = share(0.40), .block = share(0.30), .place = "tab. 9.1", .excludes = switch_track, .tracks = main_track, .speed_above = 120, .speed_to = 200}, + row{.what = element_length, .prefer = share(0.65), .warn = share(0.65), .block = share(0.55), .place = "tab. 9.1", .excludes = switch_track, .tracks = main_track, .speed_above = 200, .speed_to = 250}, + // tab. 9.10, the transition curves: at least 30 m and moving the arc in by 0.02 m (9.14) at P0 and P1, only the kinematic terms + // at P2, checked as the cant gradient and the rates of change + row{.what = transition_length, .prefer = at(30), .warn = at(30), .block = none, .place = "tab. 9.10", .excludes = switch_track}, + row{.what = transition_shift, .prefer = at(0.02), .warn = at(0.02), .block = none, .place = "9.7 pkt 10, tab. 9.10", .excludes = switch_track}, + // tab. 9.2, the least radii + row{.what = radius, .prefer = at(600), .warn = at(300), .block = at(180), .place = "tab. 9.2", .excludes = switch_track, .tracks = main_track}, + row{.what = radius, .prefer = at(500), .warn = at(500), .block = at(300), .place = "tab. 9.2", .needs = platform, .excludes = switch_track}, + row{.what = radius, .prefer = at(450), .warn = at(180), .block = at(180), .place = "tab. 9.2", .excludes = switch_track, .tracks = side_track}, + // tab. 9.6, the cant; below R 300 m also (R - 50) / 1.5 (9.8) + row{.what = cant, .prefer = at(150), .warn = at(150), .block = at(150), .place = "tab. 9.6", .excludes = switch_track | ballastless, .tracks = main_track}, + row{.what = cant, .prefer = at(150), .warn = at(150), .block = at(160), .place = "tab. 9.6", .needs = ballastless, .excludes = switch_track, .tracks = main_track}, + row{.what = cant, .prefer = at(60), .warn = at(100), .block = at(110), .place = "tab. 9.6", .needs = platform}, + row{.what = cant, .prefer = at(0), .warn = at(60), .block = at(100), .place = "tab. 9.6", .excludes = switch_track, .tracks = side_track}, + row{.what = cant, .prefer = at(0), .warn = at(100), .block = at(150), .place = "tab. 9.6", .excludes = switch_track, .radius_above = 200, .radius_to = 300}, + row{.what = cant, .prefer = at(0), .warn = at(60), .block = at(100), .place = "tab. 9.6", .excludes = switch_track, .radius_above = 0, .radius_to = 200}, + row{.what = cant, .prefer = none, .warn = none, .block = small_radius(), .place = "9.8", .excludes = switch_track, .radius_above = 0, .radius_to = 299.999}, + row{.what = cant, .prefer = at(0), .warn = at(100), .block = at(110), .place = "tab. 9.6", .needs = switch_track, .excludes = curved_switch | crossing}, + row{.what = cant, .prefer = at(60), .warn = at(100), .block = at(110), .place = "tab. 9.6", .needs = switch_track | curved_switch, .excludes = crossing}, + row{.what = cant, .prefer = at(0), .warn = at(0), .block = at(0), .place = "tab. 9.6", .needs = crossing}, + row{.what = cant_min, .prefer = at(20), .warn = at(20), .block = at(20), .place = "tab. 9.6"}, + // tab. 10.2, the least radii of the vertical curves + row{.what = vertical_radius, .prefer = square(0.77, 5000), .warn = square(0.35, 5000), .block = square(0.25, 2000), .place = "tab. 10.2", .excludes = switch_track | suburban}, + row{.what = vertical_radius, .prefer = square(0.77, 5000), .warn = square(0.77, 5000), .block = square(0.25, 2000), .place = "tab. 10.2", .needs = suburban, .excludes = switch_track}, + row{.what = vertical_radius, .prefer = square(0.35, 5000), .warn = square(0.35, 5000), .block = square(0.25, 3000), .place = "tab. 10.2", .needs = switch_track | crest}, + row{.what = vertical_radius, .prefer = square(0.35, 3000), .warn = square(0.35, 3000), .block = square(0.25, 2000), .place = "tab. 10.2", .needs = switch_track | sag}, + // tab. 10.1, the steepest grades: running lines and main tracks of the lines of type P, of types M and T (in brackets, footnote 2: + // on stretches shorter than 500 m), the useful length of station tracks, tracks at platforms + row{.what = grade, .prefer = at(6.0), .warn = at(17.5), .block = at(35.0), .place = "tab. 10.1", .excludes = station, .tracks = main_track, .traffics = passenger}, + row{.what = grade, .prefer = at(6.0), .warn = at(10.0), .block = at(20.0), .place = "tab. 10.1", .excludes = station | short_stretch, .tracks = main_track, .traffics = mixed | freight}, + row{.what = grade, .prefer = at(6.0), .warn = at(17.5), .block = at(35.0), .place = "tab. 10.1", .needs = short_stretch, .excludes = station, .tracks = main_track, .traffics = mixed | freight}, + row{.what = grade, .prefer = at(2.0), .warn = at(2.0), .block = at(2.5), .place = "tab. 10.1", .needs = station}, + row{.what = grade, .prefer = at(2.5), .warn = at(6.0), .block = at(10.0), .place = "tab. 10.1", .needs = platform}, + // tab. 9.16, the shortest element between abrupt changes of the cant deficiency for them to be taken one by one: on the lines tab. 9.1 + // at P2 (for a transition between them tab. 9.10 at P2 would do, the one of 9.1 stands in for it) + row{.what = intermediate_length, .prefer = none, .warn = none, .block = share(0.25, 20), .place = "tab. 9.16", .excludes = switch_track, .tracks = main_track, .speed_to = 120}, + row{.what = intermediate_length, .prefer = none, .warn = none, .block = share(0.30), .place = "tab. 9.16", .excludes = switch_track, .tracks = main_track, .speed_above = 120, .speed_to = 200}, + row{.what = intermediate_length, .prefer = none, .warn = none, .block = share(0.55), .place = "tab. 9.16", .excludes = switch_track, .tracks = main_track, .speed_above = 200, .speed_to = 250}, + row{.what = intermediate_length, .prefer = none, .warn = none, .block = at(6.0), .place = "tab. 9.16", .needs = switch_track, .speed_to = 60}, + row{.what = intermediate_length, .prefer = none, .warn = none, .block = share(0.15), .place = "tab. 9.16", .needs = switch_track, .speed_above = 60, .speed_to = 100}, + row{.what = intermediate_length, .prefer = none, .warn = none, .block = share(0.25), .place = "tab. 9.16", .needs = switch_track, .speed_above = 100, .speed_to = 200}, + row{.what = intermediate_length, .prefer = none, .warn = none, .block = share(0.10), .place = "tab. 9.16", .excludes = switch_track, .tracks = side_track, .speed_to = 40}, +}; + +// the TSI rows the profile "TSI only" and the global hard limits share +constexpr std::array tsi_rows{ + row{.what = cant_deficiency, .block = at(153), .place = "4.2.4.3, tab. 8", .excludes = tilting, .speed_to = 300}, + row{.what = cant_deficiency, .block = at(100), .place = "4.2.4.3, tab. 8", .excludes = tilting, .speed_above = 300}, + row{.what = cant_deficiency, .block = at(130), .place = "4.2.4.3, tab. 8", .traffics = freight, .speed_to = 160}, + row{.what = cant, .block = at(160), .place = "4.2.4.2, tab. 7", .excludes = ballastless, .traffics = mixed | freight}, + row{.what = cant, .block = at(180), .place = "4.2.4.2, tab. 7", .excludes = ballastless, .traffics = passenger}, + row{.what = cant, .block = at(170), .place = "4.2.4.2, tab. 7", .needs = ballastless, .traffics = mixed | freight}, + row{.what = cant, .block = at(180), .place = "4.2.4.2, tab. 7", .needs = ballastless, .traffics = passenger}, + row{.what = cant, .block = at(110), .place = "4.2.4.2(2)", .needs = platform}, + row{.what = cant, .block = small_radius(), .place = "4.2.4.2(3)", .traffics = mixed | freight, .radius_above = 0, .radius_to = 304.999}, + row{.what = deficiency_jump, .block = at(130), .place = "4.2.4.4(1)", .excludes = low_deficiency, .speed_to = 40}, + row{.what = deficiency_jump, .block = at(150), .place = "4.2.4.4(2)", .needs = low_deficiency, .speed_to = 40}, + row{.what = deficiency_jump, .block = at(130), .place = "4.2.4.4(1)", .speed_above = 40, .speed_to = 60}, + row{.what = deficiency_jump, .block = at(125), .place = "4.2.4.4(1)", .speed_above = 60, .speed_to = 200}, + row{.what = deficiency_jump, .block = at(85), .place = "4.2.4.4(1)", .speed_above = 200, .speed_to = 230}, + row{.what = deficiency_jump, .block = at(25), .place = "4.2.4.4(1)", .speed_above = 230}, + row{.what = radius, .block = at(150), .place = "4.2.3.4(1)"}, + row{.what = vertical_radius, .block = at(500), .place = "4.2.3.5(1)", .needs = crest}, + row{.what = vertical_radius, .block = at(900), .place = "4.2.3.5(1)", .needs = sag}, +}; + +template +constexpr std::array joined(std::array const &A, std::array const &B) +{ + std::array result{}; + std::ranges::copy(A, result.begin()); + std::ranges::copy(B, result.begin() + First); + return result; +} + +// 4.2.3.3: up to 35 per mille on the main tracks of new P1 lines for passengers alone, within the envelope of (3) a and b; 2.5 per +// mille through the platforms where vehicles are attached or detached +constexpr auto tsi{joined(tsi_rows, std::array{ + row{.what = grade, .block = at(35.0), .place = "4.2.3.3(3)", .tracks = main_track, .traffics = passenger}, + row{.what = grade, .block = at(2.5), .place = "4.2.3.3(1)", .needs = station}, +})}; + +// in every profile (editor-tracks-domain.md 6.3) the TSI, and the cant gradient of 2.5 mm/m, the exceptional limit of EN 13803-1, +// set for the twist of the track; the TSI rows of (R - 50) / 1.5 leave out the condition of a ramp steeper than 1 mm/m +constexpr auto hard{joined(tsi_rows, std::array{ + row{.what = cant_gradient, .block = at(2.5), .place = "5.2.5", .document = "EN 13803-1"}, +})}; + +constexpr std::array en{ + row{.what = radius, .warn = at(190), .block = at(150), .place = "5.2.1"}, + row{.what = radius, .prefer = at(500), .place = "5.2.1 NOTE 1", .needs = platform}, + row{.what = cant, .warn = at(160), .block = at(180), .place = "5.2.2"}, + row{.what = cant, .prefer = at(110), .place = "5.2.2 NOTE", .needs = platform}, + row{.what = cant, .warn = small_radius(), .place = "5.2.2", .radius_above = 0, .radius_to = 319.999}, + row{.what = cant_deficiency, .warn = at(130), .block = at(183), .place = "5.2.3, tab. 1", .excludes = tilting, .speed_above = 80, .speed_to = 200}, + row{.what = cant_deficiency, .warn = at(130), .block = at(168), .place = "5.2.3, tab. 1", .excludes = tilting, .speed_above = 200, .speed_to = 230}, + row{.what = cant_deficiency, .warn = at(130), .block = at(153), .place = "5.2.3, tab. 1", .excludes = tilting, .speed_above = 230, .speed_to = 250}, + row{.what = cant_deficiency, .warn = at(100), .block = at(130), .place = "5.2.3, tab. 1", .excludes = tilting, .speed_above = 250, .speed_to = 300}, + row{.what = cant_deficiency, .warn = at(275), .block = at(306), .place = "5.2.3, tab. 1", .needs = tilting, .speed_above = 79.999, .speed_to = 260}, + row{.what = cant_excess, .warn = at(110), .place = "5.2.4"}, + row{.what = cant_gradient, .warn = at(2.25), .block = at(2.5), .place = "5.2.5"}, + row{.what = deficiency_jump, .warn = unconfirmed(at(50)), .place = "7.1.3", .excludes = switch_track, .speed_to = 70, .document = "EN 13803-2"}, + row{.what = deficiency_jump, .warn = unconfirmed(at(40)), .place = "7.1.3", .excludes = switch_track, .speed_above = 70, .speed_to = 170, .document = "EN 13803-2"}, + row{.what = deficiency_jump, .warn = unconfirmed(at(30)), .place = "7.1.3", .excludes = switch_track, .speed_above = 170, .speed_to = 230, .document = "EN 13803-2"}, +}; + +constexpr std::array ch{ + // 3.2, the shortest straight and arc, 1 s (0.7 s) of the travel; 3.3 the least radius, R >= 500 m to be aimed for at platforms; 5.2.2 + // 185 m for an arc without a transition in the tracks of the trains + row{.what = element_length, .warn = travel(1.0), .block = travel(0.7), .place = "AB 17 3.2", .excludes = switch_track, .tracks = main_track}, + row{.what = radius, .warn = at(150), .place = "AB 17 3.3.1"}, + row{.what = radius, .prefer = at(500), .place = "AB 17 3.3.2", .needs = platform}, + row{.what = radius, .warn = at(185), .place = "AB 17 5.2.2", .needs = abrupt, .excludes = switch_track, .tracks = main_track}, + // 3.4 the cant, 100 mm to be aimed for at platforms; 6.3.1.1 in curved switches + row{.what = cant, .warn = at(160), .block = at(180), .place = "AB 17 3.4.1"}, + row{.what = cant, .warn = small_radius(), .place = "AB 17 3.4.2.1", .radius_above = 0}, + row{.what = cant, .prefer = at(100), .place = "AB 17 3.4.2.2", .needs = platform}, + row{.what = cant, .warn = at(120), .block = at(150), .place = "AB 17 6.3.1.1", .needs = switch_track | curved_switch}, + // 3.6.2.1 the cant deficiency by the radius, 200 < VR <= 250 by footnote 2; 6.3.3.1 the main track of the switches, 6.2.1 their + // diverging track, between 100 and 200 km/h evenly between the values; 8.3.2 the tilting trains + row{.what = cant_deficiency, .warn = at(122), .block = at(130), .place = "AB 17 3.6.2.1", .excludes = switch_track | tilting, .speed_to = 200, .radius_above = 0, .radius_to = 349.999}, + row{.what = cant_deficiency, .warn = at(130), .block = at(150), .place = "AB 17 3.6.2.1", .excludes = switch_track | tilting, .speed_to = 200, .radius_above = 349.999, .radius_to = 649.999}, + row{.what = cant_deficiency, .warn = at(150), .block = at(150), .place = "AB 17 3.6.2.1", .excludes = switch_track | tilting, .speed_to = 200, .radius_above = 649.999}, + row{.what = cant_deficiency, .warn = at(130), .block = at(150), .place = "AB 17 3.6.2.1", .excludes = switch_track | tilting, .speed_above = 200, .speed_to = 250}, + row{.what = cant_deficiency, .warn = at(110), .block = at(130), .place = "AB 17 6.3.3.1", .needs = switch_track, .excludes = diverging | movable_frog, .speed_to = 140}, + row{.what = cant_deficiency, .warn = at(100), .block = at(130), .place = "AB 17 6.3.3.1", .needs = switch_track, .excludes = diverging | movable_frog, .speed_above = 140, .speed_to = 160}, + row{.what = cant_deficiency, .warn = at(80), .block = at(130), .place = "AB 17 6.3.3.1", .needs = switch_track, .excludes = diverging | movable_frog, .speed_above = 160, .speed_to = 250}, + row{.what = cant_deficiency, .warn = at(130), .block = at(130), .place = "AB 17 6.3.3.1", .needs = switch_track | movable_frog, .excludes = diverging}, + row{.what = cant_deficiency, .warn = at(100), .block = at(120), .place = "AB 17 6.2.1", .needs = switch_track | diverging, .speed_to = 100}, + row{.what = cant_deficiency, .warn = linear(130, -0.3), .block = linear(155, -0.35), .place = "AB 17 6.2.1", .needs = switch_track | diverging, .speed_above = 100, .speed_to = 200}, + row{.what = cant_deficiency, .block = at(275), .place = "AB 17 8.3.2", .needs = tilting, .radius_above = 249.999}, + row{.what = cant_excess, .warn = at(110), .block = at(130), .place = "AB 17 3.7.1"}, + // 4.2.1 the twist of the ramps, of the tracks of the trains and of the shunting tracks; 4.3 the rates of change + row{.what = cant_gradient, .warn = at(2.0), .block = at(2.5), .place = "AB 17 4.2.1", .tracks = main_track}, + row{.what = cant_gradient, .warn = at(3.0), .place = "AB 17 4.2.1", .tracks = side_track}, + row{.what = cant_rate, .warn = at(50), .block = at(60), .place = "AB 17 4.3.2"}, + row{.what = deficiency_rate, .warn = at(55), .block = at(90), .place = "AB 17 4.3.1", .speed_to = 200}, + row{.what = deficiency_rate, .warn = at(55), .block = at(75), .place = "AB 17 4.3.1", .speed_above = 200}, + // 5.3 the abrupt change of the cant deficiency: an arc without a transition in the tracks of the trains (between 80 and 160 km/h evenly + // from 50 to 25 mm), switches and connections, shunting tracks and sidings + row{.what = deficiency_jump, .warn = at(50), .place = "AB 17 5.3.1", .excludes = switch_track, .tracks = main_track, .speed_to = 80}, + row{.what = deficiency_jump, .warn = linear(75, -0.3125), .place = "AB 17 5.3.1", .excludes = switch_track, .tracks = main_track, .speed_above = 80, .speed_to = 160}, + row{.what = deficiency_jump, .warn = at(0), .place = "AB 17 5.3.1", .excludes = switch_track, .tracks = main_track, .speed_above = 160}, + row{.what = deficiency_jump, .warn = at(102), .block = at(120), .place = "AB 17 5.3.2", .needs = switch_track, .tracks = main_track}, + row{.what = deficiency_jump, .warn = at(120), .block = at(120), .place = "AB 17 5.3.2", .tracks = side_track}, + // 5.4.1 the calming element between abrupt changes of the curvature, case a + row{.what = intermediate_length, .block = travel(0.7), .place = "AB 17 5.4.1.1", .tracks = main_track, .speed_to = 65}, + row{.what = intermediate_length, .block = travel(1.0), .place = "AB 17 5.4.1.1", .tracks = main_track, .speed_above = 65}, + row{.what = intermediate_length, .block = travel(0.7), .place = "AB 17 5.4.1.4", .tracks = side_track}, + // 7.2 - 7.4 the vertical curves: in the tracks of the trains, in their switches, in shunting tracks + row{.what = vertical_radius, .warn = square(0.35, 3000), .block = square(0.25, 500), .place = "AB 17 7.2", .needs = crest, .excludes = switch_track, .tracks = main_track}, + row{.what = vertical_radius, .warn = square(0.35, 2000), .block = square(0.175, 900), .place = "AB 17 7.2", .needs = sag, .excludes = switch_track, .tracks = main_track}, + row{.what = vertical_radius, .warn = square(0.35, 5000), .block = square(0.25, 500), .place = "AB 17 7.3", .needs = switch_track | crest, .tracks = main_track}, + row{.what = vertical_radius, .warn = square(0.35, 3000), .block = square(0.175, 900), .place = "AB 17 7.3", .needs = switch_track | sag, .tracks = main_track}, + row{.what = vertical_radius, .warn = at(1000), .block = at(500), .place = "AB 17 7.4", .needs = crest, .excludes = switch_track, .tracks = side_track}, + row{.what = vertical_radius, .warn = at(1000), .block = at(900), .place = "AB 17 7.4", .needs = sag, .excludes = switch_track, .tracks = side_track}, + row{.what = vertical_radius, .warn = at(2000), .block = at(500), .place = "AB 17 7.4", .needs = switch_track | crest, .tracks = side_track}, + row{.what = vertical_radius, .warn = at(2000), .block = at(900), .place = "AB 17 7.4", .needs = switch_track | sag, .tracks = side_track}, +}; +// clang-format on + +} // namespace + +std::span rows(profile_id const Profile) +{ + switch (Profile) + { + case profile_id::plk: return plk; + case profile_id::tsi: return tsi; + case profile_id::en13803: return en; + case profile_id::ch: return ch; + default: return {}; + } +} + +std::span hard_rows() +{ + return hard; +} + +} // namespace norms::tables diff --git a/editor/norms/normsTables.hpp b/editor/norms/normsTables.hpp new file mode 100644 index 000000000..6dded536a --- /dev/null +++ b/editor/norms/normsTables.hpp @@ -0,0 +1,78 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +#include "editor/norms/norms.hpp" + +#include +#include + +// the rows of the tables of the profiles (normsTables.cpp): a row holds the limits of the three tiers of one parameter where its +// conditions hold, with the place in the document they come from. Where several rows hold at once, the strictest limit of each tier +// is the one (a track at a platform keeps the stricter of the platform row and the main track row) +namespace norms::tables +{ + +// a limit: constant + per_speed V + per_speed2 V^2 + per_radius R, not below floor +struct formula +{ + double constant{0.0}; + double per_speed{0.0}; + double per_speed2{0.0}; + double per_radius{0.0}; + double floor{-1e300}; +}; +double value(formula const &Formula, double const Speed, double const Radius); + +struct cell +{ + formula limit; + bool present{false}; + bool confirmed{true}; +}; + +inline constexpr unsigned main_track{1u}; +inline constexpr unsigned side_track{2u}; +inline constexpr unsigned any_track{main_track | side_track}; +inline constexpr unsigned passenger{1u}; +inline constexpr unsigned mixed{2u}; +inline constexpr unsigned freight{4u}; +inline constexpr unsigned any_traffic{passenger | mixed | freight}; +inline constexpr double unbounded{1e9}; + +// the row holds where the query has all the features it needs and none it excludes, for the tracks and the traffic it names, and +// above each lower bound up to each upper one: speed_above < V <= speed_to and so on. A row of radii (radius_above >= 0) holds on +// curves only, the radius of a straight being 0 +struct row +{ + parameter what{parameter::count}; + cell prefer; + cell warn; + cell block; + std::string_view place; + unsigned needs{0}; + unsigned excludes{0}; + unsigned tracks{any_track}; + unsigned traffics{any_traffic}; + double speed_above{-1.0}; + double speed_to{unbounded}; + double radius_above{-1.0}; + double radius_to{unbounded}; + double load_above{-1.0}; + double load_to{unbounded}; + std::string_view document{}; // the profile's own when empty +}; + +bool applies(row const &Row, query const &Where); +// the rows of the profile, and the global hard ones +std::span rows(profile_id const Profile); +std::span hard_rows(); + +} // namespace norms::tables diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 6ad07f00d..1a7c5c94e 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -50,6 +50,11 @@ add_executable(${UNIT_TESTS_NAME} track_stubs.cpp # and the cant the track editor matches at the joints of the tracks "${CMAKE_SOURCE_DIR}/editor/editorTrackShape.cpp" + # the norms of the track geometry, a module of its own (test_norms_*.cpp) + "${CMAKE_SOURCE_DIR}/editor/norms/normsTables.cpp" + "${CMAKE_SOURCE_DIR}/editor/norms/normsLimits.cpp" + "${CMAKE_SOURCE_DIR}/editor/norms/normsEngine.cpp" + "${CMAKE_SOURCE_DIR}/editor/norms/normsLine.cpp" ${UNIT_TEST_CASES}) # the core library brings the game's build settings along diff --git a/tests/unit/test_norms_engine.cpp b/tests/unit/test_norms_engine.cpp new file mode 100644 index 000000000..71100e481 --- /dev/null +++ b/tests/unit/test_norms_engine.cpp @@ -0,0 +1,401 @@ +// the engine of the norms (editor/norms): the formulas of the cant with the examples of ST-T1-A6, the tier of a value, and lines +// described as elements checked: the cant deficiency at the highest speed and the excess at the slow trains, the abrupt changes of the +// cant deficiency of curves turning alike and the other way, taken together over a short element, the rates of change along the ramps +// and the transitions; the profiles of the areas, the stricter one on a boundary; a line read from its samples as elements + +#include "stdafx.h" +#include "doctest.h" +#include "editor/norms/norms.hpp" + +#include +#include +#include +#include + +namespace { + +using norms::element_kind; +using norms::parameter; +using norms::profile_id; +using norms::tier; + +// a line of elements one after another along x, the curvature signed, positive to the left +class line_builder { +public: + line_builder &straight(double const Length, double const Speed) { return add(element_kind::straight, Length, 0.0, 0.0, Speed); } + line_builder &arc(double const Radius, double const Length, double const Speed) { return add(element_kind::arc, Length, 1.0 / Radius, 1.0 / Radius, Speed); } + line_builder &transition(double const From, double const To, double const Length, double const Speed) { + return add(element_kind::transition, Length, From != 0.0 ? 1.0 / From : 0.0, To != 0.0 ? 1.0 / To : 0.0, Speed); + } + // the cant, mm, from here on evenly to the given at the chainage + line_builder &cant(double const Chainage, double const Cant) { + m_line.cant.push_back({Chainage, Cant}); + return *this; + } + line_builder &features(unsigned const Features) { + m_line.elements.back().features = Features; + return *this; + } + norms::line done() { + if (m_line.grades.empty()) { + m_line.grades.push_back({0.0, m_end, 0.0, 0.0}); + } + m_line.elements.front().open_start = true; + m_line.elements.back().open_end = true; + return m_line; + } + double end() const { return m_end; } + +private: + norms::line m_line; + double m_end{0.0}; + + line_builder &add(element_kind const Kind, double const Length, double const From, double const To, double const Speed) { + norms::element element; + element.kind = Kind; + element.start = m_end; + element.length = Length; + element.curvature_start = From; + element.curvature_end = To; + element.speed = Speed; + element.from = {m_end, 0.0}; + element.to = {m_end + Length, 0.0}; + m_line.elements.push_back(element); + m_end += Length; + return *this; + } +}; + +norms::line_class mixed_main(double const Vmax = 100.0) { + norms::line_class result; + result.vmax = Vmax; + result.kind = norms::traffic::mixed; + result.track = norms::track_kind::main; + result.load = 5.0; + return result; +} + +std::vector evaluate(norms::line const &Line, norms::line_class const &Class, profile_id const Profile = profile_id::plk) { + norms::area_map areas; + areas.scenery = Profile; + return norms::evaluate(Line, Class, areas); +} + +std::vector of(std::vector const &Findings, parameter const What) { + std::vector result; + std::ranges::copy_if(Findings, std::back_inserter(result), [What](norms::finding const &Finding) { return Finding.what == What; }); + return result; +} + +} // namespace + +TEST_CASE("norms engine: the cant of ST-T1-A6 załącznik 1, Z1-1, P160 R 2000 m, I 90 mm fast and 20 mm slow") { + // the highest speed with I 90 mm at the fast trains and 20 mm at the slow ones of 120 km/h: 162 km/h + CHECK(norms::speed_for_deficiencies(2000.0, 90.0, 20.0, 120.0) == doctest::Approx(162.0).epsilon(0.005)); + CHECK(norms::least_cant(160.0, 2000.0, 90.0) == doctest::Approx(61.0).epsilon(0.005)); + CHECK(norms::least_cant(120.0, 2000.0, 20.0) == doctest::Approx(65.0).epsilon(0.005)); +} + +TEST_CASE("norms engine: the cant of ST-T1-A6 załącznik 1, Z1-2, M160 R 1200 m, Vmin 80 km/h") { + CHECK(norms::speed_for_deficiencies(1200.0, 90.0, 20.0, 80.0) == doctest::Approx(116.0).epsilon(0.005)); + // Dmin with Idop 130 mm, written 121 mm (121.7), Dmax with Edop 80 mm 143 mm, Deq 251 mm, Dreg 139 mm + CHECK(norms::least_cant(160.0, 1200.0, 130.0) == doctest::Approx(121.7).epsilon(0.001)); + CHECK(norms::greatest_cant(80.0, 1200.0, 80.0) == doctest::Approx(143.0).epsilon(0.002)); + CHECK(norms::equilibrium_cant(160.0, 1200.0) == doctest::Approx(251.7).epsilon(0.001)); + CHECK(norms::regular_cant(160.0, 1200.0) == doctest::Approx(139.0).epsilon(0.003)); +} + +TEST_CASE("norms engine: the regular cant of the compound curve of ST-T1-A6 załącznik 2, 105, 96 and 83 mm, 95 mm on average") { + auto const first{norms::regular_cant(160.0, 1590.0)}; + auto const second{norms::regular_cant(160.0, 1730.0)}; + auto const third{norms::regular_cant(160.0, 2000.0)}; + CHECK(std::round(first) == 105.0); + CHECK(std::round(second) == 96.0); + CHECK(std::round(third) == 83.0); + CHECK(std::round((first + second + third) / 3.0) == 95.0); + CHECK(norms::cant_deficiency(160.0, 1590.0, 95.0) == doctest::Approx(11.8 * 160 * 160 / 1590.0 - 95.0)); + CHECK(norms::cant_excess(100.0, 1590.0, 95.0) == doctest::Approx(95.0 - 11.8 * 100 * 100 / 1590.0)); + CHECK(norms::least_radius(160.0, 95.0, 130.0) == doctest::Approx(11.8 * 160 * 160 / 225.0)); + CHECK(norms::greatest_speed(1590.0, 95.0, 130.0) == doctest::Approx(std::sqrt(225.0 * 1590.0 / 11.8))); +} + +TEST_CASE("norms engine: a cant gradient of ST-T1-A6 przykład Z3-2 and Z3-3, 2.28 and 2.25 mm/m, passes P1 within P2") { + norms::query where; + where.speed = 50.0; + for (auto const gradient : {2.28, 2.25}) { + CAPTURE(gradient); + auto const verdict{norms::assess(parameter::cant_gradient, gradient, norms::limits(profile_id::plk, parameter::cant_gradient, where), norms::hard_limits(parameter::cant_gradient, where))}; + CHECK(verdict.level == tier::warn); + CHECK(verdict.passed.value == doctest::Approx(2.0)); + CHECK(verdict.passed.from.place == "tab. 9.12"); + } +} + +TEST_CASE("norms engine: a value beyond an unconfirmed extended limit warns, beyond a hard one it blocks") { + norms::query where; + where.speed = 240.0; + where.features = norms::feature::switch_track | norms::feature::movable_frog; + auto const limits{norms::limits(profile_id::plk, parameter::cant_deficiency, where)}; + auto const hard{norms::hard_limits(parameter::cant_deficiency, where)}; + auto const beyond_p2{norms::assess(parameter::cant_deficiency, 120.0, limits, hard)}; + CHECK(beyond_p2.level == tier::warn); + CHECK_FALSE(beyond_p2.passed.confirmed); + auto const beyond_tsi{norms::assess(parameter::cant_deficiency, 160.0, limits, hard)}; + CHECK(beyond_tsi.level == tier::block); + CHECK(beyond_tsi.hard); + CHECK(beyond_tsi.passed.value == doctest::Approx(153.0)); + // within P0 nothing, between P0 and P1 above the recommended value + CHECK(norms::assess(parameter::cant_deficiency, 70.0, limits, hard).level == tier::none); + CHECK(norms::assess(parameter::cant_deficiency, 80.0, limits, hard).level == tier::none); + norms::query plain; + plain.speed = 100.0; + CHECK(norms::assess(parameter::cant_deficiency, 120.0, norms::limits(profile_id::plk, parameter::cant_deficiency, plain), hard).level == tier::prefer); +} + +TEST_CASE("norms engine: the cant deficiency at the highest speed and the excess at the slow trains of an arc") { + // R 600 m, transitions of 60 m, the cant 60 mm: at 100 km/h I = 196.7 - 60 = 136.7 mm, above P1 130, within P2 150 + line_builder builder; + builder.straight(200, 100).transition(0, 600, 60, 100).arc(600, 300, 100).transition(600, 0, 60, 100).straight(200, 100); + builder.cant(200, 0).cant(260, 60).cant(560, 60).cant(620, 0); + auto const findings{evaluate(builder.done(), mixed_main())}; + auto const deficiency{of(findings, parameter::cant_deficiency)}; + REQUIRE_FALSE(deficiency.empty()); + auto const &arc{*std::ranges::find_if(deficiency, [](norms::finding const &Finding) { return Finding.element == 2; })}; + CHECK(arc.value == doctest::Approx(11.8 * 100 * 100 / 600.0 - 60.0)); + CHECK(arc.level == tier::warn); + CHECK(arc.limit == doctest::Approx(130.0)); + CHECK(arc.from.place == "tab. 9.7"); + CHECK(of(findings, parameter::cant_excess).empty()); + + // the cant of 150 mm on it and slow trains of 40 km/h: E = 150 - 31.5 = 118.5 mm, above P2 110 (q <= 5 Tg a year) + line_builder steep; + steep.straight(200, 100).transition(0, 600, 100, 100).arc(600, 300, 100).transition(600, 0, 100, 100).straight(200, 100); + steep.cant(200, 0).cant(300, 150).cant(600, 150).cant(700, 0); + auto slow{mixed_main()}; + slow.vmin = 40.0; + auto const excess{of(evaluate(steep.done(), slow), parameter::cant_excess)}; + REQUIRE_FALSE(excess.empty()); + auto const &worst{*std::ranges::max_element(excess, {}, &norms::finding::value)}; + CHECK(worst.value == doctest::Approx(150.0 - 11.8 * 40 * 40 / 600.0)); + CHECK(worst.level == tier::block); + CHECK(worst.limit == doctest::Approx(110.0)); + CHECK(worst.speed == doctest::Approx(40.0)); +} + +TEST_CASE("norms engine: the abrupt change of the cant deficiency between arcs turning alike and turning the other way") { + // R 1000 m straight into R 500 m at 80 km/h with no transition: I 75.5 and 151 mm + auto const i1{11.8 * 80 * 80 / 1000.0}; + auto const i2{11.8 * 80 * 80 / 500.0}; + line_builder alike; + alike.straight(100, 80).arc(1000, 200, 80).arc(500, 200, 80).straight(100, 80); + auto const same{of(evaluate(alike.done(), mixed_main(80)), parameter::deficiency_jump)}; + auto const between = [](std::vector const &Findings, double const Chainage) { + return std::ranges::find_if(Findings, [Chainage](norms::finding const &Finding) { return std::abs(Finding.chainage - Chainage) < 1e-6; }); + }; + auto const turning{between(same, 300.0)}; + REQUIRE(turning != same.end()); + CHECK(turning->value == doctest::Approx(i2 - i1)); + CHECK(turning->level == tier::block); + + line_builder reverse; + reverse.straight(100, 80).arc(1000, 200, 80); + reverse.arc(-500, 200, 80).straight(100, 80); + auto const other{of(evaluate(reverse.done(), mixed_main(80)), parameter::deficiency_jump)}; + auto const reversing{between(other, 300.0)}; + REQUIRE(reversing != other.end()); + CHECK(reversing->value == doctest::Approx(i1 + i2)); + // above the 125 mm of the TSI too: blocked by PLK, the stricter + CHECK(reversing->level == tier::block); + CHECK(reversing->limit == doctest::Approx(50.0)); +} + +TEST_CASE("norms engine: the abrupt changes over a straight shorter than tab. 9.16 asks for are taken together, the other way round or longer one by one") { + // reverse curves of R 400 m at 60 km/h, I 106.2 mm each, with no transitions; the intermediate length at 60 km/h is 20 m + auto const each{11.8 * 60 * 60 / 400.0}; + auto const jumps = [](double const Between, double const Second) { + line_builder builder; + builder.straight(100, 60).arc(400, 80, 60).straight(Between, 60).arc(Second, 80, 60).straight(100, 60); + return of(evaluate(builder.done(), mixed_main(60)), parameter::deficiency_jump); + }; + auto const close{jumps(10.0, -400.0)}; + auto const summed{std::ranges::find_if(close, [](norms::finding const &Finding) { return std::abs(Finding.chainage - 180.0) < 1e-6; })}; + REQUIRE(summed != close.end()); + CHECK(summed->value == doctest::Approx(2.0 * each)); + CHECK(summed->length == doctest::Approx(10.0)); + CHECK(summed->level == tier::block); + // 30 m apart: each by itself + auto const apart{jumps(30.0, -400.0)}; + for (auto const &finding : apart) { + CAPTURE(finding.chainage); + CHECK(finding.value == doctest::Approx(each)); + CHECK(finding.length == 0.0); + } + CHECK(apart.size() == 4); + // turning alike, the deficiency falls and rises again: no monotonic change, each by itself + for (auto const &finding : jumps(10.0, 400.0)) { + CHECK(finding.value == doctest::Approx(each)); + } +} + +TEST_CASE("norms engine: the gradient and the rate of change of the cant along a ramp, the rate of change of the deficiency along a transition") { + // 100 mm over 50 m at 120 km/h: 2 mm/m, 66.7 mm/s + line_builder ramp; + ramp.straight(300, 120); + ramp.cant(0, 0).cant(100, 0).cant(150, 100).cant(300, 100); + auto const ramped{evaluate(ramp.done(), mixed_main(120))}; + auto const gradient{of(ramped, parameter::cant_gradient)}; + REQUIRE(gradient.size() == 1); + CHECK(gradient.front().value == doctest::Approx(2.0)); + CHECK(gradient.front().level == tier::prefer); + auto const rate{of(ramped, parameter::cant_rate)}; + REQUIRE(rate.size() == 1); + CHECK(rate.front().value == doctest::Approx(2.0 * 120 / 3.6)); + CHECK(rate.front().level == tier::block); + CHECK(rate.front().from.place == "tab. 9.13"); + // a step of the cant: the twist of 15 mm on the base of 5 m, 3 mm/m, beyond the 2.5 mm/m of every profile + line_builder step; + step.straight(300, 80); + step.cant(0, 0).cant(150, 0).cant(150, 15).cant(300, 15); + auto const stepped{of(evaluate(step.done(), mixed_main(80), profile_id::tsi), parameter::cant_gradient)}; + REQUIRE(stepped.size() == 1); + CHECK(stepped.front().value == doctest::Approx(3.0)); + CHECK(stepped.front().level == tier::block); + CHECK(stepped.front().hard); + // a transition of 40 m to R 500 m with no cant at 80 km/h: 151 mm over 40 m, 83.9 mm/s + line_builder curve; + curve.straight(100, 80).transition(0, 500, 40, 80).arc(500, 100, 80).transition(500, 0, 40, 80).straight(100, 80); + auto const change{of(evaluate(curve.done(), mixed_main(80)), parameter::deficiency_rate)}; + REQUIRE(change.size() == 2); + CHECK(change.front().value == doctest::Approx(11.8 * 80 * 80 / 500.0 * 80 / (3.6 * 40.0))); + CHECK(change.front().level == tier::block); +} + +TEST_CASE("norms engine: the lengths of the elements, the transition curves and the radius") { + line_builder builder; + builder.straight(100, 100).arc(400, 20, 100).straight(28, 100).transition(0, 400, 20, 100).arc(400, 100, 100).transition(400, 0, 60, 100).straight(100, 100); + builder.cant(0, 0).cant(148, 0).cant(168, 30).cant(268, 30).cant(328, 0); + auto const findings{evaluate(builder.done(), mixed_main(100))}; + auto const lengths{of(findings, parameter::element_length)}; + // the arc of 20 m below the 25 m of P2, the straight of 28 m below the 35 m of P1 + REQUIRE(lengths.size() == 2); + CHECK(lengths[0].level == tier::block); + CHECK(lengths[0].limit == doctest::Approx(25.0)); + CHECK(lengths[1].level == tier::warn); + CHECK(lengths[1].limit == doctest::Approx(35.0)); + auto const transitions{of(findings, parameter::transition_length)}; + REQUIRE(transitions.size() == 1); + CHECK(transitions.front().value == doctest::Approx(20.0)); + CHECK(transitions.front().level == tier::warn); + auto const radii{of(findings, parameter::radius)}; + REQUIRE_FALSE(radii.empty()); + CHECK(radii.front().value == doctest::Approx(400.0)); + CHECK(radii.front().level == tier::prefer); +} + +TEST_CASE("norms engine: the vertical curves, a break of the grade and the grade") { + line_builder builder; + builder.straight(1000, 100); + auto line{builder.done()}; + // level, a break to 8 per mille rising, a vertical curve of 40 m back to level (R 5000 m), then level + line.grades = {{0.0, 300.0, 0.0, 0.0}, {300.0, 200.0, 0.008, 0.008}, {500.0, 40.0, 0.008, 0.0}, {540.0, 460.0, 0.0, 0.0}}; + auto const findings{evaluate(line, mixed_main(100))}; + auto const vertical{of(findings, parameter::vertical_radius)}; + REQUIRE(vertical.size() == 2); + CHECK(vertical[0].value == 0.0); + CHECK(vertical[0].level == tier::block); + CHECK(vertical[0].limit == doctest::Approx(2500.0)); + CHECK(vertical[1].value == doctest::Approx(5000.0)); + CHECK(vertical[1].level == tier::prefer); + auto const grades{of(findings, parameter::grade)}; + REQUIRE(grades.size() == 1); + CHECK(grades.front().value == doctest::Approx(8.0)); + CHECK(grades.front().level == tier::prefer); +} + +TEST_CASE("norms engine: an element on the boundary of two areas gets the stricter profile, an arc across it a warning") { + // TSI west of x = 150, PLK elsewhere: a ramp of 2.2 mm/m is nothing to the TSI and a warning to PLK + norms::area_map areas; + areas.scenery = profile_id::plk; + areas.areas.push_back({"west", profile_id::tsi, {{-1000.0, -1000.0}, {150.0, -1000.0}, {150.0, 1000.0}, {-1000.0, 1000.0}}}); + auto const ramp_at = [&areas](double const From) { + line_builder builder; + builder.straight(100, 100).straight(100, 100).straight(100, 100); + builder.cant(0, 0).cant(From, 0).cant(From + 50, 110).cant(300, 110); + return of(norms::evaluate(builder.done(), mixed_main(100), areas), parameter::cant_gradient); + }; + // on the element from 0 to 100, all of it in the TSI area + CHECK(ramp_at(20.0).empty()); + // on the element from 100 to 200, across the boundary: PLK + auto const across{ramp_at(120.0)}; + REQUIRE(across.size() == 1); + CHECK(across.front().profile == profile_id::plk); + CHECK(across.front().level == tier::warn); + // on the element from 200 to 300, in PLK + REQUIRE(ramp_at(220.0).size() == 1); + + line_builder curve; + curve.straight(100, 100).arc(2000, 100, 100).straight(100, 100); + auto const boundary{of(norms::evaluate(curve.done(), mixed_main(100), areas), parameter::profile_boundary)}; + REQUIRE(boundary.size() == 1); + CHECK(boundary.front().level == tier::warn); + CHECK(boundary.front().element == 1); + // a line of its own wins over the area + areas.lines.emplace_back("main", profile_id::en13803); + CHECK(areas.at({0.0, 0.0}, "main") == profile_id::en13803); + CHECK(areas.at({0.0, 0.0}, "other") == profile_id::tsi); + CHECK(areas.at({500.0, 0.0}, "other") == profile_id::plk); +} + +TEST_CASE("norms engine: a line read from its samples: straights, transitions and arcs, the cant points and the grade line") { + // samples a metre apart: 100 m straight, a transition of 50 m to R 500 m to the right, an arc of 100 m, then at a joint with no + // transition a straight of 100 m; the cant 0 - 50 mm along the transition and back to 0 along the first 50 m of the straight; level, + // and the straight rising 5 per mille from a break at its joint + std::vector samples; + auto const add = [&samples](double const Chainage, double const Curvature, double const Cant, double const Grade) { + norms::sample sample; + sample.chainage = Chainage; + sample.at = {Chainage, 0.0}; + sample.curvature = Curvature; + sample.cant = Cant; + sample.grade = Grade; + sample.speed = 100.0; + samples.push_back(sample); + }; + for (int i = 0; i <= 100; ++i) { + add(i, 0.0, 0.0, 0.0); + } + for (int i = 0; i <= 50; ++i) { + add(100.0 + i, -i / 50.0 / 500.0, -i, 0.0); + } + for (int i = 0; i <= 100; ++i) { + add(150.0 + i, -1.0 / 500.0, -50.0, 0.0); + } + for (int i = 0; i <= 100; ++i) { + add(250.0 + i, 0.0, -50.0 + (i < 50 ? i : 50), 0.005); + } + auto const line{norms::describe(samples, "test")}; + REQUIRE(line.elements.size() == 4); + CHECK(line.elements[0].kind == element_kind::straight); + CHECK(line.elements[0].length == doctest::Approx(100.0)); + CHECK(line.elements[1].kind == element_kind::transition); + CHECK(line.elements[1].curvature_end == doctest::Approx(-1.0 / 500.0)); + CHECK(line.elements[2].kind == element_kind::arc); + CHECK(line.elements[2].length == doctest::Approx(100.0)); + CHECK(line.elements[2].curvature_start == doctest::Approx(-1.0 / 500.0)); + CHECK(line.elements[3].kind == element_kind::straight); + CHECK(line.elements[0].open_start); + CHECK(line.elements[3].open_end); + // the cant: 0 to 100 m, -50 at 150 m, held to 250 m, back to 0 at 300 m + REQUIRE(line.cant.size() >= 4); + CHECK(line.cant.front().cant == doctest::Approx(0.0)); + auto const at = [&line](double const Chainage) { return std::ranges::find_if(line.cant, [Chainage](norms::cant_point const &Point) { return std::abs(Point.chainage - Chainage) < 1e-6; }); }; + REQUIRE(at(150.0) != line.cant.end()); + CHECK(at(150.0)->cant == doctest::Approx(-50.0)); + REQUIRE(at(300.0) != line.cant.end()); + CHECK(at(300.0)->cant == doctest::Approx(0.0)); + // the grade: level to 250 m, a break, 5 per mille on + REQUIRE(line.grades.size() == 2); + CHECK(line.grades[0].grade_start == 0.0); + CHECK(line.grades[1].start == doctest::Approx(250.0)); + CHECK(line.grades[1].grade_start == doctest::Approx(0.005)); +} diff --git a/tests/unit/test_norms_tables.cpp b/tests/unit/test_norms_tables.cpp new file mode 100644 index 000000000..9869fd022 --- /dev/null +++ b/tests/unit/test_norms_tables.cpp @@ -0,0 +1,279 @@ +// the tables of the profiles of the norms (editor/norms): every value of the PLK tables of ST-T1-A6, P0 / P1 / P2, and of the TSI, at +// the edges of their bands too (a speed on the edge of two bands, R 300, 250 and 200 m), the table in the name of each test; a few of +// EN 13803-1 and of AB-EBV + +#include "stdafx.h" +#include "doctest.h" +#include "editor/norms/norms.hpp" + +#include +#include + +namespace { + +using norms::parameter; +using norms::profile_id; +using norms::track_kind; +using norms::traffic; +namespace feature = norms::feature; + +std::optional constexpr none{}; + +norms::query at(double const Speed, double const Radius = 0.0, unsigned const Features = 0, track_kind const Track = track_kind::main, traffic const Kind = traffic::mixed, double const Load = 5.0) { + norms::query query; + query.speed = Speed; + query.radius = Radius; + query.features = Features; + query.track = Track; + query.kind = Kind; + query.load = Load; + return query; +} + +void tier(std::optional const &Bound, std::optional const Expected, char const *Name) { + CAPTURE(Name); + REQUIRE(Bound.has_value() == Expected.has_value()); + if (Expected.has_value()) { + CHECK(Bound->value == doctest::Approx(*Expected).epsilon(1e-9)); + } +} + +// the limits of the three tiers, PREFER / WARN / BLOCK, empty where the profile sets none +void tiers(norms::thresholds const &Limits, std::optional const Prefer, std::optional const Warn, std::optional const Block) { + tier(Limits.prefer, Prefer, "prefer"); + tier(Limits.warn, Warn, "warn"); + tier(Limits.block, Block, "block"); +} + +norms::thresholds plk(parameter const What, norms::query const &Where) { + return norms::limits(profile_id::plk, What, Where); +} + +norms::thresholds tsi(parameter const What, norms::query const &Where) { + return norms::limits(profile_id::tsi, What, Where); +} + +std::string place(norms::thresholds const &Limits) { + return Limits.block.has_value() ? std::string{Limits.block->from.place} : std::string{}; +} + +} // namespace + +TEST_CASE("norms PLK tab. 9.7: the cant deficiency of the running lines, the sidings, the small radii, the switches, the crossings and the expansion devices") { + tiers(plk(parameter::cant_deficiency, at(160)), 110.0, 130.0, 150.0); + tiers(plk(parameter::cant_deficiency, at(80, 0.0, 0, track_kind::side)), 80.0, 100.0, 100.0); + // R 250 m is the band 200 < R <= 250, a little more the running line; R 200 m the band R <= 200 + tiers(plk(parameter::cant_deficiency, at(80, 250.0)), 80.0, 100.0, 100.0); + tiers(plk(parameter::cant_deficiency, at(80, 250.01)), 110.0, 130.0, 150.0); + tiers(plk(parameter::cant_deficiency, at(80, 200.0)), 50.0, 70.0, 70.0); + tiers(plk(parameter::cant_deficiency, at(80, 200.01)), 80.0, 100.0, 100.0); + // switches with a fixed frog: 160 km/h is the band V <= 160 + tiers(plk(parameter::cant_deficiency, at(160, 0.0, feature::switch_track)), 90.0, 110.0, 110.0); + tiers(plk(parameter::cant_deficiency, at(160.5, 0.0, feature::switch_track)), 60.0, 90.0, 90.0); + tiers(plk(parameter::cant_deficiency, at(200, 0.0, feature::switch_track)), 60.0, 90.0, 90.0); + // with a movable frog; P2 of 230 < V <= 250 is above its P1 as printed, kept unconfirmed + tiers(plk(parameter::cant_deficiency, at(230, 0.0, feature::switch_track | feature::movable_frog)), 100.0, 130.0, 130.0); + auto const fast_nose{plk(parameter::cant_deficiency, at(240, 0.0, feature::switch_track | feature::movable_frog))}; + tiers(fast_nose, 80.0, 80.0, 110.0); + CHECK_FALSE(fast_nose.block->confirmed); + tiers(plk(parameter::cant_deficiency, at(120, 0.0, feature::switch_track | feature::crossing)), 0.0, 0.0, 80.0); + tiers(plk(parameter::cant_deficiency, at(160, 0.0, feature::expansion)), 80.0, 100.0, 100.0); + tiers(plk(parameter::cant_deficiency, at(200, 0.0, feature::expansion)), 0.0, 80.0, 80.0); + tiers(plk(parameter::cant_deficiency, at(250, 0.0, feature::expansion)), 0.0, 60.0, 60.0); + CHECK(place(plk(parameter::cant_deficiency, at(160))) == "tab. 9.7"); +} + +TEST_CASE("norms PLK tab. 9.8: the cant excess by the load of the track, the switches by tab. 9.7 too (9.5 pkt 4)") { + tiers(plk(parameter::cant_excess, at(80, 0.0, 0, track_kind::main, traffic::mixed, 5.0)), 90.0, 110.0, 110.0); + auto const second{plk(parameter::cant_excess, at(80, 0.0, 0, track_kind::main, traffic::mixed, 10.0))}; + tiers(second, 95.0, 95.0, 110.0); + CHECK_FALSE(second.prefer->confirmed); + tiers(plk(parameter::cant_excess, at(80, 0.0, 0, track_kind::main, traffic::mixed, 15.0)), 80.0, 95.0, 110.0); + tiers(plk(parameter::cant_excess, at(80, 0.0, 0, track_kind::main, traffic::mixed, 20.0)), 65.0, 80.0, 110.0); + tiers(plk(parameter::cant_excess, at(80, 0.0, 0, track_kind::main, traffic::mixed, 20.5)), 50.0, 80.0, 110.0); + // the stricter of tab. 9.8 and the row of the switch in tab. 9.7 + tiers(plk(parameter::cant_excess, at(180, 0.0, feature::switch_track, track_kind::main, traffic::mixed, 15.0)), 60.0, 90.0, 90.0); + tiers(plk(parameter::cant_excess, at(100, 0.0, feature::switch_track | feature::crossing)), 0.0, 0.0, 80.0); +} + +TEST_CASE("norms PLK tab. 9.15: the abrupt change of the cant deficiency in the connections of tracks, the running lines and the sidings") { + auto const connection{feature::switch_track}; + tiers(plk(parameter::deficiency_jump, at(60, 0.0, connection)), 130.0, 130.0, 130.0); + tiers(plk(parameter::deficiency_jump, at(60.5, 0.0, connection)), 100.0, 100.0, 125.0); + tiers(plk(parameter::deficiency_jump, at(100, 0.0, connection)), 100.0, 100.0, 125.0); + tiers(plk(parameter::deficiency_jump, at(160, 0.0, connection)), 80.0, 80.0, 160.0 - 0.35 * 160.0); + tiers(plk(parameter::deficiency_jump, at(200, 0.0, connection)), 60.0, 60.0, 160.0 - 0.35 * 200.0); + tiers(plk(parameter::deficiency_jump, at(70)), 50.0, 50.0, 60.0); + tiers(plk(parameter::deficiency_jump, at(100)), 0.0, 64.0 - 0.2 * 100.0, 50.0); + tiers(plk(parameter::deficiency_jump, at(160)), 0.0, 64.0 - 0.2 * 160.0, 50.0); + tiers(plk(parameter::deficiency_jump, at(200)), 0.0, 30.0, 50.0); + tiers(plk(parameter::deficiency_jump, at(250)), 0.0, 25.0, 25.0); + tiers(plk(parameter::deficiency_jump, at(40, 0.0, 0, track_kind::side)), 50.0, 100.0, 100.0); + tiers(plk(parameter::deficiency_jump, at(50, 0.0, 0, track_kind::side)), none, none, none); +} + +TEST_CASE("norms PLK tab. 9.12, 9.13, 9.14: the cant gradient, the rate of change of the cant and of the cant deficiency") { + tiers(plk(parameter::cant_gradient, at(250)), 1.6, 2.0, 2.5); + tiers(plk(parameter::cant_rate, at(160)), 35.0, 50.0, 60.0); + tiers(plk(parameter::deficiency_rate, at(200)), 55.0, 70.0, 80.0); + tiers(plk(parameter::deficiency_rate, at(201)), 55.0, 55.0, 70.0); + CHECK(place(plk(parameter::cant_gradient, at(100))) == "tab. 9.12"); +} + +TEST_CASE("norms PLK tab. 9.1: the shortest straights and arcs") { + tiers(plk(parameter::element_length, at(80)), 30.0, 30.0, 20.0); + tiers(plk(parameter::element_length, at(120)), 42.0, 42.0, 30.0); + tiers(plk(parameter::element_length, at(160)), 64.0, 64.0, 48.0); + tiers(plk(parameter::element_length, at(250)), 162.5, 162.5, 137.5); + // not in the connections of tracks + tiers(plk(parameter::element_length, at(80, 0.0, feature::switch_track)), none, none, none); +} + +TEST_CASE("norms PLK tab. 9.10: the transition curves, 30 m and the shift of the arc by 0.02 m (9.14) at P0 and P1") { + tiers(plk(parameter::transition_length, at(100)), 30.0, 30.0, none); + tiers(plk(parameter::transition_shift, at(100)), 0.02, 0.02, none); +} + +TEST_CASE("norms PLK tab. 9.2: the least radii") { + tiers(plk(parameter::radius, at(100, 500.0)), 600.0, 300.0, 180.0); + tiers(plk(parameter::radius, at(40, 500.0, 0, track_kind::side)), 450.0, 180.0, 180.0); + // at a platform the stricter of its row, 500 / 500 / 300, and the one of the track + tiers(plk(parameter::radius, at(40, 500.0, feature::platform, track_kind::side)), 500.0, 500.0, 300.0); + tiers(plk(parameter::radius, at(100, 500.0, feature::platform)), 600.0, 500.0, 300.0); +} + +TEST_CASE("norms PLK tab. 9.6 and 9.8: the cant, (R - 50) / 1.5 below R 300 m") { + tiers(plk(parameter::cant, at(100)), 150.0, 150.0, 150.0); + tiers(plk(parameter::cant, at(100, 0.0, feature::ballastless)), 150.0, 150.0, 160.0); + tiers(plk(parameter::cant, at(100, 0.0, feature::platform)), 60.0, 100.0, 110.0); + tiers(plk(parameter::cant, at(40, 0.0, 0, track_kind::side)), 0.0, 60.0, 100.0); + // R 300 m is the band 200 < R <= 300, with no (R - 50) / 1.5 yet; R 250 m with it; R 200 m the band R <= 200, where it's 100 mm too + tiers(plk(parameter::cant, at(80, 300.0)), 0.0, 100.0, 150.0); + auto const tight{plk(parameter::cant, at(80, 250.0))}; + tiers(tight, 0.0, 100.0, (250.0 - 50.0) / 1.5); + CHECK(place(tight) == "9.8"); + tiers(plk(parameter::cant, at(80, 200.0)), 0.0, 60.0, 100.0); + tiers(plk(parameter::cant, at(80, 300.01)), 150.0, 150.0, 150.0); + tiers(plk(parameter::cant, at(80, 0.0, feature::switch_track)), 0.0, 100.0, 110.0); + tiers(plk(parameter::cant, at(80, 0.0, feature::switch_track | feature::curved_switch)), 60.0, 100.0, 110.0); + tiers(plk(parameter::cant, at(80, 0.0, feature::switch_track | feature::crossing)), 0.0, 0.0, 0.0); + tiers(plk(parameter::cant_min, at(80)), 20.0, 20.0, 20.0); +} + +TEST_CASE("norms PLK tab. 10.2: the least radii of the vertical curves") { + tiers(plk(parameter::vertical_radius, at(100, 0.0, feature::crest)), 7700.0, 5000.0, 2500.0); + tiers(plk(parameter::vertical_radius, at(160, 0.0, feature::sag)), 0.77 * 160 * 160, 0.35 * 160 * 160, 0.25 * 160 * 160); + tiers(plk(parameter::vertical_radius, at(60, 0.0, feature::sag)), 5000.0, 5000.0, 2000.0); + tiers(plk(parameter::vertical_radius, at(100, 0.0, feature::suburban | feature::crest)), 7700.0, 7700.0, 2500.0); + tiers(plk(parameter::vertical_radius, at(100, 0.0, feature::switch_track | feature::crest)), 5000.0, 5000.0, 3000.0); + tiers(plk(parameter::vertical_radius, at(100, 0.0, feature::switch_track | feature::sag)), 3500.0, 3500.0, 2500.0); +} + +TEST_CASE("norms PLK tab. 10.1: the steepest grades") { + tiers(plk(parameter::grade, at(100, 0.0, 0, track_kind::main, traffic::passenger)), 6.0, 17.5, 35.0); + tiers(plk(parameter::grade, at(100, 0.0, 0, track_kind::main, traffic::mixed)), 6.0, 10.0, 20.0); + tiers(plk(parameter::grade, at(100, 0.0, 0, track_kind::main, traffic::freight)), 6.0, 10.0, 20.0); + tiers(plk(parameter::grade, at(100, 0.0, feature::short_stretch, track_kind::main, traffic::mixed)), 6.0, 17.5, 35.0); + tiers(plk(parameter::grade, at(40, 0.0, feature::station)), 2.0, 2.0, 2.5); + tiers(plk(parameter::grade, at(40, 0.0, feature::platform, track_kind::main, traffic::passenger)), 2.5, 6.0, 10.0); +} + +TEST_CASE("norms PLK tab. 9.16: the shortest intermediate element between abrupt changes of the cant deficiency") { + tiers(plk(parameter::intermediate_length, at(100)), none, none, 25.0); + tiers(plk(parameter::intermediate_length, at(60)), none, none, 20.0); + tiers(plk(parameter::intermediate_length, at(160)), none, none, 48.0); + tiers(plk(parameter::intermediate_length, at(250)), none, none, 137.5); + tiers(plk(parameter::intermediate_length, at(60, 0.0, feature::switch_track)), none, none, 6.0); + // ST-T1-A6 przykład Z3-3: at 70 km/h on a connection 0.15 V = 10.5 m + tiers(plk(parameter::intermediate_length, at(70, 0.0, feature::switch_track)), none, none, 10.5); + tiers(plk(parameter::intermediate_length, at(150, 0.0, feature::switch_track)), none, none, 37.5); + tiers(plk(parameter::intermediate_length, at(40, 0.0, 0, track_kind::side)), none, none, 4.0); +} + +TEST_CASE("norms PLK tab. 8.1: the speed of the slow trains of the types of the lines") { + CHECK(norms::slow_speed(traffic::passenger, 250) == 120); + CHECK(norms::slow_speed(traffic::passenger, 200) == 120); + CHECK(norms::slow_speed(traffic::mixed, 200) == 80); + CHECK(norms::slow_speed(traffic::passenger, 160) == 120); + CHECK(norms::slow_speed(traffic::mixed, 160) == 80); + CHECK(norms::slow_speed(traffic::passenger, 120) == 80); + CHECK(norms::slow_speed(traffic::mixed, 120) == 60); + CHECK(norms::slow_speed(traffic::freight, 120) == 60); + CHECK(norms::slow_speed(traffic::passenger, 80) == 60); + CHECK(norms::slow_speed(traffic::mixed, 80) == 40); + CHECK(norms::slow_speed(traffic::freight, 80) == 40); + CHECK(norms::slow_speed(traffic::freight, 40) == 40); + // between the types the next faster one, never above the highest speed itself + CHECK(norms::slow_speed(traffic::passenger, 100) == 80); + CHECK(norms::slow_speed(traffic::freight, 30) == 30); +} + +TEST_CASE("norms TSI 4.2.4.3 tab. 8: the cant deficiency, 153 mm up to 300 km/h, 130 mm for the freight wagons") { + tiers(tsi(parameter::cant_deficiency, at(160)), none, none, 153.0); + tiers(tsi(parameter::cant_deficiency, at(300)), none, none, 153.0); + tiers(tsi(parameter::cant_deficiency, at(301)), none, none, 100.0); + tiers(tsi(parameter::cant_deficiency, at(160, 0.0, 0, track_kind::main, traffic::freight)), none, none, 130.0); + tiers(tsi(parameter::cant_deficiency, at(160, 0.0, feature::tilting, track_kind::main, traffic::passenger)), none, none, none); + CHECK(place(tsi(parameter::cant_deficiency, at(160))) == "4.2.4.3, tab. 8"); +} + +TEST_CASE("norms TSI 4.2.4.2 tab. 7: the cant, at the platforms, (R - 50) / 1.5 below R 305 m for mixed and freight traffic") { + tiers(tsi(parameter::cant, at(100)), none, none, 160.0); + tiers(tsi(parameter::cant, at(100, 0.0, 0, track_kind::main, traffic::passenger)), none, none, 180.0); + tiers(tsi(parameter::cant, at(100, 0.0, feature::ballastless)), none, none, 170.0); + tiers(tsi(parameter::cant, at(100, 0.0, feature::ballastless, track_kind::main, traffic::passenger)), none, none, 180.0); + tiers(tsi(parameter::cant, at(100, 0.0, feature::platform, track_kind::main, traffic::passenger)), none, none, 110.0); + tiers(tsi(parameter::cant, at(60, 300.0)), none, none, 160.0); + tiers(tsi(parameter::cant, at(60, 250.0)), none, none, 200.0 / 1.5); + tiers(tsi(parameter::cant, at(60, 250.0, 0, track_kind::main, traffic::passenger)), none, none, 180.0); +} + +TEST_CASE("norms TSI 4.2.4.4: the abrupt change of the cant deficiency, 150 mm at 40 km/h below 75 mm on both sides") { + tiers(tsi(parameter::deficiency_jump, at(40)), none, none, 130.0); + tiers(tsi(parameter::deficiency_jump, at(40, 0.0, feature::low_deficiency)), none, none, 150.0); + tiers(tsi(parameter::deficiency_jump, at(60, 0.0, feature::low_deficiency)), none, none, 130.0); + tiers(tsi(parameter::deficiency_jump, at(60.5)), none, none, 125.0); + tiers(tsi(parameter::deficiency_jump, at(200)), none, none, 125.0); + tiers(tsi(parameter::deficiency_jump, at(230)), none, none, 85.0); + tiers(tsi(parameter::deficiency_jump, at(230.5)), none, none, 25.0); +} + +TEST_CASE("norms TSI 4.2.3.3, 4.2.3.4, 4.2.3.5: the grades, the least radius, the vertical curves") { + tiers(tsi(parameter::radius, at(100, 300.0)), none, none, 150.0); + tiers(tsi(parameter::vertical_radius, at(100, 0.0, feature::crest)), none, none, 500.0); + tiers(tsi(parameter::vertical_radius, at(100, 0.0, feature::sag)), none, none, 900.0); + tiers(tsi(parameter::grade, at(100, 0.0, 0, track_kind::main, traffic::passenger)), none, none, 35.0); + tiers(tsi(parameter::grade, at(100, 0.0, 0, track_kind::main, traffic::mixed)), none, none, none); + tiers(tsi(parameter::grade, at(40, 0.0, feature::station)), none, none, 2.5); +} + +TEST_CASE("norms hard limits of every profile: the TSI and the cant gradient of 2.5 mm/m of EN 13803-1") { + auto const gradient{norms::hard_limits(parameter::cant_gradient, at(100))}; + tiers(gradient, none, none, 2.5); + CHECK(gradient.block->from.document == "EN 13803-1"); + auto const deficiency{norms::hard_limits(parameter::cant_deficiency, at(100))}; + tiers(deficiency, none, none, 153.0); + CHECK(deficiency.block->from.document == "TSI INF"); + tiers(norms::hard_limits(parameter::radius, at(100, 300.0)), none, none, 150.0); + // the grades are the profiles' own + tiers(norms::hard_limits(parameter::grade, at(100, 0.0, 0, track_kind::main, traffic::passenger)), none, none, none); +} + +TEST_CASE("norms EN 13803-1 5.2 and AB-EBV AB 17: the normal and the exceptional or maximal limits") { + auto const en = [](parameter const What, norms::query const &Where) { return norms::limits(profile_id::en13803, What, Where); }; + auto const ch = [](parameter const What, norms::query const &Where) { return norms::limits(profile_id::ch, What, Where); }; + tiers(en(parameter::cant_deficiency, at(150)), none, 130.0, 183.0); + tiers(en(parameter::cant_deficiency, at(80)), none, none, none); + tiers(en(parameter::cant_gradient, at(100)), none, 2.25, 2.5); + tiers(en(parameter::cant, at(100, 500.0)), none, 160.0, 180.0); + tiers(en(parameter::radius, at(100, 500.0)), none, 190.0, 150.0); + CHECK_FALSE(en(parameter::deficiency_jump, at(100)).warn->confirmed); + tiers(ch(parameter::cant_deficiency, at(100, 300.0)), none, 122.0, 130.0); + tiers(ch(parameter::cant_deficiency, at(100, 500.0)), none, 130.0, 150.0); + tiers(ch(parameter::cant_deficiency, at(150, 100.0, feature::switch_track | feature::diverging)), none, 130.0 - 0.3 * 150.0, 155.0 - 0.35 * 150.0); + tiers(ch(parameter::cant_rate, at(100)), none, 50.0, 60.0); + tiers(ch(parameter::element_length, at(72)), none, 20.0, 14.0); + tiers(ch(parameter::deficiency_jump, at(120)), none, 75.0 - 0.3125 * 120.0, none); + tiers(ch(parameter::vertical_radius, at(100, 0.0, feature::sag)), none, 3500.0, 1750.0); + tiers(ch(parameter::vertical_radius, at(40, 0.0, feature::sag)), none, 2000.0, 900.0); +}