Main Content

Composite Domains

You can declare a composite domain as a hierarchy of other, primitive or composite, domains. A primitive domain is a regular Foundation or custom domain that is defined by its Through and Across variables. It has corresponding nodes of a single type: electrical, gas, and so on. A composite domain is a textual equivalent of a bus port on a rigid Simscape Bus block. Composite domains have nodes that represent a bundle of connections, possibly of different types. For example, this composite domain combines two primitive domain types: mechanical translational and electrical.

domain MechElec
% Mechanical Translational and Electrical Domain
    nodes
        m = foundation.mechanical.translational.translational;
        e = foundation.electrical.electrical;
    end
end

To use a composite domain, design composite components with external ports that belong to that domain type. Connect these components to each other and to Simscape Bus or Connection Port blocks with corresponding rigid interfaces. For more information, see Example of a Custom Composite Domain.

Syntax Rules

A composite domain cannot declare inputs, outputs, variables, parameters, or equations. The only section allowed is nodes.

Composite domain nodes can refer to:

  • Foundation domains.

  • Primitive custom domains.

  • Other composite domains.

You can use composite domains when creating arrays of nodes. For example, if you declare a composite domain MechElec, you can then use it to declare an array of nodes in a component Comp1:

component Comp1
    parameters
        N = 3;
    end
    nodes
        me = repmat(MechElec, N,1);         % 1xN array of MechElec
    end
end

However, you cannot declare arrays of nodes inside a composite domain.

Example of a Custom Composite Domain

Declare a composite domain that combines two primitive domain types: mechanical translational and electrical.

domain MechElec
% Mechanical Translational and Electrical Domain
    nodes
        m = foundation.mechanical.translational.translational;
        e = foundation.electrical.electrical;
    end
end

Design composite components with external ports that belong to that domain type. In this example, create two components: a mass-spring-resistor and a source to drive it.

component MassSpringResistor
% Mass-Spring-Resistor component
    nodes
        me1 = MechElec; %L:Left
        me2 = MechElec; %R:Right
    end

    components(ExternalAccess = observe)
        s = foundation.mechanical.translational.spring;
        m = foundation.mechanical.translational.mass;
        r = foundation.electrical.elements.resistor;
    end

    connections
        connect(s.R, m.N);
        connect(s.C, me2.m);
        connect(m.N, me1.m);
        connect(r.p, me1.e);
        connect(r.n, me2.e);
    end
end
component Source
% Source
    nodes
        me1 = MechElec; %L:Left
        me2 = MechElec; %R:Right
    end

    components(ExternalAccess = observe)
        s = foundation.mechanical.sources.velocity;
        r = foundation.electrical.sources.ac_voltage;
    end

    connections
        connect(s.R, me1.m);
        connect(r.p, me1.e);
        connect(s.C, me2.m);
        connect(r.n, me2.e);
    end
end

Both of these components have nodes that belong to the MechElec composite domain.

Create a new model. Use two Simscape Component blocks to add the MassSpringResistor and the Source components to the model. Connect the blocks as shown in the diagram.

Block diagram with two Simscape Component blocks connected

Note that the blocks have rigid bus ports, the same type of port as the bus port of a Simscape Bus block with rigid interface, and when you connect them together, the connection line is thick, like a bus connection.

Add a Simscape Bus block to the model.

Block diagram with Simscape Bus block added

Configure the Simscape Bus block. Double-click the block. From the drop-down list under Connection type, select CompositeConnection: <domain name>, enter MechElec as the domain name, and click Apply.

If the domain source file is located inside a namespace, include the full path from the top-level namespace folder. For example, if you package the MechElec.ssc domain file and the two component files in a namespace folder called +MechElecBlocks, enter the domain name as MechElecBlocks.MechElec.

Simscape Bus block dialog with rigid interface applied

Note that the block bus port display has changed to rigid, and the block now has two children ports, e and m, according to the composite domain declaration.

Block diagram with Simscape Bus block configured

Add the Electrical Reference, Mechanical Translational Reference, and the Solver Configuration blocks to the model. Connect the blocks as shown.

Block diagram with all the blocks connected

You must connect the Solver Configuration block to a primitive domain connection line, such as a mechanical translational line in this example. Connecting the Solver Configuration block to a composite connection line is not supported.

See Also

|

Topics