[D0036] エアギャップ間の熱伝達

 

エアギャップ間の熱伝達を設定する

import math

def main():
	app = designer.GetApplication()
	dialog = app.CreateDialogBox()
	
	title_ja = "エアギャップ間の熱伝達"
	title_en = "Heat Transfer at Airgap"
	
	select_rotor_face_ja = "面(ロータ側)"
	select_rotor_face_en = "Surface(Rotor Side)"
	
	select_stator_face_ja = "面(ステータ側)"
	select_stator_face_en = "Surface(Stator Side)"
	
	gap_length_ja = "ギャップ長, mm"
	gap_length_en = "Gap Length, mm"
	
	select_axis_ja = "回転軸"
	select_axis_en = "Axis of Rotation"

	air_speed_ja = "流速, m/s"
	air_speed_en = "Air Speed, m/s"

	study_select_error_en = "Current Study is not Heat Study."
	study_select_error_ja = "選択されているスタディは熱解析スタディではありません。"

	no_rotor_face_selected_ja = "面(ロータ側)が選択されていません。"
	no_rotor_face_selected_en = "No Face(Rotor Side) is selected."

	no_stator_face_selected_ja = "面(ステータ側)が選択されていません。"
	no_stator_face_selected_en = "No Face(Stator Side) is selected."

	gap_zero_negative_ja = "ギャップ長には0より大きい値を入力してください。"
	gap_zero_negative_en = "Input gap length greater than zero."

	cancel_message_en = "Process is canceled."
	cancel_message_ja = "処理が中断されました。"
	
	to_meter = 0.001

	currentStudy = app.GetCurrentStudy()
	currentStudyType = currentStudy.GetScriptTypeName()
	if not currentStudyType.startswith("Heat"):
		show_error_exit_message(study_select_error_en, study_select_error_ja)
		return

	app.View().SelectFace()
	
	dialog.SetTranslation(title_en, title_ja)
	dialog.SetTranslation(select_rotor_face_en, select_rotor_face_ja)
	dialog.SetTranslation(select_stator_face_en, select_stator_face_ja)
	dialog.SetTranslation(gap_length_en, gap_length_ja)
	dialog.SetTranslation(air_speed_en, air_speed_ja)
	dialog.SetTranslation(select_axis_en, select_axis_ja)

	dialog.SetTitle(title_en)
	dialog.SetModal(False)
	dialog.AddSelectFaceList("select_rotor_face", select_rotor_face_en)
	dialog.AddSelectFaceList("select_stator_face", select_stator_face_en)
	dialog.AddReal("gap_length", gap_length_en, 0.1)
	dialog.AddReal("air_speed", air_speed_en, 1)
	dialog.AddAxisSelection("origin", "vector", select_axis_en)
	ret = dialog.Show()
	if ret==0:
		show_cancel_exit_message(cancel_message_en, cancel_message_ja)
		return
	rotor_face_ids = dialog.GetValueAsIntegerList("select_rotor_face")
	rotor_mesh_group_ids = dialog.GetMeshGroupIndices("select_rotor_face")
	if len(rotor_face_ids)==0 and len(rotor_mesh_group_ids)==0:
		show_cancel_exit_message(no_rotor_face_selected_en, no_rotor_face_selected_ja)
		return
	rotor_face_set_indices = dialog.GetSetIndices("select_rotor_face")
	stator_face_ids = dialog.GetValueAsIntegerList("select_stator_face")
	stator_mesh_group_ids = dialog.GetMeshGroupIndices("select_stator_face")
	if len(stator_face_ids)==0 and len(stator_mesh_group_ids)==0:
		show_cancel_exit_message(no_stator_face_selected_en, no_stator_face_selected_ja)
		return
	stator_face_set_indices = dialog.GetSetIndices("select_stator_face")

	# create circuit
	if currentStudy.HasCircuit():
		circuit = currentStudy.GetCircuit()
	else:
		circuit = currentStudy.CreateCircuit()

	if app.HasError():
		return

	ht_name1 = unique_name(circuit, "TB1")
	ht_name2 = unique_name(circuit, "TB2")
	app.ClearError()

	bottom = circuit_bottom_position(circuit)
	basex = 0
	basey = bottom - 2

	circuit.CreateComponent("HeatTransferBoundary", ht_name1)
	circuit.CreateInstance(ht_name1, int(basex-2), int(basey-1))
	circuit.CreateComponent("HeatTransferBoundary", ht_name2)
	circuit.CreateInstance(ht_name2, int(basex+2), int(basey-1))
	circuit.CreateWire(int(basex-2), int(basey), int(basex), int(basey))
	circuit.CreateWire(int(basex), int(basey), int(basex+2), int(basey))
	
	origin = dialog.GetPoint("origin")
	vector = dialog.GetPoint("vector")
	gap_radius = currentStudy.GetFacesMaximumDistanceFromAxis(rotor_face_ids, origin, vector)
	height = currentStudy.GetFacesHeight(stator_face_ids, vector)

	currentModel = app.GetCurrentModel()
	height_unit = currentModel.GetCurrentUnit("Length")
	converted_gap_radius = currentModel.ConvertValueToSI(height_unit, gap_radius)
	converted_height = currentModel.ConvertValueToSI(height_unit, height)

	ro_air = 1.1 # kg/m^3
	mu_air = 2.0e-5 # kg/(m s)
	k_air = 0.03 # W/(m K)
	l_ag = dialog.GetValue("gap_length") * to_meter
	r_is = converted_gap_radius
	L_ec = converted_height
	v_air = dialog.GetValue("air_speed")

	if l_ag <= 0:
		show_cancel_exit_message(gap_zero_negative_en, gap_zero_negative_ja)
		return

	Re_cr = 100.0 * math.sqrt(r_is * l_ag)
	Re = L_ec * v_air * ro_air / mu_air

	Pr = 0.7
	Nu = 2
	if Re > Re_cr:
		Nu = 0.386 * pow(Pr, 0.27) / math.sqrt(r_is * l_ag)

	h_ag = Nu * k_air / (2.0 * l_ag)

	# create condition(stator side)
	conditionStator = currentStudy.CreateCondition("HeatTransfer", "untitled 1")
	conditionStator.SetValue("RefTemperatureType", 1)
	conditionStator.SetValue("Coefficient", h_ag)
	conditionStator.SetLink(ht_name1)

	conditionStator.ClearParts()
	sel = conditionStator.GetSelection()
	for fid in stator_face_ids:
		sel.SelectFace(fid)
	conditionStator.AddSelected(sel)

	for set_index in stator_face_set_indices:
		face_set = currentModel.GetSetList().GetSet(set_index)
		conditionStator.AddSet(face_set, 0)

	for mesh_group_id in stator_mesh_group_ids:
		conditionStator.AddGroup(currentStudy.GetMeshGroupList().GetMeshGroup(mesh_group_id), 0)

	# create condition(rotor side)
	conditionRotor = currentStudy.CreateCondition("HeatTransfer", "untitled 1")
	conditionRotor.SetValue("RefTemperatureType", 1)
	conditionRotor.SetValue("Coefficient", h_ag)
	conditionRotor.SetLink(ht_name2)

	conditionRotor.ClearParts()
	sel = conditionRotor.GetSelection()
	for fid in rotor_face_ids:
		sel.SelectFace(fid)
	conditionRotor.AddSelected(sel)

	for set_index in rotor_face_set_indices:
		face_set = currentModel.GetSetList().GetSet(set_index)
		conditionRotor.AddSet(face_set, 0)

	for mesh_group_id in rotor_mesh_group_ids:
		conditionRotor.AddGroup(currentStudy.GetMeshGroupList().GetMeshGroup(mesh_group_id), 0)
	
