示例#1
0
        getOutgoingCurrentTerms: function(node) {
            var batteries = this.batteries;
            var resistors = this.resistors;
            var nodeTerms = [];
            var i;

            for (i = 0; i < batteries.length; i++) {
                if (batteries[i].node0 === node)
                    nodeTerms.push(Term.createWithOwner(this, 1, UnknownCurrent.createWithOwner(this, batteries[i])));
            }

            for (i = 0; i < resistors.length; i++) {
                // Treat resistors with R=0 as having unknown current and v1=v2
                if (resistors[i].node0 === node && resistors[i].resistance === 0)
                    nodeTerms.push(Term.createWithOwner(this, 1, UnknownCurrent.createWithOwner(this, resistors[i])));
            }

            for (i = 0; i < resistors.length; i++) {
                if (resistors[i].node0 === node && resistors[i].resistance !== 0) {
                    nodeTerms.push(Term.createWithOwner(this, -1 / resistors[i].resistance, UnknownVoltage.createWithOwner(this, resistors[i].node1)));
                    nodeTerms.push(Term.createWithOwner(this,  1 / resistors[i].resistance, UnknownVoltage.createWithOwner(this, resistors[i].node0)));
                }
            }

            return nodeTerms;
        },
示例#2
0
        getEquations: function() {
            var list = [];
            var i;

            var referenceNodes = this.getReferenceNodes();
            var nodeSet = this.getNodeSet();
            var batteries = this.batteries;
            var resistors = this.resistors;

            // Reference node in each connected component has a voltage of 0
            for (i = 0; i < referenceNodes.length; i++)
                list.push(Equation.createWithOwner(this, 0, Term.createWithOwner(this, 1, UnknownVoltage.createWithOwner(this, referenceNodes[i]))));

            // For each node, charge is conserved
            for (i = 0; i < nodeSet.length; i++)
                list.push(Equation.createWithOwner(this, this.getRHS(nodeSet[i]), this.getCurrentConservationTerms(nodeSet[i])));

            // For each battery, voltage drop is given
            for (i = 0; i < batteries.length; i++) {
                list.push(
                    Equation.createWithOwner(
                        this, 
                        batteries[i].voltage, 
                        [
                            Term.createWithOwner(this, -1, UnknownVoltage.createWithOwner(this, batteries[i].node0)), 
                            Term.createWithOwner(this,  1, UnknownVoltage.createWithOwner(this, batteries[i].node1))
                        ]
                    )
                );
            }

            // If resistor has no resistance, node0 and node1 should have same voltage
            for (i = 0; i < resistors.length; i++) {
                if (resistors[i].resistance === 0) {
                    list.push(
                        Equation.createWithOwner(
                            this, 
                            0, 
                            [
                                Term.createWithOwner(this,  1, UnknownVoltage.createWithOwner(this, resistors[i].node0)), 
                                Term.createWithOwner(this, -1, UnknownVoltage.createWithOwner(this, resistors[i].node1))
                            ]
                            
                        )
                    );    
                }
            }

            return list;
        },