Package ptolemy.actor

Examples of ptolemy.actor.TypedIORelation


        if (outputRelations.isEmpty()) {
            return;
        }

        TypedIORelation outputRelation = (TypedIORelation) outputRelations
                .get(0);
        Iterator inputPorts = inputPortList().iterator();

        while (inputPorts.hasNext()) {
            TypedIOPort port = (TypedIOPort) inputPorts.next();
            _outputWidth += port.getWidth(); // includes all linked relations
        }

        outputRelation.setWidth(_outputWidth);

        // TODO: figure out how to obey if the output relation width is
        // set (if isWidthFixed() would return a reliable true...)
    }
View Full Code Here


            // Integrators
            for (int i = 0; i < n; i++) {
                integrators[i] = new Integrator(this, "state_" + i);
                integrators[i].initialState.setExpression("initialStates(0,"
                        + i + ")");
                states[i] = new TypedIORelation(this, "relation_state_" + i);
                integrators[i].output.link(states[i]);

                // One adder per integrator.
                stateAdders[i] = new AddSubtract(this, "stateAdder_" + i);
                connect(stateAdders[i].output, integrators[i].input);
                stateOutput.link(states[i]);
            }

            // State feedback
            Scale[][] feedback = new Scale[n][n];

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    // We don't create the Scale if the corresponding element
                    // in the A matrix is 0.
                    feedback[i][j] = new Scale(this, "feedback_" + i + "_" + j);
                    feedback[i][j].factor.setExpression("A(" + i + ", " + j
                            + ")");
                    feedback[i][j].input.link(states[j]);
                    connect(feedback[i][j].output, stateAdders[i].plus);
                }
            }

            // Inputs
            Scale[][] inputScales = new Scale[n][m];
            IORelation[] inputs = new IORelation[m];

            for (int j = 0; j < m; j++) {
                inputs[j] = new TypedIORelation(this, "relation_input_" + j);
                input.link(inputs[j]);

                // Create input scales.
                for (int i = 0; i < n; i++) {
                    // We create a scale for each input even if the
View Full Code Here

                states[i] = ((StringToken) stateNames.getElement(i))
                        .stringValue().trim();
                integrators[i] = new Integrator(this, states[i]);
                integrators[i].initialState.setExpression("initialStates(0,"
                        + i + ")");
                stateRelations[i] = new TypedIORelation(this, "relation_"
                        + states[i]);

                integrators[i].output.link(stateRelations[i]);

                // One Expression per integrator.
                equations[i] = new Expression(this, states[i] + "_dot");
                equations[i].expression
                        .setExpression(((StringToken) ((Parameter) getAttribute(states[i]
                                + "_dot")).getToken()).stringValue());

                //FIXME: Why should I set type here?
                equations[i].output.setTypeEquals(BaseType.DOUBLE);
                connect(equations[i].output, integrators[i].input);
            }

            // Inputs
            String[] inputs = new String[m];
            IORelation[] inputRelations = new IORelation[m];
            Iterator inputPorts = inputPortList().iterator();
            int inputIndex = 0;

            while (inputPorts.hasNext()) {
                inputs[inputIndex] = ((NamedObj) inputPorts.next()).getName();
                inputRelations[inputIndex] = new TypedIORelation(this,
                        "relation_" + inputs[inputIndex]);
                getPort(inputs[inputIndex]).link(inputRelations[inputIndex]);
                inputIndex++;
            }
View Full Code Here

        NamedObj container = getContainer();
        if (container instanceof TypedCompositeActor) {
            // If the container is not a typed composite actor, then don't create
            // a relation. Probably the container is a library.
            try {
                _relation = new TypedIORelation(
                        (TypedCompositeActor) container, container
                                .uniqueName("publisherRelation"));
                // Prevent the relation and its links from being exported.
                _relation.setPersistent(false);
                // Prevent the relation from showing up in vergil.
View Full Code Here

            while (ports.hasNext()) {
                TypedIOPort port = (TypedIOPort) ports.next();
                TypedIOPort newPort = (TypedIOPort) port.clone(workspace());
                newPort.setContainer(_embeddedActor);
                for (int channel = 0; channel < port.getWidth(); channel++) {
                    TypedIORelation relation = new TypedIORelation(this,
                            "relation" + i++);
                    port.link(relation);
                    newPort.link(relation);
                }
            }
View Full Code Here

            while (ports.hasNext()) {
                TypedIOPort port = (TypedIOPort) ports.next();
                List insideRelationList = port.insideRelationList();
                Iterator insideRelationIterator = insideRelationList.iterator();
                while (insideRelationIterator.hasNext()) {
                    TypedIORelation relation = (TypedIORelation) insideRelationIterator
                            .next();
                    relation.setContainer(null);
                }
            }
            // If an exception occurred earlier, then
            // _embeddedActor may be null, and we don't want
            // the null pointer exception masking the real
View Full Code Here

                states[i] = ((StringToken) stateNames.getElement(i))
                        .stringValue().trim();
                integrators[i] = new Integrator(this, states[i]);
                integrators[i].initialState.setExpression("initialStates(0,"
                        + i + ")");
                stateRelations[i] = new TypedIORelation(this, "relation_"
                        + states[i]);

                integrators[i].state.link(stateRelations[i]);

                // One Expression per integrator.
                equations[i] = new Expression(this, states[i] + "_dot");
                equations[i].expression
                        .setExpression(((StringToken) ((Parameter) getAttribute(states[i]
                                + "_dot")).getToken()).stringValue());

                //FIXME: Why should I set type here?
                equations[i].output.setTypeEquals(BaseType.DOUBLE);
                connect(equations[i].output, integrators[i].derivative);
            }

            // Inputs
            String[] inputs = new String[m];
            IORelation[] inputRelations = new IORelation[m];
            Iterator inputPorts = inputPortList().iterator();
            int inputIndex = 0;

            while (inputPorts.hasNext()) {
                inputs[inputIndex] = ((NamedObj) inputPorts.next()).getName();
                inputRelations[inputIndex] = new TypedIORelation(this,
                        "relation_" + inputs[inputIndex]);
                getPort(inputs[inputIndex]).link(inputRelations[inputIndex]);
                inputIndex++;
            }
View Full Code Here

        // Make the connections.
        // The ports are public members of these classes.
        // The first connection is a three way connection, so we have
        // to create a relation and then link to it.
        TypedIORelation node = (TypedIORelation) newRelation("node");
        ramp.output.link(node);
        expInput.link(node);
        polarToCartesian.angle.link(node);

        // The rest of the connections are point-to-point, so we can use
View Full Code Here

        // Refer directly to the buffer in the _model
        int channel = 0;

        for (Iterator relations = port.linkedRelationList().iterator(); relations
                .hasNext();) {
            TypedIORelation relation = (TypedIORelation) relations.next();

            int bufferSize = _getBufferSize(relation);

            // remember the size of the buffer.
            bufferSizeValue = IntConstant.v(bufferSize);

            for (int i = 0; i < relation.getWidth(); i++, channel++) {
                Value channelValue = IntConstant.v(channel);

                // Load the correct index into indexLocal
                body.getUnits().insertBefore(
                        Jimple.v().newAssignStmt(
View Full Code Here

    private void _createBuffers() {
        // First create the circular buffers for communication.
        // Loop over all the relations, creating buffers for each channel.
        for (Iterator relations = _model.relationList().iterator(); relations
                .hasNext();) {
            TypedIORelation relation = (TypedIORelation) relations.next();

            int bufferSize = _getBufferSize(relation);

            // Determine the types that the relation is connected to.
            Map typeMap = new HashMap();
            List destinationPortList = relation.linkedDestinationPortList();

            for (Iterator destinationPorts = destinationPortList.iterator(); destinationPorts
                    .hasNext();) {
                TypedIOPort port = (TypedIOPort) destinationPorts.next();
                ptolemy.data.type.Type type = port.getType();
                typeMap.put(type.toString(), type);
            }

            for (Iterator types = typeMap.keySet().iterator(); types.hasNext();) {
                ptolemy.data.type.Type type = (ptolemy.data.type.Type) typeMap
                        .get(types.next());
                RefType tokenType = PtolemyUtilities
                        .getSootTypeForTokenType(type);
                Type arrayType = ArrayType.v(tokenType, 1);
                String fieldName = relation.getName() + "_bufferLocal";

                for (int i = 0; i < relation.getWidth(); i++) {
                    SootField field = new SootField(InlinePortTransformer
                            .getBufferFieldName(relation, i, type), arrayType,
                            Modifier.PUBLIC);
                    _modelClass.addField(field);
View Full Code Here

TOP

Related Classes of ptolemy.actor.TypedIORelation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.