This version is not peer-reviewed.
Submitted:
16 December 2023
Posted:
18 December 2023
Read the latest preprint version here
Energy Circuit Simulation Code # This code was developed and executed on Google Colab
#Prepare/Import the necessary libraries
# You may need to begin by installing: #!pip install PySpice
import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint
# Circuit Component 1 (Power Source) V_source = 10 # Source voltage in volts R_conductors = 10 # Resistance of connecting conductors in ohms
# Power input to the diodes in “Circuit Block 1” I_CB1 = V_source / R_conductors
# “Circuit Block 1” n = 1.1 # Ideality factor Vt = 0.0259 # Thermal voltage at room temperature
# Diode parameters I_s = 1.5e-14 # Saturation current for diodes
# Diode voltages V_D1 = 0.7 # Example forward voltage drop for diodes V_D2 = 0.0
# Calculate total current through Block 1 (I_CB1) I_CB1 = I_s * (np.exp(V_D1 / (n * Vt)) + np.exp(V_D2 / (n * Vt)) - 2) # Equation (4)
# Voltage across Block 1 V_CB1 = V_D1+ V_D2
# “Circuit Block 2” R_0 = 1.5 # Reference resistance R_short = 0.001 # Resistance change due to short circuit V_CB2 = 0.8 * V_CB1 # Voltage drop after short circuit a = V_source / R_0 # Current scaling factor
# Calculate short circuit effect current I_short_circuit_effect = a * np.exp(R_short / R_0)
# Calculate power input to Block 2 P_out_CB2 = V_CB2 * I_short_circuit_effect
# Calculate effective resistance in Block 2 R_CB1_overall = R_conductors # Overall resistance in Block 1 R_short_effective = R_CB1_overall + R_short
# Design and set the Boost Converter Parameters Vin = V_CB2 # Input voltage from the previous circuit (in volts) Vout = V_source # Output voltage (in volts) R = R_short_effective # Load resistance (in ohms) L = 50e-6 # Inductor value (in henries) C = 100e-6 # Output capacitor value (in farads) fsw = 50e3 # Switching frequency (in hertz) D = Vout / Vin # Duty cycle
# Use the short circuit current as the initial inductor current IL_initial = I_short_circuit_effect
# Function to define the boost converter differential equations def boost_converter(y, t): IL, VC = y # Inductor current and capacitor voltage
# Function to define the boost converter differential equations def boost_converter(y, t): IL, VC = y # Inductor current and capacitor voltage
# Boost Converter Equations dIL_dt = (Vin * D - Vout) / L dVC_dt = IL / C
return [dIL_dt, dVC_dt]
# Initial conditions with short circuit current initial_conditions = [IL_initial, Vout * D]
# Time points for simulation t = np.linspace(0, 2e-3, 1000) # 2 milliseconds simulation time
# Solve the boost converter differential equations solution = odeint(boost_converter, initial_conditions, t)
# Extract results IL = solution[:, 0] VC = solution[:, 1] VR = IL * R # Voltage across the load resistor
# Print results print("Circuit Component 1:") print("Current Input to Diodes (“Circuit Block 1”):", I_CB1, "A")
print("\n”Circuit Block 1”:") print("Total Current (I_CB1):", I_CB1, "A") print("Voltage Across Block 1 (V_CB1):", V_CB1, "V")
print("\n”Circuit Block 2”:") print("Voltage Drop After Short Circuit (V_CB2):", V_CB2, "V") print("Short Circuit Effect Current (I_short_circuit_effect):", I_short_circuit_effect, "A") print("Power Output from Block 2 (P_out_CB2):", P_out_CB2, "W") print("Effective Resistance in Block 2 (R_short_effective):", R_short_effective, "ohms")
# Print individual power values print("\nPower Input to Diodes (“Circuit Block 1”):", V_CB1 * I_CB1, "W") print("Power Input to Block 3 (P_out_CB2):", P_out_CB2, "W") print("Power Output Block 3 (W):", VR[-1] * IL[-1]) # Print the last value to represent the total power output
# Print individual power values print("\nPower Input to Diodes (“Circuit Block 1”):", V_CB1 * I_CB1, "W") print("Power Input to Block 3 (P_out_CB2):", P_out_CB2, "W") print("Power Output Block 3 (W):", VR[-1] * IL[-1]) # Print the last value to represent the total power output
# Print time, inductor current, capacitor voltage, and load voltage print("\nTime (s)\tInductor Current (A)\tCapacitor Voltage (V)\tLoad Voltage (V)") for i in range(len(t)): print(f"{t[i]:.6f}\t{IL[i]:.6f}\t\t\t{VC[i]:.6f}\t\t\t{VR[i]:.6f}")
# Plot results plt.figure(figsize=(10, 6)) plt.subplot(2, 1, 1) plt.plot(t, IL, label='Inductor Current') plt.xlabel('Time (s)') plt.ylabel('Current (A)') plt.legend()
plt.subplot(2, 1, 2) plt.plot(t, VC, label='Capacitor Voltage') plt.plot(t, VR, label='Load Voltage') plt.xlabel('Time (s)') plt.ylabel('Voltage (V)') plt.legend()
plt.tight_layout() plt.show()
Supply Voltage (V) | Diode Forward Voltage (V) | R0 (Ohms) | Ideality Factor (n) | Saturation Current () (A) |
(W) |
(A) |
(W) |
(W) |
---|---|---|---|---|---|---|---|---|
0.7 | ||||||||
0.7 | ||||||||
0.7 | ||||||||
0.7 | ||||||||
0.7 | ||||||||
0.7 | ||||||||
0.7 | ||||||||
0.7 | ||||||||
0.7 | ||||||||
0.7 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 MDPI (Basel, Switzerland) unless otherwise stated