# Modelica Fixed/Free — sources consulted (Entropyk alignment)

## Official MSL (fetched)

1. **Package** `Modelica.Fluid.Sources`  
   https://doc.modelica.org/om/Modelica.Fluid.Sources.html

2. **`MassFlowSource_T`** — prescribed **mass flow + temperature** (not pressure)  
   https://doc.modelica.org/om/Modelica.Fluid.Sources.MassFlowSource_T.html  

   Quote from OpenModelica HTML (fetched 2026-07-17):

   > Models an ideal flow source, with prescribed values of flow rate, temperature…  
   > - Prescribed mass flow rate.  
   > - Prescribed temperature.

   No “prescribed pressure” in the component description.

3. **`Boundary_pT`** — prescribed **pressure + temperature** (not ṁ)  
   https://doc.modelica.org/om/Modelica.Fluid.Sources.Boundary_pT.html  

   Quote (fetched 2026-07-17):

   > - Prescribed boundary pressure.  
   > - Prescribed boundary temperature.

4. **Context7** `/modelica/modelicastandardlibrary` — `SimplePipeline` example:

   `Boundary_pT` → `StaticPipe` (wall friction / ΔP) → `Boundary_pT`  

   Double Fixed P is legal **only** with hydraulic resistance between the ends.
   An isobaric secondary path must **not** Fixed-P both ends.

## Community

Rene Just Nielsen — legal pipe-end combinations:  
https://stackoverflow.com/questions/79349553/how-pressure-and-flow-ports-are-different-in-modelica

| Inlet | Outlet | OK? |
|-------|--------|-----|
| Boundary_pT | Boundary_pT | Yes → ṁ from ΔP |
| Boundary_pT | MassFlowSource_T | Yes |
| MassFlowSource_T | Boundary_pT | Yes |
| MassFlowSource_T | MassFlowSource_T | **No** |

Quote: *“There is no boundary component specifying both mass flow rate and pressure.”*

## Entropyk mapping

| Mode | Source | Sink | HX secondary |
|------|--------|------|--------------|
| MassFlowSource_T (default) | Fixed T, Fixed ṁ, **Free P** | Fixed P (anchor), Free T_out | `P_out−P_in+ΔP_sec(ṁ)=0` |
| Boundary_pT + friction | Fixed P, Fixed T, Free ṁ | Fixed P | Needs frictional ΔP (pipe / HX) |
| T_out rating | Free ṁ, Free P | Fixed P + Fixed T_out | Same secondary momentum |

Secondary water ΔP (quadratic, Modelica `dp_nominal` style):
`secondary_rated_pressure_drop_pa` + `secondary_rated_m_flow_kg_s`
— **not** refrigerant `dp_model=msh` (tube two-phase only).

### Why HX secondary isobaric P was missing (bug)

Entropyk stores **two edges** on a water loop (`source→HX`, `HX→sink`), each with its own `P`.  
Without `P_out − P_in = 0` on the HX, Free P on the source left `P_in` unconstrained → DoF under by 1 per loop.

Modelica closes that via the connection/pipe graph; Entropyk now closes it on Condenser / Evaporator / FloodedEvaporator secondary residuals.

Implementation:

- UI: `apps/web/src/lib/boundaryFix.ts`
- Components: `condenser.rs`, `evaporator.rs`, `flooded_evaporator.rs` (`n_secondary` + residuals)
- Ledger: `apps/web/src/lib/dofLedger.ts`
