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

Viscosity UDFs

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 21, 2009, 13:22
Default Viscosity UDFs
  #1
New Member
 
Richard
Join Date: Apr 2009
Posts: 3
Rep Power: 17
Supernova is on a distinguished road
Dear all,

I am trying to get some udfs for variable viscosity working in Fluent 6.3, although I'm having a great deal of problems in doing so...

I want to interpret the following code:

#include "udf.h"
//Works Casson
DEFINE_PROPERTY(cell_viscosity,c,t)
{
double mu_lam

double tiny = 0.0000000001;
double tauy = 0.01083;
double muinf = 0.0031;
double m = 200;
double strain;
double first;

strain = pow(C_DUDX(c, t),2)+ pow(C_DVDY(c, t),2)+
pow(C_DWDZ(c, t),2)+
2*pow(C_DUDY(c, t)+ C_DVDX(c, t),2)+
2*pow(C_DUDZ(c, t)+ C_DWDX(c, t),2)+
2*pow(C_DVDZ(c, t)+ C_DWDY(c, t),2);

strain = pow(strain, 0.5);

first = 1-exp(-pow(m*strain,0.5));

mu_lam = pow(muinf,0.5) + pow(tauy/(strain + tiny),0.5)*first;

mu_lam = pow(mu_lam, 2);
if(cell==100){printf("viscosity = %f",mu_lam);}
return mu_lam;
}


However, when I read my case file, and try to interpret this, I get the following error:

Error: c:\fluent.inc\fluent6.3.26/src/dpm.h: line 1192: parse error.

I would greatly appreciate any help I could get on this.

Many thanks in advance. Richard
mcanoenen likes this.
Supernova is offline   Reply With Quote

Old   April 22, 2009, 13:13
Default
  #2
New Member
 
Richard
Join Date: Apr 2009
Posts: 3
Rep Power: 17
Supernova is on a distinguished road
Can anyone please help me with this?

My final year project depends on this, and I don't know much about programming...

Thank you.
Supernova is offline   Reply With Quote

Old   April 23, 2009, 07:36
Default
  #3
New Member
 
Richard
Join Date: Apr 2009
Posts: 3
Rep Power: 17
Supernova is on a distinguished road
Actually forget it, I figured it out in the end: I had my header file in the same folder as my code, so it didn't work!
Supernova is offline   Reply With Quote

Old   May 11, 2009, 03:30
Default
  #4
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
Jane is on a distinguished road
Hi, Supernova

strain = pow(C_DUDX(c, t),2)+ pow(C_DVDY(c, t),2)+
pow(C_DWDZ(c, t),2)+
2*pow(C_DUDY(c, t)+ C_DVDX(c, t),2)+
2*pow(C_DUDZ(c, t)+ C_DWDX(c, t),2)+
2*pow(C_DVDZ(c, t)+ C_DWDY(c, t),2);


may i know how do you difine the C_DUDX (c,t) and the rest in your UDF??
Jane is offline   Reply With Quote

Old   May 11, 2009, 05:37
Default
  #5
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
hello Jane,

C_DUDX(c,t) is a predefined macro which returns the derivative of x-velocity with respect to x-coordinate. You do not have to define it by yourself. However there is also a macro C_STRAIN_RATE_MAG(c,t) to access the strain rate for each cell itself, thus there is no reason to compute this value by hand.

cheers
coglione is offline   Reply With Quote

Old   May 11, 2009, 06:14
Default
  #6
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
Jane is on a distinguished road
Hi, coglione

Thank you for your reply.

for example if i wan to code the equation as show in figure. below is the equation that i code for UDF.

