Skip to content

Update ApparentPowerConstraintUtil#3401

Merged
sfeilmeier merged 4 commits intoOpenEMS:developfrom
Sn0w3y:patch-21
Nov 14, 2025
Merged

Update ApparentPowerConstraintUtil#3401
sfeilmeier merged 4 commits intoOpenEMS:developfrom
Sn0w3y:patch-21

Conversation

@Sn0w3y
Copy link
Copy Markdown
Collaborator

@Sn0w3y Sn0w3y commented Nov 8, 2025

The getConstraintThroughPoints method performed division by (p2.x - p1.x) without checking if the denominator equals zero. This could occur when two consecutive points on the apparent power circle have the same x-coordinate (active power).

Impact:

  • Division by zero causing Infinity or NaN values
  • Incorrect power distribution in energy management
  • Potential system crashes during power optimization

Fix Implemented

  1. Added division-by-zero check using epsilon comparison (1e-10) for floating-point precision
  2. Special handling for vertical lines - when points have the same x-coordinate, create a constraint that directly constrains active power
  3. Comprehensive test suite with 6 test cases covering:
    • Normal operation with positive apparent power
    • Edge cases (zero, negative, small, large values)
    • Vertical line scenarios
    • Validation that all constraint values are finite (no NaN/Infinity)

The fix ensures the power optimization system can handle all geometric configurations of the apparent power circle without mathematical errors.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 8, 2025

Codecov Report

❌ Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.

❌ Your patch status has failed because the patch coverage (37.50%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3401      +/-   ##
=============================================
- Coverage      59.73%   59.73%   -0.00%     
  Complexity       112      112              
=============================================
  Files           2866     2866              
  Lines         123905   123911       +6     
  Branches        9289     9290       +1     
=============================================
+ Hits           74005    74006       +1     
+ Misses         47113    47111       -2     
- Partials        2787     2794       +7     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Sn0w3y Sn0w3y changed the title Patch 21 Update LSTM Predictor Nov 8, 2025
@Sn0w3y Sn0w3y changed the title Update LSTM Predictor Update ApparentPowerConstraintUtil Nov 8, 2025
Introduced a utility method isCloseToZero in DoubleUtils for comparing doubles to zero with an epsilon threshold. Updated ApparentPowerConstraintUtil to use this method for division by zero checks, improving code clarity and consistency.
@sfeilmeier sfeilmeier merged commit 646b2e3 into OpenEMS:develop Nov 14, 2025
6 of 7 checks passed
@Sn0w3y Sn0w3y deleted the patch-21 branch November 14, 2025 22:20
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.

3 participants