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

Velocity profile UDF divergence error

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

Like Tree4Likes
  • 1 Post By pakk
  • 1 Post By AlexanderZ
  • 1 Post By pakk
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 14, 2021, 11:33
Exclamation Velocity profile UDF divergence error
  #1
New Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 15
Rep Power: 4
Mohammad74 is on a distinguished road
Hi,

First I must say I'm pretty new to Ansys Fluent UDFs. I'm trying to solve a simple problem with a cubic domain and a custom velocity profile at inlet boundary. I've read the Ansys users' guide on UDFs and I cant find any problems with my code, however when I begin the simulation, Fluent gives me this error:

"Divergence detected in amg solver: x-momentum"

Sorry if my question is a bit obvious but what am I missing? Can someone please help me?

BTW my Fluent version is 17.0 and I'm using MVS Express 2012. Also here is my code:

Code:
 
#include "udf.h"

#define A_f	22			/* Frontal built area */
#define A_p	22			/* Planar built area */
#define A_tot 100			/* Total land area */
#define H 10				/* Mean building height-Refrence height */
#define U_H	6			/* Wind velocity at height H */
#define A 4.4			/* Building arrangement constant */
#define Cd 1.2			/* Drag coefficient for an staggered array of cubes */
#define Beta 0.55		/* Building drag correction factor */
#define k_von 0.4		/* von-Karman constant */

DEFINE_PROFILE(x_velocity,t,i)
{
	double lambda_f, lambda_p, a, d, zz, z0, U_s, x[ND_ND], z;	/* Variable declarations */
	face_t f;
	lambda_f = A_f/A_tot;				/* Frontal area density */
	lambda_p = A_p/A_tot;				/* Planar area density */
	a = 9.6*lambda_f;					/* Building morphology constant */
	d = H*(1+(pow(A,-lambda_p))*(lambda_p-1));		/* Displacement length */
	zz = 0.5*Beta*Cd*pow(k_von,-2)*(1-(d/H))*lambda_f;
	z0 = H*(1-(d/H))*exp(-(pow(zz,-0.5)));			/* Surface roughness */
	U_s = (U_H*k_von)/(log((H-d)/z0));				/* Friction velocity */
	begin_f_loop(f,t)
	{
		F_CENTROID(x,f,t);
		z = x[2];
		
		if (z <= H)
			F_PROFILE(f,t,i) = U_H*exp(a*((z/H)-1));
		else
			F_PROFILE(f,t,i) = (U_s/k_von)*log((z-d)/z0);

	}
	end_f_loop(f,t)
}
Mohammad74 is offline   Reply With Quote

Old   May 14, 2021, 13:01
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,913
Rep Power: 23
pakk will become famous soon enough
Initialize, don't solve, plot velocity on your BC.

Is it what you expect?

My guess is that you made a mistake in one of the equations, which gives you to high velocities.
Mohammad74 likes this.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   May 15, 2021, 14:37
Default
  #3
New Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 15
Rep Power: 4
Mohammad74 is on a distinguished road
Hello again and thank you for your response,

I did as u said and plotted velocity profile on inlet BC after standard initialization (hybrid initialization gives me a similar error). Unfortunately it does not plot anything...
So in order to check my equations I used Matlab to plot them and they work as they should be. I attached an image of the Matlab plot here too.
I also noticed that in initial values fields, values for k, omega and x velocity are set to " 1.#QNAN " !!
Any other ideas?

vplot.jpg
Mohammad74 is offline   Reply With Quote

Old   May 16, 2021, 00:35
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,913
Rep Power: 23
pakk will become famous soon enough
Quote:
Originally Posted by Mohammad74 View Post
I also noticed that in initial values fields, values for k, omega and x velocity are set to " 1.#QNAN " !!
Any other ideas?

[
Fix that problem, and set them to number values!
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   May 16, 2021, 05:13
Default
  #5
New Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 15
Rep Power: 4
Mohammad74 is on a distinguished road
I already did that before posting the reply and it did not help.
Mohammad74 is offline   Reply With Quote

Old   May 16, 2021, 12:54
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,913
Rep Power: 23
pakk will become famous soon enough
If you replace your UDF boundary with a simple boundary (velocity 10 m/s for example), do you get the same error? If so, it has nothing to do with the UDF.

And maybe your fluid properties are wrong?
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   May 16, 2021, 17:36
Default
  #7
New Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 15
Rep Power: 4
Mohammad74 is on a distinguished road
Hi, I've tried that with a constant 6 m/s velocity at inlet and it worked fine.

Also other things that I've tried but still got the same error:
  • I used another domain and mesh quality.
  • Changed the working fluid.
  • Used another turbulence model.
  • I even tried to use a sample code for velocity profile given in Fluent's UDF guide but even that gave the same error!
Mohammad74 is offline   Reply With Quote

Old   May 16, 2021, 22:20
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,760
Rep Power: 28
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
check this code
Code:
#include "udf.h"
DEFINE_PROFILE(vel_profile,t,i)
{
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
y = x[1];
F_PROFILE(f,t,i) = y*6;
}
end_f_loop(f,t)
}
Mohammad74 likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   May 17, 2021, 05:49
Default
  #9
New Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 15
Rep Power: 4
Mohammad74 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
check this code
Thank you, this worked fine and I was able to run the simulation. But I'm still trying to figure out what is wrong with my UDF...
Mohammad74 is offline   Reply With Quote

