## Define Relationship Between Component Variables and Nodes

### Connecting Component Variables to the Domain

After you declare the component Through and Across variables, you need to connect them to the domain Through and Across variables. You do this by establishing the relationship between the component variables and its nodes, which carry the Through and Across variables for the domain:

To establish the relationship between the Through variables, use the

`branches`

section of the component file. If the component has multiple nodes, indicate branches by writing multiple statements in the`branches`

section. For syntax and examples, see the`branches`

reference page.To establish the relationship between the Across variables, use the

`equations`

section of the component file. Add an equation that connects the component Across variable with the respective variables at the component nodes. If there is more than one Across variable, add multiple equations, connecting each variable with its respective nodes. The`equations`

section can also contain other equations that define the component action. For more information, see Defining Component Equations.

### Workflow from Domain to Component

Propagate the domain Through and Across variables into a component.

Declare the Across and Through variables in a domain file (or use an existing domain; for a complete listing of the Foundation domains, see Foundation Domain Types and Directory Structure).

For example, the following domain file, named

`rotational.ssc`

, declares angular velocity,`w`

, as an Across variable and torque,`t`

, as a Through variable.domain rotational % Define the mechanical rotational domain % in terms of across and through variables variables w = { 1 , 'rad/s' }; % angular velocity end variables(Balancing = true) t = { 1 , 'N*m' }; % torque end end

Declare the nodes in a component file and associate them with the domain, for example:

nodes node1 = MyNamespace.rotational; node2 = MyNamespace.rotational; end

Once a node is associated with a domain, it:

Carries each of the domain Across variables as a measurable quantity. In this example, each of the nodes carries one Across variable,

`w`

.Writes a conserving equation for each of the domain Through variables. In this example, there is one Through variable,

`t`

, and therefore each node writes one conserving equation. A conserving equation is a sum of terms that is set to zero`(node.t == 0)`

. The`branches`

section in the component file establishes the terms that are summed to zero at the node.

Declare the corresponding variables in the component file, for example:

variables w = { 1 , 'rad/s' }; % angular velocity t = { 1 , 'N*m' }; % torque end

The names of the component variables do not have to match those of the domain Across and Through variables, but the units must be commensurate. At this point, there is no connection between the component variables and the domain variables.

Establish the relationship between the Through variables by using the

`branches`

section of the component file. For example:branches t : node1.t -> node2.t; % t - Through variable from node1 to node2 end

This branch statement declares that

`t`

flows from`node1`

to`node2`

. Therefore,`t`

is subtracted from the conserving equation identified by`node1.t`

, and`t`

is added to the conserving equation identified by`node2.t`

. For more information and examples, see the`branches`

reference page.Establish relationship between the Across variables in the

`equations`

section of the component file, for example, by adding the following equation:equations w == node1.w - node2.w; % w - Across variable between node1 and node2 [...] % more equations describing the component behavior, as necessary end

### Connecting One Through and One Across Variable

In this example, `r`

and `c`

are
rotational nodes, while `t`

and `w`

are
component variables for torque and angular velocity, respectively.
The relationship between the variables and nodes is established in
the `branches`

and the `equations`

sections:

component spring nodes r = foundation.mechanical.rotational.rotational; c = foundation.mechanical.rotational.rotational; end [...] variables [...] t = { 0, 'N*m' }; % torque through w = { 0, 'rad/s' }; % velocity across end branches t : r.t -> c.t; % t - Through variable from r to c end equations w == r.w - c.w; % w - Across variable between r and c [...] % more equations here end end

### Connecting Two Through and Two Across Variables

This example shows setting up the Across and Through variables
of a component with two electrical windings, such as a transformer
or mutual inductor. The component has four electrical nodes, and each
winding has its own voltage and current variables. The relationship
between the variables and nodes is established in the `branches`

and
the `equations`

sections:

component two_windings nodes p1 = foundation.electrical.electrical; n1 = foundation.electrical.electrical; p2 = foundation.electrical.electrical; n2 = foundation.electrical.electrical; end [...] variables i1 = { 0, 'A' }; v1 = { 0, 'V' }; i2 = { 0, 'A' }; v2 = { 0, 'V' }; end [...] branches i1 : p1.i -> n1.i; % Current through first winding i2 : p2.i -> n2.i; % Current through second winding end equations v1 == p1.v - n1.v; % Voltage across first winding v2 == p2.v - n2.v; % Voltage across second winding [...] % more equations here end end