CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > CFX

User-defined function

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 8, 2021, 16:02
Unhappy User-defined function
  #1
Member
 
Join Date: Dec 2019
Posts: 31
Rep Power: 6
Mohamed911 is on a distinguished road
Hello to all

I am working on a simulation of a blood pump. In my study, I want to calculate the shear stress in the fluid so I can calculate the hemolysis index.
I have all the equations I need but I don't know how to use them in a user-defined function.

Can anyone help me? please
Mohamed911 is offline   Reply With Quote

Old   December 8, 2021, 17:22
Default
  #2
Senior Member
 
Gert-Jan
Join Date: Oct 2012
Location: Europe
Posts: 1,928
Rep Power: 28
Gert-Jan will become famous soon enough
What makes you think you need a user defined function?
Gert-Jan is offline   Reply With Quote

Old   December 8, 2021, 17:46
Default
  #3
Member
 
Join Date: Dec 2019
Posts: 31
Rep Power: 6
Mohamed911 is on a distinguished road
Quote:
Originally Posted by Gert-Jan View Post
What makes you think you need a user defined function?
because I can't find a way to plot either the contours or the plots of the shear stress in the variable list in CFX.
And I have read articles where the authors used UDF to calculate shear stress and hemolysis.
I thought that was the only way to do it.
Mohamed911 is offline   Reply With Quote

Old   December 8, 2021, 17:53
Default
  #4
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,870
Rep Power: 144
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
How you apply this depends on the equations you are trying to apply. Note UDFs are Fluent and CFX is different to Fluent.

Depending on what you are trying to do, you might be able to do this in post processing or you might need to put it in the solver to get your new variable. It all depends on what you are trying to do.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Old   December 8, 2021, 18:50
Default
  #5
Member
 
Join Date: Dec 2019
Posts: 31
Rep Power: 6
Mohamed911 is on a distinguished road
Quote:
Originally Posted by ghorrocks View Post
How you apply this depends on the equations you are trying to apply. Note UDFs are Fluent and CFX is different to Fluent.

Depending on what you are trying to do, you might be able to do this in post processing or you might need to put it in the solver to get your new variable. It all depends on what you are trying to do.
I tried to add the equations to CFX-Pre. however, since the shear stress is calculated using the velocity gradient. this gave me some errors.

"The parameter 'Expression Value' in object '/FLOW:Flow Analysis 1/OUTPUT CONTROL/MONITOR OBJECTS/MONITOR POINT:HII' is defined to be "Single Valued" but it depends on the following field valued variables: , Velocity u.Gradient X, Velocity u.Gradient Y, Velocity u.Gradient Z, Velocity v.Gradient X, Velocity v.Gradient Y, Velocity v.Gradient Z, Velocity w.Gradient X, Velocity w.Gradient Y, Velocity w.Gradient Z."
Mohamed911 is offline   Reply With Quote

Old   December 8, 2021, 18:53
Default
  #6
Senior Member
 
Gert-Jan
Join Date: Oct 2012
Location: Europe
Posts: 1,928
Rep Power: 28
Gert-Jan will become famous soon enough
CFX makes the shear strain rate available by default in CFD-Post. Can't you derive the shear stress from that?
Gert-Jan is offline   Reply With Quote

Old   December 8, 2021, 18:59
Default
  #7
Senior Member
 
Gert-Jan
Join Date: Oct 2012
Location: Europe
Posts: 1,928
Rep Power: 28
Gert-Jan will become famous soon enough
Quote:
Originally Posted by Mohamed911 View Post
I tried to add the equations to CFX-Pre. however, since the shear stress is calculated using the velocity gradient. this gave me some errors.

"The parameter 'Expression Value' in object '/FLOW:Flow Analysis 1/OUTPUT CONTROL/MONITOR OBJECTS/MONITOR POINT:HII' is defined to be "Single Valued" but it depends on the following field valued variables: , Velocity u.Gradient X, Velocity u.Gradient Y, Velocity u.Gradient Z, Velocity v.Gradient X, Velocity v.Gradient Y, Velocity v.Gradient Z, Velocity w.Gradient X, Velocity w.Gradient Y, Velocity w.Gradient Z."
The error "single valued" error occurs where you are using a vector while a single value is expected.
Gert-Jan is offline   Reply With Quote

Old   December 8, 2021, 22:43
Default
  #8
New Member
 
WEI Liangchuan
Join Date: Nov 2021
Posts: 9
Rep Power: 5
Liangchuan is on a distinguished road
You should figure out the derivation of the formula for shear stress, starting from the variables known to cfd-post
Liangchuan is offline   Reply With Quote

Old   December 9, 2021, 06:32
Default
  #9
Member
 
Join Date: Dec 2019
Posts: 31
Rep Power: 6
Mohamed911 is on a distinguished road
I found the solution for the shear stress. But I still have a problem concerning hemolysis because it is a variable that varies in time
Mohamed911 is offline   Reply With Quote

Old   December 9, 2021, 06:38
Default
  #10
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,870
Rep Power: 144
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
Are you going to tell us what hemolysis function you are trying to apply or should we start guessing?
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Old   December 9, 2021, 06:48
Default
  #11
Member
 
Join Date: Dec 2019
Posts: 31
Rep Power: 6
Mohamed911 is on a distinguished road
sorry

HI = C * T^a * SS^b