shear_rate = sqrt (SQR(C_DUDX(c,t))+ SQR(C_DVDY(c,t) + SQR(C_DWDZ(c,t));

may i know the equation that i code into UDF is correct or not?
Jane is offline   Reply With Quote

Old   May 11, 2009, 21:46
Default
  #7
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
Jane is on a distinguished road
Quote:
Originally Posted by Jane View Post
Hi, coglione

Thank you for your reply.

for example if i wan to code the equation as show in figure. below is the equation that i code for UDF.

shear_rate = sqrt (SQR(C_DUDX(c,t))+ SQR(C_DVDY(c,t) + SQR(C_DWDZ(c,t));

may i know the equation that i code into UDF is correct or not?

Help me please...
i'm just a UDF beginner...please tell me
Jane is offline   Reply With Quote

Old   May 12, 2009, 03:57
Default
  #8
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
Hello Jane,

the correct equation for strain rate is given by supernova in the first message of this thread. Use his coding or simply the macro C_STRAIN_RATE_MAG(c,t). It will return excactly the same and is much more efficient in terms of cpu-time.

cheers
coglione is offline   Reply With Quote

Old   May 12, 2009, 04:46
Default
  #9
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
Jane is on a distinguished road
Quote:
Originally Posted by coglione View Post
Hello Jane,

the correct equation for strain rate is given by supernova in the first message of this thread. Use his coding or simply the macro C_STRAIN_RATE_MAG(c,t). It will return excactly the same and is much more efficient in terms of cpu-time.

cheers
Hi coglione,

thank you for your reply

i've tried macro C_STRAIN_RATE_MAG(c,t) in the UDF, the problem occurs when i simulate using this predefined strain rate. the continuity graph increase until fluent show errors message.

i suspect my shear rate equation caused the increase of continuity, but i still cannot find the solution.

can you give me some idea?
Jane is offline   Reply With Quote

Old   May 12, 2009, 08:44
Default
  #10
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
Hello Jane,
non-newtonian fluids are always prone for numerical problems due to the highly non-linear nature of the momentum equation involved. I usually start the simulation with a moderate shear dependency of the viscosity (or even constant one) and switch to the actual rheological model when the approximate solution has converged. This provides a realistic and quite smooth strain field and may help convergence. If instability is still observed lower your relaxation, use first order discretization and if nothing helps at all switch to transient simulation using a small time-step.

Hope this helps
coglione is offline   Reply With Quote

Old   May 12, 2009, 09:00
Default
  #11
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
Jane is on a distinguished road
Quote:
Originally Posted by coglione View Post
Hello Jane,
non-newtonian fluids are always prone for numerical problems due to the highly non-linear nature of the momentum equation involved. I usually start the simulation with a moderate shear dependency of the viscosity (or even constant one) and switch to the actual rheological model when the approximate solution has converged. This provides a realistic and quite smooth strain field and may help convergence. If instability is still observed lower your relaxation, use first order discretization and if nothing helps at all switch to transient simulation using a small time-step.

Hope this helps
Thank you for your advice, finally i get the stable continuity.
Thank you very much

I found my UDF unable to print the numbers to console.

Below is my "message" in UDF.

/*Message("UDF: time=%f,shear_rate=%f");*/
Jane is offline   Reply With Quote

Old   May 13, 2009, 12:06
Default
  #12
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
Daniel Tanner is on a distinguished road
Leave out the outer quotation marks.

"Message("UDF: time=%f,shear_rate=%f");"

should be of the form

Message("UDF: time=%f,shear_rate=%f", X, Y);

where X and Y are the time and shear_rate variables, i.e., you have not told the MESSAGE macro where to find the time and shear rate variables.
Daniel Tanner is offline   Reply With Quote

Old   May 13, 2009, 21:49
Default
  #13
New Member
 
Jane
Join Date: Mar 2009
Posts: 18
Rep Power: 17
Jane is on a distinguished road
Quote:
Originally Posted by Daniel Tanner View Post
Leave out the outer quotation marks.

"Message("UDF: time=%f,shear_rate=%f");"

should be of the form

Message("UDF: time=%f,shear_rate=%f", X, Y);

where X and Y are the time and shear_rate variables, i.e., you have not told the MESSAGE macro where to find the time and shear rate variables.
Thank you very much
Jane is offline   Reply With Quote

Old   March 4, 2011, 11:53
Default Help
  #14
New Member
 
Join Date: Mar 2011
Posts: 1
Rep Power: 0
maple is on a distinguished road
Quote:
Originally Posted by coglione View Post
hello Jane,

C_DUDX(c,t) is a predefined macro which returns the derivative of x-velocity with respect to x-coordinate. You do not have to define it by yourself. However there is also a macro C_STRAIN_RATE_MAG(c,t) to access the strain rate for each cell itself, thus there is no reason to compute this value by hand.

cheers
Hi Coglione,

Your input here has been very useful in my project.
I would like to ask a few questions:

C_STRAIN_RATE_MAG(c,t) deos it give a dimensionless value? or just the strain rate?

This is me code for my model:
#include"udf.h"
DEFINE_PROPERTY(c_effective_viscosity, cell, thread)
{
double e_viscos;
double m = 200;
double a_viscos = 0.0031;
double y_stress = 0.01082;
double strain;
double a;
double b;
double c;
strain = C_STRAIN_RATE_MAG(cell,thread);
a = y_stress/strain;
b = m*strain;
c = 1-exp(-pow(b,0.5));
e_viscos = pow(a_viscos,0.5)+(pow(a,0.5)*c);
e_viscos = pow(e_viscos,2);
return e_viscos;
}

However, when I try to run it, Fluent does not start iterating and shows the following error message.
Error: Floating point error: invalid number
Error Object: ()

Can you please help?


Regards,
Maple
maple is offline   Reply With Quote

Old   April 10, 2011, 12:03
Default
  #15
Member
 
xianghong wu
Join Date: Mar 2009
Posts: 57
Rep Power: 17
wendywu is on a distinguished road
Hello,
I am writing a nonNewtonian viscosity model of my own,
in the myViscosityModel.c, I wrote
shearrate=max(minshearrate, sqrt(2.0*(symm(fvc::grad(u)))&&(symm(fvc::grad(u)) )/3.0);

when I compile it with "wmake",
error is given as :
arguments in max()function has different dimensions
[0 0 -1 0 0 0 0] and [0 0 0 0 0 0 0],
then I tried to delete one argument, as:
shearrate= sqrt(2.0*(symm(fvc::grad(u)))&&(symm(fvc::grad(u)) )/3.0;
wmake it, still one error exist, but I didn't found out the error,
then I changed it back, as original:
shearrate=max(minshearrate, sqrt(2.0*(symm(fvc::grad(u)))&&(symm(fvc::grad(u)) )/3.0);
then I wmake it, still one error ,but this time the output is much more than the first time, I can not find where the error is,
I am confused, the same code, leads to different output, what is the problem?
I checked the dimensions of the two arguments of max(), there are both 1/second, why it thinks the second argument 's dimension is [0 0 0 0 0 0 0]?
anybody has any idea? thank you. and sorry for disturbing.

wendy
wendywu is offline   Reply With Quote

Old   April 11, 2011, 04:08
Default
  #16
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
Are you sure this is the right forum for this question?
It sounds pretty much like OpenFoam which has its own userforum here on cfd-online.
cheers
coglione is offline   Reply With Quote

Old   April 12, 2011, 10:08
Default
  #17
Member
 
xianghong wu
Join Date: Mar 2009
Posts: 57
Rep Power: 17
wendywu is on a distinguished road
Quote:
Originally Posted by coglione View Post
Are you sure this is the right forum for this question?
It sounds pretty much like OpenFoam which has its own userforum here on cfd-online.
cheers
yeah, Thank you for reminding.
wendywu is offline   Reply With Quote

Old   November 19, 2014, 03:11
Default strain rate and scale of strain rate
  #18
Member
 
Qureshi M Z I
Join Date: Sep 2013
Posts: 81
Rep Power: 13
m zahid is on a distinguished road
hi, anybody know the difference between "strain rate" and "scale of strain rate".

please share your knowledge.
regards
m zahid is offline   Reply With Quote

Old   July 11, 2022, 04:03
Thumbs up Cylindrical Coordinate
  #19
New Member
 
Telangana
Join Date: Jul 2022
Posts: 8
Rep Power: 4
Abhijeeth is on a distinguished road
Quote:
Originally Posted by coglione View Post
hello Jane,

C_DUDX(c,t) is a predefined macro which returns the derivative of x-velocity with respect to x-coordinate. You do not have to define it by yourself. However there is also a macro C_STRAIN_RATE_MAG(c,t) to access the strain rate for each cell itself, thus there is no reason to compute this value by hand.

cheers
Can this macro C_STRAIN_RATE_MAG(c,t) be used for Cylindrical coordinate system
Abhijeeth is offline   Reply With Quote

Old   July 11, 2022, 04:05
Default Cylindrical coordinate
  #20
New Member
 
Telangana
Join Date: Jul 2022
Posts: 8
Rep Power: 4
Abhijeeth is on a distinguished road
Quote:
Originally Posted by coglione View Post
hello Jane,

C_DUDX(c,t) is a predefined macro which returns the derivative of x-velocity with respect to x-coordinate. You do not have to define it by yourself. However there is also a macro C_STRAIN_RATE_MAG(c,t) to access the strain rate for each cell itself, thus there is no reason to compute this value by hand.

cheers
Can this macro C_STRAIN_RATE_MAG(c,t) be used for Cylindrical coordinate system
Abhijeeth 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
Unsteady and Flux UDFs for UDSs tom FLUENT 0 February 13, 2009 11:27
Turbulence viscosity limited Madhukar Rapaka FLUENT 0 June 26, 2006 04:17
kinematic viscosity at diff temperatures,pressures Mecobio Main CFD Forum 0 November 7, 2005 13:55
Turbulent viscosity in a riser ap FLUENT 8 April 19, 2003 09:00
Problem of Turbulent Viscosity Ratio Limited David Yang FLUENT 3 June 3, 2002 07:13


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