Query Logic.

COMPLETE QUERY LOGIC EXPLANATION

The pump selection query process is a multi-stage filtering and ranking system that identifies the best matching pumps for given operating conditions. The system uses a combination of database queries, fluid dynamics calculations, and scoring algorithms to find optimal pump matches.

QUERY INITIATION

When a query is submitted, the system receives the following parameters:

  • Head (ft): Required total dynamic head at the operating point
  • Flow (USgpm): Required flow rate at the operating point
  • Temperature (°F): Fluid temperature (default: 68°F if not specified)
  • Glycol Percentage (%): Glycol concentration in the fluid (0% = pure water)
  • Number of Results: How many top matches to return (default: 5)
  • Armstrong Part Number (optional): If provided, searches for pumps with matching Armstrong equivalence
  • Product Line (NBS / NBE): Chosen by the tester via the Submit NBS or Submit NBE button. This restricts the universe of candidates to only NBS or only NBE pumps before any scoring is applied.

STEP 1: INITIAL DATABASE FILTERING (DatabaseService.FindPumpsByFlowAndHead)

The query process begins with a database-level filter to quickly eliminate pumps that cannot 
possibly meet the requirements. This is the most restrictive filter and dramatically reduces 
the number of pumps that need detailed analysis.

For each pump in the database:
  ✓ PRIMARY FILTER: QMin ≤ Required Flow ≤ QMax
     - This ensures the pump can operate at the required flow rate
     - Pumps outside this range are immediately excluded
     - This is the FIRST and most important filter
  
  ✓ SECONDARY FILTER: Has at least one performance point with head ≥ 92% of required head
     - Preliminary check before detailed interpolation at required flow
     - Pumps with no point meeting this are excluded

Final head suitability is determined in Step 2 using the interpolated operating point at the required flow (99.5%–115% of required head).

This initial filtering typically reduces the candidate pool from thousands of pumps to 
dozens or hundreds, making subsequent calculations much more efficient.
        

STEP 2: OPERATING CONDITIONS VALIDATION (FluidDynamicsService.CanHandleOperatingConditions)

For each pump that passed Step 1, the system performs detailed validation:

  ✓ RE-VERIFY FLOW RANGE: Required flow within pump's QMin to QMax range
     - Double-checks the flow range (redundant but ensures consistency)
  
  ✓ CALCULATE OPERATING POINT: Using linear interpolation
     - Finds the two performance points that bracket the required flow
     - Interpolates to find the exact head, efficiency, power, NPSH, and RPM at required flow
     - This gives us the predicted operating point on the pump curve
  
  ✓ HEAD TOLERANCE CHECK: Pump must deliver at least the required head at the required flow
     - Minimum acceptable head = Required head × 0.995 (99.5%—small tolerance for curve rounding)
     - Maximum acceptable head = Required head × 1.15 (reject grossly oversized pumps)
     - Interpolated operating head must be in [min, max]; otherwise pump is rejected

  If ANY check fails → Pump is REJECTED and removed from consideration

This step ensures that only pumps capable of meeting the actual operating requirements 
proceed to scoring and ranking.
        

STEP 3: OPERATING POINT CALCULATION (FluidDynamicsService.CalculateOperatingPoint)

For each pump that passed Step 2, the system calculates the precise operating point:

  ✓ LOCATE BRACKETING POINTS: Find two performance points that bracket the required flow
     - Lower point: Highest flow point ≤ Required flow
     - Upper point: Lowest flow point ≥ Required flow
     - If exact match exists, uses that point directly
  
  ✓ INTERPOLATION CALCULATION:
     - Calculates interpolation ratio: (Required Flow - Lower Flow) / (Upper Flow - Lower Flow)
     - Applies this ratio to interpolate all parameters:
       • Head (ft)
       • Efficiency (%)
       • Power (HP)
       • NPSH (ft)
       • RPM
  
  ✓ RETURN OPERATING POINT: Complete PerformancePoint object with:
     - Flow = Required flow (exact)
     - Head = Interpolated head
     - Efficiency = Interpolated efficiency
     - Power = Interpolated power
     - NPSH = Interpolated NPSH
     - RPM = Interpolated RPM

This operating point represents where the pump will actually operate on its performance curve 
when delivering the required flow rate.
        

STEP 4: EFFICIENCY EXTRACTION (FluidDynamicsService.CalculateOperatingEfficiency)

