本文整理汇总了C#中Circuit.doTick方法的典型用法代码示例。如果您正苦于以下问题:C# Circuit.doTick方法的具体用法?C# Circuit.doTick怎么用?C# Circuit.doTick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Circuit
的用法示例。
在下文中一共展示了Circuit.doTick方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CapacitorFrequencyTest
public void CapacitorFrequencyTest(double frequency, double current)
{
Circuit sim = new Circuit();
var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
source0.frequency = frequency;
var resistor0 = sim.Create<Resistor>(200);
var cap0 = sim.Create<CapacitorElm>(3E-5);
sim.Connect(source0, 1, resistor0, 0);
sim.Connect(resistor0, 1, cap0, 0);
sim.Connect(cap0, 1, source0, 0);
var capScope = sim.Watch(cap0);
double cycleTime = 1 / source0.frequency;
double quarterCycleTime = cycleTime / 4;
int steps = (int)(cycleTime / sim.timeStep);
for(int x = 1; x <= steps; x++)
sim.doTick();
Assert.AreEqual(current, Math.Round(capScope.Max((f) => f.current), 12));
}
示例2: CapacitorCapacitanceTest
public void CapacitorCapacitanceTest(double capacitance, double current)
{
Circuit sim = new Circuit();
var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
source0.frequency = 80;
var resistor0 = sim.Create<Resistor>(200);
var cap0 = sim.Create<CapacitorElm>(capacitance);
sim.Connect(source0, 1, resistor0, 0);
sim.Connect(resistor0, 1, cap0, 0);
sim.Connect(cap0, 1, source0, 0);
var capScope = sim.Watch(cap0);
double cycleTime = 1 / source0.frequency;
double quarterCycleTime = cycleTime / 4;
int steps = (int)(cycleTime / sim.timeStep);
for(int x = 1; x <= steps; x++)
sim.doTick();
double charge = cap0.capacitance * cap0.getVoltageDelta();
Debug.Log(charge); // F = I x L
Debug.Log(cap0.getCurrent(), charge / cap0.capacitance); // I = F / L
Debug.Log(cap0.capacitance, charge / cap0.getCurrent()); // L = F / I
Assert.AreEqual(current, Math.Round(capScope.Max((f) => f.current), 12));
}
示例3: ACWaveTest
public void ACWaveTest()
{
Circuit sim = new Circuit();
var voltage0 = sim.Create<VoltageInput>(Voltage.WaveType.AC);
var res0 = sim.Create<Resistor>();
var ground0 = sim.Create<Ground>();
sim.Connect(voltage0.leadPos, res0.leadIn);
sim.Connect(res0.leadOut, ground0.leadIn);
var resScope0 = sim.Watch(res0);
double cycleTime = 1 / voltage0.frequency;
double quarterCycleTime = cycleTime / 4;
int steps = (int)(cycleTime / sim.timeStep);
for(int x = 1; x <= steps; x++)
sim.doTick();
double voltageHigh = resScope0.Max((f) => f.voltage);
int voltageHighNdx = resScope0.FindIndex((f) => f.voltage == voltageHigh);
TestUtils.Compare(voltageHigh, voltage0.dutyCycle, 4);
TestUtils.Compare(resScope0[voltageHighNdx].time, quarterCycleTime, 4);
double voltageLow = resScope0.Min((f) => f.voltage);
int voltageLowNdx = resScope0.FindIndex((f) => f.voltage == voltageLow);
TestUtils.Compare(voltageLow, -voltage0.dutyCycle, 4);
TestUtils.Compare(resScope0[voltageLowNdx].time, quarterCycleTime * 3, 4);
double currentHigh = resScope0.Max((f) => f.current);
int currentHighNdx = resScope0.FindIndex((f) => f.current == currentHigh);
Debug.Log(currentHigh, "currentHigh");
double currentLow = resScope0.Min((f) => f.current);
int currentLowNdx = resScope0.FindIndex((f) => f.current == currentLow);
Debug.Log(Math.Round(currentLow, 4), "currentLow");
}
示例4: LeastResistanceTest
public void LeastResistanceTest()
{
Circuit sim = new Circuit();
var volt0 = sim.Create<VoltageInput>(Voltage.WaveType.DC);
var res0 = sim.Create<Resistor>( 100);
var res1 = sim.Create<Resistor>(1000);
var ground0 = sim.Create<Ground>();
var ground1 = sim.Create<Ground>();
sim.Connect(volt0, 0, res0, 0);
sim.Connect(volt0, 0, res1, 0);
sim.Connect(res0, 1, ground0, 0);
sim.Connect(res1, 1, ground1, 0);
for(int x = 1; x <= 100; x++)
sim.doTick();
TestUtils.Compare(ground0.getCurrent(), 0.05, 8);
TestUtils.Compare(ground1.getCurrent(), 0.005, 8);
}
示例5: Main
static void Main(string[] args)
{
Circuit sim = new Circuit();
var volt0 = sim.Create<VoltageInput>(Voltage.WaveType.DC);
var res0 = sim.Create<Resistor>();
var ground0 = sim.Create<Ground>();
sim.Connect(volt0.leadPos, res0.leadIn);
sim.Connect(res0.leadOut, ground0.leadIn);
for(int x = 1; x <= 100; x++) {
sim.doTick();
// Ohm's Law
Debug.Log(res0.getVoltageDelta(), res0.resistance * res0.getCurrent()); // V = I x R
Debug.Log(res0.getCurrent(), res0.getVoltageDelta() / res0.resistance); // I = V / R
Debug.Log(res0.resistance, res0.getVoltageDelta() / res0.getCurrent()); // R = V / I
}
Console.WriteLine("program complete");
Console.ReadLine();
}
示例6: LinearResistorTest
public void LinearResistorTest(double resistance)
{
Circuit sim = new Circuit();
var volt0 = sim.Create<VoltageInput>(Voltage.WaveType.DC);
var res0 = sim.Create<Resistor>();
var ground0 = sim.Create<Ground>();
sim.Connect(volt0.leadPos, res0.leadIn);
sim.Connect(res0.leadOut, ground0.leadIn);
for(int x = 1; x <= 100; x++) {
sim.doTick();
// Ohm's Law
Assert.AreEqual(res0.getVoltageDelta(), res0.resistance * res0.getCurrent()); // V = I x R
Assert.AreEqual(res0.getCurrent(), res0.getVoltageDelta() / res0.resistance); // I = V / R
Assert.AreEqual(res0.resistance, res0.getVoltageDelta() / res0.getCurrent()); // R = V / I
}
}
示例7: FullAdderTest
public void FullAdderTest(int in0, int in1, int in2, int i0)
{
Circuit sim = new Circuit();
var logicIn0 = sim.Create<LogicInput>();
var logicIn1 = sim.Create<LogicInput>();
var logicIn2 = sim.Create<LogicInput>();
var chip0 = sim.Create<FullAdder>();
var logicOut0 = sim.Create<LogicOutput>();
var logicOut1 = sim.Create<LogicOutput>();
sim.Connect(logicIn0.leadOut, chip0.leadIn0);
sim.Connect(logicIn1.leadOut, chip0.leadIn1);
sim.Connect(logicIn2.leadOut, chip0.leadIn2);
sim.Connect(logicOut0.leadIn, chip0.leadOut1);
sim.Connect(logicOut1.leadIn, chip0.leadOut2);
logicIn0.setPosition(in0);
logicIn1.setPosition(in1);
logicIn2.setPosition(in2);
sim.analyze();
for(int x = 1; x <= 100; x++)
sim.doTick();
int i = 0;
if(logicOut0.isHigh()) i += 1;
if(logicOut1.isHigh()) i += 2;
Assert.AreEqual(i0, i);
}
示例8: CapacitorTest
public void CapacitorTest()
{
Circuit sim = new Circuit();
var volt0 = sim.Create<DCVoltageSource>();
var cap0 = sim.Create<CapacitorElm>(2E-4);
var res0 = sim.Create<Resistor>();
var switch0 = sim.Create<SwitchSPDT>();
/*sim.Connect(volt0, 1, switch0, 1);
sim.Connect(switch0, 1, switch0, 1);
sim.Connect(switch0, 2, res0, 1);
sim.Connect(cap0, 1, res0, 0);
sim.Connect(res0, 1, volt0, 0);*/
// leadNeg 0
// leadPos 1
sim.Connect(volt0, 1, switch0, 1);
sim.Connect(switch0, 0, cap0, 0);
sim.Connect(cap0, 1, res0, 0);
sim.Connect(res0, 1, volt0, 0);
sim.Connect(switch0, 2, volt0, 0);
switch0.setPosition(0);
var capScope0 = sim.Watch(cap0);
for(int x = 1; x <= 28000; x++)
sim.doTick();
Debug.LogF("{0} [{1}]", sim.time, SIUnits.Normalize(sim.time, "s"));
{
double voltageHigh = capScope0.Max((f) => f.voltage);
int voltageHighNdx = capScope0.FindIndex((f) => f.voltage == voltageHigh);
Debug.Log("voltageHigh", voltageHigh, voltageHighNdx);
double voltageLow = capScope0.Min((f) => f.voltage);
int voltageLowNdx = capScope0.FindIndex((f) => f.voltage == voltageLow);
Debug.Log("voltageLow ", voltageLow, voltageLowNdx);
double currentHigh = capScope0.Max((f) => f.current);
int currentHighNdx = capScope0.FindIndex((f) => f.current == currentHigh);
Debug.Log("currentHigh", currentHigh, currentHighNdx);
double currentLow = capScope0.Min((f) => f.current);
int currentLowNdx = capScope0.FindIndex((f) => f.current == currentLow);
Debug.Log("currentLow ", currentLow, currentLowNdx);
Assert.AreEqual(27999, voltageHighNdx);
Assert.AreEqual( 0, voltageLowNdx);
Assert.AreEqual( 0, currentHighNdx);
Assert.AreEqual(27999, currentLowNdx);
}
switch0.setPosition(1);
sim.analyze();
capScope0.Clear();
for(int x = 1; x <= 28000; x++)
sim.doTick();
Debug.Log();
Debug.LogF("{0} [{1}]", sim.time, SIUnits.Normalize(sim.time, "s"));
{
double voltageHigh = capScope0.Max((f) => f.voltage);
int voltageHighNdx = capScope0.FindIndex((f) => f.voltage == voltageHigh);
Debug.Log("voltageHigh ", voltageHigh, voltageHighNdx);
double voltageLow = capScope0.Min((f) => f.voltage);
int voltageLowNdx = capScope0.FindIndex((f) => f.voltage == voltageLow);
Debug.Log("voltageLow ", voltageLow, voltageLowNdx);
double currentHigh = capScope0.Max((f) => f.current);
int currentHighNdx = capScope0.FindIndex((f) => f.current == currentHigh);
Debug.Log("currentHigh", currentHigh, currentHighNdx);
double currentLow = capScope0.Min((f) => f.current);
int currentLowNdx = capScope0.FindIndex((f) => f.current == currentLow);
Debug.Log("currentLow ", currentLow, currentLowNdx);
Assert.AreEqual(voltageHighNdx, currentLowNdx);
Assert.AreEqual(voltageLowNdx, currentHighNdx);
Assert.AreEqual( 0, voltageHighNdx);
Assert.AreEqual(27999, voltageLowNdx);
Assert.AreEqual(27999, currentHighNdx);
Assert.AreEqual( 0, currentLowNdx);
}
}
示例9: SquareWaveTest
public void SquareWaveTest()
{
Circuit sim = new Circuit();
var voltage0 = sim.Create<VoltageInput>(Voltage.WaveType.SQUARE);
var res0 = sim.Create<Resistor>();
var ground0 = sim.Create<Ground>();
sim.Connect(voltage0.leadPos, res0.leadIn);
sim.Connect(res0.leadOut, ground0.leadIn);
var resScope0 = sim.Watch(res0);
double cycleTime = 1 / voltage0.frequency;
double quarterCycleTime = cycleTime / 4;
int steps = (int)(cycleTime / sim.timeStep);
for(int x = 1; x <= steps; x++)
sim.doTick();
double voltageHigh = resScope0.Max((f) => f.voltage);
int voltageHighNdx = resScope0.FindIndex((f) => f.voltage == voltageHigh);
Assert.AreEqual(voltageHigh, voltage0.dutyCycle);
Assert.AreEqual(0, voltageHighNdx);
double voltageLow = resScope0.Min((f) => f.voltage);
int voltageLowNdx = resScope0.FindIndex((f) => f.voltage == voltageLow);
Assert.AreEqual(voltageLow, -voltage0.dutyCycle);
Assert.AreEqual(2501, voltageLowNdx);
double currentHigh = resScope0.Max((f) => f.current);
int currentHighNdx = resScope0.FindIndex((f) => f.current == currentHigh);
Assert.AreEqual(voltageHigh / res0.resistance, currentHigh);
double currentLow = resScope0.Min((f) => f.current);
int currentLowNdx = resScope0.FindIndex((f) => f.current == currentLow);
Assert.AreEqual(voltageLow / res0.resistance, currentLow);
}
示例10: SimpleOpAmpTest
public void SimpleOpAmpTest()
{
Circuit sim = new Circuit();
var volt0 = sim.Create<VoltageInput>(Voltage.WaveType.DC);
volt0.maxVoltage = 3;
var volt1 = sim.Create<VoltageInput>(Voltage.WaveType.DC);
volt1.maxVoltage = 4;
var opAmp0 = sim.Create<OpAmp>();
var analogOut0 = sim.Create<Output>();
sim.Connect(volt0.leadPos, opAmp0.leadNeg);
sim.Connect(volt1.leadPos, opAmp0.leadPos);
sim.Connect(opAmp0.leadOut, analogOut0.leadIn);
for(int x = 1; x <= 100; x++)
sim.doTick();
TestUtils.Compare(analogOut0.getVoltageDelta(), 15, 2);
}
示例11: SimpleDiodeTest
public void SimpleDiodeTest()
{
Circuit sim = new Circuit();
var voltage0 = sim.Create<VoltageInput>(Voltage.WaveType.AC);
var diode = sim.Create<DiodeElm>();
var ground = sim.Create<Ground>();
sim.Connect(voltage0.leadPos, diode.leadIn);
sim.Connect(diode.leadOut, ground.leadIn);
var diodeScope = sim.Watch(diode);
double cycleTime = 1 / voltage0.frequency;
double quarterCycleTime = cycleTime / 4;
int steps = (int)(cycleTime / sim.timeStep);
for(int x = 1; x <= steps; x++)
sim.doTick();
double voltageHigh = diodeScope.Max((f) => f.voltage);
int voltageHighNdx = diodeScope.FindIndex((f) => f.voltage == voltageHigh);
TestUtils.Compare(voltageHigh, voltage0.dutyCycle, 4);
TestUtils.Compare(diodeScope[voltageHighNdx].time, quarterCycleTime, 4);
double voltageLow = diodeScope.Min((f) => f.voltage);
int voltageLowNdx = diodeScope.FindIndex((f) => f.voltage == voltageLow);
TestUtils.Compare(voltageLow, -voltage0.dutyCycle, 4);
TestUtils.Compare(diodeScope[voltageLowNdx].time, quarterCycleTime * 3, 4);
double currentHigh = diodeScope.Max((f) => f.current);
int currentHighNdx = diodeScope.FindIndex((f) => f.current == currentHigh);
TestUtils.Compare(diodeScope[voltageHighNdx].time, diodeScope[currentHighNdx].time, 5);
double currentLow = diodeScope.Min((f) => f.current);
int currentLowNdx = diodeScope.FindIndex((f) => f.current == currentLow);
TestUtils.Compare(currentLow, 0, 8);
}
示例12: InductorFrequencyTest
public void InductorFrequencyTest(double frequency, double current)
{
Circuit sim = new Circuit();
var source0 = sim.Create<Voltage>(Voltage.WaveType.AC);
source0.frequency = frequency;
source0.phaseShift = 90;
var resistor0 = sim.Create<Resistor>(100);
var induct0 = sim.Create<InductorElm>(0.4);
sim.Connect(source0, 1, resistor0, 0);
sim.Connect(resistor0, 1, induct0, 0);
sim.Connect(induct0, 1, source0, 0);
var inductScope = sim.Watch(induct0);
double cycleTime = 1 / source0.frequency;
double quarterCycleTime = cycleTime / 4;
int steps = (int)(cycleTime / sim.timeStep);
for(int x = 1; x <= steps; x++)
sim.doTick();
Assert.AreEqual(current, Math.Round(inductScope.Max((f) => f.current), 12));
}
示例13: SimpleACVoltageTest
public void SimpleACVoltageTest(double frequency)
{
Circuit sim = new Circuit();
var voltage0 = sim.Create<VoltageInput>(Voltage.WaveType.AC);
voltage0.frequency = frequency;
var resistor = sim.Create<Resistor>();
var ground = sim.Create<Ground>();
sim.Connect(voltage0.leadPos, resistor.leadIn);
sim.Connect(resistor.leadOut, ground.leadIn);
var voltScope = sim.Watch(voltage0);
// Cycle time is:
// 1s
// ---
// (X)Hz
double cycleTime = 1 / voltage0.frequency;
// Peak values of the wave occur on
// quarter values of the cycle time
double quarterCycleTime = cycleTime / 4;
int steps = (int)(cycleTime / sim.timeStep);
for(int x = 1; x <= steps; x++)
sim.doTick();
double voltageHigh = voltScope.Max((f) => f.voltage);
int voltageHighNdx = voltScope.FindIndex((f) => f.voltage == voltageHigh);
TestUtils.Compare(voltageHigh, voltage0.dutyCycle, 4);
TestUtils.Compare(voltScope[voltageHighNdx].time, quarterCycleTime, 4); // Max voltage is reached by 1/4 of a cycle
double voltageLow = voltScope.Min((f) => f.voltage);
int voltageLowNdx = voltScope.FindIndex((f) => f.voltage == voltageLow);
TestUtils.Compare(voltageLow, -voltage0.dutyCycle, 4);
TestUtils.Compare(voltScope[voltageLowNdx].time, quarterCycleTime * 3, 4); // Min voltage is reached by 3/4 of a cycle
double currentHigh = voltScope.Max((f) => f.current);
int currentHighNdx = voltScope.FindIndex((f) => f.current == currentHigh);
Debug.Log(currentHigh, "currentHigh");
double currentLow = voltScope.Min((f) => f.current);
int currentLowNdx = voltScope.FindIndex((f) => f.current == currentLow);
Debug.Log(Math.Round(currentLow, 4), "currentLow");
}
示例14: VoltageDividerTest
public void VoltageDividerTest()
{
Circuit sim = new Circuit();
var volt0 = sim.Create<DCVoltageSource>();
volt0.maxVoltage = 10;
var res0 = sim.Create<Resistor>(10000);
var res1 = sim.Create<Resistor>(10000);
sim.Connect(volt0, 1, res0, 0);
sim.Connect(res0, 1, res1, 0);
sim.Connect(res1, 1, volt0, 0);
var res2 = sim.Create<Resistor>(10000);
var res3 = sim.Create<Resistor>(10000);
var res4 = sim.Create<Resistor>(10000);
var res5 = sim.Create<Resistor>(10000);
sim.Connect(volt0, 1, res2, 0);
sim.Connect(res2, 1, res3, 0);
sim.Connect(res3, 1, res4, 0);
sim.Connect(res4, 1, res5, 0);
sim.Connect(res5, 1, volt0, 0);
var out0 = sim.Create<Output>();
var out1 = sim.Create<Output>();
var out2 = sim.Create<Output>();
var out3 = sim.Create<Output>();
sim.Connect(out0, 0, res0, 1);
sim.Connect(out1, 0, res2, 1);
sim.Connect(out2, 0, res3, 1);
sim.Connect(out3, 0, res4, 1);
for(int x = 1; x <= 100; x++)
sim.doTick();
TestUtils.Compare(res0.getVoltageDelta(), 5.0, 8);
TestUtils.Compare(res1.getVoltageDelta(), 5.0, 8);
TestUtils.Compare(res2.getVoltageDelta(), 2.5, 8);
TestUtils.Compare(res3.getVoltageDelta(), 2.5, 8);
TestUtils.Compare(res4.getVoltageDelta(), 2.5, 8);
TestUtils.Compare(res5.getVoltageDelta(), 2.5, 8);
TestUtils.Compare(out0.getVoltageDelta(), 5.0, 8);
TestUtils.Compare(out1.getVoltageDelta(), 7.5, 8);
TestUtils.Compare(out2.getVoltageDelta(), 5.0, 8);
TestUtils.Compare(out3.getVoltageDelta(), 2.5, 8);
}
示例15: WheatstoneBridgeTest
public void WheatstoneBridgeTest()
{
Circuit sim = new Circuit();
var volt0 = sim.Create<DCVoltageSource>();
var res0 = sim.Create<Resistor>(200);
var res1 = sim.Create<Resistor>(400);
sim.Connect(volt0, 1, res0, 0);
sim.Connect(volt0, 1, res1, 0);
var wire0 = sim.Create<Wire>();
sim.Connect(wire0, 0, res0, 1);
sim.Connect(wire0, 1, res1, 1);
var res2 = sim.Create<Resistor>(100);
var resX = sim.Create<Resistor>(200);
sim.Connect(res0, 1, res2, 0);
sim.Connect(res1, 1, resX, 0);
sim.Connect(volt0, 0, res2, 1);
sim.Connect(volt0, 0, resX, 1);
for(int x = 1; x <= 100; x++)
sim.doTick();
TestUtils.Compare(0.025, volt0.getCurrent(), 3);
TestUtils.Compare(res0.getCurrent(), 0.01666667, 8);
TestUtils.Compare(res1.getCurrent(), 0.00833334, 8);
TestUtils.Compare(res2.getCurrent(), 0.01666667, 8);
TestUtils.Compare(resX.getCurrent(), 0.00833334, 8);
Assert.AreEqual(0, wire0.getCurrent());
}