1- """Module that controles recording of various data"""
1+ """Module that controls recording various data"""
22
33import numpy as np
44
55from freepaths .config import cf
66from freepaths .scattering_types import Scattering
77
8- class PathData :
8+ class Data :
9+ """Parent data class with functions common to all classes below"""
10+
11+ def read_data (self , data_dict ):
12+ """Read the data from the finished worker and add new data to already existing"""
13+ for key , value in data_dict .items ():
14+ setattr (self , key , getattr (self , key ) + value )
15+
16+
17+ class PathData (Data ):
918 """Paths of phonons in space"""
1019
1120 def __init__ (self ):
@@ -33,17 +42,11 @@ def write_into_files(self):
3342 np .savetxt (filename , data , fmt = '%2.4f' , delimiter = "," , header = "X (μm), Y (μm), Z (μm)" , encoding = 'utf-8' )
3443
3544 def dump_data (self ):
36- return {
37- 'phonon_paths' : self .phonon_paths ,
38- }
45+ """Return data of a process in the form of a dictionary to be attached to the global data"""
46+ return {'phonon_paths' : self .phonon_paths }
3947
40- def read_data (self , data_dict ):
41- """Read the data from the finished worker"""
42- for key , value in data_dict .items ():
43- # Perform element-wise addition
44- setattr (self , key , getattr (self ,key ) + value )
4548
46- class GeneralData :
49+ class GeneralData ( Data ) :
4750 """General statistics of various phonon properties"""
4851
4952 def __init__ (self ):
@@ -75,17 +78,18 @@ def save_flight_data(self, flight):
7578
7679 def write_into_files (self ):
7780 """Write all the data into files"""
78- np .savetxt ("Data/All free paths.csv" , self .free_paths , fmt = '%2.4e' , delimiter = "," , header = "L [m]" , encoding = 'utf-8' )
79- np .savetxt ("Data/All free paths in plane.csv" , self .free_paths_along_y , fmt = '%2.4e' , delimiter = "," , header = "Ly [m]" , encoding = 'utf-8' )
80- np .savetxt ("Data/All initial frequencies.csv" , self .frequencies , fmt = '%2.4e' , delimiter = "," , header = "f [Hz]" , encoding = 'utf-8' )
81- np .savetxt ("Data/All exit angles.csv" , self .exit_angles , fmt = '%2.4e' , delimiter = "," , header = "Angle [rad]" , encoding = 'utf-8' )
82- np .savetxt ("Data/All initial angles.csv" , self .initial_angles , fmt = '%2.4e' , delimiter = "," , header = "Angle [rad]" , encoding = 'utf-8' )
83- np .savetxt ("Data/All group velocities.csv" , self .group_velocities , fmt = '%2.4e ' , delimiter = "," , header = "Vg [rad ]" , encoding = 'utf-8' )
84- np .savetxt ("Data/All travel times.csv" , self .travel_times , fmt = '%2.4e' , delimiter = "," , header = "Travel time [s]" , encoding = 'utf-8' )
85- np .savetxt ("Data/All mean free paths.csv" , self .mean_free_paths , fmt = '%2.4e' , delimiter = "," , header = "MFPs [m]" , encoding = 'utf-8' )
86- np .savetxt ("Data/All thermal conductivities.csv" , self .thermal_conductivity , fmt = '%2.4e' , delimiter = "," , header = "K [W/mK]" , encoding = 'utf-8' )
81+ np .savetxt ("Data/All free paths.csv" , self .free_paths , fmt = '%2.4e' , header = "L [m]" , encoding = 'utf-8' )
82+ np .savetxt ("Data/All free paths in plane.csv" , self .free_paths_along_y , fmt = '%2.4e' , header = "Ly [m]" , encoding = 'utf-8' )
83+ np .savetxt ("Data/All initial frequencies.csv" , self .frequencies , fmt = '%2.4e' , header = "f [Hz]" , encoding = 'utf-8' )
84+ np .savetxt ("Data/All exit angles.csv" , self .exit_angles , fmt = '%.4f' , header = "Angle [rad]" , encoding = 'utf-8' )
85+ np .savetxt ("Data/All initial angles.csv" , self .initial_angles , fmt = '%.4f' , header = "Angle [rad]" , encoding = 'utf-8' )
86+ np .savetxt ("Data/All group velocities.csv" , self .group_velocities , fmt = '%.4f ' , header = "Vg [m//s ]" , encoding = 'utf-8' )
87+ np .savetxt ("Data/All travel times.csv" , self .travel_times , fmt = '%2.4e' , header = "Travel time [s]" , encoding = 'utf-8' )
88+ np .savetxt ("Data/All mean free paths.csv" , self .mean_free_paths , fmt = '%2.4e' , header = "MFPs [m]" , encoding = 'utf-8' )
89+ np .savetxt ("Data/All thermal conductivities.csv" , self .thermal_conductivity , fmt = '%2.4e' , header = "K [W/mK]" , encoding = 'utf-8' )
8790
8891 def dump_data (self ):
92+ """Return data of a process in the form of a dictionary to be attached to the global data"""
8993 return {
9094 'initial_angles' : self .initial_angles ,
9195 'exit_angles' : self .exit_angles ,
@@ -98,13 +102,8 @@ def dump_data(self):
98102 'thermal_conductivity' : self .thermal_conductivity ,
99103 }
100104
101- def read_data (self , data_dict ):
102- """Read the data from the finished worker"""
103- for key , value in data_dict .items ():
104- # Perform element-wise addition
105- setattr (self , key , getattr (self ,key ) + value )
106105
107- class ScatteringData :
106+ class ScatteringData ( Data ) :
108107 """Statistics of phonon scattering events"""
109108
110109 def __init__ (self ):
@@ -162,6 +161,7 @@ def write_into_files(self):
162161 np .savetxt (filename , data , fmt = '%1.3e' , delimiter = "," , header = header , encoding = 'utf-8' )
163162
164163 def dump_data (self ):
164+ """Return data of a process in the form of a dictionary to be attached to the global data"""
165165 return {
166166 'wall_diffuse' : self .wall_diffuse ,
167167 'wall_specular' : self .wall_specular ,
@@ -176,13 +176,8 @@ def dump_data(self):
176176 'total' : self .total
177177 }
178178
179- def read_data (self , data_dict ):
180- for key , value in data_dict .items ():
181- # Perform element-wise addition
182- setattr (self , key , getattr (self ,key ) + value )
183-
184179
185- class SegmentData :
180+ class SegmentData ( Data ) :
186181 """Statistics of events happening in different segments"""
187182
188183 def __init__ (self ):
@@ -211,10 +206,6 @@ def write_into_files(self):
211206 np .savetxt (filename , data , fmt = '%1.3e' , delimiter = "," , header = "Y [um], Time [ns]" , encoding = 'utf-8' )
212207
213208 def dump_data (self ):
209+ """Return data of a process in the form of a dictionary to be attached to the global data"""
214210 return {'time_spent' : self .time_spent }
215211
216- def read_data (self , data_dict ):
217- """Read the data from the finished worker"""
218- for key , value in data_dict .items ():
219- # Perform element-wise addition
220- setattr (self , key , getattr (self ,key ) + value )
0 commit comments