CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > EnSight

Working with Python: Query of through-plane flow of multiple clips in one plot

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 4, 2017, 07:15
Default Working with Python: Query of through-plane flow of multiple clips in one plot
  #1
New Member
 
Patrick Winter
Join Date: Mar 2017
Posts: 5
Rep Power: 5
PedroInvierno is on a distinguished road
Hello everyone.

I am working with 3D velocity data. Since I need to evaluate parameters such as through-plane flow, wall shear stress etc. in several clips (n>10) I am looking for (semi-)automatic evaluation of the flow data. For that reason I am working on a python script. In doing so, I have two major questions regarding python and the implementation of a python script in Ensight. At the moment I am using Ensight 10.02(h).

1. Question:
I would like to plot the through-plane flow in several (previously calulated) 2D-clips (perpendicular to the aorta) as a time vs. flow curve. The final goal is the plot of several curves in one graph by pushing only one button.
I calculated the through-plane flow in this python script:

Quote:
#Calculate the plane normals of the clip
ensight.variables.evaluate("N_plane=Normal(plist)" )

#Calculate the through-plane velocity (VEL= 3D velocity field)
ensight.variables.evaluate("vel_plane=DOT(VEL,N_pl ane)")

#Through-plane flow = surface integral of through-plane velocity values
ensight.variables.evaluate("flow_plane=IntegralSur face(plist,vel_plane)")
After calculating flow_plane I plot the through-plane flow as a function of time by using the query function.
I would like to achieve this for several clips (n>10) in the most time-efficient way and I would like to have the data in one large *csv file so I can import all data at once into Excel, Matlab etc.

However, I couldn't find any useful solution to achieve this since Ensight seems to only allow queries of one clip at a time. My first idea was to achieve such a plot in a for loop over the clips. Unfortunately, since the variable flow_plane is updated with each clip and the query of the last clip is always overwritten with the values of the next clip, this solution does not work. So my question is: How can I achieve that Ensight keeps different queries of the same variable (flow_plane), even when the variable is updated with each clip.





2. Question:
For further evaluations I also need to determine the plane normals and the coordinates of the center of the clip. At the moment I am using the plane tool (right click -> edit) and copy and paste the coordinates into a python script. However, since the goal is to have a (semi-) automatic evaluation of the flow data, this solution is not optimal. So my second questions is: What are the python commands to get the important coordinates of a clip (i.e., plane normals, plane center coordinates)?




I am thanking everyone who has a useful solution for my problem or has at least some advices for me.
PedroInvierno is offline   Reply With Quote

Old   March 4, 2017, 21:01
Default
  #2
Senior Member
 
kevincolburn's Avatar
 
Kevin Colburn
Join Date: Mar 2009
Location: The Woodlands, TX
Posts: 131
Rep Power: 13
kevincolburn is on a distinguished road
1. There are a couple of ways to do this.
a. If you wanted to upgrade to EnSight 10.2, there is a new variable type called "constant per part". You can have EnSight compute those variables for all of the parts at once, yet keep them separate for each part. You'd select all of the clip planes, perform the operations very similar to what you have done (you add a flag at the end of each constant calculation which tells EnSight to maintain the constant per part). And you have it automatically.

b. If you wanted to do this an older version of EnSight, you'd loop over each of the clip plane parts, and create unique variables for each part. You can leverage python to do this:
# Let's assume a part_id_list contains the partIDs that you'd like to operate over.
part_id_list = [4,5,6,7,8,9,10]

# Loop over the list of part_id_list, and create unique set of variables for each PartID
for i in range(len(part_id_list)):
this_id = part_id_list[i]
n_name = "N_plane_"+str(this_id)
vel_name = "vel_plane_"+str(this_id)
flow_name = "flow_plane_"+str(this_id)
#
ensight.part.select_begin(this_id)
ensight.variables.evaluate(n_name+" = Normal(plist)")
ensight.variables.evaluate(vel_name+" = DOT(VEL,"+n_name+")")
ensight.variables.evaluate(flow_name+" = IntegralSurface(plist,"+vel_name+")")

