Coverage for fiqus/post_processors/PostProcessAC_Rutherford.py: 12%
97 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-12-09 14:33 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2025-12-09 14:33 +0000
1import os, logging
2import numpy as np
3import matplotlib.pyplot as plt
5logger = logging.getLogger('FiQuS')
7class PostProcess:
8 def __init__(self, solution_folder_path):
9 self.solution_folder_path = solution_folder_path
11 self.plot_transport()
12 # self.plot_strand_split()
13 self.plot_fluxhyst()
14 self.plot_power_rohf()
16 def load_standard_txt(self, file_rel_path, skiprows=1):
17 """Load the content of a txt file into a nested numpy array
19 :param file_rel_path: relative file path in the solution folder (with file extension)
20 :param skiprows: number of rows to skip at the top of the txt file, defaults to 1
21 :return: nested np.array with time at index 0
22 """
23 file_path = os.path.join(self.solution_folder_path, file_rel_path)
24 return np.loadtxt(file_path, skiprows=skiprows).T if os.path.isfile(file_path) else None
26 def plot_transport(self):
27 """ Plots transport current and voltage over time if existing """
29 Vt_data = self.load_standard_txt('txt_files\\Vt.txt')
30 It_data = self.load_standard_txt('txt_files\\It.txt')
32 if all(x is not None for x in (It_data, Vt_data)):
33 fig, ax1 = plt.subplots()
34 ax1.set_title("Transport current and voltage")
35 ax1.set_xlabel(r'Time $(s)$')
36 ax1.set_ylabel(r'Current $(A)$', color = 'red')
37 ax1.plot(It_data[0], It_data[1], color = 'red')
38 ax1.grid(axis='x', linestyle='dotted')
39 ax1.tick_params(axis='y', labelcolor = 'red')
41 ax2 = ax1.twinx()
42 ax2.set_ylabel(r'Voltage $(V)$', color = 'blue')
43 ax2.plot(Vt_data[0], Vt_data[1], color = 'blue')
44 ax2.tick_params(axis='y', labelcolor = 'blue')
45 ax2.grid(axis='y', linestyle='dotted')
46 fig.tight_layout()
48 def plot_fluxhyst(self):
49 """ Plots the internal flux hysteresis and resulting voltages if existing (ROHF enabled and stranded strands) """
51 fluxhyst_data = self.load_standard_txt('txt_files\\flux_hyst.txt')
52 voltage_rohf = self.load_standard_txt('txt_files\\voltage_rohf.txt')
53 Is_data = self.load_standard_txt('txt_files\\Is.txt')
55 if all(x is not None for x in (fluxhyst_data, Is_data)):
56 # plot only the first quarter of the strands because of symmetry ...
57 q_idx = round((len(fluxhyst_data)-1) / 4)
58 colors = plt.cm.rainbow(np.linspace(0,1,q_idx))
59 plt.figure(figsize=(10,5))
60 # Flux in strand currents
61 plt.subplot(121)
62 plt.title('ROHF Flux hysteresis')
63 for i in range(1,q_idx+1):
64 plt.plot(Is_data[i], fluxhyst_data[i], label='Strand '+str(i), color=colors[i-1])
65 plt.xlabel(r"Strand current (A)")
66 plt.ylabel(r'Internal flux (Wb/m$)')
67 plt.legend()
69 # Resulting strand ROHF voltages
70 plt.subplot(122)
71 plt.title('ROHF voltages')
72 if voltage_rohf is not None:
73 for i in range(1, q_idx+1):
74 plt.plot(voltage_rohf[0], voltage_rohf[i], label='Strand '+str(i), color=colors[i-1])
75 #plt.plot(self.linflux_voltage[0], self.linflux_voltage[i], linestyle='dashed', color=colors[i-1])
76 plt.xlabel('Time (s)')
77 plt.ylabel(r'Voltage (V/m)')
78 plt.legend()
80 def plot_strand_split(self):
81 """ Plots the Strand currents and voltages for stranded strands enabled """
83 Vt_data = self.load_standard_txt('txt_files\\Vt.txt')
84 It_data = self.load_standard_txt('txt_files\\It.txt')
85 Vs_data = self.load_standard_txt('txt_files\\Vs.txt')
86 Is_data = self.load_standard_txt('txt_files\\Is.txt')
88 if all(x is not None for x in (It_data, Vt_data, Is_data, Vs_data)):
89 # plot only the first quarter of the strands because of symmetry ...
90 q_idx = round((len(Vs_data)-1) / 4)
91 colors = plt.cm.rainbow(np.linspace(0,1,q_idx))
93 plt.figure(figsize=(9,5))
94 plt.subplot(121)
95 plt.title('Strand voltages')
96 plt.plot(Vt_data[0], Vt_data[1], label='Total transport voltage')
97 for i in range(1,q_idx+1):
98 plt.plot(Vs_data[0], Vs_data[i], label='Strand '+str(i), color=colors[i-1])
99 plt.plot(Vs_data[0], sum(Vs_data[1:]), 'r.--', label=r'$\sum \ V_s$')
100 #plt.scatter(self.Vs_data[0], self.Vs_data[36], marker='x', label='Strand 36')
101 plt.xlabel(r"Time (s)")
102 plt.ylabel(r'Voltage (V/m)')
103 plt.legend()
105 plt.subplot(122)
106 plt.title('Strand currents')
107 plt.plot(It_data[0], It_data[1], label='Total transport current')
108 for i in range(1,q_idx+1):
109 plt.plot(Is_data[0], Is_data[i], label='Strand '+str(i), color=colors[i-1])
110 plt.plot(Is_data[0], sum(Is_data[1:]), 'r.--', label=r'$\sum \ I_s$')
111 #plt.scatter(self.Is_data[0], self.Is_data[36], marker='x', label='Strand 36')
112 plt.xlabel(r"Time (s)")
113 plt.ylabel(r'Current (A)')
114 plt.legend()
116 def plot_power_rohf(self):
117 """ Plots the ROHF related power contributions if existing """
119 power = self.load_standard_txt('txt_files\\power.txt')
120 power_hyst_rohf = self.load_standard_txt('txt_files\\power_hyst_ROHF.txt')
121 power_eddy_rohf = self.load_standard_txt('txt_files\\power_eddy_ROHF.txt')
123 if power is not None and len(power) == 5:
124 colors = plt.cm.rainbow(np.linspace(0,1,4))
126 plt.figure()
127 plt.title('Instantaneous power loss contributions')
128 #plt.plot(self.power[0], self.power[1], label='Total', color=colors[0])
129 plt.plot(power[0], power[2], label='hyst powerfile', linestyle='--', color=colors[1])
130 plt.plot(power_hyst_rohf[0], sum(power_hyst_rohf[1:]), label='Hyst', color=colors[1])
131 plt.plot(power[0], power[3], label='Eddy powerfile', linestyle='--', color=colors[2])
132 plt.plot(power_eddy_rohf[0], sum(power_eddy_rohf[1:]), label='Eddy', color=colors[2])
133 #plt.plot(power_hyst_strands[0], sum(power_hyst_strands[1:]), label='strands sum')
134 plt.xlabel(r"Time (s)")
135 plt.ylabel(r'Power loss (W/m)')
136 plt.legend()
138 def show(self):
139 """ Display all generated plots at once """
140 plt.show() if len(plt.get_fignums()) > 0 else logger.info('- NO POSTPROC DATA -')