找回密码
 注册
Simdroid-非首页
查看: 305|回复: 8

Maxwell 3D v11 VBScript Example

[复制链接]
发表于 2008-6-20 11:47:41 | 显示全部楼层 |阅读模式 来自 湖北荆州
参考官方的文档An M3DFS Macro Example编写了Maxwell 3D v11的脚本,与原文档格式基本一致,方便对照,主要的变动是原mac采用重新建立模型,这里采用修改模型的方法。没有采用中文编写,我英语水平超水(四级都没有过) ,语法、词汇错误就别指正了

这个问题不用宏,直接采用参数化分析就可以完成。该脚本仅做参考,不保证正常运行

遗留问题:关于Force的输出存在问题,以下语句不对:
oDesign.AddOutputVariable "ForceVal", "Force_magnitude"

在Maxwell 12中则可以使用如下语句:
Set oModule = oDesign.GetModule("OutputVariable")
oModule.CreateOutputVariable "ForceVal", "group1.Force_mag",  _
   "SolnOptnSetup : LastAdaptive", "Magnetostatic", Array()

注:初步发现v12的脚本和v11脚本有一些不同,使用12的朋友注意了,具体差异可以参考软件自带的online help。

[ 本帖最后由 hottomson 于 2008-6-20 11:58 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

 楼主| 发表于 2008-6-20 11:49:38 | 显示全部楼层 来自 湖北荆州

完整脚本

Simdroid开发平台

  1. Dim oAnsoftApp
  2. Dim oDesktop
  3. Dim oProject
  4. Dim oDesign
  5. Dim oEditor
  6. Dim oModule
  7. 'Define
  8. Dim u_plate_length
  9. Dim u_plate_width
  10. Dim u_plate_thick
  11. Dim u_plate_high
  12. Dim armature_length
  13. Dim armature_width
  14. Dim armature_thick
  15. Dim core_radius
  16. Dim core_height
  17. Dim coil_1_height
  18. Dim coil_1_inner_rad
  19. Dim coil_1_outer_rad
  20. Dim coil_1_position
  21. Dim no_current_steps
  22. Dim no_turns_coil1
  23. Dim current_min
  24. Dim current_max
  25. Dim no_gaps
  26. Dim gap_min
  27. Dim gap_max
  28. u_plate_length = 100
  29. u_plate_width = 60
  30. u_plate_thick = 5
  31. u_plate_high = 75
  32. armature_length = 120
  33. armature_width = 80
  34. armature_thick = 5
  35. core_radius = 10
  36. core_height = 70
  37. coil_1_height = 5
  38. coil_1_inner_rad = 15
  39. coil_1_outer_rad = 25
  40. coil_1_position = 25
  41. no_current_steps = 2
  42. no_turns_coil1 = 1000
  43. current_min = 0.5
  44. current_max = 1
  45. no_gaps = 2
  46. gap_min = 0.01
  47. gap_max = 1
  48. Set oAnsoftApp = CreateObject("AnsoftMaxwell.MaxwellScriptInterface.11")
  49. Set oDesktop = oAnsoftApp.GetAppDesktop()
  50. oDesktop.RestoreWindow
  51. Set oProject = oDesktop.NewProject
  52. oProject.InsertDesign "Maxwell", "MaxwellDesign1", "Magnetostatic", ""
  53. Set oDesign = oProject.SetActiveDesign("MaxwellDesign1")
  54. Set oEditor = oDesign.SetActiveEditor("3D Modeler")
  55. Dim temp,temp1,temp2,temp3,gap,gap_loop_index
  56. gap_loop_index=0
  57. temp = gap_max - gap_min
  58. temp3 = no_gaps - 1
  59. temp1 = temp/temp3
  60. temp2 = temp1*gap_loop_index
  61. gap = gap_min + temp2
  62. Dim u_plate_x,u_plate_y
  63. u_plate_x=u_plate_width/2
  64. u_plate_y=u_plate_length/2
  65. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  66.   "0mm", "YPosition:=", "0mm", "ZPosition:=", "0mm", "XSize:=", CStrmm(u_plate_x), "YSize:=",  _
  67.   CStrmm(u_plate_y), "ZSize:=", CStrmm(u_plate_thick)), Array("NAME:Attributes", "Name:=", "u_plate", _
  68.   "Flags:=", "", "Color:=",  "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=", "Global", "MaterialName:=",  _
  69.   "vacuum", "SolveInside:=", true)
  70. '
  71. 'Calculate dimensions for quarter model U Plate
  72. '  
  73. temp1 = u_plate_x*(-1)
  74. temp2 = u_plate_thick*(-1)
  75. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  76.   CStrmm(u_plate_x), "YPosition:=", CStrmm(u_plate_y), "ZPosition:=", CStrmm(u_plate_thick), "XSize:=", CStrmm(temp1), "YSize:=",  _
  77.   CStrmm(temp2), "ZSize:=", CStrmm(u_plate_high)), Array("NAME:Attributes", "Name:=", "u1", _
  78.   "Flags:=", "", "Color:=",  "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=", "Global", "MaterialName:=",  _
  79.   "vacuum", "SolveInside:=", true)
  80. oEditor.Unite Array("NAME:Selections", "Selections:=", "u_plate,u1"), Array("NAME:UniteParameters", "CoordinateSystemID:=",  _
  81.   -1, "KeepOriginals:=", false)
  82. '
  83. 'Calculate dimensions for armature
  84. '  
  85. temp = u_plate_thick
  86. temp = temp + u_plate_high
  87. temp = temp + gap
  88. arm_y = armature_length/2
  89. arm_x = armature_width/2
  90. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  91.   "0mm", "YPosition:=", "0mm", "ZPosition:=", CStrmm(temp), "XSize:=", CStrmm(arm_x), "YSize:=",  _
  92.   CStrmm(arm_y), "ZSize:=", CStrmm(armature_thick)), Array("NAME:Attributes", "Name:=", "armature", "Flags:=", _
  93.   "", "Color:=", "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=",  _
  94.   "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
  95. '
  96. 'Calculate dimensions for the core
  97. '
  98. temp = u_plate_thick
  99. oEditor.CreateRectangle Array("NAME:RectangleParameters", "CoordinateSystemID:=",  _
  100.   -1, "IsCovered:=", true, "XStart:=", "0mm", "YStart:=", "0mm", "ZStart:=", CStrmm(temp), "Width:=",  _
  101.   CStrmm(core_height), "Height:=", CStrmm(core_radius), "WhichAxis:=", "Y"), Array("NAME:Attributes", "Name:=",  _
  102.   "core", "Flags:=", "", "Color:=", "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=",  _
  103.   "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
  104. oEditor.SweepAroundAxis Array("NAME:Selections", "Selections:=", "core"), Array("NAME:AxisSweepParameters", "CoordinateSystemID:=",  _
  105.   -1, "DraftAngle:=", "0deg", "DraftType:=", "Round", "CheckFaceFaceIntersection:=",  _
  106.   false, "SweepAxis:=", "Z", "SweepAngle:=", "90deg", "NumOfSegments:=", "8")
  107. '
  108. 'Calculate dimensions for coil_1
  109. '
  110. temp = u_plate_thick
  111. temp = temp + coil_1_position
  112. temp1 = coil_1_outer_rad - coil_1_inner_rad
  113. oEditor.CreateRectangle Array("NAME:RectangleParameters", "CoordinateSystemID:=",  _
  114.   -1, "IsCovered:=", true, "XStart:=", CStrmm(coil_1_inner_rad), "YStart:=", "0mm", "ZStart:=",  _
  115.   CStrmm(temp), "Width:=", CStrmm(temp1), "Height:=", CStrmm(coil_1_height), "WhichAxis:=", "Y"), Array("NAME:Attributes", "Name:=",  _
  116.   "coil1", "Flags:=", "", "Color:=", "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=",  _
  117.   "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
  118. oEditor.SweepAroundAxis Array("NAME:Selections", "Selections:=", "coil1"), Array("NAME:AxisSweepParameters", "CoordinateSystemID:=",  _
  119.   -1, "DraftAngle:=", "0deg", "DraftType:=", "Round", "CheckFaceFaceIntersection:=",  _
  120.   false, "SweepAxis:=", "Z", "SweepAngle:=", "90deg", "NumOfSegments:=", "8")
  121.   
  122. oEditor.Section Array("NAME:Selections", "Selections:=", "coil1"), Array("NAME:SectionToParameters", "CoordinateSystemID:=",  _
  123.   -1, "SectionPlane:=", "ZX")
  124. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",  _
  125. "Section1"), Array("NAME:ChangedProps", Array("NAME:Name", "Value:=", "term1"))))
  126. oEditor.Section Array("NAME:Selections", "Selections:=", "coil1"), Array("NAME:SectionToParameters", "CoordinateSystemID:=",  _
  127. -1, "SectionPlane:=", "YZ")
  128. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",  _
  129.   "Section1"), Array("NAME:ChangedProps", Array("NAME:Name", "Value:=", "term2"))))
  130. '
  131. 'the new region defination
  132. '
  133. oEditor.CreateRegion Array("NAME:RegionParameters", "CoordinateSystemID:=", -1, "+XPadding:=", _
  134.   "300", "-XPadding:=", "0", "+YPadding:=", "300", "-YPadding:=", "0", "+ZPadding:=",  _
  135.   "100", "-ZPadding:=", "50"), Array("NAME:Attributes", "Name:=", "Region", "Flags:=", _
  136.   "Wireframe#", "Color:=", "(255 0 0)", "Transparency:=", 0, "PartCoordinateSystem:=", _
  137.   "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
  138. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",  _
  139.   "armature", "u_plate", "core"), Array("NAME:ChangedProps", Array("NAME:Material", "Material:=",  _
  140.   "steel_1010"))))
  141. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",  _
  142.   "coil1"), Array("NAME:ChangedProps", Array("NAME:Material", "Material:=", "copper"))))
  143. Set oModule = oDesign.GetModule("BoundarySetup")
  144. '
  145. 'Loop for current steps
  146. '
  147. loop_index = 0
  148. loop_limit = no_current_steps
  149. temp = current_max - current_min
  150. temp3 =no_current_steps -1
  151. temp1 = temp/temp3
  152. temp2 = temp1*loop_index
  153. curr = current_min + temp2
  154. curr = curr * no_turns_coil1
  155. oModule.AssignCurrent Array("NAME:curr1_in", "Current:=", CStrA(curr), "IsSolid:=",  _
  156.   true, "Point out of terminal:=", false, "Objects:=", Array("term1"))
  157. oModule.AssignCurrent Array("NAME:curr1_out", "Current:=", CStrA(curr), "IsSolid:=",  _
  158.   true, "Point out of terminal:=", true, "Objects:=", Array("term2"))
  159.   
  160. Set oModule = oDesign.GetModule("MaxwellParameterSetup")
  161. oModule.AssignForce Array("NAME:group1", "Is Virtual:=", true, "Reference CS:=",  _
  162.   "Global", "Objects:=", Array("armature"))
  163.   
  164. oModule.AssignMatrix Array("NAME:Matrix1", Array("NAME:MatrixEntry", Array("NAME:MatrixEntry", "Source:=", _
  165.   "curr1_in", "NumberOfTurns:=", "1")), Array("NAME:MatrixGroup"), "Objects:=", Array( _
  166.   "coil1"))
  167.   
  168. Set oModule = oDesign.GetModule("AnalysisSetup")
  169. oModule.InsertSetup "Magnetostatic", Array("NAME:SolnOptnSetup", "MaximumPasses:=", 10, "MinimumPasses:=",  _
  170.   2, "MinimumConvergedPasses:=", 1, "PercentRefinement:=", 50, "LinearResidual:=", _
  171.   1E-006, "ConvergenceDispParamId:=", -1, "SolveFieldOnly:=", false, "PercentError:=", _
  172.   1, "SolveMatrixAtLast:=", true, "UseOutputVariable:=", false, "PreAdaptMesh:=",  _
  173.   false, "NonLinearResidual:=", 0.01, "SolverType:=", 0, "MuNonLinearBH:=", true, "ComputeHc:=",  _
  174.   false, "HcNonLinearBH:=", true)
  175.   
  176. oDesign.AddOutputVariable "ForceVal", "Force_magnitude" '这里不正确
  177. oDesign.AddOutputVariable "MatrixVal", "L(curr1_in,curr1_in)"
  178. Dim ForceVal,MatrixVal
  179. '  
  180. 'Create the file, open it for data entry, and output the column labels.
  181. '
  182. Set oFS = CreateObject("Scripting.FileSystemObject")
  183. Set ofile1 = oFS.CreateTextFile ("force.txt")
  184. line = chr(9) & "Force vs gap"
  185. ofile1.WriteLine line
  186. line = "GAP [ mm ]" & chr(9)& "FORCE [ Newtons ]"
  187. ofile1.WriteLine line
  188. Set ofile2 = oFS.CreateTextFile ("L11.txt")
  189. line = chr(9) & "L_11 vs gap"
  190. ofile2.WriteLine line
  191. line = "GAP [ mm ]" & chr(9)& "INDUCTANCE [ Henries ]"
  192. ofile2.WriteLine line
  193. While gap_loop_index < no_gaps
  194. temp = gap_max - gap_min
  195. temp3 = no_gaps - 1
  196. temp1 = temp/temp3
  197. temp2 = temp1*gap_loop_index
  198. gap = gap_min + temp2
  199. temp = u_plate_thick
  200. temp = temp + u_plate_high
  201. temp = temp + gap
  202. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DCmdTab", Array("NAME:PropServers",  _
  203.   "armature:CreateBox:1"), Array("NAME:ChangedProps", Array("NAME:Position", "X:=", "0mm", "Y:=",  _
  204.   "0mm", "Z:=", CStrmm(temp)))))
  205.   
  206. loop_limit = no_current_steps
  207. While loop_index < loop_limit
  208.   temp = current_max - current_min
  209.   temp3 =no_current_steps -1
  210.   temp1 = temp/temp3
  211.   temp2 = temp1*loop_index
  212.   curr = current_min + temp2
  213.   curr = curr * no_turns_coil1
  214.   
  215.   line = "Current: "  & curr
  216.   ofile1.WriteLine line
  217.   ofile2.WriteLine line
  218.   
  219.   oDesign.ChangeProperty Array("NAME:AllTabs", Array("NAME:MaxwellTab", Array("NAME:PropServers",  _
  220.    "BoundarySetup:curr1_in"), Array("NAME:ChangedProps", Array("NAME:Current", "Value:=",  _
  221.    CStrA(curr)))))
  222.   oDesign.ChangeProperty Array("NAME:AllTabs", Array("NAME:MaxwellTab", Array("NAME:PropServers",  _
  223.    "BoundarySetup:curr1_out"), Array("NAME:ChangedProps", Array("NAME:Current", "Value:=",  _
  224.    CStrA(curr)))))
  225.   
  226.   oDesign.Analyze "SolnOptnSetup"
  227.   
  228.   ForceVal = oDesign.GetOutputVariableValue("ForceVal", "SolnOptnSetup : LastAdaptive","", "")
  229.   MatrixVal = oDesign.GetOutputVariableValue("MatrixVal", "SolnOptnSetup : LastAdaptive","", "")
  230.   
  231.   ForceVal = ForceVal*4
  232.   line = gap & chr(9) & ForceVal
  233.   ofile1.WriteLine line
  234.   
  235.   MatrixVal = MatrixVal*4*no_turns_coil1*no_turns_coil1
  236.   line = gap & chr(9) & MatrixVal
  237.   ofile2.WriteLine line
  238.   loop_index = loop_index +1
  239. Wend
  240. gap_loop_index = gap_loop_index+1
  241. Wend
  242. ofile1.close
  243. ofile2.close
  244.   
  245. Function CStrmm(nDig)
  246. CStrmm = CStr(nDig)+"mm"
  247. End Function
  248. Function CStrA(nDig)
  249. CStrA = CStr(nDig)+"A"
  250. End Function
