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

UDF is giving incorrect value for fraction define_zone_motion?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 15, 2015, 02:00
Default UDF is giving incorrect value for fraction define_zone_motion?
  #1
New Member
 
Join Date: Mar 2015
Posts: 9
Rep Power: 11
dtmith is on a distinguished road
Hi all,

I've been running LES simulations of plate rotating about an axis. It starts from rest, accelerates to a certain velocity and then continues to rotate at that velocity for the rest of the simulation.

I define an "omega" profile for the acceleration portion. It is made up of a quartic polynomial followed by a linear section followed by another quartic. I noticed in the force data a non-physical spike when it transitioned from the quartic profile to the linear profile and back again.

Here's my UDF:
Code:
#include "udf.h"

DEFINE_ZONE_MOTION(motion3,omega,axis,origin,velocity,time,dtime)
{
	real pi, w, tscl;
	
	pi = 3.141592654;
	w = -1.402;
	tscl = 5.58505360638183;
	
	if (time<0.1/tscl)
	{
		*omega = (-5000/9*pow((time*tscl),4.) + 1000/9*pow((time*tscl),3.))*w;
	}
	else
	{
		if (time<0.9/tscl)
		{
			*omega = (10/9*(time*tscl) - 1/18)*w;
		}
		else
			if (time<1/tscl)
			{
				*omega = (-(-5000/9*pow((1-(time*tscl)),4.) + 1000/9*pow((1-(time*tscl)),3.))+1)*w;
			}
			else
			{
				*omega = w;
			}
			
	}
	Message ("time = %f, omega = %f\n", time, *omega);
	N3V_D(axis,=,0.0,1.0,0.0);

	}
So basically w and tscl are scaling factors for omega and time respectively. For time is 0 to 0.1/tscl, my velocity profile is this quartic...

*omega = (-5000/9*pow((time*tscl),4.) + 1000/9*pow((time*tscl),3.))*w;

Then from 0.1/tscl to 0.9/tscl the profile is linear...

*omega = (10/9*(time*tscl) - 1/18)*w;

Then from 0.9/tscl to 1/tscl it goes to another quartic...

*omega = (-(-5000/9*pow((1-(time*tscl)),4.) + 1000/9*pow((1-(time*tscl)),3.))+1)*w;

Finally that quartic smoothly transitions to a constant rotation velocity above 1/tscl

*omega = w;


After a LOT of screwing around I discovered the problem was with the linear portion, typing my constants as fractions (10/9 and 1/18) meant the fractions were ignored, it was basically evaluating...

(time*tscl)*w instead of (10/9*(time*tscl) - 1/18)*w

If I type out the fractions as 1.1111111 and 0.05555555 instead of 10/9 and 1/18 it seems to work fine.

But for the other segments, I am also using fractions to define omega (5000/9) and it seems to be working fine?

Does anyone know why for that particular line it can't accept a fraction? I've looked at it so many times and can't figure out why it would work for the quartic but not the linear portion. Maybe it'll save me from screwing up in future, lol.
dtmith is offline   Reply With Quote

Old   March 15, 2015, 05:14
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Well for a start, add a trailing period to your integer numerators and denominators. For example: "10./9.". This syntax tells the C compiler to treat these numbers as real data types rather than integers because otherwise the compiler will evaluate this fraction and keep the type as an integer (perhaps 10/9 == 1). The precise treatment of integer divisions depend on the compiler you're using (C89 behaves differently to C99 etc).
`e` 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
incorrect cg motion UDF sdof_properties::libudf on zone 6 (assuming no motion) M.Magdy Fluent UDF and Scheme Programming 9 April 4, 2023 13:00
Source Term UDF VS Porous Media Model pchoopanya Fluent UDF and Scheme Programming 1 August 28, 2013 07:12
incorrect cg motion UDF sdof_properties::libudf on zone 6 (assuming no motion) M.Magdy Fluent UDF and Scheme Programming 0 March 22, 2013 07:58
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01
UDF modification merac FLUENT 4 March 1, 2001 07:42


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