How can I automatically setup the imported load data from Maxwell inside mechanical thermal analysis

Member, Moderator, Employee Posts: 312
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭

So say we have a transient thermal analysis with imported load data (say heat generation) from Maxwell (Electronic/Magnetic Transient analysis). One needs then to manually add rows, then enter all the time steps from Maxwell (source start and end times), and finally insert the corresponding analysis time steps. This can be very tedious and possibly take long time especially if we have many time steps in the Maxwell analysis.
Could this be perhaps automated?

Comments

  • Member, Moderator, Employee Posts: 312
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited March 2024

    Below is a mechanical script, that reads the time steps from a Maxwell file (AnsoftTransferData.xml), creates an imported load (heat gen.), and then adds all of the rows + corresponding input data (source and analysis times - taken from the Maxwell file).

    1. model = ExtAPI.DataModel.Project.Model
    2. Parts = model.Geometry.GetChildren(DataModelObjectCategory.Part,True)
    3. first_analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
    4. solver_directory = first_analysis.WorkingDir
    5. file = solver_directory+"Maxwell3DSolution\AnsoftTransferData.xml" # this folder might need change, so we should find the Ansoft xml file
    6.  
    7. SolveOutLines = [] #Declare an empty list
    8. mytime=[]
    9. myind=[]
    10. with open(file, "r") as in_file:
    11. for line in in_file: #For each line of text store in a string variable named "SolveOutLines", and
    12. SolveOutLines.append(line) #add that line to list of lines.
    13. myind=SolveOutLines[0].split("<TIME>")
    14. myind.pop(0)
    15. for myt in myind:
    16. mytime.append(myt.split("</TIME>")[0])
    17.  
    18. impLoadGrp = ExtAPI.DataModel.GetObjectsByName('Imported Load (B4) ')[0] # change as needed
    19. heatGen=impLoadGrp.AddImportedHeatGeneration()
    20. selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    21. bolist=[]
    22. ids=[]
    23. for Part in Parts:
    24. for Body in Part.Children:
    25. bolist.append(Body.GetGeoBody().Id)
    26. selection.Ids=bolist
    27. heatGen.Location = selection
    28.  
    29. for myrow in range(0,len(mytime)-1):
    30. table=heatGen.GetTableByName("") # get the worksheet table
    31. if float(mytime[myrow])>0.005: # change as needed - get times above 0.005 sec, to avoid initial small time steps
    32. NewRow = Ansys.ACT.Automation.Mechanical.WorksheetRow()
    33. table.Add(NewRow)
    34. NewRow[0]=mytime[myrow]
    35. NewRow[1]=mytime[myrow+1]
    36. NewRow[2]=mytime[myrow+1]
    37. NewRow[3]=1
    38.  
    39. table.RemoveAt(0)
    40. ExtAPI.DataModel.Tree.Refresh()
    41. heatGen.ImportLoad()
This discussion has been closed.