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

syntax error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 17, 2018, 08:51
Default syntax error
  #1
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
I am getting the following error :-
..\..\src\tegtr.c(22): error C2143: syntax error: missing ';' before '{'

for following code :-
Quote:
#include "udf.h"
#include "math.h"

enum
{
teg,
N_REQUIRED_UDS
};

DEFINE_DIFFUSIVITY(teg_diffusivity, cell, thread, i)
{

Thread *t;
cell_t c;
face_t f;

begin_c_loop (c,t)
{
real T;
T = C_T(c,t);
real rho_function(real T)
{
return -3.982*pow(10,-5) + 2.98*pow(10,-7)*T - 4.685*pow(10,-10)*pow(T,2) + 2.51*pow(10,-12)*pow(T,3) ;
}
C_UDSI(c,t,teg) = rho_function(C_T(c,t))*C_T_G(c,t)[0];
}
end_c_loop (c,t)
real T;
T = C_T(cell, thread);
return 1/C_UDSI(cell, thread,teg);
}
But I don't think, there is any error in line 22.
I have also tried to solve the error following this link :-
what is syntax error : missing ')' before ';'

But it didn't work. Any suggestions will be greatly appreciated.
Thank you
sahoo is offline   Reply With Quote

Old   June 17, 2018, 11:01
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Your code has a definition for rho_function within the cell loop; this definition should be moved above the DEFINE_DIFFUSIVITY call. Also, these lines of code are redundant (not used):

Code:
real T;
T = C_T(c,t);
...
real T;
T = C_T(cell, thread);
as the temperature is directly called into rho_function with C_T. Lastly, variables should be declared at the beginning of a code block (for compliance with the programming language, ANSI C), and numbers should have a trailing dot to indicate that the value is a real number (to avoid erroneous typecasting).
`e` is offline   Reply With Quote

Old   June 17, 2018, 11:38
Default
  #3
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
Thank you, it worked
sahoo is offline   Reply With Quote

Old   June 17, 2018, 12:42
Default
  #4
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
Is it necessary to define the rho_function() inside the loop?
Because without the loop I don't get any error but with the loop I am getting the following error:-
..\..\src\tegtr.c(10): error C2449: found '{' at file scope (missing function header?)
..\..\src\tegtr.c(18): error C2059: syntax error: '}'


for the following code:-
Quote:
#include "udf.h"
#include "math.h"

enum
{
teg,
N_REQUIRED_UDS
};

begin_c_loop (c,t)
{
real rho_function(real T)
{
return -3.982*pow(10.,-5.) + 2.98*pow(10.,-7.)*T - 4.685*pow(10.,-10.)*pow(T,2.) + 2.51*pow(10.,-12.)*pow(T,3.) ;
}
C_UDSI(c,t,teg) = rho_function(C_T(c,t));
}
end_c_loop (c,t)

DEFINE_DIFFUSIVITY(teg_diffusivity, cell, thread, i)
{
Thread *t;
cell_t c;
face_t f;
return 1/C_UDSI(cell, thread,teg);
}
sahoo is offline   Reply With Quote

Old   June 17, 2018, 22:22
Default
  #5
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The functions should be defined outside of the loops and other functions. Remember that we can use 1.e-3 instead of calling pow(10,-3); improving readability and slightly reducing the compute time. Similarly, if the power is an integer, then expanding the power expression is the standard approach.

The DEFINE_DIFFUSIVITY macro is called for each cell (check the UDF manual for the description), and therefore you do not use the cell loop. The trailing dot is especially important for divisions such as 1/x. Here is the corrected code:

Code:
#include "udf.h"
#include "math.h"

enum
{
	teg,
	N_REQUIRED_UDS
};

real rho_function(real T)
{
	return -3.982e-5 + 2.98e-7*T - 4.685e-10*T*T + 2.51e-12*T*T*T;
}

DEFINE_DIFFUSIVITY(teg_diffusivity, c, t, i)
{
	C_UDSI(c,t,teg) = rho_function(C_T(c,t));
	return 1./C_UDSI(c,t,teg);
}
Although, are you sure you want to set the UDS values within the DEFINE_DIFFUSIVITY macro? Perhaps take a step back and think about what equations you are solving and which functions / macros need to be hooked into Fluent.
`e` is offline   Reply With Quote

