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

UDF error_ undeclared variable

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 16, 2019, 12:08
Unhappy UDF error_ undeclared variable
  #1
New Member
 
greece
Join Date: Jul 2016
Posts: 8
Rep Power: 9
panos_metal21 is on a distinguished road
Hello,

i am using Fluent 19.2 and i am trying a very simple UDF that i found on Ansys Customer Portal just to get familiar with that before trying to make my own UDF.
So i copy the text and produce a .c file located at the same location with my case and dat file. The UDF text follows below:


/************************************************** ********************
UDF that models a custom law for evaporation swelling of particles
************************************************** *********************/

#include "udf.h"

DEFINE_DPM_LAW(Evapor_Swelling_Law,tp,ci)
{
real swelling_coeff = 1.1;
/* first, call standard evaporation routine to calculate
the mass and heat transfer */
VaporizationLaw(tp);

/* compute new particle diameter and density */
TP_DIAM(tp) = TP_INIT_DIAM(tp)*(1. + (swelling_coeff - 1.)*
(TP_INIT_MASS(tp)-TP_MASS(tp))/(DPM_VOLATILE_FRACTION(tp)*TP_INIT_MASS(tp)));
TP_RHO(tp) = TP_MASS(tp) / (3.14159*TP_DIAM(tp)*TP_DIAM(tp)*TP_DIAM(tp)/6);
TP_RHO(tp) = MAX(0.1, MIN(1e5, TP_RHO(tp)));
}

After trying to compile it using Fluent GUI, i receive the following error:


cpp -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/main" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/addon-wrapper" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/io" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/species" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/pbns" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/numerics" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/sphysics" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/storage" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/mphase" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/bc" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/models" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/material" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/amg" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/util" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/mesh" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/udf" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/ht" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/dx" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/turbulence" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/parallel" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/etc" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/ue" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/dpm" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/dbns" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/tgrid/src" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/PRIME/tgrid/src" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/multiport/src" -I. -DUDFCONFIG_H="<udfconfig-host.h>" "D:/OneDrive - central.ntua.gr/drive/projects/VEF_design&exper_CFD/new_runs/recent/grid dependence/paper/non_isothermal/swel.c"
Error: D:/OneDrive - central.ntua.gr/drive/projects/VEF_design&exper_CFD/new_runs/recent/grid dependence/paper/non_isothermal/swel.c: line 15: TP_DIAM: undeclared variable

cpp -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/main" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/addon-wrapper" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/io" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/species" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/pbns" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/numerics" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/sphysics" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/storage" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/mphase" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/bc" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/models" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/material" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/amg" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/util" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/mesh" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/udf" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/ht" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/dx" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/turbulence" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/parallel" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/etc" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/ue" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/dpm" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/dbns" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/tgrid/src" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/PRIME/tgrid/src" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/multiport/src" -I. -DUDFCONFIG_H="<C:/Users/PANAGI~1/AppData/Local/Temp/udfconfig-17984-node0.h>" "C:/Users/PANAGI~1/AppData/Local/Temp/swel.c.17984.0.c"
Error: C:/Users/PANAGI~1/AppData/Local/Temp/swel.c.17984.0.c: [/U]line 15: TP_DIAM: undeclared variable

Note: The second paragraph appears about 7 times with different swel.c. number

Can someone inform me on the followings:
1. Is it an compiling or code error?
2. Should i declare TP_DIAM at the beginning of the code?
3. Other possible sources of error?

Thanks in advance.
Panos
panos_metal21 is offline   Reply With Quote

Old   December 17, 2019, 06:23
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
seems like you've changed automatically all p to tp....

change all macros names back to P
TP_DIAM -> P_DIAM
panos_metal21 likes this.
__________________
best regards


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

Old   December 17, 2019, 12:44
Default
  #3
New Member
 
greece
Join Date: Jul 2016
Posts: 8
Rep Power: 9
panos_metal21 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
seems like you've changed automatically all p to tp....

change all macros names back to P
TP_DIAM -> P_DIAM
Thank you Alexander for the comment.

I did make the change you proposed. Please see below the code

/************************************************** ********************
UDF that models a custom law for evaporation swelling of particles
************************************************** *********************/

#include "udf.h"

DEFINE_DPM_LAW(Evapor_Swelling_Law,p,ci)
{
real swelling_coeff = 1.1;
/* first, call standard evaporation routine to calculate
the mass and heat transfer */
VaporizationLaw(p);

/* compute new particle diameter and density */
P_DIAM(p) = P_INIT_DIAM(p)*(1. + (swelling_coeff - 1.)*(P_INIT_MASS(p)-P_MASS(p))/(DPM_VOLATILE_FRACTION(p)*P_INIT_MASS(p)));
P_RHO(p) = P_MASS(p) / (3.14159*P_DIAM(p)*P_DIAM(p)*P_DIAM(p)/6);
P_RHO(p) = MAX(0.1, MIN(1e5,P_RHO(p)));
}

