{"id":306,"date":"2015-12-11T16:42:21","date_gmt":"2015-12-11T16:42:21","guid":{"rendered":"http:\/\/box5393.temp.domains\/~quranive\/\/?p=306"},"modified":"2022-01-24T01:24:52","modified_gmt":"2022-01-24T01:24:52","slug":"using-a-snippet-to-extract-ansys-workbench-results-to-a-text-file-with-vmask-and-vget","status":"publish","type":"post","link":"https:\/\/mechanicsandmachines.com\/?p=306","title":{"rendered":"Using a Snippet to Extract Ansys Workbench Results to a Text File with vmask and vget"},"content":{"rendered":"<p>Commonly, we need to save results from an Ansys Workbench study as a text file for post-processing in another program, such as Excel. &nbsp;One can right-click on a desired result and use <em>Export,<\/em> but that can be tedious if there a lot of results to save. &nbsp;With a snippet one inserts a <em>Commands (APDL)<\/em> <em>object<\/em> in the solution and writes APDL code to perform the desired &nbsp;functions.<\/p>\n<p><!--more--><\/p>\n<p>Below we use a simple example of an L-shaped bracket. &nbsp;In this static structural example, there are three time steps as we change the forces on the bracket. &nbsp;One could also use this in a thermal, modal, or transient structural with a few changes needed.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/L-bracket-geom.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-307\" src=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/L-bracket-geom-300x276.png?resize=300%2C276\" alt=\"L bracket geom\" width=\"300\" height=\"276\" srcset=\"https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/L-bracket-geom.png?resize=300%2C276&amp;ssl=1 300w, https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/L-bracket-geom.png?w=421&amp;ssl=1 421w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>We begin&nbsp;by creating a <em>Named Selection<\/em> to define the regions of the model where we are interested in results.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/insert-named-selection.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-308\" src=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/insert-named-selection-300x250.png?resize=388%2C323\" alt=\"insert named selection\" width=\"388\" height=\"323\" srcset=\"https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/insert-named-selection.png?resize=300%2C250&amp;ssl=1 300w, https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/insert-named-selection.png?w=615&amp;ssl=1 615w\" sizes=\"auto, (max-width: 388px) 100vw, 388px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Here we have chosen to use a single face as the named selection. &nbsp;One could use a set of faces or edges, vertices, or volumes.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/named-selection-face.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-310\" src=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/named-selection-face-300x229.png?resize=387%2C295\" alt=\"named selection face\" width=\"387\" height=\"295\" srcset=\"https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/named-selection-face.png?resize=300%2C229&amp;ssl=1 300w, https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/named-selection-face.png?w=408&amp;ssl=1 408w\" sizes=\"auto, (max-width: 387px) 100vw, 387px\" \/><\/a><\/p>\n<p>Then, we must make sure to set the output to save an <em>mapdl db file<\/em> to<em> yes. &nbsp;<\/em><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/output-save-db-file.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-309\" src=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/output-save-db-file-300x218.png?resize=440%2C320\" alt=\"output save db file\" width=\"440\" height=\"320\" srcset=\"https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/output-save-db-file.png?resize=300%2C218&amp;ssl=1 300w, https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/output-save-db-file.png?w=891&amp;ssl=1 891w\" sizes=\"auto, (max-width: 440px) 100vw, 440px\" \/><\/a><\/p>\n<p>Next, we insert a <em>Commands (APDL) object<\/em> into the <em>Solution<\/em><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/insert-commands-object-in-solu.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-311\" src=\"https:\/\/i0.wp.com\/box5393.temp.domains\/~quranive\/\/wp-content\/uploads\/2015\/12\/insert-commands-object-in-solu-300x251.png?resize=319%2C267\" alt=\"insert commands object in solu\" width=\"319\" height=\"267\" srcset=\"https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/insert-commands-object-in-solu.png?resize=300%2C251&amp;ssl=1 300w, https:\/\/i0.wp.com\/mechanicsandmachines.com\/wp-content\/uploads\/2015\/12\/insert-commands-object-in-solu.png?w=616&amp;ssl=1 616w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Below is the command snippet that we use to export the data. &nbsp;For a structural system in which I am interested in deformations, I typically like to a file format of &#8220;X &nbsp;Y &nbsp;Z &nbsp;UX &nbsp;UY &nbsp;UZ&#8221; where X, Y, Z are the coordinate locations and UX,UY,UZ are the deformations at each node in the named selection. &nbsp;I typically do not use a file header but one could insert that if desired.<\/p>\n<p>The general method below is to load the results from the db file using&nbsp;<em>RESUME<\/em>. &nbsp;Then, calculate the total number of results sets in the study. &nbsp;We use a <em>DO<\/em><em>-loop<\/em>&nbsp;to cycle through all results. &nbsp;Then, we select the nodal named selection. &nbsp;Alternatively to using a named selection, we could select nodes of interest using the available selection commands such as <em>NSEL<\/em>&nbsp;and <em>ESEL<\/em>. &nbsp;The desired information (coordinate locations and displacements) for the full model are put into an array using <em>*VGET<\/em>. &nbsp;Using the node numbers of the named selection in combination with the&nbsp;<em>*VMASK<\/em> command, we create a compressed array of the desired information only at the nodes of interest. &nbsp;Finally, using <em>*VWRITE<\/em> we write that array into a text file.<\/p>\n<pre>! Commands inserted into this file will be executed immediately after the ANSYS \/POST1 command.\n! Active UNIT system in Workbench when this object was created: Metric (m, kg, N, s, V, A)\n! NOTE: Any data that requires units (such as mass) is assumed to be in the consistent solver unit system.\n! See Solving Units in the help system for more information.\n!\nRESUME     !this is necessary to read the db file which was saved earlier\n!\nalls     !this selects everything, good place to start\n!\n*GET,numb_sets,ACTIVE,0,SET,NSET !get number of results sets\nset,first\n!\nCMSEL,s,face_of_interest  !select the named selection\n!\n*get,nummax,NODE,,num,max !Max Node id in selected nodes\n*get,numnode,NODE,,count !Number of selected nodes\n*dim,mask,array,nummax\n*vget,mask(1),NODE,,NSEL !mask for selected nodes\n*dim,nodal_data_full,array,nummax,6 !array for pressures of all 1-to-nummax nodes\n*dim,nodal_data_comp,array,numnode,6 !array for pressures of ONLY selected nodes\n*dim,nodeid_full,array,nummax !array for containing NODE ID\n*dim,nodeid_comp,array,numnode !array for containing NODE ID for ONLY selected nodes\n*vfill,nodeid_full,ramp,1,1 !array from 1-to-nummnode (1,2,3,....)\n!\n*do,i_set,1,numb_sets,1\n*GET,current_time,ACTIVE,0,SET,TIME\n!Retrieving DATA\n*vmask,mask(1)\n*vget,nodal_data_full(1,1),node,,LOC,X\n*vmask,mask(1)\n*vget,nodal_data_full(1,2),node,,LOC,Y\n*vmask,mask(1)\n*vget,nodal_data_full(1,3),node,,LOC,Z\n*vmask,mask(1)\n*vget,nodal_data_full(1,4),node,,U,X !*VGET,ParR,Entity,ENTNUM,Item1,IT1NUM,Item2,IT2NUM,KLOOP\n*vmask,mask(1)\n*vget,nodal_data_full(1,5),node,,U,Y\n*vmask,mask(1)\n*vget,nodal_data_full(1,6),node,,U,Z\n!\n!COMPRESSING ARRAYS TO ONLY SELECTED NODES for the coordinate locations and displacements:\n*vmask,mask(1)\n*vfun,nodal_data_comp(1,1),COMP,nodal_data_full(1,1)\n*vmask,mask(1)\n*vfun,nodal_data_comp(1,2),COMP,nodal_data_full(1,2)\n*vmask,mask(1)\n*vfun,nodal_data_comp(1,3),COMP,nodal_data_full(1,3)\n*vmask,mask(1)\n*vfun,nodal_data_comp(1,4),COMP,nodal_data_full(1,4)\n*vmask,mask(1)\n*vfun,nodal_data_comp(1,5),COMP,nodal_data_full(1,5)\n*vmask,mask(1)\n*vfun,nodal_data_comp(1,6),COMP,nodal_data_full(1,6)\n!\n!GETTING THE SELECTED NODE ID LIST !only necessary if you also want to keep the node numbers\n*vmask,mask(1)\n*vfun,nodeid_comp(1),COMP,nodeid_full(1)\n!\n!WRITING TO A FILE: !set the file name as desired.  includes the time step in the file name as a variable\n*cfopen,named_deformation_data_time_%current_time%,DAT\n*vwrite,nodal_data_comp(1,1),nodal_data_comp(1,2),nodal_data_comp(1,3),nodal_data_comp(1,4), nodal_data_comp(1,5), nodal_data_comp(1,6)\n%F %F %F %E %E %E   !formats for each column\n*cfclos\n!\nset,next !read next set\n*ENDDO !end loop\n!\n!DELETING USED VARIABLES\n*del,nodal_data_full,nopr\n*del,nodeid_full,nopr\n*del,nodal_data_comp,nopr\n*del,nodeid_comp,nopr\n*del,mask,nopr\n*del,nummax,nopr\n*del,numnode,nopr\nALLS\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Commonly, we need to save results from an Ansys Workbench study as a text file for post-processing in another program, such as Excel. &nbsp;One can right-click on a desired result and use Export, but that can be tedious if there a lot of results to save. &nbsp;With a snippet one inserts a Commands (APDL) object &hellip; <a href=\"https:\/\/mechanicsandmachines.com\/?p=306\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using a Snippet to Extract Ansys Workbench Results to a Text File with vmask and vget<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9],"tags":[],"series":[],"class_list":["post-306","post","type-post","status-publish","format-standard","hentry","category-fea"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p5f9h7-4W","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=\/wp\/v2\/posts\/306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=306"}],"version-history":[{"count":12,"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":752,"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions\/752"}],"wp:attachment":[{"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/mechanicsandmachines.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}