Old   June 18, 2018, 04:53
Default
  #6
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
Thanks Mr. 'e' your advice always works.
Actually I am solving the following equation:-
∇V= -α(T)∇T-ρ(T)J

for which 2 UDS are as follows:-
Quote:
#include "udf.h"
#include "math.h"

enum
{
teg,
N_REQUIRED_UDS
};

real rho_function(real T)
{
return -3.982e-5 + 2.98e-7*T - 4.685e-10*T*T + 2.51e-12*T*T*T;
}

DEFINE_DIFFUSIVITY(teg_diffusivity, c, t, i)
{
C_UDSI(c,t,teg) = rho_function(C_T(c,t));
return 1./C_UDSI(c,t,teg);
}
Quote:
#include "udf.h"
#include "math.h"

enum
{
teg1,
N_REQUIRED_UDS
};

real alpha_function(real T)
{
return 8.439e-4 - 3.81e-6*T + 6.736e-9*pow(T,-9.) - 3.934e-12*pow(T,-12.);
}

DEFINE_SOURCE(teg1_source, c, t, dS, eqn)
{
real T = C_T(c,t);
C_UDSI(c,t,teg1) = alpha_function(C_T(c,t))*C_T_G(c,t)[0];
dS[eqn] = C_UDSI(c,t,teg1);
return C_UDSI_G(c,t,teg1)[0];
}
I don't have any errors in this UDSs but, is it correct as per the given equation? Please let me know.
And also there is a term 'J' in the equation for which I need to create a profile on which I am still working.
sahoo is offline   Reply With Quote

Old   June 18, 2018, 07:47
Default
  #7
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
And what can you say about the following error:-
..\..\src\teg2.c(12): error C2065: 'thread': undeclared identifier
..\..\src\teg2.c(12): error C2223: left of '->t' must point to struct/union


I get this error frequently. I don't get this, since thread is a data type why do we need to declare it?
I get this error for the following code :-

Quote:
#include "udf.h"
#include "math.h"

enum
{
teg2,
N_REQUIRED_UDS
};

DEFINE_EXECUTE_AT_END(execute_at_end)
{
Thread *t = thread->t;
cell_t c = F_C(c,thread);
real T = C_T(c,t);
begin_c_loop(c,t)
{
C_UDSI(c,t,teg2) = 8.439e-4 - 3.81e-6*T + 6.736e-9*pow(T,-9.) - 3.934e-12*pow(T,-12.);
}
end_c_loop(c,t)
}
I have tried to solve following many posts, but still I get it in every code.
sahoo is offline   Reply With Quote

Old   June 18, 2018, 08:30
Default
  #8
Senior Member
 
Cees Haringa
Join Date: May 2013
Location: Delft
Posts: 607
Rep Power: 0
CeesH is on a distinguished road
what are you trying to do with the thread t thing? point to itself?

I think you are looking for

Code:
Thread *t;
begin_thread_loop_c
{ - insert the cell loop -}
With that, you'll loop over all threads (and then all cells within them)

If you want to select a single thread, use:

Code:
t = Lookup_Thread(domain,zone_ID);
with the zone_ID being the cell zone or boundary zone number in FLUENT.
CeesH is offline   Reply With Quote

Old   June 18, 2018, 11:05
Default
  #9
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
yeah I got it. You mean I don't need to point to itself if I am going to use it in the UDS to store another value.

Thank you
sahoo 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
[OpenFOAM] an error in Calculator's equation immortality ParaView 12 June 29, 2021 01:10
[OpenFOAM.org] compile error in dynamicMesh and thermophysicalModels libraries NickG OpenFOAM Installation 3 December 30, 2019 01:21
Pressure outlet boundary condition rolando OpenFOAM Running, Solving & CFD 62 September 18, 2017 07:45
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM Community Contributions 300 October 29, 2014 19:00
Undeclared Identifier Errof UDF SteveGoat Fluent UDF and Scheme Programming 7 October 15, 2014 08:11


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