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

UDF with 2 source terms

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

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 14, 2019, 11:01
Default UDF with 2 source terms
  #1
Member
 
Saurabh Das
Join Date: Jul 2018
Posts: 43
Rep Power: 4
Sorabh is on a distinguished road
Hello I have written the following udf:
Code:
#include "udf.h"
#define PI 3.1415926 //Pi, a constant
#define IO 1E14 //IO, initial intensity
#define R 0.002 //R, radius of beam
#define rho_b 1050
#define wb 0.29
#define cb 3850
#define tq 0.001
DEFINE_SOURCE(top_hat,c,t,dS,eqn)
{
	real x[ND_ND],time;
	real r, source,vol;
	time=RP_Get_Real("flow-time");

	C_CENTROID(x,c,t);
	r = sqrt(pow((x[0]-0.0125),2) + pow((x[1]-0.0025),2));
	vol = (2*r*r)/(R*R);
	if (time < 6e-5)
		if (r < 0.002)
		{
			source = IO*exp(-vol);
			dS[eqn] = 0;
		}
		else
		{
			source = 0;
			dS[eqn] = 0;
		}
	else
	{
		source = 0;
		dS[eqn] = 0;
	}

	return source;
}

DEFINE_SOURCE(perfusion,c,t,dS,eqn)
{
	real physical_dt,temp_old,temp_now,T_derivative,source;
	physical_dt = RP_Get_Real("physical-time-step");
	temp_old= C_T_M1(c,t);
	temp_now=C_T(c,t);
	T_derivative=(temp_now-temp_old)/physical_dt;

	source = rho_b*wb*cb*tq*T_derivative;
	dS[eqn]=0;
}

In this code, the first source term is a gaussian heat source, while the second source term corresponds to the second term of the LHS of the following equation:


However, the results are absolutely the same, with or without the second source term.

Is there an error in the udf? Any advice would be appreciated.
Sorabh is offline   Reply With Quote

Old   March 14, 2019, 11:52
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,677
Rep Power: 22
pakk will become famous soon enough
There is either an error in your physical equations, or in how you converted these equations to code, or the effect of the second term is really too small to see.

(Below, I assume you use SI units, but that's just for notation, the conclusion does not depend on it.)

To estimate the magnitude of your first term, I look at r=0, so at the point (x,y)=(0.0125,0.0025) m. Things simplify with r=0, so your first term becomes 1E14 W/m3.

To estimate the magnitude of your second term, just put in all the constants, and it is approximately 1E3*T_derivative.

So for the two terms to be similar in size, T_derivative needs to be 1E11 K/s.
That is a very high temperature change rate.
If your temperature would increase one million kelvin per second (which is a lot), then your first term would still be 100000 times bigger. That is why you don't see any effect on the solution.
pakk is offline   Reply With Quote

Old   March 14, 2019, 21:46
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,578
Rep Power: 21
AlexanderZ will become famous soon enough
run your code with second source ONLY, check if it works

best regards
AlexanderZ is offline   Reply With Quote

Old   March 15, 2019, 01:20
Default
  #4
Member
 
Saurabh Das
Join Date: Jul 2018
Posts: 43
Rep Power: 4
Sorabh is on a distinguished road
I ran the simulation without the first source term, and unfortunately there seems to be no difference whatsoever. The thermal history, with or without the second source term is the same.
Sorabh is offline   Reply With Quote

Old   March 15, 2019, 05:18
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,578
Rep Power: 21
AlexanderZ will become famous soon enough
from Ansys Fluent Customization Manual
Quote:
Important
Note that data from C_T_M1 is available only if user-defined scalars are defined. It can also
be used with adaptive time stepping.
I've never used this macro so I don't know what exactly does it mean "if user-defined scalars are defined"

try simplified version of code first
Code:
DEFINE_SOURCE(perfusion,c,t,dS,eqn)
{
	real physical_dt,temp_now,T_derivative,source;
	physical_dt = RP_Get_Real("physical-time-step");
	temp_now=C_T(c,t);
	T_derivative=(temp_now)/physical_dt;

	source = rho_b*wb*cb*tq*T_derivative;
	dS[eqn]=0;
}
it should work, if not, than check setting of your model

best regards
AlexanderZ is offline   Reply With Quote

Old   March 18, 2019, 10:05
Default
  #6
Member
 
Saurabh Das
Join Date: Jul 2018
Posts: 43
Rep Power: 4
Sorabh is on a distinguished road
This is not working. I remove the complicated temperature term,

Code:
DEFINE_SOURCE(perfusion,c,t,dS,eqn)
{
	real physical_dt,temp_old,temp_now,T_derivative,source;
	physical_dt = RP_Get_Real("physical-time-step");
	//temp_old= C_T_M1(c,t);
	temp_now=C_T(c,t);
	T_derivative=(-temp_now)/physical_dt;

	source = rho_b*wb*cb*tq*T_derivative;
	printf("\n %g",source);
	dS[eqn]=0;
}
On the console, the value is shown to be -1.59e7, but stiill no change whatsoever to the temperature profile.

However, if I include that value as the source term itself, then there's a change in the temperature profile..

This is very vexing.
Sorabh is offline   Reply With Quote

Old   March 18, 2019, 22:21
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,578
Rep Power: 21
AlexanderZ will become famous soon enough
there is no return line in code
Code:
return source;
add it

best regards
pakk likes this.
AlexanderZ is offline   Reply With Quote

Old   March 19, 2019, 01:14
Default
  #8
Member
 
Saurabh Das
Join Date: Jul 2018
Posts: 43
Rep Power: 4
Sorabh is on a distinguished road
Oh my goodness! Thank you, it's working!

I am so embarrassed right now....
Sorabh is offline   Reply With Quote

Reply

Tags
source terms, 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
[foam-extend.org] Problems installing foam-extend-4.0 on openSUSE 42.2 and Ubuntu 16.04 ordinary OpenFOAM Installation 19 September 3, 2019 19:13
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 Seroga OpenFOAM Community Contributions 9 June 12, 2015 18:18
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 06:18
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


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