复制代码

[ 本帖最后由 hottomson 于 2008-6-20 17:19 编辑 ]
回复 不支持

使用道具 举报

发表于 2008-6-20 19:46:37 | 显示全部楼层 来自 陕西西安
v11 2D里面只在后处理里面用到的宏和3D里面的Script不一样吧
mac里面连Dim命令都不认
回复 不支持

使用道具 举报

 楼主| 发表于 2008-6-20 21:34:13 | 显示全部楼层 来自 湖北荆州
你说vbscript,我以为是v12的2D了,v11 2D用的是macro,那你可以参考Maxwell 2D参数化后处理宏编写小技巧http://www.simwe.com/forum/thread-790983-1-1.html
回复 不支持

使用道具 举报

发表于 2008-6-29 17:49:24 | 显示全部楼层 来自 辽宁沈阳

回复 4# 的帖子

Hottomson大哥编程相当厉害了!这看这满篇的程序我头就疼,至少我要先学下VB了(笨的可以了,VB俺也不懂)
回复 不支持

使用道具 举报

发表于 2008-7-20 13:36:39 | 显示全部楼层 来自 上海松江区
有maxwell v12 了?
回复 不支持

使用道具 举报

发表于 2008-7-20 20:50:42 | 显示全部楼层 来自 黑龙江哈尔滨
今年3月底公布的
回复 不支持

使用道具 举报

发表于 2008-7-25 10:30:24 | 显示全部楼层 来自 上海
:lol :lol :lol
回复 不支持

使用道具 举报

发表于 2008-7-30 20:32:08 | 显示全部楼层 来自 辽宁沈阳

回复 7# zhaobo_ren 的帖子

号称是Maxwell的最终完美版 绝唱了都
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-5-14 08:10 , Processed in 0.047724 second(s), 18 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表