# You should end up with a series of variables created. Each one has the PartID as part of the Name
# Now, select all of the constants with name = "flow_plane_4", "flow_plane_5", etc.

2. Plane Coordinates, and Normals.
Coordinates[X] will create a scalar variable for the CoordinateX of each node on the part.
You can utilize the SpaMean() function to return the area weighted average value of that scalar.
Repeat for Y and Z coordinates.

Plane Normals can be achieved in a similar manner. Above, you created a Vector Field of the
Normal (N_plane_4, N_plane_5, etc.) You can use the same process as above to return the average Normal via
Nx = N_plane_4[X]; Ave_Nx = SpaMean(plist,Nx)
Repeat for Y and Z directions.

Feel free to reach out to your local EnSight Representative or the main office for additional help/questions.

-Kevin
__________________
Kevin Colburn
Computational Engineering International, Inc.
www.ceisoftware.com
kevin@ensight.com
kevincolburn is offline   Reply With Quote

Old   March 5, 2017, 07:46
Default
  #3
New Member
 
Patrick Winter
Join Date: Mar 2017
Posts: 5
Rep Power: 5
PedroInvierno is on a distinguished road
Hello. Thank you for your help, this was already very useful.
However, I have now another question.

Now I have >10 queries for different clips. What I want now is to have the data of all these queries in one single *.csv file in order to import this into Excel. Is this possible? I already know that I can select all the queries and add these queries into a single plot (see below). However, when using data->save csv to file it only saves the data of one clip.

PedroInvierno is offline   Reply With Quote

Old   March 5, 2017, 08:55
Default
  #4
Senior Member
 
kevincolburn's Avatar
 
Kevin Colburn
Join Date: Mar 2009
Location: The Woodlands, TX
Posts: 131
Rep Power: 13
kevincolburn is on a distinguished road
Yes, python can help here as well. Firstly, you'll probably want to reference the "Interface Manual", Chapter 6 for some of the details. The function that you are going to exercise is the "ensight.QUERY_DATA". For query #3, you can obtain the values from that query (know that query #3 has ID = 2 (programmers start at 0)) via : query_vals = ensight.query(ensight.QUERY_DATA,2). You can place this into a loop, appending to a list perhaps as you go. You can then use standard python write() functions to write out the values of the list to a text file.

-kevin
__________________
Kevin Colburn
Computational Engineering International, Inc.
www.ceisoftware.com
kevin@ensight.com
kevincolburn is offline   Reply With Quote

Old   March 5, 2017, 12:33
Default
  #5
New Member
 
Patrick Winter
Join Date: Mar 2017
Posts: 5
Rep Power: 5
PedroInvierno is on a distinguished road
Thank you again for your help, I will look into that.

Thanks to your advices already a giant leap was possible for making my data evaluation much faster and more user-friendly.
PedroInvierno is offline   Reply With Quote

Old   April 7, 2017, 10:23
Default
  #6
New Member
 
Patrick Winter
Join Date: Mar 2017
Posts: 5
Rep Power: 5
PedroInvierno is on a distinguished road
Hello again.
I have one more question.
Now I wrote a script to evaluate my data. On my Mac (2014, OSX 10.10.05, 3 GHz Intel Core i7, 16 GB Ram, Intel Iris 1536 MB) it works.

However, when I save the session as *.ens file (with option packed data) and restore the session on a Windows 10 computer and work with the restored session, the program often crashes (mostly when saving or exporting images). At my Mac Book everything works fine.
The specs of the computer are: Graphics Card NVidia NVS 510, Windows 10 64 Bit Enterprise, 16 GB Ram, Core I5 6600.

We tried Ensight 10.0.2 and Ensight 10.2 (trial version).
Do you have any recommendations how I can improve the performance and reduce the number of crashes?

When we use Ensight 10.0.2 we need to run the program from the command window with ensight100 -X, since otherwise transparencies do not work.

Last edited by PedroInvierno; April 7, 2017 at 12:09.
PedroInvierno is offline   Reply With Quote