Old   May 17, 2021, 07:29
Default
  #10
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,760
Rep Power: 28
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
your code seems to be ok,
the only thing I would change is double type to real here:
Code:
	real lambda_f, lambda_p, a, d, zz, z0, U_s, x[ND_ND], z;	/* Variable declarations */
compile code
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   May 17, 2021, 08:55
Default
  #11
New Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 15
Rep Power: 4
Mohammad74 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
your code seems to be ok,
the only thing I would change is double type to real here:
nope, its still not working. gives the same error.
Mohammad74 is offline   Reply With Quote

Old   May 19, 2021, 18:03
Default
  #12
Senior Member
 
Join Date: Nov 2013
Posts: 1,913
Rep Power: 23
pakk will become famous soon enough
You have some tabs in your #define's, which might be a problem (I don't know if that is allowed or not).

And you can write some values to show if there is an intermediate problem, like this:

Code:
#include "udf.h"

#define A_f 22			/* Frontal built area */
#define A_p 22			/* Planar built area */
#define A_tot 100			/* Total land area */
#define H 10				/* Mean building height-Refrence height */
#define U_H 6			/* Wind velocity at height H */
#define A 4.4			/* Building arrangement constant */
#define Cd 1.2			/* Drag coefficient for an staggered array of cubes */
#define Beta 0.55		/* Building drag correction factor */
#define k_von 0.4		/* von-Karman constant */

DEFINE_PROFILE(x_velocity,t,i)
{
	double lambda_f, lambda_p, a, d, zz, z0, U_s, x[ND_ND], z;	/* Variable declarations */
	face_t f;
	lambda_f = A_f/A_tot;				/* Frontal area density */
	lambda_p = A_p/A_tot;				/* Planar area density */
	a = 9.6*lambda_f;					/* Building morphology constant */
	d = H*(1+(pow(A,-lambda_p))*(lambda_p-1));		/* Displacement length */
	zz = 0.5*Beta*Cd*pow(k_von,-2)*(1-(d/H))*lambda_f;
	z0 = H*(1-(d/H))*exp(-(pow(zz,-0.5)));			/* Surface roughness */
	U_s = (U_H*k_von)/(log((H-d)/z0));				/* Friction velocity */
	begin_f_loop(f,t)
	{
		F_CENTROID(x,f,t);
		z = x[2];
		
		if (z <= H)
			F_PROFILE(f,t,i) = U_H*exp(a*((z/H)-1));
		else
			F_PROFILE(f,t,i) = (U_s/k_von)*log((z-d)/z0);

	}
	end_f_loop(f,t)

Message("z=%f ",z);
Message("U_s=%f ",U_s);
Message("z0=%f ",z0);
Message("zz=%f ",zz);
Message("d=%f ",d);
}
This will just show the values of the last face that was visited, but it might just be enough to help understand what is going on.
Mohammad74 likes this.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   May 22, 2021, 12:32
Post
  #13
New Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 15
Rep Power: 4
Mohammad74 is on a distinguished road
Hi,

So I've finally managed to solve this error. Apparently "#define" that I used to define some constants was not working properly so constant values were set to zero in equations. I used the method below to define my constants and its working now:

Code:
const float A_f=22, A_p=22, A_tot=100, H=10 ,U_H=6, A=4.4, Cd=1.2, Beta=0.55, k_von=0.4;
I'm still confused about why "#define" is not working though.
Mohammad74 is offline   Reply With Quote

Old   May 22, 2021, 13:41
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,913
Rep Power: 23
pakk will become famous soon enough
Quote:
Originally Posted by Mohammad74 View Post
Hi,

I'm still confused about why "#define" is not working though.

Thank you for completely ignoring my message directly above yours.
Mohammad74 likes this.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   May 22, 2021, 14:57
Default
  #15
New Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 15
Rep Power: 4
Mohammad74 is on a distinguished road
Quote:
Originally Posted by pakk View Post
Thank you for completely ignoring my message directly above yours.
No I did not ignore it. Those are not tabs but spaces and that is how the syntax of #define works.

And about using the "Message" command, I did try it but it was not working since my simulation could not even start to run that command.
Anyhow, thank you so much for taking the time to answer my question.
Mohammad74 is offline   Reply With Quote

Old   May 23, 2021, 02:13
Default
  #16
Senior Member
 
Join Date: Nov 2013
Posts: 1,913
Rep Power: 23
pakk will become famous soon enough
The code that you posted here has tabs. If you don't believe me, check for yourself, after A_f, A_p and U_H.

But anyway, good that it is solved.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Reply

Tags
udf and programming, velocity profile 3d udf

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
DPM udf error haghshenasfard FLUENT 0 April 13, 2016 06:35
[OpenFOAM] Native ParaView Reader Bugs tj22 ParaView 270 January 4, 2016 11:39
Building OpenFOAM1.7.0 from source ata OpenFOAM Installation 42 May 14, 2012 20:48
checking the system setup and Qt version vivek070176 OpenFOAM Installation 22 June 1, 2010 12:34
[swak4Foam] groovyBC: problems compiling: "flex: not found" and "undefined reference to ..." sega OpenFOAM Community Contributions 12 February 17, 2010 09:30


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