当前位置: 首页>>代码示例>>C#>>正文


C# Circuit.stampMatrix方法代码示例

本文整理汇总了C#中Circuit.stampMatrix方法的典型用法代码示例。如果您正苦于以下问题:C# Circuit.stampMatrix方法的具体用法?C# Circuit.stampMatrix怎么用?C# Circuit.stampMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Circuit的用法示例。


在下文中一共展示了Circuit.stampMatrix方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: step

 public override void step(Circuit sim)
 {
     bool v1 = lead_volt[0] > 2.5;
     bool v2 = lead_volt[1] > 2.5;
     if(v1 && !pins[0].value)
         ff1 = true;
     if(v2 && !pins[1].value)
         ff2 = true;
     if(ff1 && ff2)
         ff1 = ff2 = false;
     double @out = (ff1) ? 5 : (ff2) ? 0 : -1;
     // System.out.println(out + " " + v1 + " " + v2);
     if(@out != -1) {
         sim.stampVoltageSource(0, lead_node[2], pins[2].voltSource, @out);
     } else {
         // tie current through output pin to 0
         int vn = sim.nodeCount + pins[2].voltSource;
         sim.stampMatrix(vn, vn, 1);
     }
     pins[0].value = v1;
     pins[1].value = v2;
 }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:22,代码来源:PhaseCompElm.cs

