3次元FEMコンダクタ推奨設定の適用
import designer
import platform
class Settings:
def __init__(self, study):
self.ICCGToleranceType=2
self.NonlinearConvergenceB=0
self.AutoAccel=0
def apply_settings(self, study):
study.GetStudyProperties().SetValue(u"ICCGToleranceType", self.ICCGToleranceType)
study.GetStudyProperties().SetValue(u"NonlinearConvergenceB", self.NonlinearConvergenceB)
study.GetStudyProperties().SetValue(u"AutoAccel", self.AutoAccel)
class Settings_TR(Settings):
def __init__(self, study):
super().__init__(study)
self.APhiMethod=1
self.NonlinearSpeedup=1
self.IccgTolerance=1e-8
if(study.GetStudyProperties().GetValue(u"UseMultiCPU") == 1 or study.GetStudyProperties().GetValue(u"UseMultiCPU") == 0):
self.IccgAccel=1.2
else:
self.IccgAccel = 1.2
def apply_settings(self, study):
super().apply_settings(study)
study.GetStudyProperties().SetValue(u"APhiMethod", self.APhiMethod)
study.GetStudyProperties().SetValue(u"NonlinearSpeedup", self.NonlinearSpeedup)
study.GetStudyProperties().SetValue(u"IccgTolerance", self.IccgTolerance)
study.GetStudyProperties().SetValue(u"IccgAccel", self.IccgAccel)
class Settings_TR_Patch(Settings):
def __init__(self, study):
super().__init__(study)
self.APhiMethod=1
self.NonlinearSpeedup=0
self.IccgTolerance=1e-8
if(study.GetStudyProperties().GetValue(u"UseMultiCPU") == 1 or study.GetStudyProperties().GetValue(u"UseMultiCPU") == 0):
self.IccgAccel=1.2
else:
self.IccgAccel = 1.2
def apply_settings(self, study):
super().apply_settings(study)
study.GetStudyProperties().SetValue(u"APhiMethod", self.APhiMethod)
study.GetStudyProperties().SetValue(u"NonlinearSpeedup", self.NonlinearSpeedup)
study.GetStudyProperties().SetValue(u"IccgTolerance", self.IccgTolerance)
study.GetStudyProperties().SetValue(u"IccgAccel", self.IccgAccel)
def check_conductor_condition(study):
flag_has_conductor=0
num_condition = study.NumConditions()
num_instance_circuit = study.GetCircuit().NumInstances()
for i in range(num_condition):
if(study.GetCondition(i).GetScriptTypeName() == "FEMConductor"):
flag_has_conductor=1
break
for i in range(num_instance_circuit):
if(study.GetCircuit().GetComponentInstance(i).GetType() == "巻線3相コンダクタ" or study.GetCircuit().GetComponentInstance(i).GetType() == "Winding Three Phase Conductor" or \
study.GetCircuit().GetComponentInstance(i).GetType() == "巻線多相コンダクタ" or study.GetCircuit().GetComponentInstance(i).GetType() == "Winding Multiphase Conductor" or \
study.GetCircuit().GetComponentInstance(i).GetType() == "巻線かご" or study.GetCircuit().GetComponentInstance(i).GetType() == "Winding Cage"):
flag_has_conductor=1
break
return flag_has_conductor
def make_settings_class(study):
if(study.GetType() == "磁界:3次元磁界過渡応答解析" or study.GetType() == "Magnetic:3D Magnetic Field Transient Analysis" or \
study.GetType() == "磁界:3次元効率マップ解析" or study.GetType() == "Magnetic:3D Efficiency Map Analysis"):
flag_has_conductor = check_conductor_condition(study)
if(flag_has_conductor == 0):
settings = Settings(study)
type=-1
else:
if(study.GetMeshControl().GetValue(u"MeshType") != 2):
settings = Settings_TR(study)
type=0
else:
settings = Settings_TR_Patch(study)
type=2
elif(study.GetType() == "磁界:3次元磁界周波数応答解析" or study.GetType() == "Magnetic:3D Magnetic Field Frequency Analysis"):
flag_has_conductor = check_conductor_condition(study)
if(flag_has_conductor == 0):
settings = Settings(study)
type=-1
else:
settings = Settings(study)
type=1
else:
settings = Settings(study)
type=-1
return type, settings
def create_dialog(app, study, type, settings):
dialog = app.CreateDialogBox()
title_en = "Recommended settings for 3D FEM conductor condtions"
title_jp = "3次元FEMコンダクタ推奨設定"
explain_en="Recommended settings below will be applied."
explain_jp = "設定を下記推奨設定に変更します。"
linear_en="Linear solver"
linear_jp="線形ソルバー"
iccg_en="Use fixed tolerance per step:"+str(settings.IccgTolerance)
iccg_jp="ステップごとの残差に対応するICCG判定を行う(固定):"+str(settings.IccgTolerance)
method_en="Calculation Method:A-phi Method 1"
method_jp="解法:A-φ法1"
accel_en="Acceleration coefficient:"+str(settings.IccgAccel)
accel_jp="加速係数:"+str(settings.IccgAccel)
non_linear_en="Nonlinear"
non_linear_jp="非線形計算"
if(type==0):
HS_en="Use high speed solver"
HS_jp="高速解法を用いる"
elif(type == 2):
HS_en="Not use high speed solver"
HS_jp="高速解法を用いない"
dB_en = "Maximum Change in Magnetic Flux Density: No"
dB_jp = "磁束密度の最大変化量:なし"
dialog.SetTranslation(title_en, title_jp)
dialog.SetTranslation(explain_en, explain_jp)
dialog.SetTranslation(linear_en, linear_jp)
dialog.SetTranslation(iccg_en, iccg_jp)
dialog.SetTranslation(method_en, method_jp)
dialog.SetTranslation(accel_en, accel_jp)
dialog.SetTranslation(non_linear_en, non_linear_jp)
if(type==0 or type==2):
dialog.SetTranslation(HS_en, HS_jp)
dialog.SetTranslation(dB_en, dB_jp)
dialog.SetTitle(title_en)
dialog.AddLabel(explain_en)
dialog.AddLine()
dialog.AddLabel(linear_en)
dialog.AddLabel("")
dialog.AddLabel(accel_en)
dialog.AddLabel(iccg_en)
dialog.AddLabel(method_en)
dialog.AddLine()
dialog.AddLabel(non_linear_en)
dialog.AddLabel("")
if(type==0 or type == 2):
dialog.AddLabel(HS_en)
dialog.AddLabel(dB_en)
return dialog
def show_message(app, title_en, title_jp, message_en, message_jp):
msgdlg = app.CreateDialogBox()
msgdlg.SetTranslation(title_en, title_jp)
msgdlg.SetTranslation(message_en, message_jp)
msgdlg.SetCancelButtonVisible(False)
msgdlg.SetTitle(title_en)
msgdlg.AddLabel(message_en)
msgdlg.Show()
return
def show_error_message(app, message_en, message_jp):
title_en = "Error"
title_jp = "エラー"
show_message(app, title_en, title_jp, message_en, message_jp)
return
def show_normal_end_message(app):
title_en = "Settings is changed"
title_jp = "設定適用終了"
message_en = "Recommended settigs is applied."
message_jp = "推奨設定が適用されました。"
show_message(app, title_en, title_jp, message_en, message_jp)
return
def show_cancel_end_message(app):
title_en = "Canceled"
title_jp = "設定適用終了"
message_en = "The application of the settings is cancelled."
message_jp = "設定の適用がキャンセルされました。"
show_message(app, title_en, title_jp, message_en, message_jp)
return
def main():
app = designer.GetApplication()
study = app.GetCurrentStudy()
version,sub1,sub2 = platform.python_version_tuple()
if (version == "2"):
message_en = "This function is not supported with python 2.7."
message_jp = "この機能はpython2.7には対応していません。"
show_error_message(app, message_en, message_jp)
return
type, settings = make_settings_class(study)
if(type == -1):
message_en = "This study is not 3D, or does not have FEM conductor conditions."
message_jp = "このスタディは3次元かつFEMコンダクタが設定されたスタディではありません。"
show_error_message(app, message_en, message_jp)
return
elif(type == 1):
message_en = "This study is not transient analysis."
message_jp = "このスタディは過渡応答解析のスタディではありません。"
show_error_message(app, message_en, message_jp)
return
dialog = create_dialog(app, study, type, settings)
is_OK = dialog.Show()
if(is_OK == 1):
settings.apply_settings(study)
study.SetCurrentCase(study.GetCurrentCase())
show_normal_end_message(app)
else:
show_cancel_end_message(app)
return
if __name__ == "__main__":
main()