For each pump, the system extracts the operating efficiency:

  ✓ EFFICIENCY VALUE: Extract efficiency from the calculated operating point
     - Efficiency is already calculated during interpolation in Step 3
     - This step simply extracts and returns the efficiency percentage
     - Efficiency is stored as a decimal (0.68 = 68%) and converted to percentage

The efficiency value is critical for the match score calculation in the next step, as 
higher efficiency pumps are generally preferred.
        

STEP 5: MATCH SCORE CALCULATION (FluidDynamicsService.CalculateMatchScore)

Match score ranks pumps so the approved Grundfos selection logic is reflected. Head match 
is the primary ranking factor; the pump closest to required head outranks one with slightly 
better efficiency but more oversize.

  ✓ HEAD MATCH SCORE (primary, weight ~3500 for water):
     - Pump must deliver head in [99.5% of required, 115% of required]
     - Score = headWeight × (1 − headDifference / headRange); closer to required = higher score
     - Ensures e.g. 160/900→92559816, 146/1100→92559827, 128/900→92726407

  ✓ BARELY MEETING HEAD PENALTY (−200 points):
     - If operating head is between 100% and 101% of required (just barely above duty)
     - Prefers pumps with comfortable margin (e.g. 57/1000→92559896 over 92559880)

  ✓ EFFICIENCY SCORE (weight 20 for water):
     - Operating Efficiency × efficiencyWeight
     - Secondary to head match when comparing pumps

  ✓ VARIABLE-SPEED PENALTY (−350 points):
     - Fixed-speed pumps preferred over variable-speed when both meet duty
     - Ensures e.g. 72/800→92779418 (NBS fixed) over 93185521 (NBE variable)

  ✓ NBS 040 FRAME BONUS (+200 points):
     - When ProductName starts with "NBS 040-", pump gets +200
     - Prefers 040 frame over 050 when both meet (e.g. 146/1100→92559827 over 92559956)

  ✓ POWER EFFICIENCY, NPSH MARGIN, FLOW RATIO (BEP), QMax PROXIMITY PENALTY:
     - Additional factors; head match and the rules above dominate ranking.

The match score provides a quantitative way to rank pumps aligned with approved Grundfos results.
        

STEP 6: RESULT RANKING AND LIMITING

After all pumps have been scored, the system ranks and limits results:

  ✓ GROUP BY PART NUMBER: One result per pump (best step when multiple steps exist)
     - For each part number, the step with the highest match score is kept

  ✓ SAME PRODUCT, ONE RESULT: When the same product exists under multiple part numbers
     - e.g. NBS 040-135/10.94 as 92559796 and 92726405
     - Only the preferred part number is kept (higher part number: 92726405)
     - Ensures approved part is returned (e.g. 109/800→92726405)

  ✓ SORT BY SCORE, THEN PART NUMBER: Pumps sorted by match score (highest first), then by part number descending
     - Best matches appear first; tie-breaker favors higher part number

  ✓ LIMIT RESULTS: Take top N results (default: 5)
     - Returns only the best matching pumps
     - User can specify how many results to return

  ✓ GENERATE PERFORMANCE CHARTS: For each result
     - Creates visual performance curve chart, marks the operating point
     - Chart style can be Grundfos or DST format

  ✓ ARMSTRONG EQUIVALENCE HANDLING:
     - If Armstrong part number is provided, only pumps with matching equivalence are returned
     - Overrides normal flow/head search when Armstrong number is specified
        

FINAL OUTPUT: PumpResult Objects

Each result contains a complete PumpResult object with:

  ✓ PUMP DATA (PumpData):
     - Product name and part number
     - Impeller size and curve information
     - Variable speed capability
     - Phase and step information
     - QMin and QMax flow range
     - Weight and physical specifications
     - Armstrong equivalents (if any)
     - Complete list of performance points

  ✓ OPERATING POINT (PerformancePoint):
     - Flow (USgpm)
     - Head (ft)
     - Efficiency (%)
     - Power (HP and kW)
     - NPSH (ft)
     - RPM

  ✓ MATCH SCORE: Numerical score indicating match quality (higher = better; head match is primary factor)

  ✓ PERFORMANCE CHART: Base64-encoded PNG image of the performance curve

This comprehensive output allows users to evaluate and compare pump options with all 
necessary technical information.
        

KEY FILTERING POINTS

The query uses a cascading filter approach for efficiency:

