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 inverts calcH with Newton-Raphson,

  • sign convention: +1 for sources (pump-like), -1 for resistances.

Extension pattern:

  1. Subclass Comp_Base.

  2. Override fixed class attributes (group/part/prefix/ports/sign).

  3. Override calcH (and optional helpers such as calcK).

  4. Keep constructor validation via GetArgs + vFun for 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: object

Base 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
__init__(**kwargs: Any) None[source]
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 medium: Medium

Medium property.

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

clone() Any[source]

Return a deep copy of the component.

__str__() str[source]

Return str(self).

toString(detail: int = 0) str[source]

Return a string representation.

class fluidsolve.comp_base.Comp_Dummy(**kwargs: Any)[source]

Bases: Comp_Base

Dummy / empty component.

_part: str = 'Dummy'
__init__(**kwargs: Any) Any[source]

Initialize without requiring additional data.

class fluidsolve.comp_base.Comp_Reverse(**kwargs: Any)[source]

Bases: Comp_Base

Adapter that reverses flow direction of a wrapped component.

_part: str = 'Reverse'
__init__(**kwargs: Any) Any[source]
calcK(Q: Quantity, sense: int = 1, pin: int = 1, pout: int = 2) Any[source]
calcH(Q: Any, sense: int = 1, pin: int = 1, pout: int = 2) float[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

toString(detail: int = 0) str[source]

Return a string representation.

__getattr__(name: Any) Any[source]

Delegate unknown attributes to the wrapped component.