Skip to content

Update math#421

Open
gr812b wants to merge 30 commits intodevelopfrom
update-math
Open

Update math#421
gr812b wants to merge 30 commits intodevelopfrom
update-math

Conversation

@gr812b
Copy link
Owner

@gr812b gr812b commented Mar 17, 2026

Description
Complete update to the math in the backend, major refactor. Variables names and such but also whole new equations.

This PR performs a major refactor of the CVT simulation “math”/state representation in the Python model and propagates the new schema through the backend API types and frontend consumers (unit conversion, graphs, 3D viewer, and input/session UX).

Changes:

  • Refactors backend simulation state to a 4-DOF core (SystemState) and moves kinematic signals into a derived-state layer; restructures outputs into a drivetrain breakdown and adds a termination context.
  • Updates traction/slip + pulley dynamics math (torque bounds, axial-force modeling), adds rolling resistance, and introduces new helper utilities for state conversions/integration.
  • Updates frontend types, conversion utilities, graph accessors, and UI elements to match the new API shape; improves session/edit/new flows and some layout/visualization controls.

@gr812b gr812b marked this pull request as ready for review March 22, 2026 18:14
Copilot AI review requested due to automatic review settings March 22, 2026 18:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs a major refactor of the CVT simulation “math”/state representation in the Python model and propagates the new schema through the backend API types and frontend consumers (unit conversion, graphs, 3D viewer, and input/session UX).

Changes:

  • Refactors backend simulation state to a 4-DOF core (SystemState) and moves kinematic signals into a derived-state layer; restructures outputs into a drivetrain breakdown and adds a termination context.
  • Updates traction/slip + pulley dynamics math (torque bounds, axial-force modeling), adds rolling resistance, and introduces new helper utilities for state conversions/integration.
  • Updates frontend types, conversion utilities, graph accessors, and UI elements to match the new API shape; improves session/edit/new flows and some layout/visualization controls.

Reviewed changes

Copilot reviewed 66 out of 69 changed files in this pull request and generated no comments.

