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

New to UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 12, 2015, 10:45
Smile
  #21
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thank you very much. that is indeed helpful..
shivakumar is offline   Reply With Quote

Old   March 18, 2015, 04:57
Exclamation .....Error while compiling....
  #22
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
I am getting error like this. Is this because of declaration? Not getting properly. Any help would be appreciated.

.\..\src\Untitled1.c(58) : error C2440: 'function' : cannot convert from 'real [2]' to 'double'
..\..\src\Untitled1.c(58) : warning C4024: 'fabs' : different types for formal and actual parameter 1
shivakumar is offline   Reply With Quote

Old   March 18, 2015, 05:10
Default
  #23
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
This is because of this part in your code:
Code:
fabs(C_P_G(c,t))
To understand the problem, you need to know two things:
1. What does C_P_G give as output? (Look up in the Fluent manual, because this is a Fluent macro.)
2. What does fabs expect as input? (Look up in a c-reference, for example this one.)

You will see that they don't match. But look it up anyway, it is useful to see these things.

How to fix this: think about what you want. What should that part of code do? If you would explain it to a human, how would you describe it?
pakk is offline   Reply With Quote

Old   March 18, 2015, 05:39
Question
  #24
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Quote:
Originally Posted by pakk View Post
This is because of this part in your code:
Code:
fabs(C_P_G(c,t))
To understand the problem, you need to know two things:
1. What does C_P_G give as output? (Look up in the Fluent manual, because this is a Fluent macro.)
2. What does fabs expect as input? (Look up in a c-reference, for example this one.)

You will see that they don't match. But look it up anyway, it is useful to see these things.

How to fix this: think about what you want. What should that part of code do? If you would explain it to a human, how would you describe it?

Thank you for the reply. Those are good examples for beginners like me, thank u...

I used the same code but still getting the same error

Code:
	f_shock=((C_U(c,t)*C_P_G(c,t)[0]) + (C_V(c,t)*C_P_G(c,t)[1]) + (C_W(c,t)*C_P_G(c,t)[2]))/(a*fabs(C_P_G(c,t)));
what is that real[2] to double??
shivakumar is offline   Reply With Quote

Old   March 18, 2015, 05:47
Default
  #25
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You forgot to actually read my post. It has some questions that you should try to answer. Let me repeat them:

1. What does C_P_G give as output? (Look up in the Fluent manual, because this is a Fluent macro.)
2. What does fabs expect as input? (Look up in a c-reference, for example this one.)

How to fix this: think about what you want. What should that part of code do? If you would explain it to a human, how would you describe it?
pakk is offline   Reply With Quote

Old   March 20, 2015, 00:44
Unhappy
  #26
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
C_P_G it gives the pressure gradient vector, and its components can be accessed by specifying it as an argument in the gradient vector call (0 for the x component; 1 for y; and 2 for z).
Even I did the same but why this error is occurring??

The fabs yields the absolute value of some quantity, which is in the header file #include "math.h"
This one also I included.. Still the error is same.

Please help.
shivakumar is offline   Reply With Quote

Old   March 20, 2015, 02:23
Default
  #27
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
According to your code here, if the fabs() function requires a scalar variable as input then it would spit out an error because C_P_G(c,t) returns a pressure gradient vector.
`e` is offline   Reply With Quote

Old   March 20, 2015, 03:53
Default
  #28
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
That is right. "fabs" calculates the absolute value of a number.

So fabs(1) will give 1.
And fabs(-2) will give 2.
And fabs("test") will give an error, because "test" is not a number.
And fabs(C_P_G(c,t)) will give an error, because C_P_G(c,t) is not a number.

Honestly, I know exactly what you have to do. But I want to teach you the approach to solve these problems. So again I ask you:

What should that part of code do? If you would explain it to a human, how would you describe it?
pakk is offline   Reply With Quote

Old   March 20, 2015, 04:00
Default
  #29
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Quote:
Originally Posted by `e` View Post
According to your code here, if the fabs() function requires a scalar variable as input then it would spit out an error because C_P_G(c,t) returns a pressure gradient vector.
Thank you for the reply. you're right. I expanded that del p and then inserted inside the fabs. It is compiled now.
Thank you very much.
shivakumar is offline   Reply With Quote

Old   March 20, 2015, 04:09
Default
  #30
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Too bad you went for the complicated approach.

If you would have just said: "I want the magnitude of the vector", I would have told you "Then you should use NV_MAG". But it looks like you are not interested in understanding what your code does, and are only interested in getting rid of compilation errors. Good for the short term, bad for the longer term.
pakk is offline   Reply With Quote

Old   March 20, 2015, 04:22
Post
  #31
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Quote:
Originally Posted by pakk View Post
That is right. "fabs" calculates the absolute value of a number.

So fabs(1) will give 1.
And fabs(-2) will give 2.
And fabs("test") will give an error, because "test" is not a number.
And fabs(C_P_G(c,t)) will give an error, because C_P_G(c,t) is not a number.

Honestly, I know exactly what you have to do. But I want to teach you the approach to solve these problems. So again I ask you:

What should that part of code do? If you would explain it to a human, how would you describe it?
Thank you very much.
That part of the code contains dot product of velocity vector and del p. velocity vector is (ui+vj+wk) and del p is expanded as dp/dx i +dp/dy j +dp/dy k. This product yields a scalar but when it comes to the denominator fabs(del p), the output of del p normally gives a vector. correct?. How it is possible to divide scalar by vector?. I am just confused..
shivakumar is offline   Reply With Quote

