current_drag_measurement = None; current_moment_measurement = None; while current_sim_time <= MAX_SIM_TIME: # Run simulation. print "Running OpenFOAM simulation to "+str(current_sim_time) os.system("pimpleFoam > logs/simulation") # Extract averaged performance figure. latest_force_time = force_read.get_latest_force_time("wing") forces_file = "postProcessing/wing/"+str(latest_force_time)+"/forces.dat" master_list = force_read.get_forces_dict(forces_file) time = master_list[0] drag = master_list[1] lift = master_list[2] moment = master_list[3] new_lift_measurement = force_read.trailing_average(time, lift, TRAIL_CHECK) new_drag_measurement = force_read.trailing_average(time, drag, TRAIL_CHECK) new_moment_measurement = \ force_read.trailing_average(time, moment, TRAIL_CHECK) # Check to stop if current_lift_measurement != None: diff_lift = abs(new_lift_measurement-current_lift_measurement) diff_drag = abs(new_drag_measurement-current_drag_measurement) diff_moment = abs(new_moment_measurement-current_moment_measurement) ratio_lift = diff_lift / current_lift_measurement ratio_drag = diff_drag / current_drag_measurement ratio_moment = diff_moment / current_moment_measurement ratio = max([ratio_lift, ratio_drag, ratio_moment]) if ratio*100 < STOP_THRESHOLD_PERCENT: break
import os from openfoam_python import force_read from openfoam_python import file_operations # Extract averaged performance figure. latest_force_time = force_read.get_latest_force_time("wing") forces_file = "postProcessing/wing/"+str(latest_force_time)+"/forces.dat" master_list = force_read.get_forces_dict(forces_file) time = master_list[0] drag = master_list[1] lift = master_list[2] moment = master_list[3] # Post-processing print "Obtaining performance figures." L = force_read.trailing_average(time, lift, TRAIL_CHECK) D = force_read.trailing_average(time, drag, TRAIL_CHECK) M = force_read.trailing_average(time, moment, TRAIL_CHECK) V = force_read.get_V() q = 0.5*1.18*V*V c = force_read.get_overall_chord() A = c*force_read.get_cell_depth() cl = L / A / q cd = D / A / q cm = M / A / q / c # Store CFD solution print "Storing CFD solution." biggest_number = file_operations.get_highest_folder("../vault", "v") new_vault_name = "v"+str(biggest_number+1) new_vault_folder = "../vault/"+new_vault_name