示例2: step

        public override void step(Circuit sim)
        {
            double vc = lead_volt[3] - lead_volt[2];
            double vo = lead_volt[1];
            int dir = (vo < 2.5) ? 1 : -1;
            // switch direction of current through cap as we oscillate
            if (vo < 2.5 && vc > 4.5) {
                vo = 5;
                dir = -1;
            }
            if (vo > 2.5 && vc < .5) {
                vo = 0;
                dir = 1;
            }

            // generate output voltage
            sim.updateVoltageSource(0, lead_node[1], pins[1].voltSource, vo);
            // now we set the current through the cap to be equal to the
            // current through R1 and R2, so we can measure the voltage
            // across the cap
            int cur1 = sim.nodeCount + pins[4].voltSource;
            int cur2 = sim.nodeCount + pins[5].voltSource;
            sim.stampMatrix(lead_node[2], cur1, dir);
            sim.stampMatrix(lead_node[2], cur2, dir);
            sim.stampMatrix(lead_node[3], cur1, -dir);
            sim.stampMatrix(lead_node[3], cur2, -dir);
            cDir = dir;
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:28,代码来源:VCOElm.cs

示例3: step

 public override void step(Circuit sim)
 {
     double[] vs = new double[3];
     vs[0] = lead_volt[0];
     vs[1] = lead_volt[1];
     vs[2] = lead_volt[2];
     if(vs[1] > lastv1 + .5) vs[1] = lastv1 + .5;
     if(vs[1] < lastv1 - .5) vs[1] = lastv1 - .5;
     if(vs[2] > lastv2 + .5) vs[2] = lastv2 + .5;
     if(vs[2] < lastv2 - .5) vs[2] = lastv2 - .5;
     int source = 1;
     int drain = 2;
     if((pnp ? -1 : 1) * vs[1] > (pnp ? -1 : 1) * vs[2]) {
         source = 2;
         drain = 1;
     }
     int gate = 0;
     double vgs = vs[gate] - vs[source];
     double vds = vs[drain] - vs[source];
     if(Math.Abs(lastv1 - vs[1]) > .01 || Math.Abs(lastv2 - vs[2]) > .01)
         sim.converged = false;
     lastv1 = vs[1];
     lastv2 = vs[2];
     double realvgs = vgs;
     double realvds = vds;
     vgs *= (pnp ? -1 : 1);
     vds *= (pnp ? -1 : 1);
     ids = 0;
     gm = 0;
     double Gds = 0;
     double beta = getBeta();
     if(vgs > .5 && this is JfetElm) {
         sim.panic("JFET is reverse biased!", this);
         return;
     }
     if(vgs < _threshold) {
         // should be all zero, but that causes a singular matrix,
         // so instead we treat it as a large resistor
         Gds = 1e-8;
         ids = vds * Gds;
         mode = 0;
     } else if(vds < vgs - _threshold) {
         // linear
         ids = beta * ((vgs - _threshold) * vds - vds * vds * .5);
         gm = beta * vds;
         Gds = beta * (vgs - vds - _threshold);
         mode = 1;
     } else {
         // saturation; Gds = 0
         gm = beta * (vgs - _threshold);
         // use very small Gds to avoid nonconvergence
         Gds = 1e-8;
         ids = 0.5 * beta * (vgs - _threshold) * (vgs - _threshold) + (vds - (vgs - _threshold)) * Gds;
         mode = 2;
     }
     double rs = -(pnp ? -1 : 1) * ids + Gds * realvds + gm * realvgs;
     sim.stampMatrix(lead_node[drain], lead_node[drain], Gds);
     sim.stampMatrix(lead_node[drain], lead_node[source], -Gds - gm);
     sim.stampMatrix(lead_node[drain], lead_node[gate], gm);
     sim.stampMatrix(lead_node[source], lead_node[drain], -Gds);
     sim.stampMatrix(lead_node[source], lead_node[source], Gds + gm);
     sim.stampMatrix(lead_node[source], lead_node[gate], -gm);
     sim.stampRightSide(lead_node[drain], rs);
     sim.stampRightSide(lead_node[source], -rs);
     if(source == 2 && (pnp ? -1 : 1) == 1 || source == 1 && (pnp ? -1 : 1) == -1)
         ids = -ids;
 }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:67,代码来源:Mosfet.cs

示例4: return

        /*public override double getPower() {
            return (lead_volt[0] - lead_volt[2]) * current;
        }*/
        public override void step(Circuit sim)
        {
            double[] vs = new double[3];
            vs[0] = lead_volt[0];
            vs[1] = lead_volt[1];
            vs[2] = lead_volt[2];
            if(vs[1] > lastv1 + 0.5) vs[1] = lastv1 + 0.5;
            if(vs[1] < lastv1 - 0.5) vs[1] = lastv1 - 0.5;
            if(vs[2] > lastv2 + 0.5) vs[2] = lastv2 + 0.5;
            if(vs[2] < lastv2 - 0.5) vs[2] = lastv2 - 0.5;
            int grid = 1;
            int cath = 2;
            int plate = 0;
            double vgk = vs[grid] - vs[cath];
            double vpk = vs[plate] - vs[cath];
            if(Math.Abs(lastv0 - vs[0]) > 0.01 || Math.Abs(lastv1 - vs[1]) > 0.01 || Math.Abs(lastv2 - vs[2]) > 0.01)
                sim.converged = false;
            lastv0 = vs[0];
            lastv1 = vs[1];
            lastv2 = vs[2];
            double ids = 0;
            double gm = 0;
            double Gds = 0;
            double ival = vgk + vpk / mu;
            currentg = 0;
            if(vgk > .01) {
                sim.stampResistor(lead_node[grid], lead_node[cath], gridCurrentR);
                currentg = vgk / gridCurrentR;
            }
            if(ival < 0) {
                // should be all zero, but that causes a singular matrix,
                // so instead we treat it as a large resistor
                Gds = 1E-8;
                ids = vpk * Gds;
            } else {
                ids = Math.Pow(ival, 1.5) / kg1;
                double q = 1.5 * Math.Sqrt(ival) / kg1;
                // gm = dids/dgk;
                // Gds = dids/dpk;
                Gds = q;
                gm = q / mu;
            }
            currentp = ids;
            currentc = ids + currentg;
            double rs = -ids + Gds * vpk + gm * vgk;
            sim.stampMatrix(lead_node[plate], lead_node[plate], Gds);
            sim.stampMatrix(lead_node[plate], lead_node[cath], -Gds - gm);
            sim.stampMatrix(lead_node[plate], lead_node[grid], gm);

            sim.stampMatrix(lead_node[cath], lead_node[plate], -Gds);
            sim.stampMatrix(lead_node[cath], lead_node[cath], Gds + gm);
            sim.stampMatrix(lead_node[cath], lead_node[grid], -gm);

            sim.stampRightSide(lead_node[plate], rs);
            sim.stampRightSide(lead_node[cath], -rs);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:59,代码来源:Triode.cs

示例5: step

        public override void step(Circuit sim)
        {
            double vd = lead_volt[1] - lead_volt[0];
            if(Math.Abs(lastvd - vd) > 0.1) {
                sim.converged = false;
            } else if(lead_volt[2] > maxOut + 0.1 || lead_volt[2] < minOut - 0.1) {
                sim.converged = false;
            }

            double x = 0;
            int vn = sim.nodeCount + voltSource;
            double dx = 0;
            if(vd >= maxOut / gain && (lastvd >= 0 || getRand(4) == 1)) {
                dx = 1E-4;
                x = maxOut - dx * maxOut / gain;
            } else if(vd <= minOut / gain && (lastvd <= 0 || getRand(4) == 1)) {
                dx = 1E-4;
                x = minOut - dx * minOut / gain;
            } else {
                dx = gain;
            }

            // newton-raphson
            sim.stampMatrix(vn, lead_node[0], dx);
            sim.stampMatrix(vn, lead_node[1], -dx);
            sim.stampMatrix(vn, lead_node[2], 1);
            sim.stampRightSide(vn, x);

            lastvd = vd;
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:30,代码来源:OpAmp.cs

示例6: getVoltageText

 /*public override void getInfo(String[] arr) {
     arr[0] = "op-amp";
     arr[1] = "V+ = " + getVoltageText(lead_volt[1]);
     arr[2] = "V- = " + getVoltageText(lead_volt[0]);
     // sometimes the voltage goes slightly outside range, to make
     // convergence easier. so we hide that here.
     double vo = Math.Max(Math.Min(lead_volt[2], maxOut), minOut);
     arr[3] = "Vout = " + getVoltageText(vo);
     arr[4] = "Iout = " + getCurrentText(current);
     arr[5] = "range = " + getVoltageText(minOut) + " to " + getVoltageText(maxOut);
 }*/
 public override void stamp(Circuit sim)
 {
     int vn = sim.nodeCount + voltSource;
     sim.stampNonLinear(vn);
     sim.stampMatrix(lead_node[2], vn, 1);
 }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:17,代码来源:OpAmp.cs

示例7: step

        public override void step(Circuit sim)
        {
            double vbc = lead_volt[0] - lead_volt[1]; // typically negative
            double vbe = lead_volt[0] - lead_volt[2]; // typically positive
            if(Math.Abs(vbc - lastvbc) > 0.01 || Math.Abs(vbe - lastvbe) > 0.01)
                sim.converged = false;

            gmin = 0;
            if(sim.subIterations > 100) {
                // if we have trouble converging, put a conductance in parallel with
                // all P-N junctions. Gradually increase the conductance value for each iteration.
                gmin = Math.Exp(-9 * Math.Log(10) * (1 - sim.subIterations / 3000.0));
                if(gmin > .1) gmin = .1;
            }

            vbc = pnp * limitStep(sim, pnp * vbc, pnp * lastvbc);
            vbe = pnp * limitStep(sim, pnp * vbe, pnp * lastvbe);
            lastvbc = vbc;
            lastvbe = vbe;
            double pcoef = vdcoef * pnp;
            double expbc = Math.Exp(vbc * pcoef);

            double expbe = Math.Exp(vbe * pcoef);
            if(expbe < 1) expbe = 1;

            ie = pnp * leakage * (-(expbe - 1) + rgain * (expbc - 1));
            ic = pnp * leakage * (fgain * (expbe - 1) - (expbc - 1));
            ib = -(ie + ic);

            double gee = -leakage * vdcoef * expbe;
            double gec = rgain * leakage * vdcoef * expbc;
            double gce = -gee * fgain;
            double gcc = -gec * (1 / rgain);

            // stamps from page 302 of Pillage. Node 0 is the base,
            // node 1 the collector, node 2 the emitter. Also stamp
            // minimum conductance (gmin) between b,e and b,c
            sim.stampMatrix(lead_node[0], lead_node[0], -gee - gec - gce - gcc + gmin * 2);
            sim.stampMatrix(lead_node[0], lead_node[1], gec + gcc - gmin);
            sim.stampMatrix(lead_node[0], lead_node[2], gee + gce - gmin);
            sim.stampMatrix(lead_node[1], lead_node[0], gce + gcc - gmin);
            sim.stampMatrix(lead_node[1], lead_node[1], -gcc + gmin);
            sim.stampMatrix(lead_node[1], lead_node[2], -gce);
            sim.stampMatrix(lead_node[2], lead_node[0], gee + gec - gmin);
            sim.stampMatrix(lead_node[2], lead_node[1], -gec);
            sim.stampMatrix(lead_node[2], lead_node[2], -gee + gmin);

            // we are solving for v(k+1), not delta v, so we use formula
            // 10.5.13, multiplying J by v(k)
            sim.stampRightSide(lead_node[0], -ib - (gec + gcc) * vbc - (gee + gce) * vbe);
            sim.stampRightSide(lead_node[1], -ic + gce * vbe + gcc * vbc);
            sim.stampRightSide(lead_node[2], -ie + gee * vbe + gec * vbc);
        }
开发者ID:DotNetSparky,项目名称:SharpCircuit,代码行数:53,代码来源:Transistor.cs


注:本文中的Circuit.stampMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。