The error now is the following:
cpp -I"C:\PROGRA~1\ANSYSI~1\v192\fluent\fluent19.2.0/src/main" -
.
.
.
Error: C:/Users/PANAGI~1/AppData/Local/Temp/swelp.c.2364.11.c: line 15: TP_MATERIAL: undeclared variable

The variable that appears in line 15 for the first time is P_INIT_MASS(p)

Do you think that this might cause the error?

Thank you again!
panos_metal21 is offline   Reply With Quote

Old   December 17, 2019, 23:17
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Code:
#include "udf.h"

DEFINE_DPM_LAW(Evapor_Swelling_Law,p,ci)
{
real swelling_coeff = 1.1;
/* first, call standard evaporation routine to calculate
the mass and heat transfer */
VaporizationLaw(p);

/* compute new particle diameter and density */
P_DIAM(p) = P_INIT_DIAM(p)*(1. + (swelling_coeff - 1.)*(P_INIT_MASS(p)-P_MASS(p))/(DPM_VOLATILE_FRACTION(p)*P_INIT_MASS(p)));
P_RHO(p) = P_MASS(p) / (3.14159*P_DIAM(p)*P_DIAM(p)*P_DIAM(p)/6);
P_RHO(p) = MAX(0.1, MIN(1e5,P_RHO(p)));
}
this code is compiled on my machine with no errors
panos_metal21 likes this.
__________________
best regards


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

Old   December 18, 2019, 04:13
Default
  #5
New Member
 
greece
Join Date: Jul 2016
Posts: 8
Rep Power: 9
panos_metal21 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
Code:
#include "udf.h"

DEFINE_DPM_LAW(Evapor_Swelling_Law,p,ci)
{
real swelling_coeff = 1.1;
/* first, call standard evaporation routine to calculate
the mass and heat transfer */
VaporizationLaw(p);

/* compute new particle diameter and density */
P_DIAM(p) = P_INIT_DIAM(p)*(1. + (swelling_coeff - 1.)*(P_INIT_MASS(p)-P_MASS(p))/(DPM_VOLATILE_FRACTION(p)*P_INIT_MASS(p)));
P_RHO(p) = P_MASS(p) / (3.14159*P_DIAM(p)*P_DIAM(p)*P_DIAM(p)/6);
P_RHO(p) = MAX(0.1, MIN(1e5,P_RHO(p)));
}
this code is compiled on my machine with no errors
Hi Alexander.

Still same issue, message is line 11: P_MATERIAL: undeclared variable

But i do intepret the UDF and not compile it since i find compliling more complicated since it involved setting of VS , open Fluent from command line etc (i have not found somewhere the PC setting steps for UDFs compiling) . IS there any other setting/ requirement that needs to be done to allow Fluent perform simple UDFs intepretation, except of (1) having code without mistakes, and (2) the code to be at the same folder with cas and dat file?

Your help is appreciated!
Thanks
panos_metal21 is offline   Reply With Quote

Old   December 18, 2019, 13:04
Default Update
  #6
New Member
 
greece
Join Date: Jul 2016
Posts: 8
Rep Power: 9
panos_metal21 is on a distinguished road
I try to use another simple UDF that is closer to what i want to do.
Please see the code below:

/************************************************** ********************
UDF that calculates a temperature dependent swelling factor
************************************************** *********************/

#include "udf.h"

DEFINE_DPM_LAW(Swelling_Factor,p,ci)
{
real swelling_coeff;
real temp = P_T(p);
swelling_coeff = temp/400.;
return swelling_coeff;
}


After trying to interpret the UDF, Fluent returns the following error:
Error: C:/Users/PANAGI~1/AppData/Local/Temp/swelcoef2.c.11368.11.c: line 12: function returning void returns double.

Any suggestion would be appreciated.

Thanks
panos_metal21 is offline   Reply With Quote

Old   December 19, 2019, 00:44
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
interpretation leads to errors in my machine too, so I recommend you to compile code

regarding your last code:
DEFINE_DPM_LAW has type void, it means, it doesn't return any value
in example from manual (ansys fluent customization manual) they modified density according to swelling coef. they used P_RHO(p) macro
panos_metal21 likes this.
__________________
best regards


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

Reply

Tags
dpm fluent, fluent - udf, udf and programming


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
UDF error for variable Cp B.Hamada Fluent UDF and Scheme Programming 4 May 18, 2015 06:27
udf for variable cp B.Hamada Fluent UDF and Scheme Programming 2 April 22, 2015 14:20
UDF extern variable - mean time moment coefficient enry Fluent UDF and Scheme Programming 0 November 14, 2009 06:51
name variable in UDF using Thread : syntax error before numeric constant Laurence Wallian FLUENT 0 October 8, 2009 09:18
UDF: exporting a variable between two DEFINE function Carlo FLUENT 3 August 19, 2009 12:21


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