def convert_files_at_path(path): for in_file in os.listdir(path): file_path, file_extension = os.path.splitext(in_file) if file_extension == ".msh": in_file = path + in_file out_file = path + file_path + ".xml" if os.path.isfile(out_file): print path + out_file + " already exists!" else: gmsh2xml(in_file, out_file) if os.path.isfile(in_file): try: os.remove(in_file) except: print "Could not remove " + str( in_file) + " due to unexpected error:", sys.exc_info( )[0]
def airfoil(i_angle, i_nodes, i_levels): angle = str(i_angle) nodes = str(i_nodes) levels = str(i_levels) call("sudo rm msh/*", shell=True) call("sudo rm geo/*", shell=True) results = [] print "Generate mesh files for angle " + angle check_call("./run.sh " + angle + " " + angle +" 1 " + nodes + " " + levels , shell=True) print "Converting the generated mesh files to xml" msh_files = glob.glob('msh/r*a' + angle + 'n*.msh') for msh in msh_files: gmsh2xml(msh, msh[:-3] + 'xml') print "Finished convert " + msh #check_call("sudo rm " + msh, shell=True) #print "Deleted mesh: " + msh #check_call("sudo rm geo/" + msh[6:-3] + 'geo' , shell=True) #print "Deleted geo: geo/" + msh[6:-3] + 'geo' print "Run airfiol on every xml file" xml_files = glob.glob('msh/r*a' + angle + 'n*.xml') for xml in xml_files: try: check_call("sudo ./navier_stokes_solver/airfoil 10 0.0001 10. 0.2 ./" + xml, shell=True) check_call("sudo rm " + xml, shell=True) print "Deleted xml: " + xml with open("results/drag_ligt.m", 'r') as f: result = f.read() results.append({'name':xml[4:-4], 'data':result}) except CalledProcessError as e: print e.returncode return results
#!/usr/bin/env python # # Converts one or more msh files to xml files. # Using dolfin-convert.py by Anders Logg for file conversion. # def gmsh2xml ( ifilename, ofilename ): from dolfin_convert import gmsh2xml from os import listdir import os path = '../naca_airfoil/msh/' for in_file in listdir(path): file_path, file_extension = os.path.splitext(in_file) if file_extension == ".msh": in_file = path+in_file out_file = path+file_path+".xml" if os.path.isfile(out_file): print path+out_file + " already exists!" continue gmsh2xml(in_file, out_file)
def convertFile(angle, n_nodes, n_levels, num_samples, visc, speed, T): ############################################################# # Creating names and output place ############################################################# FNULL = open(os.devnull, 'w') mshFileName = "r" + n_levels + "a" + str(angle) + "n" + n_nodes + ".msh" fileNameWithoutExtension = os.path.splitext(mshFileName)[0] xmlFileName = fileNameWithoutExtension + ".xml" currentFolderLocation = "/home/ubuntu/molnProject/" + fileNameWithoutExtension + "/" mshFileLocation = "/home/ubuntu/molnProject/" + fileNameWithoutExtension + "/msh/" ############################################################# # Remove folder if exists ############################################################# content = sorted(os.listdir("/home/ubuntu/molnProject/")) if fileNameWithoutExtension in content: print "Folder exists!!! Remove!!" os.system("sudo rm -rf " + fileNameWithoutExtension + "*") ############################################################# # Create layout for task ############################################################# print "Started to process file: " + str(mshFileName) print "Copying and creating files and directorys" subprocess.check_call(["mkdir", fileNameWithoutExtension]) subprocess.check_call(['chmod', '-R', '777', fileNameWithoutExtension]) subprocess.check_call(["cp", "-a", "run.sh", fileNameWithoutExtension]) subprocess.check_call(["cp", "-a", "naca2gmsh_geo.py", fileNameWithoutExtension]) subprocess.check_call(["cp", "-a", "airfoil", fileNameWithoutExtension]) subprocess.check_call(["mkdir", "msh"], cwd=fileNameWithoutExtension+"/") subprocess.check_call(["mkdir", "geo"], cwd=fileNameWithoutExtension+"/") subprocess.check_call(['chmod', '-R', '777', fileNameWithoutExtension+"/msh"]) ############################################################# # Running run.sh ############################################################# print "Running run.sh..." subprocess.check_call( ["sudo", "./run.sh", str(angle), str(angle), "1", n_nodes, n_levels], cwd=fileNameWithoutExtension+"/") ############################################################# # Running dolfin-convert ############################################################# print "Running dolfin-convert..." #subprocess.check_call(["sudo","dolfin-convert", "msh/"+mshFileName, xmlFileName], cwd=fileNameWithoutExtension+"/", stdout=FNULL, stderr=subprocess.STDOUT) gmsh2xml(mshFileLocation + mshFileName, currentFolderLocation + xmlFileName) ############################################################# # Run airfoil on file ############################################################# print "Running airfoil..." num = str(num_samples) visc_s = str(visc) speed_s = str(speed) T_s = str(T) subprocess.check_call( ["sudo","./airfoil", num, visc_s, speed_s, T_s, xmlFileName], cwd=fileNameWithoutExtension+"/", stdout=FNULL, stderr=subprocess.STDOUT) ############################################################# # Extracting information from frag_ligt.m ############################################################# print "Getting drag_ligt.m to lists" resultLists = readFile("/home/ubuntu/molnProject/" +fileNameWithoutExtension+"/results/drag_ligt.m") pictureName = fileNameWithoutExtension + "Num" + num + "Visc" + visc_s + "Speed" + speed_s + "T" + T_s + ".png" dbName = fileNameWithoutExtension + "Num" + num + "Visc" + visc_s + "Speed" + speed_s + "T" + T_s ############################################################# # Ploting the values and puting them in container ############################################################# print "Plot the values" plot_file(pictureName, resultLists) pictureFile = open(pictureName, "r") print "Sending png to container" object_id = conn.put_object(bucket_name, pictureName, pictureFile) os.system("sudo rm -rf " + fileNameWithoutExtension + "*") FNULL.close() return (dbName)
def convertToXML(i): meshes = glob.glob("msh/r*a" + str(i) + "n*.msh") for fn in meshes: gmsh2xml(fn, fn[:-3] + "xml")