Skip to content
MANUAL

Connectors and Networks ​

A connector defines how a component interacts with its surroundings. connect(...) joins compatible connectors and generates the equations implied by their field qualifiers. Use physical connectors for conserved quantities such as current, and signal connectors for commands and measurements.

Physical ports and conservation ​

An electrical pin carries voltage and current: Download as a Dyad projectlanguage_connectors.zipOpen in Dyad Studio

dyad
connector Pin
  potential v::Real
  flow i::Real
end

Connecting pins makes their voltages equal and generates current conservation. Current is positive into a component. Keep this convention at every component boundary; the compiler accounts for hierarchy when connecting an external port to an internal part.

A complete network ​

The following definitions form a small resistive circuit. They share the Pin definition above. The viewers show code beside the diagram when space allows; on narrower screens, use the Diagram and Code tabs.

dyad
component Resistor
  parameter R::Real = 10
  p = Pin()
  n = Pin()
relations
  p.v - n.v = R * p.i
  p.i + n.i = 0
end

component VoltageSource
  parameter V::Real = 5
  p = Pin()
  n = Pin()
relations
  p.v - n.v = V
  p.i + n.i = 0
end

component Ground
  p = Pin()
relations
  p.v = 0
end

In the viewer's code, ResistiveCircuit assembles the three parts with two connect calls. connect(source.p, load.p) joins the positive pins; connect(source.n, load.n, ground.p) joins the negative pins and ground. Select a part in the diagram to inspect its parameters.

The ground fixes the negative pins at 0 V. The source sets the positive pins to 5 V, so the 10 Ω load draws 0.5 A. The three-port connection creates one connection set: its voltages are equal, and its currents satisfy source.n.i + load.n.i + ground.p.i = 0.

Physical connections express simultaneous constraints. A resistor can carry either sign of current; the connector does not impose a direction of causality on the solver.

Use partial components to share port declarations and conservation equations across a family of parts.

Causal signals ​

Signal connectors express a producer–consumer relationship. An output supplies a value; connected inputs receive it. A signal connection equates values without a conservation sum.

dyad
connector SignalInput
  input value::Real
end

connector SignalOutput
  output value::Real
end

component ConstantSignal
  parameter k::Real = 1
  y = SignalOutput()
relations
  y.value = k
end

component Gain
  parameter k::Real = 2
  u = SignalInput()
  y = SignalOutput()
relations
  y.value = k * u.value
end

The viewer's SignalChain component assembles these parts with connect(source.y, gain.u). Follow that connection in the diagram, then select gain to inspect its multiplier k. With the default parameters, gain.y.value = 2.

Give a signal connection a single producer. A signal input is useful for commands and measurements; a physical flow field is useful for conserved transport.

The standard libraries provide signal connector types, including Dyad.RealInput and Dyad.RealOutput. For clock compatibility and sampling between continuous and discrete models, see Discrete-Time Modeling.

Connector field reference ​

Field qualifierConnection meaningExample
potentialConnected values are equalVoltage, pressure
flowSigned flows obey conservationCurrent, mass flow
inputThe component receives a signalController measurement
outputThe component supplies a signalController command
streamA flow transports an intensive propertySpecific enthalpy
pathA network shares a value with one defining sourceShared configuration

Stream transport ​

A stream field describes the property of material leaving a component through a port. The associated flow determines transport direction. A connector containing stream fields has one flow field.

For a fluid port with stream h_outflow, instream(port.h_outflow) gives the incoming mixture seen at that port. It combines the contributions from the other connected ports according to stream semantics. This lets a component describe flow reversal using one interface.

Do not equate every connected h_outflow manually: outgoing fluid from different components can have different properties. Use connect and the stream operators to express mixing and transport. The Media and Fluids guide develops the library pattern, including the port's shared medium.

Shared network choices ​

A path field lets connected components share one definition of a configuration value. For example, a fluid circuit needs a consistent medium definition across its boundaries, pipes, and storage components. A path can carry that choice through the circuit, with exactly one defining source.

Consider a simple liquid circuit with an inlet, a resistance, and an outlet. Each fluid port declares path cp::Real for the liquid's specific heat capacity. The containing model defines final path cp::Real = 4184.0, in J/(kg·K). These relations carry that definition through the circuit:

RelationWhat it joins
continuity(cp, inlet.port.cp)The circuit's definition and the inlet port
connect(inlet.port, resistance.a)The inlet port and the resistance's first port
continuity(a.cp, b.cp) inside the resistanceThe resistance's two path fields
connect(resistance.b, outlet.port)The resistance's second port and the outlet port

Both boundaries now read port.cp as 4184.0 when calculating outflow enthalpy. Changing the circuit's single definition changes the value used at both boundaries. Each boundary still supplies its own temperature: the path shares a property constant, while the stream field describes transported enthalpy.

The Media and Fluids example contains this complete circuit and its interactive diagram. It also explains the explicit structural forwarding used by the current MediaComponents and FluidComponents development sources.

Build interfaces that compose ​

Expose the physical ports where material or energy crosses a subsystem boundary, and signal ports where another component supplies a command or receives a measurement. Give every physical port a documented sign convention. Choose boundary components that provide the reference, source, or sink needed to make a network well posed.

Port icons and positions are stored as metadata on the connector instances. They affect the graphical representation; connect defines the network. See Graphical Models and Metadata.