Old   March 20, 2015, 04:28
Default
  #32
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Pakk

I am interested in understanding all the concepts and codes.
shivakumar is offline   Reply With Quote

Old   March 20, 2015, 05:09
Default
  #33
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Let's be sure you have the terminology correct. The pressure, p, is a scalar field and the vector derivative of this scalar field is called the gradient; namely \nabla p.

\nabla p = {\partial p \over \partial x} {\boldsymbol{\hat{\textbf{\i}}}} + {\partial p \over \partial y} {\boldsymbol{\hat{\textbf{\j}}}} + {\partial p \over \partial z} {\boldsymbol{\hat{\textbf{k}}}}

The denominator of your equation (11) includes \left| \nabla p \right|; the vertical lines represent the norm of the pressure gradient.

\left| \nabla p \right| = \sqrt{\left({\partial p \over \partial x}\right)^2 + \left({\partial p \over \partial y}\right)^2 + \left({\partial p \over \partial z}\right)^2}

pakk has mentioned you could use the vector operation macro NV_MAG to compute \left| \nabla p \right|.

Code:
NV_MAG(C_P_G(c,t))
`e` is offline   Reply With Quote

Old   March 20, 2015, 05:18
Default
  #34
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Quote:
Originally Posted by `e` View Post
Let's be sure you have the terminology correct. The pressure, p, is a scalar field and the vector derivative of this scalar field is called the gradient; namely \nabla p.

\nabla p = {\partial p \over \partial x} {\boldsymbol{\hat{\textbf{\i}}}} + {\partial p \over \partial y} {\boldsymbol{\hat{\textbf{\j}}}} + {\partial p \over \partial z} {\boldsymbol{\hat{\textbf{k}}}}

The denominator of your equation (11) includes \left| \nabla p \right|; the vertical lines represent the norm of the pressure gradient.

\left| \nabla p \right| = \sqrt{\left({\partial p \over \partial x}\right)^2 + \left({\partial p \over \partial y}\right)^2 + \left({\partial p \over \partial z}\right)^2}

pakk has mentioned you could use the vector operation macro NV_MAG to compute \left| \nabla p \right|.

Code:
NV_MAG(C_P_G(c,t))
Thank you for the reply. I just gone through that topic.. That is indeed helpful. I understood that topic completely and now I am able to do programming on that.. Thank u very much 'e' and 'pakk'. I have little doubt in the viscous sensor..
shivakumar is offline   Reply With Quote

Old   March 23, 2015, 02:37
Question
  #35
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Hi,

Is it possible to obtain the freesteam laminar and turbulent viscosity from the fluent udf?
The below code is compiling well but I am not sure about the freestream laminar and turbulent viscosities. Is there any other way to compute the freestream viscosities.?
any help would be appriciated.

Code:
#include "udf.h"
#include "mem.h"


DEFINE_ON_DEMAND(viscous_sen)
{
	Domain *d;
	Thread *t;
	cell_t c;
	
	real f_viscous;
	
	real viscous_sensor;
	
	d=Get_Domain(1);
	
	
	thread_loop_c(t,d)
	{
		f_viscous = (C_MU_L(c,t)+C_MU_T(c,t))/C_MU_L(c,t);
		
		if(f_viscous>=(1.1 * f_viscous))
		
		begin_c_loop(c,t)
		{
			C_UDMI(c,t,0) = viscous_sensor;
		}
		end_c_loop(c,t)
	}
}

Thanks
shivakumar
Attached Images
File Type: jpg captured.JPG (30.1 KB, 12 views)
shivakumar is offline   Reply With Quote

Old   March 23, 2015, 02:47
Exclamation
  #36
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
I got error like this while executing the above code..

FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
shivakumar is offline   Reply With Quote

Old   March 23, 2015, 03:23
Default
  #37
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
You haven't yet set a value for the cell ID, c, when you call the C_MU_L(c,t) macro. Specifically, Fluent uses the number previously allocated in memory (most likely an irrelevant number; "garbage") at the location where you've declared it with "cell_t c". There'd be a similar problem with the viscous_sensor variable (it's declared but no value has been added).

Move the f_viscous line to within the cell loop. Similarly, either set a value for viscous_sensor in the loops or where you've declared this variable.
`e` is offline   Reply With Quote

Old   March 23, 2015, 04:26
Smile
  #38
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thank you for the reply. I made changes and is compiled. Its going well..


Is that correct formula for finding the freestream laminar and turbulant viscosity?


Thanks
shivakumar is offline   Reply With Quote

Old   March 23, 2015, 05:00
Default
  #39
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Yes, your code looks correct according to equation (12) of your attached file.
`e` is offline   Reply With Quote

Old   March 23, 2015, 05:13
Question
  #40
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thanks for the reply

Ok. Is there any other formula to calculate the freestream values of those two.?
Attached Images
File Type: jpg Capture2.JPG (61.5 KB, 11 views)
shivakumar is offline   Reply With Quote

Reply


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
WILLING TO PAY/ FREELANCER REQUIRED / small UDF coding force loads over body / 6DOF acasas CFD Freelancers 1 January 23, 2015 08:26
Source Term UDF VS Porous Media Model pchoopanya Fluent UDF and Scheme Programming 1 August 28, 2013 07:12
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 22:38
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 05:03


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