Show a summary per file
File Description
frontend/src/utils/conversion/timeStepDataConversion.ts Converts new derived_state + drivetrain time step shape and adds termination time conversions.
frontend/src/utils/conversion/constantsConversion.ts Converts newly added inertia + rolling resistance constants.
frontend/src/types/ramp.ts Updates default ramp segment sign/quadrant conventions.
frontend/src/types/parameter.ts Updates default parameter ramp configurations to new conventions.
frontend/src/types/graph.ts Migrates graph accessors/series to derived_state/drivetrain fields and adds external load torque graphs.
frontend/src/types/api.ts Regenerates/updates OpenAPI-derived schema types to reflect new backend models and fields.
frontend/src/pages/input/Input.tsx Adds top bar showing selected parameter set + “changes” badge; passes ramp changed-state into ramp builder.
frontend/src/pages/input/Input.module.scss Styles new top bar/session info and adjusts home button layout.
frontend/src/pages/dashboard/Dashboard.module.scss Adjusts dashboard layout behavior (overflow/flex shrink).
frontend/src/hooks/useSimulations.ts Fixes edit flow ordering: clears session params, sets loaded simulation id, sets parameters, navigates.
frontend/src/hooks/useSessionPersistence.ts Reworks hydration/restore priority (session > loadedId), adds recent-run restore, revises change detection logic.
frontend/src/hooks/useFormState.ts Keeps form state synced with external context updates (session restore / edit / new).
frontend/src/contexts/ParameterContext.tsx Simplifies initialization by loading from storage in reducer init; removes load-on-mount action.
frontend/src/constants/defaultSimulations.ts Updates default simulation ramps and adds a new “Best shift curve” preset.
frontend/src/components/simulationsTable/SimulationsTable.module.scss Improves table scrolling/flex sizing.
frontend/src/components/scene3DViewer/Scene3DViewer.tsx Migrates to new drivetrain fields, adjusts angle handling, defaults grids off, adds cross-section clipping toggle.
frontend/src/components/scene3DViewer/Scene3DViewer.module.scss Styles new cross-section toggle button.
frontend/src/components/rampBuilder/RampPreview.tsx Improves axis bounds handling for ramps with positive/negative heights; memoizes CSS-derived colors.
frontend/src/components/rampBuilder/RampBuilder.tsx Adds “changed” badge/header and supports hasChanged prop; wraps internal class styling.
frontend/src/components/rampBuilder/RampBuilder.module.scss Adds styles for ramp header/changed badge.
cvtModel/test/utils/test_theoretical_models.py Updates tests for renamed theoretical model methods and ratio naming.
cvtModel/test/utils/test_system_state.py Updates tests for 4-DOF SystemState and clamping behavior.
cvtModel/test/utils/test_simulation_result.py Updates tests for 4-DOF solver output parsing/CSV fields and plot default field.
cvtModel/test/utils/test_ramp_config.py Adds tests for payload coercion/validation (quadrant parsing).
cvtModel/test/simulations/test_belt_simulator.py Removes belt simulator tests (file deleted).
cvtModel/src/cvt_simulator/utils/theoretical_models.py Adds sign/rolling resistance helpers, renames geometry accessors, switches to effective radius/ratio methods.
cvtModel/src/cvt_simulator/utils/system_state.py Redefines solver state as 4 DOF, clamps shift distance in from_array.
cvtModel/src/cvt_simulator/utils/state_computations.py Adds centralized kinematic conversions + trapezoidal integration helper.
cvtModel/src/cvt_simulator/utils/simulation_result.py Adds derived outputs (positions/velocities) to CSV writing and updates parsing/plotting for new state.
cvtModel/src/cvt_simulator/utils/simulation_constraints.py Updates velocity constraint to use computed car velocity; adds mid-shift steady/wake events.
cvtModel/src/cvt_simulator/utils/simulation_args.py Removes deprecated geometry fields; fixes default secondary ramp factory usage.
cvtModel/src/cvt_simulator/utils/print_progress.py Removes unused progress-printing utility (file deleted).
cvtModel/src/cvt_simulator/utils/generate_graphs.py Refactors graph generation to read CSV and output fixed image files via a CLI.
cvtModel/src/cvt_simulator/utils/frontend_output.py Emits new derived_state, drivetrain, and a structured termination context for the frontend.
cvtModel/src/cvt_simulator/utils/diagnostics/solver_slowdown_diagnostic.py Adds a diagnostic script for investigating solver slowdowns and transition/event behavior.
cvtModel/src/cvt_simulator/utils/cvt_ratio_utils.py Renames/expands CVT geometry APIs; adds effective ratio + derivative calculations.
cvtModel/src/cvt_simulator/solvers/shift_initiation/shift_initiation_solver.py Updates solver logic and documentation for axial-force based shift initiation and new slip API.
cvtModel/src/cvt_simulator/solvers/prim_engagement/primary_cvt_engagement_solver.py Updates engagement solver to use primary torque bounds with engine torque/inertia inputs.
cvtModel/src/cvt_simulator/models/system_model.py Replaces prior engine/car breakdown with primary/secondary pulley dynamics breakdown under DrivetrainBreakdown.
cvtModel/src/cvt_simulator/models/slip_model.py Replaces t_max-based logic with per-pulley torque bounds and traction-limited coupling torque.
cvtModel/src/cvt_simulator/models/secondary_pulley_model.py Adds a secondary-side angular acceleration model and inertia aggregation.
cvtModel/src/cvt_simulator/models/ramps/theta_ramp_visualization.py Adds visualization tooling for the new theta-ramp helix representation.
cvtModel/src/cvt_simulator/models/ramps/theta_ramp.py Introduces ThetaRamp converting helix-angle ramps into circumferential displacement / rotation.
cvtModel/src/cvt_simulator/models/ramps/ramp_preview.py Updates example ramp preview config to new positive angle/quadrant convention.
cvtModel/src/cvt_simulator/models/ramps/ramp_config.py Adds robust numeric coercion and quadrant validation for payload parsing.
cvtModel/src/cvt_simulator/models/ramps/circular_segment.py Updates quadrant semantics/validation and simplifies position-angle mapping.
cvtModel/src/cvt_simulator/models/ramps/init.py Exports ThetaRamp.
cvtModel/src/cvt_simulator/models/pulley/secondary_pulley_torque_reactive.py Refactors secondary pulley model to theta ramp helix and returns detailed torque bounds breakdown.
cvtModel/src/cvt_simulator/models/pulley/secondary_pulley_interface.py Updates geometry/velocity accessors for new effective radius and 4-DOF state.
cvtModel/src/cvt_simulator/models/pulley/pulley_interface.py Changes pulley force modeling to axial-only + belt centrifugal axial term; introduces torque bounds API.
cvtModel/src/cvt_simulator/models/pulley/primary_pulley_interface.py Updates geometry/velocity accessors for new effective radius and 4-DOF state.
cvtModel/src/cvt_simulator/models/pulley/primary_pulley_flyweight.py Updates primary flyweight ramp convention and refactors torque bounds computation + ramp admissibility checks.
cvtModel/src/cvt_simulator/models/primary_pulley_model.py Adds a primary-side angular acceleration model using engine torque and coupling torque.
cvtModel/src/cvt_simulator/models/model_initializer.py Rewires model initialization for new primary/secondary dynamics models and theta ramp for helix.
cvtModel/src/cvt_simulator/models/external_load_model.py Adds rolling resistance and returns force + torque breakdown at secondary; takes full SystemState.
cvtModel/src/cvt_simulator/models/engine_accel_model.py Removes legacy engine acceleration model (file deleted).
cvtModel/src/cvt_simulator/models/dataTypes.py Renames/expands breakdown dataclasses for drivetrain, forces, torque bounds, and external load terms.
cvtModel/src/cvt_simulator/models/cvt_shift_model.py Converts shift dynamics to use axial forces and effective CVT ratio.
cvtModel/src/cvt_simulator/models/car_model.py Removes legacy car model (file deleted).
cvtModel/src/cvt_simulator/constants/constants.py Updates friction constant value.
cvtModel/src/cvt_simulator/constants/car_specs.py Adds inertias + rolling resistance coefficient; updates defaults and exports new constants.
cvtModel/src/cvt_simulator/init.py Updates public exports to new breakdown type names.
cvtModel/README.md Documents local simulation + validation graph generation workflow.
backend/app/api/endpoints.py Adds 400 responses for invalid inputs (ValueError) for /run and /solvers.
.gitignore Ignores generated plot artifacts directories.
Comments suppressed due to low confidence (1)

frontend/src/hooks/useSessionPersistence.ts:131

  • baselineParameters is memoized with [parameters] but reads from storage (getLoadedSimulationId(), getSessionParameters(), etc.). This causes the "baseline" to be recomputed as parameters change and, in the session_baseline case, can effectively move the baseline forward as session storage is auto-saved, making hasChanges() compare against the last save rather than the initially loaded baseline. Consider capturing the baseline once during hydration (e.g., store it in a ref/state in the init effect) and make the memo depend on a stable loadedId value instead of parameters (and update the comment which currently claims it only recomputes when loadedId changes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants