How to write command in workbench to save results to text file

  • 2.8K Views
  • Last Post 07 June 2019
  • Topic Is Solved
Magneticfluxquantum posted this 23 January 2019

Hi everyone,

I'm trying to write a command to save a certain result set as txt-file automatically after the analysis. I'm using workbench, therefore I'm not really familiar with APDL code.

Currently I'm running an analysis with several design points, which need certain post-processing. I wrote a python script for this task and would like to keep using it, as the analysis is quite complex. Currently I open each design point and extract each relevant result set by hand, namely right-click -> export ->export text file. As an example I'd extract the maximum principal stress (at all nodes) and the custom result volume.

This task is tedious and time consuming and ultimately limiting the quality of my analysis.

It would seem like such a simple task to simply add a command to save the result set after the analysis, however I can't figure it out. If someone could hint me to the right direction I'd be much obliged.

 

Best regards

Magneticfluxquantum

Order By: Standard | Newest | Votes
sathya posted this 23 January 2019

Hi,

I suggest you to go with Parameter for various design points in workbench.

After defining input(design variable) and output parameter(result),In design points table activate Retain and select all Design points.

After solving,select the design points results you want using Set as current option.

jpasquerell posted this 23 January 2019

If you are searching for an ANSYS Mechanical APDL command that will dump the complete contents of a results set to an ASCII text file, there is the AUX2 DUMP command however the rst file must have been created using a single processor.  also the output is by record id and you will need to refer to the Programmers Manual in the help to interpret each records content.  If the file was created with multiple processors then you would have to use many ptr commands to step thru the records. 

There are two other approaches that use commands.  The first would be to use the POST1 print commands for the desired items.  These include PRNSOL, PRESOL, PRETAB, PRNLD, PRRSOL, PRENERGY, and a few others.  Use the /OUPUT command to specify the file name.  See the /HEADER, /FORMAT, and /PAGE for output controls on some of them.  The output format is otherwise fixed by the program code.  The second approach would be to use *VGET commands along with *GET command in do loops to retrieve the desired quantities into array parameters then use *VWRITE or *MWRITE to output the arrays to ASCII text files.  You have control over the output format and contents.    Additionally you can use array and parameter operations (*VFUN for example) to do calculations and output calculated values.  A few quantities may not be retrievable into parameters.

 

Magneticfluxquantum posted this 24 January 2019

@sathya: This is what I'm already doing. Lots of work for numerous points. I wish to do this efficiently.

@jpasquerell: This is more like it. However, I can't really get into this APDL syntax. I added a command object to an existing analysis.This is what I had in mind:

#################################################

! Retrieve the first principal stress

\post1                                                        !I suppose we need to work here
!number_of_nodes=NNOD                        !Should be a callable quantity, right? Maybe obsolete

*do,i,1,number_of_nodes                           !Start the loop over all nodes
    *vget,princ,NODE,1,number_of_nodes   !An array which includes the first principal stress values
*enddo

/output,'myfile','txt'                                       !Set output path
*vwrite,princ                                                !write array to file
/out
####################################################
This doesn't produce the correct result, as the output file only contains an error message and information.

sathya posted this 25 January 2019

Hi,

I request you to find help from the link:

Revert back if you have query

Magneticfluxquantum posted this 28 January 2019

@Sathya

The code provided by the forum does kinda work, my regards for that. However, it seems to have trouble actually receiving the data, as it only writes '0' in each column. However, I was able to contact a coworker and managed to get the code working. If anyone is looking for a solution, using ANSYS 19.0 and adding a COMMANDS (APDL)-Object in the SOLUTION-tree, here goes:

/post1
set,lastplns,s,1
*get,numnode,node,,count
*dim,nd_sig1,array,numnode
*vget,nd_sig1(1),node,,s,1
*cfopen,'myfile','txt'
*vlen,1
*vwrite,'Nodal','Stress_1'
(A8,X,A8)
*vwrite,sequ,nd_sig1(1)
(F8.0,X,E13.6,X,E13.6)
*cfclos

I consider the problem solved. Thanks to everyone involved.

 

 

 

 

Magneticfluxquantum posted this 31 January 2019

Hi again,

turns out I still need your expertise in another thing. Say I had a system of two components, each with different materials. Since each material must be treated differently, I wanted to write all stresses associated with component A to a separate file and all stresses of component B into another.

I'd have to select all nodes of component A first and then get the number of nodes on that selection, get the stresses and write them. I suppose Named Selections can be used to define my selection. How can I call these selections. I tried CMSEL, but this command seemingly cannot call Named Selections. I think CM can create a selection, but cannot be used to flag my selection.

Again, a simple problem, but quite difficult for me to solve.

sathya posted this 31 January 2019

Hi, Every expert starts as beginner. So nothing to worry. From your previous reply, I am sure that you can able to code for retrieving stress results. Sometimes keeping it simple always work. So I request you to make sure the components you wanted to select is actually available in the setup. Issue cmlist,all to know list of available components and make sure your desired component is available and not empty. Then call the component using cmsel,s,comp_name. Select displayed nodes using nsle,s,active. Now to make sure the desired nodes are selected,issue nlist command and check. If it is fine then proceed to previous code you mentioned. Revert back if needed.

Magneticfluxquantum posted this 01 February 2019

@sathya: Thanks for the heads up

While I was still unable to utilize a named selection this way, even going through the procedure described by sathya, I found a solution to my problem. If anyone want to post a solution for Named Selections for future seekers of guidance, by my guest

If you want to select a COMPONENT of your overall model, do this:

1. BEFORE you do anything else, insert a COMMANDS-object directly to your body component, under GEOMETRY/... .I don't know why that is necessary, but else it does not seem to work. Set a new reference using *SET,comp_name,matid. Now the components ID should be callable.

2. Then, after setting up your analysis, insert a COMMAND-object into SOLUTION, begin with the following code:

/post1   !postprocessor
set,lastplns,s,1   !last
esel,s,mat,,comp_name   !select the elements of the component
nsle,s,active   !select the nodes of the selected object

3. Then you can use my code above to extract and write data. Does the trick for me, probably not the most elegant way.

Thanks again to everyone, happy coding

 

prasannakumar92 posted this 07 June 2019

i want to extract nodal velocities at particular nodes at all time steps in transient analysis (post processing)

SET,LIST

*DIM,VELY,ARRAY,3125,800  !!!!! FOR 800 NODES AT 3125 TIME STEPS

NODENUMBER=141475          ! INITIAL NODE NUMBER

*CFOPEN,VEL,CSV

*DO,KK,1,800,1

*GET,VELY(1,KK),NODE,NODENUMBER,V,Y

*VWRITE,VELY(1)

(E15.8)

NODENUMBER=NODENUMBER+1

*ENDDO

*CFCLOSE

please help me out??

prasannakumar92 posted this 07 June 2019

i want to extract nodal velocities in y direction at some nodes (here 800 nodes) at all times (here 3125 steps) and write it to a file (transient analysis). this is my code.please help me ???

 

SET,LIST

*DIM,VELY,ARRAY,3125,800  !!!!! FOR 800 NODES AT 3125 TIME STEPS

NODENUMBER=141475          ! INITIAL NODE NUMBER

*CFOPEN,VEL,CSV

*DO,KK,1,800,1

*GET,VELY(1,KK),NODE,NODENUMBER,V,Y

*VWRITE,VELY(1)

(E15.8)

NODENUMBER=NODENUMBER+1

*ENDDO

*CFCLOSE

 

Close