def show_error_exit_message(message_en, message_ja):
	title_en = "Error"
	title_ja = "エラー"
	show_message(title_en, title_ja, message_en, message_ja)

def show_cancel_exit_message(message_en, message_ja):
	title_en = "Cancel"
	title_ja = "キャンセル"
	show_message(title_en, title_ja, message_en, message_ja)

def show_message(title_en, title_ja, message_en, message_ja):
	app = designer.GetApplication()
	msgdlg = app.CreateDialogBox()

	msgdlg.SetTranslation(title_en, title_ja)
	msgdlg.SetTranslation(message_en, message_ja)

	msgdlg.SetCancelButtonVisible(False)
	msgdlg.SetTitle(title_en)
	msgdlg.AddLabel(message_en)
	msgdlg.Show()

def unique_name(circuit, base_name):
	count = 0
	candidate = base_name
	while True:
		component = circuit.GetComponent(candidate)
		if not component.IsValid():
			return candidate
		candidate = base_name + "_" + str(count)
		count += 1

def circuit_bottom_position(circuit):
	bottom = 0
	for i in range(circuit.NumInstances()):
		instance = circuit.GetComponentInstance(i)
		pos = instance.GetPosition()
		bottom = min(pos.y(), bottom)
	return bottom

main()

Download Python source code

ファイルご利用の注意点

JMAGスクリプトライブラリをご利用されるに際し、以下の利用規約をよくお読みいただき、ご同意の上ご利用下さるようお願い申し上げます。