@[TOC]First Example
ansoft的Maxwell仿真软件: 电机设计,电磁分析的专业软件。
python:一个无敌的编程软件,而且免费,免费,免费!!!
懂英文,懂英文,懂英文!!!
1、软件安装
略。
2、python 安装插件,通过windows com(组件对象模型,component object model,感兴趣可以百度https://blog.youkuaiyun.com/zhu2695/article/details/8977214)来调用Maxwell软件,这个可以调用很多软件,只要其它的软件具有接口
python 安装pywin32库文件
3、代码讲解(案例给出的是一个导体的空间静磁场分布,三维模型)
from win32com import client
oAnsoftApp = client.Dispatch("Ansoft.ElectronicsDesktop")
oDesktop = oAnsoftApp.getAppDesktop()
oDesktop.RestoreWindow()
oProject = oDesktop.NewProject()
oProject.InsertDesign("Maxwell 3D", "Maxwell3DDesign1", "Magnetostatic", "")
oDesign = oProject.SetActiveDesign("Maxwell3DDesign1")
oEditor = oDesign.SetActiveEditor("3D Modeler")
以上代码块是头文件和开始的部分,调用库函数,其中包括调用软件,新建工程,插入项目,最后得到的编辑器oEditor
具体内容后续发表的内容会逐步讲解(包括如何打开软件,二维模型,瞬态场分析等等)。
oEditor.CreateCylinder(
[
"NAME:CylinderParameters",
"XCenter:=" , "0mm",
"YCenter:=" , "0mm",
"ZCenter:=" , "0mm",
"Radius:=" , "1mm",
"Height:=" , "2mm",
"WhichAxis:=" , "Z",
"NumSides:=" , "0"
],
[
"NAME:Attributes",
"Name:=" , "Cylinder1",
"Flags:=" , "",
"Color:=" , "(143 175 143)",
"Transparency:=" , 0,
"PartCoordinateSystem:=", "Global",
"UDMId:=" , "",
"MaterialValue:=" , "\"vacuum\"",
"SurfaceMaterialValue:=", "\"\"",
"SolveInside:=" , True,
"IsMaterialEditable:=" , True,
"UseMaterialAppearance:=", False
])
oEditor.CreateCylinder(
[
"NAME:CylinderParameters",
"XCenter:=" , "0mm",
"YCenter:=" , "0mm",
"ZCenter:=" , "0mm",
"Radius:=" , "2mm",
"Height:=" , "2mm",
"WhichAxis:=" , "Z",
"NumSides:=" , "0"
],
[
"NAME:Attributes",
"Name:=" , "Cylinder2",
"Flags:=" , "",
"Color:=" , "(143 175 143)",
"Transparency:=" , 0,
"PartCoordinateSystem:=", "Global",
"UDMId:=" , "",
"MaterialValue:=" , "\"vacuum\"",
"SurfaceMaterialValue:=", "\"\"",
"SolveInside:=" , True,
"IsMaterialEditable:=" , True,
"UseMaterialAppearance:=", False
])
创建两个圆柱体,一个是金属导体,另外一个是求解域,就是所谓的真空材料。
两个圆柱体的高度是一致的,是因为工程通入的激励源是电流源,电流源所在的导体应该是首尾联通,或者在求解区域的边界上,否则就会报错,current leak to the air
oEditor.AssignMaterial(
[
"NAME:Selections",
"Selections:=" , "Cylinder1"
],
[
"NAME:Attributes",
"MaterialValue:=" , "\"copper\"",
"SolveInside:=" , True,
"IsMaterialEditable:=" , True,
"UseMaterialAppearance:=", False
])
给中间的圆柱体配置材料,材料为铜
oEditor.Section(
[
"NAME:Selections",
"Selections:=" , "Cylinder1",
"NewPartsModelFlag:=" , "Model"
],
[
"NAME:SectionToParameters",
"CreateNewObjects:=" , True,
"SectionPlane:=" , "XY",
"SectionCrossObject:=" , False
])
oEditor.Move(
[
"NAME:Selections",
"Selections:=" , "Cylinder1_Section1",
"NewPartsModelFlag:=" , "Model"
],
[
"NAME:TranslateParameters",
"TranslateVectorX:=" , "0mm",
"TranslateVectorY:=" , "0mm",
"TranslateVectorZ:=" , "0.5mm"
])
oDesign.ChangeProperty(
[
"NAME:AllTabs",
[
"NAME:LocalVariableTab",
[
"NAME:PropServers",
"LocalVariables"
],
[
"NAME:NewProps",
[
"NAME:I_phase",
"PropType:=" , "VariableProp",
"UserDef:=" , True,
"Value:=" , "0A"
]
]
]
])
oModule = oDesign.GetModule("BoundarySetup")
oModule.AssignCurrent(
[
"NAME:Current1",
"Objects:=" , ["Cylinder1_Section1"],
"Current:=" , "I_phase",
"IsSolid:=" , False,
"Point out of terminal:=", False
])
设置激励,激励需要设置在sheet上,不能是三维体的表面!!!
oModule = oDesign.GetModule("AnalysisSetup")
oModule.InsertSetup("Magnetostatic",
[
"NAME:Setup1",
"Enabled:=" , True,
"MaximumPasses:=" , 5,
"MinimumPasses:=" , 2,
"MinimumConvergedPasses:=", 1,
"PercentRefinement:=" , 30,
"SolveFieldOnly:=" , False,
"PercentError:=" , 0.5,
"SolveMatrixAtLast:=" , True,
"PercentError:=" , 0.5,
"UseIterativeSolver:=" , False,
"RelativeResidual:=" , 1E-006,
"NonLinearResidual:=" , 0.002,
[
"NAME:MuOption",
"MuNonLinearBH:=" , True
]
])
这个是设定一个解算器,具体参数看英文吧。。
oModule = oDesign.GetModule("Optimetrics")
oModule.InsertSetup("OptiParametric",
[
"NAME:ParametricSetup1",
"IsEnabled:=" , True,
[
"NAME:ProdOptiSetupDataV2",
"SaveFields:=" , False,
"CopyMesh:=" , False,
"SolveWithCopiedMeshOnly:=", True
],
[
"NAME:StartingPoint"
],
"Sim. Setups:=" , ["Setup1"],
[
"NAME:Sweeps",
[
"NAME:SweepDefinition",
"Variable:=" , "I_phase",
"Data:=" , "LIN 0A 10A 10A",
"OffsetF1:=" , False,
"Synchronize:=" , 0
]
],
[
"NAME:Sweep Operations"
],
[
"NAME:Goals"
]
])
设置参数来进行计算,之前设定激励电流为变量I_phase
仿真不同的I_phase值对应的仿真结果。
oProject.SaveAs("E:\\Maxwell\\Project1.aedt", True)
oModule.SolveSetup("ParametricSetup1")
保存,并开始仿真。