comparison sim.py @ 17:f0665f53b854

Show FET power dissipation, don't bother with mod rail
author Daniel O'Connor <darius@dons.net.au>
date Sun, 19 Nov 2023 17:59:58 +1030
parents ac2ff6be22f7
children 28475b505f1f
comparison
equal deleted inserted replaced
16:1c4ff82b5704 17:f0665f53b854
27 27
28 cmd = [simexe, '-b'] 28 cmd = [simexe, '-b']
29 cmd.extend(simflags) 29 cmd.extend(simflags)
30 cmd.append(runname.name) 30 cmd.append(runname.name)
31 then = datetime.datetime.now() 31 then = datetime.datetime.now()
32 print(f'Starting run {runname} at {then}') 32 #print(f'Starting run {runname} at {then}')
33 p = subprocess.Popen(cmd, cwd = rundir) 33 p = subprocess.Popen(cmd, cwd = rundir)
34 p.communicate() 34 p.communicate()
35 now = datetime.datetime.now() 35 now = datetime.datetime.now()
36 taken = now - then 36 taken = now - then
37 37
38 if p.returncode != 0: 38 if p.returncode != 0:
39 print('Run failed: ' + ' '.join(map(shlex.quote, cmd))) 39 raise Exception(' '.join(map(shlex.quote, cmd)) + ' failed with code ' + str(p.returncode))
40 return 100000
41 40
42 #rawpath = rundir / runname.with_suffix('.raw') 41 #rawpath = rundir / runname.with_suffix('.raw')
43 #raw = spicelib.RawRead(rawpath) 42 #raw = spicelib.RawRead(rawpath)
44 logpath = rundir / runname.with_suffix('.log') 43 logpath = rundir / runname.with_suffix('.log')
45 log = LTSpiceLogReader(logpath) 44 log = LTSpiceLogReader(logpath)
108 cur.execute('COMMIT') 107 cur.execute('COMMIT')
109 108
110 # Run the simulation 109 # Run the simulation
111 # Need to convert units to suit 110 # Need to convert units to suit
112 runname = pathlib.Path(circ).stem + '-' + str(run) + '.net' 111 runname = pathlib.Path(circ).stem + '-' + str(run) + '.net'
113 then, taken, power, eff, thd, ipeak = simulate(circ, simexe, simflags, rundir, runname, 112 try:
114 {'dutypct' : duty, 'C1' : c1 * 1e-12, 'C2' : c2 * 1e-12, 'L1' : l1 * 1e-6, 'L2' : l2 * 1e-9}) 113 then, taken, power, eff, thd, ipeak = simulate(circ, simexe, simflags, rundir, runname,
114 {'dutypct' : duty, 'C1' : c1 * 1e-12, 'C2' : c2 * 1e-12, 'L1' : l1 * 1e-6, 'L2' : l2 * 1e-9})
115 except:
116 return 100000
115 # Calculate the cost 117 # Calculate the cost
116 cost = calccost(power, eff, thd, ipeak) 118 cost = calccost(power, eff, thd, ipeak)
117 119
118 # Log & save the results 120 # Log & save the results
119 print(f'Run {run:3d}: Duty {duty:3.0f}%, C1 {c1:3.0f}pF, C2 {c2:3.0f}pF, L1 {l1:3.0f}uH, L2 {l2:4.0f}nH -> Power: {power:6.1f}W Efficiency: {eff:5.1f}% THD: {thd:5.1f}% IPeak: {ipeak:4.1f}A Cost: {cost:6.2f}') 121 print(f'Run {run:3d}: Duty {duty:3.0f}%, C1 {c1:3.0f}pF, C2 {c2:3.0f}pF, L1 {l1:3.0f}uH, L2 {l2:4.0f}nH -> Power: {power:6.1f}W Efficiency: {eff:5.1f}% THD: {thd:5.1f}% IPeak: {ipeak:4.1f}A Cost: {cost:6.2f}')