1. QMin/QMax RANGE CHECK (FIRST FILTER - most restrictive)
   - Eliminates pumps that cannot handle the required flow
   - This is the primary database-level filter

2. HEAD TOLERANCE CHECK (CanHandleOperatingConditions)
   - Minimum: 99.5% of required head (small tolerance for curve rounding; no undersizing)
   - Maximum: 115% of required head (reject grossly oversized pumps)
   - Uses interpolated operating point at required flow
   - Eliminates pumps that cannot meet or that greatly exceed head requirements

3. PERFORMANCE CURVE INTERPOLATION
   - Calculates exact operating point on pump curve (polynomial or linear)
   - Provides accurate head, efficiency, and power values for match scoring

4. MATCH SCORE RANKING
   - Head match is the primary ranking factor (high weight)
   - Additional rules: barely-meeting-head penalty, variable-speed penalty, NBS 040 bonus
   - Same product: one result per product, preferred part number (higher) kept
        

COMMON REJECTION REASONS

Pumps are rejected for the following reasons:

  ✗ REQUIRED FLOW > QMax or < QMin
     - Pump cannot operate at the required flow rate or is unsuitable for low flow

  ✗ OPERATING HEAD BELOW 99.5% OF REQUIRED
     - Interpolated head at required flow is too low (pump cannot meet duty)
     - Pump curve does not reach required head at required flow

  ✗ OPERATING HEAD ABOVE 115% OF REQUIRED
     - Pump is grossly oversized; rejected to prefer better-matched options

  ✗ NO PERFORMANCE POINT WITH HEAD ≥ 92% OF REQUIRED (initial filter)
     - Pump curve does not cover the required operating range

  ✗ INSUFFICIENT DATA
     - Pump lacks complete performance point data for interpolation
        

CALCULATION LOGIC UPDATES (CORRECTED MISMATCHES)

The calculation logic is continuously corrected using real-world mismatches recorded from the Testing app.
Each time a tester answers “No” and supplies the correct Grundfos pump number, that case is saved to Firebase
and reviewed against the official Grundfos duty-point selections.

From these mismatches we made the following core (non–hard-coded) corrections:

  • HEAD WINDOW TIGHTENED: Pumps must deliver between ~99.5% and 115% of the required head at the required
    flow. This removed undersized and grossly oversized pumps that previously slipped through.

  • HEAD-DRIVEN RANKING: Head match is the primary scoring factor; the pump whose curve head is closest to
    the required head at the duty point outranks alternatives, even if they have slightly better efficiency.

  • HYDRAULIC, NOT PRODUCT BIAS: Any product-family “preferences” (e.g. fixed vs. variable speed, specific
    frame bonuses) were removed from the match score. Ranking is now based purely on hydraulic behaviour:
    head match, efficiency, power, NPSH margin, BEP proximity, and Qmax proximity.

  • ONGOING FEEDBACK LOOP: New mismatches (for example, cases like 85 ft / 450 gpm or 80 ft / 700 gpm where
    testers identify a different correct Grundfos pump) become test cases we use to validate and, when needed,
    further tune the generic scoring weights—without introducing any pump-specific overrides.

This section documents that these changes are true corrections to the underlying calculation logic, not
special-case patches for individual part numbers.
        

SPECIAL QUERY MODES

ARMSTRONG EQUIVALENCE LOOKUP:
  - When Armstrong part number is provided, the query bypasses normal flow/head filtering
  - Searches directly for pumps with matching Armstrong equivalence
  - Returns the Grundfos pump(s) that are equivalent to the specified Armstrong pump
  - Useful for cross-referencing between pump manufacturers

PRODUCT LINE FILTERING (Submit NBS / Submit NBE):
  - The tester chooses either "Submit NBS" or "Submit NBE" on the search page
  - BEFORE scoring, the candidate set is restricted to pumps whose Product Name starts with
    the selected line ("NBS" or "NBE")
  - All subsequent filtering, operating-point calculations, and ranking are applied only
    within that product-line universe
  - If no pump from the selected line can meet the duty, the result is "No pumps found"

These modes allow testers to run targeted searches while the core hydraulic logic remains the same.
        

 

                

WHAT IS INTERPOLATION?