Old   April 7, 2017, 16:00
Default
  #7
Senior Member
 
kevincolburn's Avatar
 
Kevin Colburn
Join Date: Mar 2009
Location: The Woodlands, TX
Posts: 131
Rep Power: 13
kevincolburn is on a distinguished road
Pedro,

Session (and Context files) are "final state" files, and therefore fail when the creation/settings/file i/o has to anything to do with the state of EnSight. For example, if data comes in from an python routine, this is not captured in the state file (session/context). If you perform operations intertwined with python macros or scripts, those may not restore properly, as the context/session file does not call or utilize any user defined python.

Now, if you can save/restore the context on Mac, but fail on Windows, and you are utilizing python scripts/macros, my first suggestion is to understand what your python is doing, is see if that needs/should be called explicitly from Windows.

A more robust method typically involves using command files, rather than session/context files, as these are not state dependand files. When using the command files, ensure that if you are trying to intertwine python scripts in there, that you ensure those scripts' calls are envoked within the command files. As a slight alternative, you could use python from start-to-finish (both for command execution and your own scripts/macros).

As far as "packed data", we typically just copy over the dataset, or use remote client/server to access the data (packed data just does a zip of the entire directory and subdirectories, which can be excessive).

If you can give us some output from the attempts at trying to restore the packed data ens file, we can try to see what specifically about this situation is causing the problem, and suggested workarounds.

-kevin
__________________
Kevin Colburn
Computational Engineering International, Inc.
www.ceisoftware.com
kevin@ensight.com
kevincolburn is offline   Reply With Quote

Old   April 7, 2017, 17:01
Default
  #8
New Member
 
Patrick Winter
Join Date: Mar 2017
Posts: 5
Rep Power: 5
PedroInvierno is on a distinguished road
Hello Kevin.
Do I understand this correctly. Wenn I load my data, execute the python files and, after all variables are calculated with the python script, save the results as *ens file, there is no guarantee that the session files can be restored correctly?
Another question. Will the "full backup" question help? I will definitely look into the command file solution, however, I still hope that the *.ens session files are not completely useless.
PedroInvierno is offline   Reply With Quote

Old   April 10, 2017, 10:23
Default
  #9
Senior Member
 
kevincolburn's Avatar
 
Kevin Colburn
Join Date: Mar 2009
Location: The Woodlands, TX
Posts: 131
Rep Power: 13
kevincolburn is on a distinguished road
"Do I understand this correctly. When I load my data, execute the python files and, after all variables are calculated with the python script, save the results as *ens file, there is no guarantee that the session files can be restored correctly?"

That very much depends upon what the python script does. If it calls in external files or populates queries via python provided information, those items are not explicitly stored in the context file, and therefore will not restore. If the python script simply operates on model variables, or performs operations which generate a state which is captured in the context file, then it will restore just fine.


"Another question. Will the "full backup" question help? I will definitely look into the command file solution, however, I still hope that the *.ens session files are not completely useless."

Full backups are ONLY for the machine which you ran EnSight (you can't open the full backup on any other machine), and is tied specifically to that exact dataset. It can also be VERY large in size. It is just a memory dump to disk.

Command files are the most robust/transportable/size efficient.

-kevin
__________________
Kevin Colburn
Computational Engineering International, Inc.
www.ceisoftware.com
kevin@ensight.com
kevincolburn is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Gmsh] Problem with Gmsh nishant_hull OpenFOAM Meshing & Mesh Conversion 23 August 5, 2015 03:09
Define Profile, time dependent flow variation query Sdezmond Fluent UDF and Scheme Programming 5 March 3, 2013 12:13
Unable to view contour plot on a plane azurespirit ANSYS 0 May 23, 2011 09:35
Need advice on softwares working for dilute gas flow Mason Main CFD Forum 4 July 22, 2010 16:55
Multiple Fluid Flow Brian_Pal FLUENT 8 January 28, 2010 13:49


All times are GMT -4. The time now is 03:41.