def __CreateResponseFunctions( specified_responses, model ): response_functions = {} sho_response_functions = ["plane_based_packaging", "mesh_based_packaging"] csm_response_functions = ["strain_energy", "mass", "eigenfrequency", "adjoint_local_stress", "adjoint_max_stress"] convdiff_response_functions = ["point_temperature"] for (response_id, response_settings) in specified_responses: if response_id in response_functions.keys(): raise NameError("There are multiple response functions with the following identifier: " + response_id) response_type = response_settings["response_type"].GetString() if response_type in csm_response_functions: if csm_response_factory is None: raise RuntimeError("ShapeOpt: {} response function requires StructuralMechanicsApplication.".format(response_type)) response_functions[response_id] = csm_response_factory.CreateResponseFunction(response_id, response_settings, model) elif response_type in convdiff_response_functions: if convdiff_response_factory is None: raise RuntimeError("ShapeOpt: {} response function requires ConvectionDiffusionApplication.".format(response_type)) response_functions[response_id] = convdiff_response_factory.CreateResponseFunction(response_id, response_settings, model) elif response_type in sho_response_functions: response_functions[response_id] = sho_response_factory.CreateResponseFunction(response_id, response_settings, model) else: raise NameError("The response function '{}' of type '{}' is not available.".format(response_id, response_type)) return response_functions
def __CreateResponseFunctions(specified_responses, model): response_functions = {} available_csm_response_functions = [ "strain_energy", "mass", "eigenfrequency", "adjoint_local_stress", "adjoint_max_stress" ] for (response_id, response_settings) in specified_responses: if response_id in response_functions.keys(): raise NameError( "There are multiple response functions with the following identifier: " + response_id) if response_settings["response_type"].GetString( ) in available_csm_response_functions: response_functions[ response_id] = csm_response_factory.CreateResponseFunction( response_id, response_settings, model) else: raise NameError( "The following structural response function is not available: " + response_id) return response_functions
def setUp(self): with KratosUnittest.WorkFolderScope(_get_test_working_dir(), __file__): with open(self.file_name + "_parameters.json",'r') as parameter_file: parameters = KM.Parameters( parameter_file.read()) # To avoid many prints if (parameters["problem_data"]["echo_level"].GetInt() == 0): KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING) self.problem_name = parameters["problem_data"]["problem_name"].GetString() model = KM.Model() self.response_function = structural_response_function_factory.CreateResponseFunction("dummy", parameters["response_settings"], model) # call response function self.response_function.Initialize()
def __CreateResponseFunctions( specified_responses, model ): response_functions = {} available_sho_response_functions = ["plane_based_packaging", "mesh_based_packaging"] available_csm_response_functions = ["strain_energy", "mass", "eigenfrequency", "adjoint_local_stress", "adjoint_max_stress"] for (response_id, response_settings) in specified_responses: if response_id in response_functions.keys(): raise NameError("There are multiple response functions with the following identifier: " + response_id) response_type = response_settings["response_type"].GetString() if response_type in available_csm_response_functions: response_functions[response_id] = csm_response_factory.CreateResponseFunction(response_id, response_settings, model) elif response_type in available_sho_response_functions: response_functions[response_id] = sho_response_factory.CreateResponseFunction(response_id, response_settings, model) else: raise NameError("The response function '{}' of type '{}' is not available.".format(response_id, response_type)) return response_functions
"\n\n##########################################################################" ) print(">> Starting finite difference level ", itr, "for node ", str(move_node_id)) print( "##########################################################################\n\n" ) # Perturb current_delta = 1 * 10**(-itr) kratos_response_settings["step_size"].SetDouble(current_delta) # Run simulation model = KM.Model() response = structural_response_function_factory.CreateResponseFunction( kratos_response_settings["response_type"].GetString(), kratos_response_settings, model) response.RunCalculation(True) # Write results gradient_of_interest = response.GetNodalGradient( KM.SHAPE_SENSITIVITY)[move_node_id] with open(results_filename, 'a') as open_file: line_to_write = '%.0E' % Decimal(str(current_delta)) + ",\t" line_to_write += '%.6E' % Decimal(str( gradient_of_interest[0])) + ",\t" line_to_write += '%.6E' % Decimal(str( gradient_of_interest[1])) + ",\t" line_to_write += '%.6E' % Decimal(str( gradient_of_interest[2])) + ",\t" line_to_write += str(time.ctime()) + "\n"
def __CreateResponseFunctions(specified_responses, model): response_functions = {} sho_response_functions = [ "plane_based_packaging", "mesh_based_packaging", "surface_normal_shape_change", "face_angle", "airfoil_angle_of_attack", "airfoil_chord_length", "airfoil_perimeter" ] csm_response_functions = [ "strain_energy", "mass", "eigenfrequency", "adjoint_local_stress", "adjoint_max_stress" ] cps_response_functions = [ "adjoint_lift_potential_jump", "stochastic_adjoint_lift_potential_jump" ] convdiff_response_functions = ["point_temperature"] for (response_id, response_settings) in specified_responses: if response_id in response_functions.keys(): raise NameError( "There are multiple response functions with the following identifier: " + response_id) response_type = response_settings["response_type"].GetString() if response_type in csm_response_functions: if csm_response_factory is None: raise RuntimeError( "ShapeOpt: {} response function requires StructuralMechanicsApplication." .format(response_type)) response_functions[ response_id] = csm_response_factory.CreateResponseFunction( response_id, response_settings, model) elif response_type in convdiff_response_functions: if convdiff_response_factory is None: raise RuntimeError( "ShapeOpt: {} response function requires ConvectionDiffusionApplication." .format(response_type)) response_functions[ response_id] = convdiff_response_factory.CreateResponseFunction( response_id, response_settings, model) elif response_type in cps_response_functions: if potential_flow_response_factory is None: raise RuntimeError( "ShapeOpt: {} response function requires CompressiblePotentialFlowApplication." .format(response_type)) response_functions[ response_id] = potential_flow_response_factory.CreateResponseFunction( response_id, response_settings, model) elif response_type in sho_response_functions: response_functions[ response_id] = sho_response_factory.CreateResponseFunction( response_id, response_settings, model) else: raise NameError( "The response function '{}' of type '{}' is not available." .format(response_id, response_type)) return response_functions