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

Uninitialized local variable 't' used

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 19, 2021, 18:15
Default Uninitialized local variable 't' used
  #1
Member
 
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6
Venky_94 is on a distinguished road
Hey,

I'm writing a UDF to calculate the viscosity of one of the phases in a multiphase simulation. I've hooked the UDF using DEFINE_PROPERTY macro and I know the code works properly but I want to define it using the DEFINE_ADJUST macro as I want the store the value in a UDM which I can access in the other UDFs.

I'm getting errors of "uninitialized local variable 't' used" and "uninitialized local variable 'c' used". I understand that it means that the thread pointer is not defined, but I'm not quite sure how to rectify it.

I want to access the cell thread that will be passed to the UDF in the case of hooking it by material properties tab, but I'm not quite sure how to achieve that. Any help would be appreciated.

Code:
/******************************************************************************
UDM for storing the non-Newtonian fluid viscosity calculated using APL model
*******************************************************************************/

#include "udf.h"

DEFINE_ADJUST(non_newtonian_viscosity_udm, domain)
{
Thread *t, *pt;
Thread *mixture_thread = THREAD_SUPER_THREAD(t);
pt = THREAD_SUB_THREAD(mixture_thread, 0);
cell_t c;
domain = Get_Domain(2);		/*Defines the primary phase which is the non-Newtonian fluid */

/* Declare the coefficients for APL model to calculate non-Newtonian viscosity */
real mu_0 = 15.9350;
real k = 19.5531;
real n = 0.2891;
real p = -1.00;
real shear_rate;

/* Calculate the viscosity and store in UDM */
shear_rate = C_STRAIN_RATE_MAG(c,pt);
C_UDMI(c,pt,0) = pow((pow(mu_0,p) + pow((k*pow(shear_rate, (n-1))),p)),pow(p,-1));
}
Venky_94 is offline   Reply With Quote

Old   March 21, 2021, 05:36
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Thread *thread = Lookup_Thread(domain, ID);

(copied from the manual)
__________________
"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   March 21, 2021, 16:40
Default
  #3
Member
 
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6
Venky_94 is on a distinguished road
Quote:
Originally Posted by pakk View Post
Thread *thread = Lookup_Thread(domain, ID);

(copied from the manual)
I'm aware of that command but I do not understand the difference between Domain ID and Zone ID. I'm running a multiphase simulation and I need my loop to run only on the thread pertaining to one phase (similar to hooking a UDF using a material properties tab).

I know that the domain ID for the phase is 2 from the "Phases" tab. But I'm unsure of the cell zone ID as there are two cell zones (with IDs 3 and 4) and both contain both fluids.

Also is any thread pointer passed by the solver at all when using a DEFINE_ADJUST macro by default?

Last edited by Venky_94; March 21, 2021 at 16:44. Reason: Mentioned wrong zone ids earlier
Venky_94 is offline   Reply With Quote

Old   March 22, 2021, 04:58
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You can see what is passed by looking at the function header:

Code:
DEFINE_ADJUST(non_newtonian_viscosity_udm, domain)
The only thing that is passed is the domain. So you don't need to get the domain yourself anymore.

But you do have to 'select' cell zones. If you have two cell zones, why don't you just use both?
__________________
"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   March 22, 2021, 09:16
Default
  #5
Member
 
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6
Venky_94 is on a distinguished road
Quote:
Originally Posted by pakk View Post
You can see what is passed by looking at the function header:

Code:
DEFINE_ADJUST(non_newtonian_viscosity_udm, domain)
The only thing that is passed is the domain. So you don't need to get the domain yourself anymore.

But you do have to 'select' cell zones. If you have two cell zones, why don't you just use both?
The domain that is passed with the DEFINE_ADJUST macros is the mixture domain, and I want the phase domain in my case which is why I'm specifying a domain.

Also how do I select multiple cell zones? I can select a cell zone using the LOOKUP_THREAD command, but I'm not sure how to select multiple zones.

Code:
/* Calculate the viscosity and store in UDM */
shear_rate = C_STRAIN_RATE_MAG(c,pt);
C_UDMI(c,pt,0) = pow((pow(mu_0,p) + pow((k*pow(shear_rate, (n-1))),p)),pow(p,-1));
Or should I perform the same calculation again for the other zone after obtaining the corresponding thread using LOOKUP_THREAD command?
Venky_94 is offline   Reply With Quote

Old   March 22, 2021, 14:04
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by Venky_94 View Post
The domain that is passed with the DEFINE_ADJUST macros is the mixture domain, and I want the phase domain in my case which is why I'm specifying a domain.
OK, I don't have much experience in mixtures in UDFs. Maybe this is correct, but it feels strange.
Quote:
Also how do I select multiple cell zones? I can select a cell zone using the LOOKUP_THREAD command, but I'm not sure how to select multiple zones.

Code:
/* Calculate the viscosity and store in UDM */
shear_rate = C_STRAIN_RATE_MAG(c,pt);
C_UDMI(c,pt,0) = pow((pow(mu_0,p) + pow((k*pow(shear_rate, (n-1))),p)),pow(p,-1));
Or should I perform the same calculation again for the other zone after obtaining the corresponding thread using LOOKUP_THREAD command?
The last option : just do it twice.
__________________
"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   March 23, 2021, 03:30
Default
  #7
Member
 
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6
Venky_94 is on a distinguished road
Quote:
Originally Posted by pakk View Post
OK, I don't have much experience in mixtures in UDFs. Maybe this is correct, but it feels strange.

The last option : just do it twice.
I used a cell thread and cell loop and it works fine now

I'm writing another UDF to store area-averaged phase fraction of air in a UDM. I need to obtain the phase level thread pointer st for which I'm using the THREAD_SUB_THREAD command and it requires the mixture-level thread as an argument. DEFINE_ADJUST unfortunately doesn't pass the thread pointer as an argument and only allows to loop over all threads in the domain.

I'm using the Lookup_Thread command to get a mixture-level thread pointer. I need the same thread pointer that will be passed by the solver within DEFINE_ADJUST if I'm looping over all threads in the domain. Would my below approach guarantee that, or do I need to specify some particular ID?

Code:
#include "udf.h"
#define ID 1						/* zone ID for the interior */

DEFINE_ADJUST(phase_fraction_udm, domain)		/* domain is defined as the mixture-level domain by default */
{
Thread *t, *st;
t = Lookup_Thread(domain, ID);				/* define the mixture-level thread to be used for identifying the secondary phase thread pointer */
st = THREAD_SUB_THREAD(t, 1);				/* st is the thread pointer for secondary phase i.e. air */
Venky_94 is offline   Reply With Quote

Reply

Tags
compiled udf, define_adjust, multiphase, udf


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
uninitialized local variable 't' used Blackhawks84 Fluent UDF and Scheme Programming 1 October 29, 2018 13:02
error: uninitialized local variable 't' used MASOUD Fluent UDF and Scheme Programming 5 October 17, 2016 05:24
InterFoam negative alpha karasa03 OpenFOAM 7 December 12, 2013 04:41
AMI interDyMFoam for mixer nu problem danny123 OpenFOAM Programming & Development 8 September 6, 2013 03:34
same geometry,structured and unstructured mesh,different behaviour. sharonyue OpenFOAM Running, Solving & CFD 13 January 2, 2013 23:40


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