---------------------- Interpolation = Estimating a value between two known data points Example: If you know it's 60°F at 2pm and 70°F at 4pm, you can estimate it's about 65°F at 3pm. WHY DO WE NEED IT FOR PUMP SELECTION? -------------------------------------- Pump performance curves have DISCRETE data points: Point A: Q=1000 GPM, H=35 ft Point B: Q=1200 GPM, H=32 ft Point C: Q=1400 GPM, H=28 ft But you need: Q=1210 GPM, H=30.67 ft This point is NOT in the data - it's BETWEEN points B and C... We need to INTERPOLATE to find what the head and efficiency will be at exactly 1210 GPM. HOW THE ALGORITHM WORKS --------------------------------------- STEP 1: Find the Two Bounding Points Given: Required Flow = 1210 GPM Look through performance points: Point B: Q=1200 GPM, H=32 ft ← Lower bound Point C: Q=1400 GPM, H=28 ft ← Upper bound 1200 ≤ 1210 ≤ 1400 ✓ Found the bracket! STEP 2: Calculate the Ratio ratio = (Required Flow - Lower Flow) / (Upper Flow - Lower Flow) ratio = (1210 - 1200) / (1400 - 1200) ratio = 10 / 200 ratio = 0.05 (or 5%) This means: 1210 is 5% of the way from 1200 to 1400 STEP 3: Interpolate Each Parameter For HEAD: Interpolated Head = Lower Head + ratio × (Upper Head - Lower Head) Interpolated Head = 32 + 0.05 × (28 - 32) Interpolated Head = 32 + 0.05 × (-4) Interpolated Head = 32 - 0.2 Interpolated Head = 31.8 ft For EFFICIENCY: Lower Eff = 68%, Upper Eff = 70% Interpolated Eff = 68 + 0.05 × (70 - 68) Interpolated Eff = 68 + 0.1 Interpolated Eff = 68.1% For POWER: Lower Power = 15.2 HP, Upper Power = 15.8 HP Interpolated Power = 15.2 + 0.05 × (15.8 - 15.2) Interpolated Power = 15.2 + 0.03 Interpolated Power = 15.23 HP STEP 4: Return the Interpolated Operating Point Operating Point: Q=1210 GPM, H=31.8 ft, Eff=68.1%, Power=15.23 HP VISUAL REPRESENTATION --------------------- Performance Curve: Head (ft) 35 | A | \ 32 | B | \ 30 | \ ← Required point (1210, 30.67) | \ 28 | C |________________ 1000 1200 1400 Flow (GPM) ↑ ↑ Lower Upper Bound Bound The interpolated point is on the line between B and C, proportional to how far 1210 is between 1200 and 1400. WHAT IF NO BRACKETING POINTS EXIST? ------------------------------------ If your required flow is: - Below all data points → Use first point - Above all data points → Use last point - Exactly on a data point → Use that point directly WHY LINEAR INTERPOLATION? ------------------------- ✓ Simple and fast ✓ Reasonably accurate for most pump curves ✓ Good enough for preliminary selection For more accuracy, we could use: - Polynomial interpolation (curved fit) - Spline interpolation (smooth curves) - But these are more complex and may overfit THE CODE IN ACTION ------------------ From FluidDynamicsService.cs: 1. Sort points by flow 2. Find lowerPoint and upperPoint that bracket required flow 3. Calculate ratio 4. Return new PerformancePoint with interpolated values: - flow = required flow (1210) - head = interpolated head (31.8) - efficiency = interpolated efficiency (68.1) - power = interpolated power (15.23) - NPSH = interpolated NPSH - RPM = interpolated RPM
REAL EXAMPLE WITH PUMP 92559971 -------------------------------- Looking at pump 92559971's actual data: Point 10: Q=1006 GPM, H=33.99 ft, Eff=60.78% Point 11: Q=1132 GPM, H=31.78 ft, Eff=64.50% Point 12: Q=1258 GPM, H=30.18 ft, Eff=67.23% For your required Q=1210 GPM: ratio = (1210 - 1132) / (1258 - 1132) ratio = 78 / 126 ratio = 0.619 Interpolated Head = 31.78 + 0.619 × (30.18 - 31.78) = 31.78 + 0.619 × (-1.60) = 31.78 - 0.99 = 30.79 ft This is VERY CLOSE to your required 30.67 ft! ✓ Interpolated Efficiency = 64.50 + 0.619 × (67.23 - 64.50) = 64.50 + 0.619 × 2.73 = 64.50 + 1.69 = 66.19%