CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Request for UDF code explanation: calculation of a specific alpha expression

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By `e`
  • 1 Post By `e`

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 25, 2015, 17:36
Red face Request for UDF code explanation: calculation of a specific alpha expression
  #1
Member
 
Join Date: Mar 2015
Posts: 30
Rep Power: 11
mimi0201 is on a distinguished road
Can anyone please explain the meaning of the sentence "alpha = M_PI/2. - acos(MAX(-1.,MIN(1.,NV_DOT(normal,p->state.V)/MAX(NV_MAG(p->state.V),DPM_SMALL))));".
mimi0201 is offline   Reply With Quote

Old   March 25, 2015, 18:44
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Where did you get this equation from and what is this equation describing?

The first term, M_PI/2., is simply \pi \over 2.

Let's now analyse the second term by expanding the brackets to make some sense of this line of code:

Code:
-acos(
	MAX(
		-1.,
		MIN(
			1.,
			NV_DOT(normal,p->state.V)/MAX(NV_MAG(p->state.V),DPM_SMALL)
		)
	)
);
Briefly, these functions are: acos (inverse cosine), max (maximum of a set of values), min (minimum of a set of values), NV_DOT (dot product vector operation), NV_MAG (magnitude of a vector).

"p->state.V" is the velocity vector; could also be accessed with C_U(c,t). DPM_SMALL is a small number.
`e` is offline   Reply With Quote

Old   March 25, 2015, 18:58
Default
  #3
Member
 
Join Date: Mar 2015
Posts: 30
Rep Power: 11
mimi0201 is on a distinguished road
Quote:
Originally Posted by `e` View Post
Where did you get this equation from and what is this equation describing?

The first term, M_PI/2., is simply \pi \over 2.

Let's now analyse the second term by expanding the brackets to make some sense of this line of code:

Code:
-acos(
	MAX(
		-1.,
		MIN(
			1.,
			NV_DOT(normal,p->state.V)/MAX(NV_MAG(p->state.V),
			DPM_SMALL
			)
		)
	)
);
Briefly, these functions are: acos (inverse cosine), max (maximum of a set of values), min (minimum of a set of values), NV_DOT (dot product vector operation), NV_MAG (magnitude of a vector).

"p->state.V" is the velocity vector; could also be accessed with C_U(c,t). DPM_SMALL is a small number.
Thank you so much for the explanation, this equation is from DPM udf, determining the angle between wall tangent and the incoming particle. It is hard for me to understand the principle of calculating the angle like why need max and min. Cheers.
mimi0201 is offline   Reply With Quote

Old   March 25, 2015, 19:08
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The inverse cosine function is real only if evaluated between -1 and 1. The MIN() and MAX() functions restrict the input value to between -1 and 1 to avoid imaginary/garbage numbers as an output.
mimi0201 likes this.
`e` is offline   Reply With Quote

Old   March 25, 2015, 19:32
Default
  #5
Member
 
Join Date: Mar 2015
Posts: 30
Rep Power: 11
mimi0201 is on a distinguished road
Quote:
Originally Posted by `e` View Post
The inverse cosine function is real only if evaluated between -1 and 1. The MIN() and MAX() functions restrict the input value to between -1 and 1 to avoid imaginary/garbage numbers as an output.
I think I got it, min() and max() only act to restrict the value from -1 to 1 which suits the input range of acos(), and the actual calculation of incident angle is "NV_DOT(normal,p->state.V)/MAX(NV_MAG(p->state.V)," this equation right?
mimi0201 is offline   Reply With Quote

Old   March 25, 2015, 19:55
Default
  #6
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Have a read of scalar projection to understand the mathematics.

The equation this code is solving:

\alpha = {\pi \over 2} - \arccos \left( {\frac {\mathbf{n} \cdot \mathbf{v}} {|\mathbf{n}| \, |\mathbf{v}|}} \right)

where \mathbf{n} is the normal vector of the wall and \mathbf{v} is the velocity vector of the particle.

Ideally, the corresponding code:

Code:
alpha = M_PI/2. - acos(NV_DOT(normal,p->state.V)/NV_MAG(p->state.V));
Except to ensure there are no errors, the coders have restricted the inputs for the acos() function by using MAX() and MIN(). Note that they have used the second MAX() function with DPM_SMALL because if |\mathbf{v}| = 0, you'd be trying to divide by zero!
mimi0201 likes this.
`e` is offline   Reply With Quote

Old   March 25, 2015, 20:31
Default
  #7
Member
 
Join Date: Mar 2015
Posts: 30
Rep Power: 11
mimi0201 is on a distinguished road
Quote:
Originally Posted by `e` View Post
Have a read of scalar projection to understand the mathematics.

The equation this code is solving:

\alpha = {\pi \over 2} - \arccos \left( {\frac {\mathbf{n} \cdot \mathbf{v}} {|\mathbf{n}| \, |\mathbf{v}|}} \right)

where \mathbf{n} is the normal vector of the wall and \mathbf{v} is the velocity vector of the particle.

Ideally, the corresponding code:

Code:
alpha = M_PI/2. - acos(NV_DOT(normal,p->state.V)/NV_MAG(p->state.V));
Except to ensure there are no errors, the coders have restricted the inputs for the acos() function by using MAX() and MIN(). Note that they have used the second MAX() function with DPM_SMALL because if |\mathbf{v}| = 0, you'd be trying to divide by zero!
It helps a lot! Cheers!
mimi0201 is offline   Reply With Quote

Reply

Tags
dpm fluent


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
alphaEqn.H in twoPhaseEulerFoam cheng1988sjtu OpenFOAM Bugs 15 May 1, 2016 16:12
Specific OpenFOAM Code pbhuter OpenFOAM 13 June 30, 2012 19:06
How to install CGNS under windows xp? lzgwhy Main CFD Forum 1 January 11, 2011 18:44
CGNS lib and Fortran compiler manaliac Main CFD Forum 2 November 29, 2010 06:25
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 15:56


All times are GMT -4. The time now is 07:35.