The comp_base submodule
Base classes and adapters for hydraulic components.
This module defines the foundational component API used across fluidsolve.
Most concrete hydraulic elements (resistances, pumps, valves, paths, etc.)
inherit from Comp_Base and specialize its physics methods.
Core responsibilities of Comp_Base:
standardized argument parsing and unit normalization,
shared component metadata (name, group, part, ports, sign, state),
default head/pressure/flow calculation interface,
cloning and human-readable representation helpers.
Physics conventions:
calcH(Q, sense, pin, pout)returns head change,calcP(...)derives pressure change from head and medium density,calcQ(H, ...)numerically invertscalcHwith Newton-Raphson,signconvention:+1for sources (pump-like),-1for resistances.
Extension pattern:
Subclass
Comp_Base.Override fixed class attributes (group/part/prefix/ports/sign).
Override
calcH(and optional helpers such ascalcK).Keep constructor validation via
GetArgs+vFunfor consistency.
Additional utility classes:
Comp_Dummy: placeholder/no-op component.Comp_Reverse: adapter that reverses flow-direction use of a wrapped component while delegating the rest of its interface.
Example:
class MyLoss(Comp_Base):
_group = 'Resistance'
_part = 'MyLoss'
def calcH(self, Q, sense=1, pin=1, pout=2):
return 0.5 * sense * u.m
- class fluidsolve.comp_base.Comp_Base(**kwargs: Any)[source]
Bases:
objectBase hydraulic component class used by specific component types.
- Parameters:
name (str, optional) – Component name.
state (int, optional) – Component state (for example valve position).
medium (str | flsme.Medium, optional) – Fluid medium.
e (int | float | Quantity, optional) – Absolute roughness.
- Returns:
None
- _group: str = 'Base'
- _part: str = 'Base'
- _prefix: str = 'X'
- _nports: int = 2
- _ports: list = [[1, 2]]
- _conn: dict = {1: [[1, 2]]}
- _sign: float = -1.0
- property name: str
Component name
- property group: str
Component group
- property part: str
Component part type
- property nports: int
Number of ports
- property ports: list
Component ports
- connections(state: int | None = None)[source]
Return internal port connections for the given state. Default: simple 2-port component
- property e: Quantity
Absolute roughness property.
- property sign: float
Energy sign: +1 = pump / energy source -1 = resistance (bends, tubes) For static height this depends on direction (up = -1.0, down = +1.0). Therefore the sign is handled in the static head term and the component sign remains +1.0.
- property isSource: bool
Energy sign: +1 = pump / energy source -1 = resistance (bends, tubes) For static height this depends on direction (up = -1.0, down = +1.0). Therefore the sign is handled in the static head term and the component sign remains +1.0.
- property state: int | float
Component state (e.g. valve position)
- calcH(Q: int | float | Quantity, sense: int = 1, pin: int = 1, pout: int = 2) Quantity[source]
Calculate head change.
- Parameters:
Q – Flow rate.
sense – +1 if flow is from pin to pout, -1 for reverse flow.
pin – Inlet port number.
pout – Outlet port number.
- Returns:
Head change in meters.
- Return type:
Quantity
- calcP(Q: int | float | Quantity, sense: int = 1, pin: int = 1, pout: int = 2) Quantity[source]
Calculate pressure change.
- Returns:
Pressure change.
- Return type:
Quantity
- calcQ(H: Quantity, guess: Any | None = None, sense: int = 1, pin: int = 1, pout: int = 2) Quantity[source]
Calculate flow rate for a given head.
- Parameters:
H – Head.
guess – Initial flow guess.
sense – Flow direction.
pin – Inlet port number.
pout – Outlet port number.
- Returns:
Flow rate in m3/h.
- Return type:
Quantity
- class fluidsolve.comp_base.Comp_Dummy(**kwargs: Any)[source]
Bases:
Comp_BaseDummy / empty component.
- _part: str = 'Dummy'
- class fluidsolve.comp_base.Comp_Reverse(**kwargs: Any)[source]
Bases:
Comp_BaseAdapter that reverses flow direction of a wrapped component.
- _part: str = 'Reverse'