HI: Hemolysis Index
c : constant (=3.620*10^-5)
T : time (= ti - t(i-1))
a : constant (= 0.7850)
b: constant (= 2.416)
SS: Shear Stress
Mohamed911 is offline   Reply With Quote

Old   December 9, 2021, 06:52
Default
  #12
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,870
Rep Power: 144
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
Does this accumulate on the flow as it passes through regions of different shear stress?

Or is this implemented at a specific time point over the domain?

Or how do you want to implement it?
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Old   December 9, 2021, 06:58
Default
  #13
Member
 
Join Date: Dec 2019
Posts: 31
Rep Power: 6
Mohamed911 is on a distinguished road
since I am tracking the movement of red blood cells. I think the best option is to use the hemolysis index function on the streamlines. It would be possible to follow the variation of the hemolysis index when the red cell is present in the simulation field.
Mohamed911 is offline   Reply With Quote

Old   December 9, 2021, 18:43
Default
  #14
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,870
Rep Power: 144
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
Do not confuse what you can do with what you actually want to do.

Please explain what you want to do. Does the hemolysis index accumulate on the blood cells as it progresses through to domain? (ie: is it integrated over the flow path?) Or is it just an instantaneous value (ie: is it a scalar field?) Or a scalar field which is only meaningful in some locations (eg along the streamlines?)

Please describe mathematically what you want to do, otherwise we are going to have to guess that as well.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Old   December 18, 2021, 12:14
Default
  #15
Member
 
Join Date: Dec 2019
Posts: 31
Rep Power: 6
Mohamed911 is on a distinguished road
Quote:
Originally Posted by ghorrocks View Post
Do not confuse what you can do with what you actually want to do.

Please explain what you want to do. Does the hemolysis index accumulate on the blood cells as it progresses through to domain? (ie: is it integrated over the flow path?) Or is it just an instantaneous value (ie: is it a scalar field?) Or a scalar field which is only meaningful in some locations (eg along the streamlines?)

Please describe mathematically what you want to do, otherwise we are going to have to guess that as well.
the actual equation is something like this: HI (%) = ∑ (C * τ_i^α* ∆t_i^β).

Normally, we calculate the hemolysis index for a defined number of red blood cells. to make the calculation easier, we assume that the streamlines are trajectories for the red blood cells. using this strategy, we can calculate the variation of the shear stress as well as the hemolysis index along the streamlines. for the variable (t), we can use the time on the streamlines.
I have already done this with a C code I developed. but to do all this work, I have to do the simulations, extract the streamline data (1000 streamlines), and then import the data into my code. but, this process takes time and I cannot get contours for the hemolysis index.

Ps: Sorry for the delai
Mohamed911 is offline   Reply With Quote

Old   December 18, 2021, 17:53
Default
  #16
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,870
Rep Power: 144
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
You have not defined what your equation means. I assume C, alpha and beta are constants, but what are tau_i and Delta tau_i? Also, what is the sum over? Is it along a streamline? If so, why isn't it a line integral rather than a sum?

If these guesses are correct and you make the assumption that the streamlines are trajectories for the red blood cells then by far the easiest way to do this is to model the flow as single phase (so no particles) but with an additional variable set to convection only (diffusion=0). Define a source term to increment the additional variable according to your equation and rerun the simulation. This approach does not require calculation along streamlines, it does that automatically, and produces an answer in the solver which is easily viewed in the post processor.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Old   December 23, 2021, 08:04
Default
  #17
Member
 
Join Date: Dec 2019
Posts: 31
Rep Power: 6
Mohamed911 is on a distinguished road
yes. C, alpha, and beta are constants. tau_i is the scalar heart stress exerted on the red blood cell in the instant t_i. since the mathematical model is a time_depending model. the only way I could find is to use the time on streamlines. but, as I mentioned previously, I couldn't implement it in CFD-post, since I don't know how to add a time-varying variable.

as for the second, I didn't understand it. however, now I'm trying to redo the simulations using a two-phase flow (with particles). I'll see if I can track the particles
Mohamed911 is offline   Reply With Quote

Old   December 23, 2021, 12:41
Default
  #18
Senior Member
 
Gert-Jan
Join Date: Oct 2012
Location: Europe
Posts: 1,928
Rep Power: 28
Gert-Jan will become famous soon enough
You can calculate time as scalar variable, starting with zero on the inlet, while increasing in the flow domain. Similar like the time on streamlines, but then as continuous variable.
This time can be used in expressions to couple it with your other variables.

How can you do this? Follow this link:

Residence Time Distribution
Gert-Jan is offline   Reply With Quote

Old   December 24, 2021, 06:27
Default
  #19
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,870
Rep Power: 144
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
The approach I suggested is much easier and better for your case than particle tracking I suspect. You should give it a try. If you don't understand it then ask questions about what you don't understand.

Gert-Jan's link uses a similar approach and explains it a bit more. Make sure you read that as well.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Reply

Tags
hemolysis, shear stress, udf


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
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 18:22
[blockMesh] Errors during blockMesh meshing Madeleine P. Vincent OpenFOAM Meshing & Mesh Conversion 51 May 30, 2016 11:51
How to use date from previous time step in user defined field function? samantkumarnagraj STAR-CCM+ 2 December 12, 2014 07:08
ParaView for OF-1.6-ext Chrisi1984 OpenFOAM Installation 0 December 31, 2010 07:42
Help: user defined function alice FLUENT 3 December 13, 2000 01:10


All times are GMT -4. The time now is 15:13.