def get_data_TimeConv(time): global folder ls = os.listdir(folder) condition_folder= lambda name: "l1x1" in name and gridsize in name ls_selected=list(np.extract(map(condition_folder,ls),ls)) subfolders=sorted(ls_selected) #print "subfolders:", subfolders num_runs=len(subfolders) print "No. of runs: ", num_runs #get the spatial coordinates x=exnode_reader.parse_file(folder+subfolders[0]+"/"+"Time_2_0.part0.exnode",[["Coordinate",1]]) #field_name and component_no #print "x: ",x Vm=[0.0 for i in range(num_runs)] timesteps=[0.0 for i in range(num_runs)] for i in range(num_runs): #print "i: ",i #print"subfolders: ", subfolders[i] timesteps[i]=get_timestep(subfolders[i]) Indx=int(time/timesteps[i]) #print Indx fileToread = folder+subfolders[i]+"/"+"Time_2_"+str(Indx)+".part0.exnode" #serial version #print 'file',fileToread Vm[i]=exnode_reader.parse_file(fileToread,[["Vm",1]]) #print Vm[i] print "timesteps: ", timesteps return x,Vm,timesteps
def animate(t, create_image=False): global foldername, image_name ax1.clear() # get all exnode files sorted in that directory files = exnode_reader.get_exnode_files(foldername) if t >= len(files): return iron_filename = files[t] iron_data = exnode_reader.parse_file( foldername + iron_filename, [["Vm", 1]]) # extract field Vm, component 1 n = len(iron_data) nx = int(np.sqrt(n)) - 1 ny = int(np.sqrt(n)) - 1 print "t=", t, "/", len(files), ", n=", n, ", nx=", nx, ", ny=", ny X = range(nx + 1) Y = range(ny + 1) X, Y = np.meshgrid(X, Y) Z_iron = X.copy() for x in range(nx + 1): for y in range(ny + 1): try: Z_iron[x, y] = iron_data[x * (ny + 1) + y] except: # fails for nans Z_iron[x, y] = 0.0 ax1.plot_surface(X, Y, Z_iron, cmap=cm.coolwarm, linewidth=1, antialiased=False, rstride=1, cstride=1) ax1.set_zlim(-80, 30) plt.title("t = " + str(t * 0.005)) if t % 100 == 0 or create_image: filenamepng = image_name + "_t" + str(t) + ".png" filenameeps = image_name + "_t" + str(t) + ".eps" plt.savefig(filenamepng) print "Image saved to {}".format(filenamepng) os.system("convert " + filenamepng + " " + filenameeps)
input_filename_exelem += ".exelem" if len(sys.argv) >= 3: input_filename_exelem = sys.argv[2] else: print("usage: ./exfile_to_vtk.py <filename.exnode> [<filename.exelem>]") sys.exit(0) output_filename, _ = os.path.splitext(input_filename_exnode) print("filename exnode: \"{}\"".format(input_filename_exnode)) print("filename exelem: \"{}\"".format(input_filename_exelem)) print("output filename: \"{}.vtu\"".format(output_filename)) nodal_values = exnode_reader.parse_file( input_filename_exnode, [["coordinates", 1], ["coordinates", 2], ["coordinates", 3]]) element_nodes = exnode_reader.parse_exelem_file(input_filename_exelem) if True: print("element_nodes:") print(element_nodes) print("result:") print(nodal_values) # create geometry for vtk unstructured grid n_points = np.size(nodal_values, 0) n_elements = len(list(element_nodes))
print "foldername: ", foldername # creat image name imagenamepng = "{}".format(foldername) + "image.png" imagenameeps = "{}".format(foldername) + "image.eps" # get all exnode files (sorted) from the folder files = exnode_reader.get_exnode_files(foldername) #print 'exnode files',files n_timestep = len(files) - 1 #print "No. of time steps: ", n_timestep #get the number of data in each file x = exnode_reader.parse_file(foldername + files[0], [["Coordinate", 1]]) #field_name and component_no n_data = len(x) #print "No. of data point: ",n_data #print x # get the data Vm = [0.0 for i in range(n_timestep)] for i_time in range(n_timestep): Vm[i_time] = exnode_reader.parse_file(foldername + files[i_time + 1], [["Vm", 1]]) #print "time step: ", i_time #print Vm[i_time] #print "Vm: ",Vm def makeplot(x, y, z):
status = " matlab file: {}\n".format(foldername+matlab_filename) matlab_data = None if os.path.exists(foldername): matlab_data = np.loadtxt(foldername+matlab_filename) # read iron reference data foldername = "reference/iron/l1x1_n"+str(nx)+"x"+str(ny)+"_i"+str(i)+"_s"+str(s)+"/" pde_time_step = 0.005 filenumber = int(t / pde_time_step) iron_reference_filename = "Time_2_"+str(filenumber)+".part0.exnode" status += " iron reference file: {}\n".format(foldername+iron_reference_filename) iron_reference_data = exnode_reader.parse_file(foldername+iron_reference_filename, [["Vm", 1]]) # extract field Vm, component 1 # read iron data of current run foldername = "current_run/l1x1_n"+str(nx)+"x"+str(ny)+"_i"+str(i)+"_s"+str(s)+"_p"+str(p)+"/" pde_time_step = 0.005 filenumber = int(t / pde_time_step) iron_filename = "Time_2_"+str(filenumber)+".part0.exnode" status += " iron file: {}\n".format(foldername+iron_filename) iron_data = exnode_reader.parse_file(foldername+iron_filename, [["Vm", 1]]) # extract field Vm, component 1 if iron_data is None: print "Warning! no data available for:\n"+status continue # determine which iron file would produce the least l2 error to the current matlab file