def ExecuteFinalizeSolutionStep(self): if (self.fluid_model_part.ProcessInfo.GetValue( KratosMultiphysics.DOMAIN_SIZE) == 2): CPFApp.ComputeEmbeddedLiftProcess2D( self.fluid_model_part, self.resultant_force).Execute() elif (self.fluid_model_part.ProcessInfo.GetValue( KratosMultiphysics.DOMAIN_SIZE) == 3): CPFApp.ComputeEmbeddedLiftProcess3D( self.fluid_model_part, self.resultant_force).Execute() else: raise (Exception( "Dimension of the problem is different than 2 or 3.")) self._CalculateWakeTangentAndNormalDirections() self._ProjectForceToFreeStreamVelocity(self.resultant_force / self.reference_area) KratosMultiphysics.Logger.PrintInfo('ComputeEmbeddedLiftProcess', ' Cl = ', self.lift_coefficient) KratosMultiphysics.Logger.PrintInfo('ComputeEmbeddedLiftProcess', ' Cd = ', self.drag_coefficient) self.fluid_model_part.ProcessInfo.SetValue(CPFApp.LIFT_COEFFICIENT, self.lift_coefficient) self.fluid_model_part.ProcessInfo.SetValue(CPFApp.DRAG_COEFFICIENT, self.drag_coefficient)
def __CreateResponseFunction(self): computing_model_part = self.GetComputingModelPart() if self.response_function_settings["response_type"].GetString( ) == "adjoint_lift_jump_coordinates": response_function = KCPFApp.AdjointLiftJumpCoordinatesResponseFunction( computing_model_part, self.response_function_settings) elif self.response_function_settings["response_type"].GetString( ) == "adjoint_lift_far_field": response_function = KCPFApp.AdjointLiftFarFieldResponseFunction( computing_model_part, self.response_function_settings) else: raise Exception( "Invalid response_type: " + self.response_function_settings["response_type"].GetString()) return response_function
def _ComputeLiftFromJumpCondition3D(self): nodal_value_process = CPFApp.ComputeNodalValueProcess(self.fluid_model_part, ["VELOCITY"]) nodal_value_process.Execute() potential_integral = 0.0 drag_integral = 0.0 for cond in self.trailing_edge_model_part.Conditions: length = cond.GetGeometry().Area() for node in cond.GetNodes(): potential = node.GetSolutionStepValue(CPFApp.VELOCITY_POTENTIAL) auxiliary_potential = node.GetSolutionStepValue(CPFApp.AUXILIARY_VELOCITY_POTENTIAL) velocity = node.GetValue(KratosMultiphysics.VELOCITY) velocity_normal_component = _DotProduct(self.wake_normal,velocity) potential_jump = potential - auxiliary_potential potential_integral += 0.5 * length * potential_jump drag_integral -= 0.5 * length * potential_jump * velocity_normal_component free_stream_velocity = self.fluid_model_part.ProcessInfo.GetValue(CPFApp.FREE_STREAM_VELOCITY) free_stream_velocity_norm2 = free_stream_velocity.norm_2() self.drag_coefficient_jump = drag_integral/(free_stream_velocity_norm2*self.reference_area) self.lift_coefficient_jump = 2*potential_integral/(self.free_stream_velocity_norm*self.reference_area) KratosMultiphysics.Logger.PrintInfo('ComputeLiftProcess',' Cl = ', self.lift_coefficient_jump, 'Potential Jump') KratosMultiphysics.Logger.PrintInfo('ComputeLiftProcess',' Cd = ', self.drag_coefficient_jump, 'Potential Jump') self.fluid_model_part.ProcessInfo.SetValue(CPFApp.LIFT_COEFFICIENT_JUMP, self.lift_coefficient_jump)
def MappingAndEvaluateQuantityOfInterest(self): nodal_value_process = KCPFApp.ComputeNodalValueProcess(self.adjoint_analysis._GetSolver().main_model_part, ["PRESSURE_COEFFICIENT"]) nodal_value_process.Execute() KratosMultiphysics.VariableUtils().SetNonHistoricalVariableToZero(KratosMultiphysics.PRESSURE_COEFFICIENT, self.mapping_reference_model.GetModelPart(self.main_model_part_name).Nodes) KratosMultiphysics.VariableUtils().SetNonHistoricalVariableToZero(KratosMultiphysics.SHAPE_SENSITIVITY, self.mapping_reference_model.GetModelPart(self.main_model_part_name).Nodes) # map from current model part of interest to reference model part mapping_parameters = KratosMultiphysics.Parameters("""{ "mapper_type": "nearest_element", "echo_level" : 0 }""") mapping_parameters.AddString("interface_submodel_part_origin", self.design_surface_sub_model_part_name) mapping_parameters.AddString("interface_submodel_part_destination", self.design_surface_sub_model_part_name) mapper = KratosMultiphysics.MappingApplication.MapperFactory.CreateMapper(self.adjoint_analysis._GetSolver().main_model_part,self.mapping_reference_model.GetModelPart(self.main_model_part_name),mapping_parameters) mapper.Map(KratosMultiphysics.PRESSURE_COEFFICIENT, \ KratosMultiphysics.PRESSURE_COEFFICIENT, \ KratosMultiphysics.MappingApplication.Mapper.FROM_NON_HISTORICAL | \ KratosMultiphysics.MappingApplication.Mapper.TO_NON_HISTORICAL) mapper.Map(KratosMultiphysics.SHAPE_SENSITIVITY, \ KratosMultiphysics.SHAPE_SENSITIVITY, KratosMultiphysics.MappingApplication.Mapper.TO_NON_HISTORICAL) # evaluate qoi qoi_list = self.EvaluateQuantityOfInterest() return qoi_list
def Initialize(self): """Perform initialization after adding nodal variables and dofs to the main model part. """ if self.response_function_settings["response_type"].GetString( ) == "adjoint_lift_jump_coordinates": self.response_function = KCPFApp.AdjointLiftJumpCoordinatesResponseFunction( self.main_model_part, self.response_function_settings) else: raise Exception( "invalid response_type: " + self.response_function_settings["response_type"].GetString()) self.sensitivity_builder = KratosMultiphysics.SensitivityBuilder( self.sensitivity_settings, self.main_model_part, self.response_function) self.sensitivity_builder.Initialize() scheme = KratosMultiphysics.ResidualBasedAdjointStaticScheme( self.response_function) builder_and_solver = KratosMultiphysics.ResidualBasedBlockBuilderAndSolver( self.linear_solver) self.solver = KratosMultiphysics.ResidualBasedLinearStrategy( self.main_model_part, scheme, self.linear_solver, builder_and_solver, self.settings["compute_reactions"].GetBool(), self.settings["reform_dofs_at_each_step"].GetBool(), self.settings["calculate_solution_norm"].GetBool(), self.settings["move_mesh_flag"].GetBool()) self.solver.SetEchoLevel(self.settings["echo_level"].GetInt()) self.solver.Check() self.response_function.Initialize() KratosMultiphysics.Logger.PrintInfo( "::[PotentialFlowAdjointSolver]:: ", "Finished initialization.")
def ExecuteInitialize(self): # If stl available, read wake from stl and create the wake model part start_time = time.time() self.__CreateWakeModelPart() exe_time = time.time() - start_time KratosMultiphysics.Logger.PrintInfo( 'DefineWakeProcess3D', 'Executing __CreateWakeModelPart took ', round(exe_time, 2), ' sec') KratosMultiphysics.Logger.PrintInfo( 'DefineWakeProcess3D', 'Executing __CreateWakeModelPart took ', round(exe_time / 60, 2), ' min') start_time = time.time() CPFApp.Define3DWakeProcess( self.trailing_edge_model_part, self.body_model_part, self.wake_model_part, self.wake_process_cpp_parameters).ExecuteInitialize() exe_time = time.time() - start_time KratosMultiphysics.Logger.PrintInfo( 'DefineWakeProcess3D', 'Executing Define3DWakeProcess took ', round(exe_time, 2), ' sec') KratosMultiphysics.Logger.PrintInfo( 'DefineWakeProcess3D', 'Executing Define3DWakeProcess took ', round(exe_time / 60, 2), ' min') # # Output the wake in GiD for visualization if (self.output_wake): self.__VisualizeWake()
def ExecuteFinalizeSolutionStep(self): if not self.elemental_variables_list_to_project: KratosMultiphysics.Logger.PrintWarning( 'ComputeNodalValueProcess', 'No elemental variables were specified to compute its nodal projection' ) else: CPFApp.ComputeNodalValueProcess( self.main_model_part, self.elemental_variables_list_to_project).Execute()
def ExecuteInitializeSolutionStep(self): ini_time = time.time() self._DefineWakeModelPart() self._MoveAndRotateWake() # Executing define wake process CPFApp.DefineEmbeddedWakeProcess(self.main_model_part, self.wake_model_part).Execute() KratosMultiphysics.Logger.PrintInfo('EmbeddedWake', 'Wake computation time: ', time.time() - ini_time)
def _MoveAndRotateWake(self): ''' This function moves and rotates the wake with the same parameters as the geometry. ''' self.moving_parameters = KratosMultiphysics.Parameters() self.moving_parameters.AddEmptyValue("origin") self.moving_parameters["origin"].SetVector( self.main_model_part.ProcessInfo.GetValue(CPFApp.WAKE_ORIGIN)) self.moving_parameters.AddEmptyValue("rotation_angle") angle = math.radians( -self.main_model_part.ProcessInfo.GetValue(CPFApp.ROTATION_ANGLE)) self.moving_parameters["rotation_angle"].SetDouble(angle) CPFApp.MoveModelPartProcess(self.wake_model_part, self.moving_parameters).Execute()
def _InitializeSkinModelPart(self): ''' This function loads and moves the skin_model_part in the main_model_part to the desired initial point (origin). It also rotates the skin model part around the origin point according to the rotation_angle''' self.skin_model_part=self.model.CreateModelPart("skin") ini_time=time.time() # Reading skin model part KratosMultiphysics.ModelPartIO(self.skin_model_part_name).ReadModelPart(self.skin_model_part) # Moving and rotating the skin model part angle=math.radians(-self.moving_parameters["rotation_angle"].GetDouble()) self.moving_parameters["rotation_angle"].SetDouble(angle) CompressiblePotentialFlow.MoveModelPartProcess(self.skin_model_part, self.moving_parameters).Execute() KratosMultiphysics.Logger.PrintInfo('LevelSetRemeshing','InitializeSkin time: ',time.time()-ini_time)
def Finalize(self): super().Finalize() aoa = self.project_parameters["processes"]["boundary_conditions_process_list"][0]["Parameters"]["angle_of_attack"].GetDouble() mach = self.project_parameters["processes"]["boundary_conditions_process_list"][0]["Parameters"]["mach_infinity"].GetDouble() self.primal_model_part = self._GetSolver().main_model_part nodal_velocity_process = KCPFApp.ComputeNodalValueProcess(self.primal_model_part, ["VELOCITY"]) nodal_velocity_process.Execute() # Store mesh to solve with adjoint after remeshing self.primal_model_part.RemoveSubModelPart("fluid_computational_model_part") self.primal_model_part.RemoveSubModelPart("wake_sub_model_part") KratosMultiphysics.ModelPartIO(self.auxiliary_mdpa_path+"_"+str(self.sample[0]), KratosMultiphysics.IO.WRITE | KratosMultiphysics.IO.MESH_ONLY).WriteModelPart(self.primal_model_part) with open(self.adjoint_parameters_path,'r') as parameter_file: adjoint_parameters = KratosMultiphysics.Parameters( parameter_file.read() ) # Create the adjoint solver adjoint_parameters = _CheckParameters(adjoint_parameters) adjoint_model = KratosMultiphysics.Model() adjoint_parameters["processes"]["boundary_conditions_process_list"][0]["Parameters"]["mach_infinity"].SetDouble(mach) adjoint_parameters["processes"]["boundary_conditions_process_list"][0]["Parameters"]["angle_of_attack"].SetDouble(aoa) adjoint_parameters["solver_settings"]["model_import_settings"]["input_filename"].SetString(self.auxiliary_mdpa_path+"_"+str(self.sample[0])) self.adjoint_analysis = potential_flow_analysis.PotentialFlowAnalysis(adjoint_model, adjoint_parameters) self.primal_state_variables = [KCPFApp.VELOCITY_POTENTIAL, KCPFApp.AUXILIARY_VELOCITY_POTENTIAL] self.adjoint_analysis.Initialize() self.adjoint_model_part = self.adjoint_analysis._GetSolver().main_model_part # synchronize the modelparts self._SynchronizeAdjointFromPrimal() self.adjoint_analysis.RunSolutionLoop() self.adjoint_analysis.Finalize() self.response_function = self.adjoint_analysis._GetSolver()._GetResponseFunction()
def EvaluateQuantityOfInterest(self): """ Method evaluating the QoI of the problem: lift coefficient. """ qoi_list = [self.response_function.CalculateValue(self.primal_model_part)] Logger.PrintInfo("StochasticAdjointResponse", " Lift Coefficient: ",qoi_list[0]) pressure_coefficient = [] nodal_value_process = KCPFApp.ComputeNodalValueProcess(self.adjoint_analysis._GetSolver().main_model_part, ["PRESSURE_COEFFICIENT"]) nodal_value_process.Execute() if (self.mapping is not True): for node in self.adjoint_analysis._GetSolver().main_model_part.GetSubModelPart(self.design_surface_sub_model_part_name).Nodes: this_pressure = node.GetValue(KratosMultiphysics.PRESSURE_COEFFICIENT) pressure_coefficient.append(this_pressure) elif (self.mapping is True): for node in self.mapping_reference_model.GetModelPart(self.main_model_part_name).GetSubModelPart(self.design_surface_sub_model_part_name).Nodes: this_pressure = node.GetValue(KratosMultiphysics.PRESSURE_COEFFICIENT) pressure_coefficient.append(this_pressure) # Fill the rest of the list to match SHAPE_SENSITIVITY data structure length pressure_coefficient.extend([0.0]*self.mapping_reference_model.GetModelPart(self.main_model_part_name).GetSubModelPart(self.design_surface_sub_model_part_name).NumberOfNodes()*2) qoi_list.append(pressure_coefficient) shape_sensitivity = [] if (self.mapping is not True): for node in self.adjoint_analysis._GetSolver().main_model_part.GetSubModelPart(self.design_surface_sub_model_part_name).Nodes: this_shape = node.GetSolutionStepValue(KratosMultiphysics.SHAPE_SENSITIVITY) shape_sensitivity.extend(this_shape) elif (self.mapping is True): for node in self.mapping_reference_model.GetModelPart(self.main_model_part_name).GetSubModelPart(self.design_surface_sub_model_part_name).Nodes: this_shape = node.GetValue(KratosMultiphysics.SHAPE_SENSITIVITY) shape_sensitivity.extend(this_shape) qoi_list.append(shape_sensitivity) Logger.PrintInfo("StochasticAdjointResponse", "Total number of QoI:",len(qoi_list)) return qoi_list
def ExecuteInitialize(self): CPFApp.Define2DWakeProcess(self.body_model_part, self.epsilon).ExecuteInitialize()
def __ComputeNodalVelocity(self): nodal_velocity_process = CPFApp.ComputeNodalValueProcess( self.main_model_part, ["VELOCITY"]) nodal_velocity_process.Execute()
def ExecuteFinalizeSolutionStep(self): super(WriteForcesProcess, self).ExecuteFinalizeSolutionStep() nodal_value_process = CPFApp.ComputeNodalValueProcess( self.fluid_model_part, ["PRESSURE_COEFFICIENT"]) nodal_value_process.Execute()
def ExecuteInitializeSolutionStep(self): if self.compute_wake_at_each_step and self.fluid_model_part.ProcessInfo[KratosMultiphysics.STEP] > 1: CPFApp.Define2DWakeProcess(self.body_model_part, self.epsilon).ExecuteInitialize()
def ExecuteFinalizeSolutionStep(self): super(WriteForcesProcess, self).ExecuteFinalizeSolutionStep() nodal_value_process = CPFApp.ComputeNodalValueProcess(self.fluid_model_part, ["PRESSURE_COEFFICIENT"]) nodal_value_process.Execute() if self.compute_trefft_plane_forces: potential_integral = 0.0 drag_integral = 0.0 for cond in self.trefft_plane_cut_model_part.Conditions: length = cond.GetGeometry().Area() for node in cond.GetNodes(): potential = node.GetSolutionStepValue(CPFApp.VELOCITY_POTENTIAL) auxiliary_potential = node.GetSolutionStepValue(CPFApp.AUXILIARY_VELOCITY_POTENTIAL) velocity = node.GetValue(KratosMultiphysics.VELOCITY) velocity_normal_component = _DotProduct(self.wake_normal,velocity) potential_jump = auxiliary_potential - potential potential_integral += 0.5 * length * potential_jump drag_integral -= 0.5 * length * potential_jump * velocity_normal_component self.lift_coefficient_jump_trefft = 2*potential_integral/(self.free_stream_velocity_norm*self.reference_area) free_stream_velocity = self.fluid_model_part.ProcessInfo.GetValue(CPFApp.FREE_STREAM_VELOCITY) free_stream_velocity_norm2 = _DotProduct(free_stream_velocity,free_stream_velocity) self.drag_coefficient_jump_trefft = drag_integral/(free_stream_velocity_norm2*self.reference_area) KratosMultiphysics.Logger.PrintInfo('ComputeLiftProcess',' Cl = ', self.lift_coefficient_jump_trefft, 'Potential Jump Trefft Plane') KratosMultiphysics.Logger.PrintInfo('ComputeLiftProcess',' Cd = ', self.drag_coefficient_jump_trefft, 'Potential Jump Trefft Plane') # with open('results_3d_finite_wing.dat', 'a') as file: # file.write('{0:12.4f} {1:12.4f} {2:12.4f} {3:12.2e} {4:12.2e} {4:12.2e} {6:12.4e}'.format( # self.lift_coefficient, # 0 # self.lift_coefficient_far_field, # 1 # self.lift_coefficient_jump, # 2 # self.drag_coefficient, # 3 # self.drag_coefficient_far_field, # 4 # self.lateral_force_coefficient, # 5 # self.lateral_force_coefficient_far_field)) # 6 # file.flush() NumberOfNodes = self.fluid_model_part.NumberOfNodes() self.cl_reference = self.read_cl_reference(self.AOA) self.cd_reference = self.read_cd_reference(self.AOA) self.cm_reference = self.read_cm_reference(self.AOA) if(abs(self.cl_reference) < 1e-6): self.cl_p_relative_error = abs(self.lift_coefficient - self.cl_reference) else: self.cl_p_relative_error = abs(self.lift_coefficient - self.cl_reference)/abs(self.cl_reference)*100.0 if(abs(self.cd_reference) < 1e-6): self.cd_p_relative_error = abs(self.drag_coefficient - self.cd_reference) else: self.cd_p_relative_error = abs(self.drag_coefficient - self.cd_reference)/abs(self.cd_reference)*100.0 if(abs(self.cm_reference) < 1e-6): self.cm_p_relative_error = abs(self.moment_coefficient[1] - self.cm_reference) else: self.cm_p_relative_error = abs(self.moment_coefficient[1] - self.cm_reference)/abs(self.cm_reference)*100.0 cl_data_directory_name = self.input_dir_path + '/plots/cl/' + 'data/cl_AOA_' + str(self.AOA) cl_p_results_file_name = cl_data_directory_name + '/cl_p_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cl_p_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.lift_coefficient)) cl_file.flush() cl_f_results_file_name = cl_data_directory_name + '/cl_f_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cl_f_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.lift_coefficient_far_field)) cl_file.flush() cl_j_results_file_name = cl_data_directory_name + '/cl_j_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cl_j_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.lift_coefficient_jump)) cl_file.flush() cl_reference_results_file_name = cl_data_directory_name + '/cl_ref.dat' with open(cl_reference_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.cl_reference)) cl_file.flush() cd_data_directory_name = self.input_dir_path + '/plots/cd/' + 'data/cd_AOA_' + str(self.AOA) cd_p_results_file_name = cd_data_directory_name + '/cd_p_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cd_p_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.drag_coefficient)) cl_file.flush() cd_results_file_name = cd_data_directory_name + '/cd_f_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cd_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.drag_coefficient_far_field)) cl_file.flush() cd_reference_results_file_name = cd_data_directory_name + '/cd_ref.dat' with open(cd_reference_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.cd_reference)) cl_file.flush() cm_data_directory_name = self.input_dir_path + '/plots/cm/' + 'data/cm_AOA_' + str(self.AOA) cm_results_file_name = cm_data_directory_name + '/cm_p_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cm_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.moment_coefficient[1])) cl_file.flush() cm_reference_results_file_name = cm_data_directory_name + '/cm_ref.dat' with open(cm_reference_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.cm_reference)) cl_file.flush() cl_error_data_directory_name = self.input_dir_path + '/plots/cl_error/' + 'data/cl_error_AOA_' + str(self.AOA) cl_error_p_results_file_name = cl_error_data_directory_name + '/cl_error_p_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cl_error_p_results_file_name,'a') as cl_file: cl_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.cl_p_relative_error)) cl_file.flush() cd_error_data_directory_name = self.input_dir_path + '/plots/cd_error/' + 'data/cd_error_AOA_' + str(self.AOA) cd_error_p_results_file_name = cd_error_data_directory_name + '/cd_error_p_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cd_error_p_results_file_name,'a') as cd_file: cd_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.cd_p_relative_error)) cd_file.flush() cm_error_data_directory_name = self.input_dir_path + '/plots/cm_error/' + 'data/cm_error_AOA_' + str(self.AOA) cm_error_p_results_file_name = cm_error_data_directory_name + '/cm_error_p_results_GRD_' + str(self.Growth_Rate_Domain) + '.dat' with open(cm_error_p_results_file_name,'a') as cm_file: cm_file.write('{0:16.2e} {1:15f}\n'.format(NumberOfNodes, self.cm_p_relative_error)) cm_file.flush() mesh_size = self.Growth_Rate_Wing * self.Growth_Rate_Domain if mesh_size < self.minimum_mesh_growth_rate + 1e-9: cl_aoa_results_file_name = self.input_dir_path + '/plots/cl_aoa/' + 'data/cl_aoa/cl_aoa.dat' with open(cl_aoa_results_file_name,'a') as cl_aoa_file: cl_aoa_file.write('{0:15f} {1:15f}\n'.format(self.AOA, self.lift_coefficient)) cl_aoa_file.flush() cl_aoa_ref_results_file_name = self.input_dir_path + '/plots/cl_aoa/' + 'data/cl_aoa/cl_aoa_ref.dat' with open(cl_aoa_ref_results_file_name,'a') as cl_aoa_file: cl_aoa_file.write('{0:15f} {1:15f}\n'.format(self.AOA, self.cl_reference)) cl_aoa_file.flush() cd_aoa_results_file_name = self.input_dir_path + '/plots/cd_aoa/' + 'data/cd_aoa/cd_aoa.dat' with open(cd_aoa_results_file_name,'a') as cd_aoa_file: cd_aoa_file.write('{0:15f} {1:15f}\n'.format(self.AOA, self.drag_coefficient)) cd_aoa_file.flush() cd_aoa_ref_results_file_name = self.input_dir_path + '/plots/cd_aoa/' + 'data/cd_aoa/cd_aoa_ref.dat' with open(cd_aoa_ref_results_file_name,'a') as cd_aoa_file: cd_aoa_file.write('{0:15f} {1:15f}\n'.format(self.AOA, self.cd_reference)) cd_aoa_file.flush() cm_aoa_results_file_name = self.input_dir_path + '/plots/cm_aoa/' + 'data/cm_aoa/cm_aoa.dat' with open(cm_aoa_results_file_name,'a') as cm_aoa_file: cm_aoa_file.write('{0:15f} {1:15f}\n'.format(self.AOA, self.moment_coefficient[1])) cm_aoa_file.flush() cm_aoa_ref_results_file_name = self.input_dir_path + '/plots/cm_aoa/' + 'data/cm_aoa/cm_aoa_ref.dat' with open(cm_aoa_ref_results_file_name,'a') as cm_aoa_file: cm_aoa_file.write('{0:15f} {1:15f}\n'.format(self.AOA, self.cm_reference)) cm_aoa_file.flush() potential_jump_dir_name = self.input_dir_path + '/plots/potential_jump/data/AOA_' + str(self.AOA) + '/Growth_Rate_Domain_' + str( self.Growth_Rate_Domain) + '/Growth_Rate_Wing_' + str(self.Growth_Rate_Wing) potential_jump_file_name = potential_jump_dir_name + '/potential_jump_results.dat' with open(potential_jump_file_name, 'w') as jump_file: for node in self.trailing_edge_model_part.Nodes: potential = node.GetSolutionStepValue(CPFApp.VELOCITY_POTENTIAL) auxiliary_potential = node.GetSolutionStepValue(CPFApp.AUXILIARY_VELOCITY_POTENTIAL) potential_jump = potential - auxiliary_potential jump_file.write('{0:15f} {1:15f}\n'.format(node.Y, potential_jump)) potential_jump_file_name = potential_jump_dir_name + '/potential_jump_trefftz_results.dat' with open(potential_jump_file_name, 'w') as jump_file: for node in self.trefft_plane_cut_model_part.Nodes: potential = node.GetSolutionStepValue(CPFApp.VELOCITY_POTENTIAL) auxiliary_potential = node.GetSolutionStepValue(CPFApp.AUXILIARY_VELOCITY_POTENTIAL) potential_jump = auxiliary_potential - potential jump_file.write('{0:15f} {1:15f}\n'.format(node.Y, potential_jump)) cp_dir_name = self.input_dir_path + '/plots/cp/data/AOA_' + str(self.AOA) + '/Growth_Rate_Domain_' + str( self.Growth_Rate_Domain) + '/Growth_Rate_Wing_' + str(self.Growth_Rate_Wing) cp_file_name = cp_dir_name + '/cp_results.dat' aoa_rad = self.AOA * math.pi / 180.0 with open(cp_file_name, 'w') as cp_file: for node in self.middle_airfoil_model_part.Nodes: pressure_coeffient = node.GetValue(KratosMultiphysics.PRESSURE_COEFFICIENT) x = node.X * math.cos(aoa_rad) - node.Z * math.sin(aoa_rad) + 0.5 #x = node.X + 0.5 #if node.GetValue(CPFApp.UPPER_SURFACE): cp_file.write('{0:15f} {1:15f}\n'.format(x, pressure_coeffient)) cp_tikz_file_name = cp_dir_name + '/cp.tikz' output_file_name = cp_dir_name + '/xflr5/section_0/aoa' + str(int(self.AOA)) + '.dat' with open(cp_tikz_file_name,'w') as cp_tikz_file: cp_tikz_file.write('\\begin{tikzpicture}\n' + '\\begin{axis}[\n' + ' title={ $c_l$ = ' + "{:.6f}".format(self.lift_coefficient) + ' $c_d$ = ' + "{:.6f}".format(self.drag_coefficient) + '},\n' + ' xlabel={$x/c$},\n' + ' ylabel={$c_p[\\unit{-}$]},\n' + ' %xmin=-0.01, xmax=1.01,\n' + ' y dir=reverse,\n' + ' %xtick={0,0.2,0.4,0.6,0.8,1},\n' + ' %xticklabels={0,0.2,0.4,0.6,0.8,1},\n' + ' ymajorgrids=true,\n' + ' xmajorgrids=true,\n' + ' grid style=dashed,\n' + ' legend style={at={(0.5,-0.2)},anchor=north},\n' + ' width=12cm\n' + ']\n\n' + '\\addplot[\n' + ' only marks,\n' + ' color=red,\n' + #' mark=square,\n' + ' mark=*,\n' + ' mark size=1pt,\n' + ' ]\n' + ' table {cp_results.dat}; \n' + ' \\addlegendentry{Kratos}\n\n' + '\\addplot[\n' + ' color=black,\n' + ' mark=none,\n' + ' mark options={solid},\n' + ' ]\n' + ' table {' + output_file_name + '}; \n' + ' \\addlegendentry{XFLR5}\n\n' + '\end{axis}\n' + '\end{tikzpicture}') cp_tikz_file.flush() cp_100_dir_name = self.input_dir_path + '/plots/cp_section_100/data/AOA_' + str(self.AOA) + '/Growth_Rate_Domain_' + str( self.Growth_Rate_Domain) + '/Growth_Rate_Wing_' + str(self.Growth_Rate_Wing) cp_100_file_name = cp_100_dir_name + '/cp_results.dat' aoa_rad = self.AOA * math.pi / 180.0 with open(cp_100_file_name, 'w') as cp_file: for node in self.section_100_model_part.Nodes: pressure_coeffient = node.GetValue(KratosMultiphysics.PRESSURE_COEFFICIENT) x = node.X * math.cos(aoa_rad) - node.Z * math.sin(aoa_rad) + 0.5 #x = node.X + 0.5 #if node.GetValue(CPFApp.UPPER_SURFACE): cp_file.write('{0:15f} {1:15f}\n'.format(x, pressure_coeffient)) cp_tikz_file_name = cp_100_dir_name + '/cp.tikz' output_file_name = cp_100_dir_name + '/xflr5/section_100/aoa' + str(int(self.AOA)) + '.dat' with open(cp_tikz_file_name,'w') as cp_tikz_file: cp_tikz_file.write('\\begin{tikzpicture}\n' + '\\begin{axis}[\n' + ' title={ Section 100, $c_l$ = ' + "{:.6f}".format(self.lift_coefficient) + ' $c_d$ = ' + "{:.6f}".format(self.drag_coefficient) + '},\n' + ' xlabel={$x/c$},\n' + ' ylabel={$c_p[\\unit{-}$]},\n' + ' %xmin=-0.01, xmax=1.01,\n' + ' y dir=reverse,\n' + ' %xtick={0,0.2,0.4,0.6,0.8,1},\n' + ' %xticklabels={0,0.2,0.4,0.6,0.8,1},\n' + ' ymajorgrids=true,\n' + ' xmajorgrids=true,\n' + ' grid style=dashed,\n' + ' legend style={at={(0.5,-0.2)},anchor=north},\n' + ' width=12cm\n' + ']\n\n' + '\\addplot[\n' + ' only marks,\n' + ' color=red,\n' + #' mark=square,\n' + ' mark=*,\n' + ' mark size=1pt,\n' + ' ]\n' + ' table {cp_results.dat}; \n' + ' \\addlegendentry{Kratos}\n\n' + '\\addplot[\n' + ' color=black,\n' + ' mark=none,\n' + ' mark options={solid},\n' + ' ]\n' + ' table {' + output_file_name + '}; \n' + ' \\addlegendentry{XFLR5}\n\n' + '\end{axis}\n' + '\end{tikzpicture}') cp_tikz_file.flush() cp_150_dir_name = self.input_dir_path + '/plots/cp_section_150/data/AOA_' + str(self.AOA) + '/Growth_Rate_Domain_' + str( self.Growth_Rate_Domain) + '/Growth_Rate_Wing_' + str(self.Growth_Rate_Wing) cp_150_file_name = cp_150_dir_name + '/cp_results.dat' aoa_rad = self.AOA * math.pi / 180.0 with open(cp_150_file_name, 'w') as cp_file: for node in self.section_150_model_part.Nodes: pressure_coeffient = node.GetValue(KratosMultiphysics.PRESSURE_COEFFICIENT) x = node.X * math.cos(aoa_rad) - node.Z * math.sin(aoa_rad) + 0.5 #x = node.X + 0.5 #if node.GetValue(CPFApp.UPPER_SURFACE): cp_file.write('{0:15f} {1:15f}\n'.format(x, pressure_coeffient)) cp_tikz_file_name = cp_150_dir_name + '/cp.tikz' output_file_name = cp_150_dir_name + '/xflr5/section_150/aoa' + str(int(self.AOA)) + '.dat' with open(cp_tikz_file_name,'w') as cp_tikz_file: cp_tikz_file.write('\\begin{tikzpicture}\n' + '\\begin{axis}[\n' + ' title={ Section 150, $c_l$ = ' + "{:.6f}".format(self.lift_coefficient) + ' $c_d$ = ' + "{:.6f}".format(self.drag_coefficient) + '},\n' + ' xlabel={$x/c$},\n' + ' ylabel={$c_p[\\unit{-}$]},\n' + ' %xmin=-0.01, xmax=1.01,\n' + ' y dir=reverse,\n' + ' %xtick={0,0.2,0.4,0.6,0.8,1},\n' + ' %xticklabels={0,0.2,0.4,0.6,0.8,1},\n' + ' ymajorgrids=true,\n' + ' xmajorgrids=true,\n' + ' grid style=dashed,\n' + ' legend style={at={(0.5,-0.2)},anchor=north},\n' + ' width=12cm\n' + ']\n\n' + '\\addplot[\n' + ' only marks,\n' + ' color=red,\n' + #' mark=square,\n' + ' mark=*,\n' + ' mark size=1pt,\n' + ' ]\n' + ' table {cp_results.dat}; \n' + ' \\addlegendentry{Kratos}\n\n' + '\\addplot[\n' + ' color=black,\n' + ' mark=none,\n' + ' mark options={solid},\n' + ' ]\n' + ' table {' + output_file_name + '}; \n' + ' \\addlegendentry{XFLR5}\n\n' + '\end{axis}\n' + '\end{tikzpicture}') cp_tikz_file.flush() cp_180_dir_name = self.input_dir_path + '/plots/cp_section_180/data/AOA_' + str(self.AOA) + '/Growth_Rate_Domain_' + str( self.Growth_Rate_Domain) + '/Growth_Rate_Wing_' + str(self.Growth_Rate_Wing) cp_180_file_name = cp_180_dir_name + '/cp_results.dat' aoa_rad = self.AOA * math.pi / 180.0 with open(cp_180_file_name, 'w') as cp_file: for node in self.section_180_model_part.Nodes: pressure_coeffient = node.GetValue(KratosMultiphysics.PRESSURE_COEFFICIENT) x = node.X * math.cos(aoa_rad) - node.Z * math.sin(aoa_rad) + 0.5 #x = node.X + 0.5 #if node.GetValue(CPFApp.UPPER_SURFACE): cp_file.write('{0:15f} {1:15f}\n'.format(x, pressure_coeffient)) cp_tikz_file_name = cp_180_dir_name + '/cp.tikz' output_file_name = cp_180_dir_name + '/xflr5/section_180/aoa' + str(int(self.AOA)) + '.dat' with open(cp_tikz_file_name,'w') as cp_tikz_file: cp_tikz_file.write('\\begin{tikzpicture}\n' + '\\begin{axis}[\n' + ' title={ Section 180, $c_l$ = ' + "{:.6f}".format(self.lift_coefficient) + ' $c_d$ = ' + "{:.6f}".format(self.drag_coefficient) + '},\n' + ' xlabel={$x/c$},\n' + ' ylabel={$c_p[\\unit{-}$]},\n' + ' %xmin=-0.01, xmax=1.01,\n' + ' y dir=reverse,\n' + ' %xtick={0,0.2,0.4,0.6,0.8,1},\n' + ' %xticklabels={0,0.2,0.4,0.6,0.8,1},\n' + ' ymajorgrids=true,\n' + ' xmajorgrids=true,\n' + ' grid style=dashed,\n' + ' legend style={at={(0.5,-0.2)},anchor=north},\n' + ' width=12cm\n' + ']\n\n' + '\\addplot[\n' + ' only marks,\n' + ' color=red,\n' + #' mark=square,\n' + ' mark=*,\n' + ' mark size=1pt,\n' + ' ]\n' + ' table {cp_results.dat}; \n' + ' \\addlegendentry{Kratos}\n\n' + '\\addplot[\n' + ' color=black,\n' + ' mark=none,\n' + ' mark options={solid},\n' + ' ]\n' + ' table {' + output_file_name + '}; \n' + ' \\addlegendentry{XFLR5}\n\n' + '\end{axis}\n' + '\end{tikzpicture}') cp_tikz_file.flush() velocity_nodal_value_process = CPFApp.ComputeNodalValueProcess(self.fluid_model_part, ["VELOCITY"]) velocity_nodal_value_process.Execute()
def ExecuteInitializeSolutionStep(self): far_field_process = CPFApp.ApplyFarFieldProcess( self.far_field_model_part, self.inlet_potential_0, self.initialize_flow_field) far_field_process.Execute()
def __ComputeNodalVelocity(self): nodal_velocity_process = CPFApp.ComputeNodalPotentialFlowVelocityProcess( self.main_model_part) nodal_velocity_process.Execute()