SMASIF

WPT Dataset V2.0

Aug 28th, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.12 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from scipy.special import ellipk, ellipe
  4. import os
  5. import time
  6.  
  7. # Constants
  8. mu_0 = 4 * np.pi * 1e-7  # Permeability of free space (H/m)
  9.  
  10. # Define the updated Rx coil dimensions (in mm)
  11. rx_total_width = 37.0  # Total available width for Rx segments
  12. rx_total_length = 20.0  # Total available length for Rx segments
  13.  
  14. # Define the Tx coil dimensions (5 times larger than Rx)
  15. tx_total_width = rx_total_width * 5  # Total available width for Tx
  16. tx_total_length = rx_total_length * 5  # Total available length for Tx
  17.  
  18. # Define the range for Trace Width, Thickness, Gap, and Center Area Percentage
  19. trace_widths = np.arange(0.06, 0.82, 0.04)  # Varying from 0.06 mm to 0.8 mm
  20. trace_thicknesses = np.arange(0.06, 0.82, 0.04)  # Varying from 0.06 mm to 0.8 mm
  21. gaps = np.arange(0.05, 1, 0.05)  # Gap between segments varies from 0.1 mm to 0.5 mm
  22. center_area_percentages = np.arange(0.15, 0.30, 0.05)  # Varying center area percentage from 15% to 30%
  23.  
  24. # Set constant distance between coils (z = 20 mm)
  25. z = 20.0  # Constant distance in mm
  26.  
  27. # Initialize a counter to track the number of iterations
  28. counter = 0
  29.  
  30. # Total number of iterations for progress tracking
  31. total_iterations = len(trace_widths) * len(trace_thicknesses) * len(gaps) * len(center_area_percentages)
  32.  
  33. # Check if there's an existing partial dataset
  34. output_file = 'mutual_inductance_dataset_updated.csv'
  35. if os.path.exists(output_file):
  36.     df_existing = pd.read_csv(output_file)
  37.     counter = len(df_existing)
  38.     dataset = df_existing.to_dict('records')
  39.     print(f"Resuming from {counter} configurations.")
  40. else:
  41.     dataset = []
  42.  
  43. # Function to calculate mutual inductance between filaments
  44. def calculate_mutual_inductance_for_filaments(a, b, c, d, z):
  45.     R = np.sqrt((a + c) ** 2 + (b + d) ** 2 + z ** 2)
  46.     if R == 0:
  47.         return 0.0
  48.  
  49.     k_sq = 4 * a * c / ((a + c) ** 2 + (b + d) ** 2 + z ** 2)
  50.     if k_sq < 0 or k_sq > 1:
  51.         return 0.0
  52.  
  53.     try:
  54.         K_k = ellipk(k_sq)
  55.         E_k = ellipe(k_sq)
  56.     except ValueError:
  57.         return 0.0
  58.  
  59.     sqrt_ac = np.sqrt(a * c)
  60.     M = (mu_0 / np.pi) * sqrt_ac * ((1 - k_sq / 2) * K_k - E_k) / R
  61.  
  62.     if np.isnan(M) or np.isinf(M):
  63.         return 0.0
  64.  
  65.     return M
  66.  
  67. # Function to calculate the mutual inductance between segments
  68. def calculate_mutual_inductance_for_segment(segment_length_rx, segment_width_rx, segment_length_tx, segment_width_tx,
  69.                                             N_rx, Tw_rx, T_rx, gap_length, z):
  70.     if N_rx <= 0:
  71.         return 0.0
  72.  
  73.     P_T_rx = max(int(Tw_rx / 0.025), 1)  # Finer division
  74.     Q_T_rx = max(int(T_rx / 0.01), 1)    # Finer division
  75.  
  76.     M_total = 0.0
  77.  
  78.     for q_T_rx in range(1, 2 * Q_T_rx + 2):
  79.         for p_T_rx in range(1, 2 * P_T_rx + 2):
  80.             for q_T_tx in range(1, 2 * Q_T_rx + 2):
  81.                 for p_T_tx in range(1, 2 * P_T_rx + 2):
  82.                     a_rx = (segment_length_rx - p_T_rx * (Tw_rx + gap_length)) / N_rx
  83.                     b_rx = (segment_width_rx - q_T_rx * (T_rx + gap_length)) / N_rx
  84.  
  85.                     a_tx = (segment_length_tx - p_T_tx * (Tw_rx + gap_length)) / N_rx
  86.                     b_tx = (segment_width_tx - q_T_tx * (T_rx + gap_length)) / N_rx
  87.  
  88.                     # Ensure filament dimensions are positive
  89.                     if min(a_rx, b_rx, a_tx, b_tx) <= 0:
  90.                         continue
  91.  
  92.                     M_ij = calculate_mutual_inductance_for_filaments(a_rx, b_rx, a_tx, b_tx, z)
  93.                     M_total += M_ij
  94.  
  95.     # Direct summation approach, no normalization factor
  96.     return M_total
  97.  
  98. # Iterate over all combinations of trace width, thickness, gap, and center area percentage
  99. start_time = time.time()  # Start the timer
  100. for center_area_percentage in center_area_percentages:
  101.     for Tw_rx in trace_widths:
  102.         for T_rx in trace_thicknesses:
  103.             for gap_length in gaps:
  104.                 cap_area_length = rx_total_length * center_area_percentage
  105.                 cap_area_width = rx_total_width * center_area_percentage
  106.  
  107.                 coil_area_length_rx = rx_total_length - cap_area_length
  108.                 coil_area_width_rx = rx_total_width - cap_area_width
  109.  
  110.                 coil_area_length_tx = tx_total_length - (cap_area_length * 5)
  111.                 coil_area_width_tx = tx_total_width - (cap_area_width * 5)
  112.  
  113.                 available_length_rx = coil_area_length_rx - gap_length
  114.                 available_length_tx = coil_area_length_tx - gap_length
  115.  
  116.                 # Ensure available lengths are positive
  117.                 if available_length_rx > 0 and available_length_tx > 0:
  118.                     segment_length_rx_L = available_length_rx / 2
  119.                     segment_length_rx_LC = available_length_rx / 2
  120.                     segment_length_tx = available_length_tx / 2
  121.  
  122.                     turn_pitch_rx_L = Tw_rx + gap_length
  123.                     N_rx_L = int(segment_length_rx_L / turn_pitch_rx_L)
  124.                     turn_pitch_rx_LC = Tw_rx + gap_length
  125.                     N_rx_LC = int(segment_length_rx_LC / turn_pitch_rx_LC)
  126.                     N_tx = int(segment_length_tx / turn_pitch_rx_L)
  127.  
  128.                     # Ensure segment lengths and number of turns are positive
  129.                     if segment_length_rx_L > 0 and segment_length_rx_LC > 0 and segment_length_tx > 0 \
  130.                             and N_rx_L > 0 and N_rx_LC > 0 and N_tx > 0:
  131.  
  132.                         M1_L = calculate_mutual_inductance_for_segment(segment_length_rx_L, coil_area_width_rx,
  133.                                                                        segment_length_tx, coil_area_width_tx, N_rx_L, Tw_rx,
  134.                                                                        T_rx, gap_length, z)
  135.                         M1_LC = calculate_mutual_inductance_for_segment(segment_length_rx_LC, coil_area_width_rx,
  136.                                                                         segment_length_tx, coil_area_width_tx, N_rx_LC, Tw_rx,
  137.                                                                         T_rx, gap_length, z)
  138.  
  139.                         M_final = M1_L + M1_LC
  140.  
  141.                         dataset.append({
  142.                             'Trace Width (Rx L mm)': Tw_rx,
  143.                             'Trace Thickness (Rx L mm)': T_rx,
  144.                             'Number of Turns (Rx L)': N_rx_L,
  145.                             'Trace Width (Rx L+C mm)': Tw_rx,
  146.                             'Trace Thickness (Rx L+C mm)': T_rx,
  147.                             'Number of Turns (Rx L+C)': N_rx_LC,
  148.                             'Gap Between Segments (mm)': gap_length,
  149.                             'Center Area Percentage': center_area_percentage,
  150.                             'Capacitor Area Length (mm)': cap_area_length,
  151.                             'Capacitor Area Width (mm)': cap_area_width,
  152.                             'Rx Coil Area Length (mm)': coil_area_length_rx,
  153.                             'Rx Coil Area Width (mm)': coil_area_width_rx,
  154.                             'Tx Coil Area Length (mm)': coil_area_length_tx,
  155.                             'Tx Coil Area Width (mm)': coil_area_width_tx,
  156.                             'Mutual Inductance Segment L (H)': M1_L,
  157.                             'Mutual Inductance Segment L+C (H)': M1_LC,
  158.                             'Final Mutual Inductance (H)': M_final
  159.                         })
  160.  
  161.                         counter += 1
  162.                         if counter % 100 == 0 or counter == total_iterations:
  163.                             end_time = time.time()  # End the timer
  164.                             elapsed_time = end_time - start_time  # Calculate the elapsed time
  165.                             print(
  166.                                 f"Processed {counter}/{total_iterations} configurations. Time for last 100 configurations: {elapsed_time:.2f} seconds.")
  167.                             start_time = time.time()  # Reset the timer
  168.  
  169.                             # Save progress
  170.                             pd.DataFrame(dataset).to_csv(output_file, index=False)
  171.  
  172. # Final save to ensure no data is lost
  173. pd.DataFrame(dataset).to_csv(output_file, index=False)
  174. print(f"Final dataset saved with {counter} configurations.")
  175.  
Tags: ML dataset WPT
Advertisement
Add Comment
Please, Sign In to add comment