TAGGED: automation-code, mapdl, PyMAPDL, python-apdl, workbench
-
-
January 22, 2024 at 10:34 pmuser deletedSubscriber
I am trying to design multiple signals for ansys transient-structural.Â
My signals are many, and this makes it tedious for me to import the data before each run.
Is there a way to automate the import process?
I already have a code to modify the.XML fileÂ
-
January 23, 2024 at 9:42 amErik KostsonAnsys Employee
Hi
You can use scripting for something like that (automate load application workflow), but again do not understand exactly what you want to do (you mention xml, where does that come in??, and what is multiple signals - there is nothing called signal(s) in Ansys Transient Analysis).
This post gives an idea how to do something like importing data from a csv file and applying it as a load.
https://discuss.ansys.com/discussion/comment/2028#Comment_2028?utm_source=community-search&utm_medium=organic-search&utm_term=import+load+and+csvWe hope this helps.
All the best
ErikÂ
-
January 23, 2024 at 4:00 pmdloomanAnsys Employee
The MAPDL way is with *TREAD. The commands below read a csv file named time_adj.csv with 101 rows of data to create the table array, time_adj, which is a function of time. This array can be used as transient input: d,all,ux,%time_adj%
*dim,time_adj,table,101,1,1,TIME
*tread,time_adj(1,0),time_adj,csvThe first few lines of the csv file look like below. There is a row 0 with arbitrary integers 0 and 1. The data could also be space delimited.
0 Â 1
0,0.018315639
0.1,0.021459239
0.2,0.025062063
0.3,0.029176257
0.4,0.033857322
0.5,0.039163895
0.6,0.04515745
0.7,0.051901894
0.8,0.05946306
0.9,0.067908097
1,0.07730474
1.1,0.08772047
1.2,0.099221555...
Â
-
January 23, 2024 at 4:59 pmuser deletedSubscriber
Hi, @Erik and @Dave
Thank you for your reply.
This is what I am trying to do.
In my simulation, I have two force inputs; these inputs are defined as components, and the Y component is a Tabular Data.Â
1. I exported a .xml from each force input (this process is to have an Ansys .xml file format that I can use for the steps that follow).2. I design an excitation signal in Python and then put this signal data, which is a function of time, in the .xml file.
3. Go back to the Ansys workbench and import this .xml file (using the Import Load History Data. since I have two forces input, I do this twice).
4. Run the simulation.
5. Export the acceleration probe data to a .csv using a Python script.
Â
My Challenge: I test different excitation signal configurations and types, and each time I generate a signal, I have to import for all input point which is tedious.
Â
My Question: This import and assignment process (import .xml, select force data in the imported xml file) can I automate it such that when I run the simulation, it reads the excitation data from somewhere and assigns it to a particular force input?
@Dave
I previously tried the Tread technique, but I don't know how to assign it to a force input in my model.Â
Thank you so much in advance.
Â
Â
Â
-
January 23, 2024 at 5:00 pmuser deletedSubscriber
-
January 23, 2024 at 5:15 pmuser deletedSubscriber
Also, I have written the code to export the acceleration probe data (Python in the mechanical scripting environment).
After each simulation I have to manually run the code.ÂÂ
Can I make the code automatically run at the end of the simulation?
Thank you -
January 24, 2024 at 1:04 amuser deletedSubscriber
Â
Â
Hey @Erik and @Dave,
Thank you. I figured out the automated import of load history data.
I have the code running in the mechanical script.
Is it possible to have it run automatically at the beginning of the simulation?
This is what I have tried:
Using the code from the mechanical script, I tried this: Script Tip Friday- "Python Code"​ object in Mechanical | Ansys Developer Portal
but I did not get any resultsÂ
Â
Â
-
January 24, 2024 at 2:12 pmuser deletedSubscriberThis is my code for the Input force
import csvfilePath = 'FilePath'timesteps = [] #Create empty list to store timestep valuesloads = [] #Create empty list to store load valueswith open(filePath, 'r') as csvFile:  csvRead = csv.reader(csvFile, delimiter=',')  next(csvRead) #Skip first line (assumed headers)  Â  for row in csvRead:    timesteps.append(row[0]) #Populate list with first column's values    loads.append(row[1]) #Populate list with second column's valuesÂ#Configure liststimeUnit = '[sec]' #Timestep unitloadUnit = '[N]' #Load unittimesteps = [str(time) + timeUnit for time in timesteps] #Convert values to strings and append unitloads = [str(load) + loadUnit for load in loads] #Convert values to strings and append unit#Create loadanalysis_104 = DataModel.GetObjectById(207)force_207 = DataModel.GetObjectById(207)force_207.Magnitude.Inputs[0].DiscreteValues = [Quantity(time) for time in timesteps]force_207.Magnitude.Output.DiscreteValues = [Quantity(load) for load in loads] -
January 24, 2024 at 2:23 pmdloomanAnsys Employee
If you were applying the force to a single node, the command to input the MAPDL table would be f,node_numb,fx,%time_adj%. If you are applying it to an area you could convert your csv data to a pressure by dividing by the area in excel and use the commands:
cmsel,s,named_selection   ! Mechanical named selection for the face. Or could select some other way
sf,all,pres,%time_adj%
allsel
-
January 24, 2024 at 2:51 pmuser deletedSubscriber
Thank you, Dave
I already got the Python code to import the Load history data.
My problem is making it run automatically at the beginning of the solve.Â
Â
-
January 26, 2024 at 11:23 amuser deletedSubscriber
For anyone looking through this thread in the future
This is the code adapted to componentwise force import (in this case Y direction)
import csvfilePath = 'filepath\\force.csv'timesteps = [] #Create empty list to store timestep valuesloads = [] #Create empty list to store load valueswith open(filePath, 'r') as csvFile:  csvRead = csv.reader(csvFile, delimiter=',')  next(csvRead) #Skip first line (assumed headers)  Â  for row in csvRead:    timesteps.append(row[0]) #Populate list with first column's values    loads.append(row[1]) #Populate list with second column's valuesÂ#Configure liststimeUnit = '[sec]' #Timestep unitloadUnit = '[N]' #Load unittimesteps = [str(time) + timeUnit for time in timesteps] #Convert values to strings and append unitloads = [str(load) + loadUnit for load in loads] #Convert values to strings and append unit#Create loadanalysis_104 = DataModel.GetObjectById(207)force_207 = DataModel.GetObjectById(207)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [23]force_207.Location = selectionforce_207.DefineBy = LoadDefineBy.ComponentYforce_207.YComponent.Inputs[0].DiscreteValues = [Quantity(time) for time in timesteps]force_207.YComponent.Output.DiscreteValues = [Quantity(load) for load in loads]ÂDon't forget to change the Ids!!
Also, I got the automation working these are resources for both after and before
Script Tip Friday - Examples of Python Results for Mechanical (Part 2) | Ansys Developer Portal
Script Tip Friday - Examples of Python Results for Mechanical (Part 1) | Ansys Developer Portal
Script Tip Friday- "Python Code"​ object in Mechanical | Ansys Developer Portal
Note these codes work when the mechanical GUI is open.
Cheers -
January 26, 2024 at 2:31 pmdloomanAnsys Employee
Thanks for sharing that with the forum.
-
- The topic ‘Automated Import of Load history data uisng scripts (Python or Mapdl)’ is closed to new replies.
- Problem with access to session files
- Ayuda con Error: “Unable to access the source: EngineeringData”
- At least one body has been found to have only 1 element in at least 2 directions
- Error when opening saved Workbench project
- Geometric stiffness matrix for solid elements
- How to select the interface delamination surface of a laminate?
- How to apply Compression-only Support?
- Timestep range set for animation export
- SMART crack under fatigue conditions, different crack sizes can’t growth
- Image to file in Mechanical is bugged and does not show text
-
1191
-
513
-
488
-
225
-
209
© 2024 Copyright ANSYS, Inc. All rights reserved.