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

source term UDF- gettnig "error"

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By blackmask

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 22, 2013, 15:18
Default source term UDF- gettnig "error"
  #1
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Hi to all,

I am trying to define a source term as a function of "CURRENT TEMPERATURE" as its a transient analysis.

indeed, this source term for a specific range of temperature will be applied when its between upper and lower temperature defined).

but I gave this error :

Error: CURRENT_TEMPERATURE: undeclared variable"

while the temperature profile already defined by another code before reading the current code. so shouldn't it recognize by Fluent ?


best regards,


start the code:




/************************************************** *******************
UDF that simulates M-source specifying a temperature-
dependent
************************************************** ********************/


#include "udf.h"

#define T_upper 290.8833
#define T_lower 296.7833

DEFINE_SOURCE(cell_source, cell, thread,SRC_ON)
{
real source;




real temp = CURRENT_TEMPERATURE;


static int SRC_ON=1;


if(temp>=T_upper)
{
SRC_ON = 0;
}

if (temp < T_lower)
{
SRC_ON = 1;
}

if(SRC_ON)
{
source=(-0.02*pow(temp,3.))+(18.131*pow(temp,2.))-(5464.6*pow(temp,1.))+548332;

} else {
source = 0.
}



return source;
}
ahvz is offline   Reply With Quote

Old   May 22, 2013, 23:05
Default
  #2
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
Code:
/*********************************************************************
   UDF that simulates  M-source specifying a temperature-
   dependent 
 **********************************************************************/

 
#include "udf.h"

#define T_upper 290.8833
#define T_lower 296.7833

DEFINE_SOURCE(cell_source, cell, thread,eqn)
{
real source;
real temp;
static int SRC_ON=1;
Domain* domain;
real xc[ND_ND];
real xdist = 1.E10;
cell_t  c;
thread *t;
static cell_t c0;
static thread *t0;
static int FOUND = 0;
if (! FOUND) {
FOUND = 1;
domain = Get_Domain(1);
thread_loop_c(t, domain) {

begin_c_loop(c,t)
C_CENTROID(xc, c, t);
 if ( NV_MAG(xc) < xdist ) {
xdist = NV_MAG(xc);
c0 = c;
t0 = t;
}
end_c_loop(c,t)

}

}

temp = C_T(c0, t0);

if(temp>=T_upper)
{
SRC_ON = 0;
}

if (temp < T_lower)
{
SRC_ON = 1;
}

if(SRC_ON)
{
source=(-0.02*pow(temp,3.))+(18.131*pow(temp,2.))-(5464.6*pow(temp,1.))+548332;

} else {
source = 0.
}



return source;
}
blackmask is offline   Reply With Quote

Old   May 23, 2013, 05:46
Default
  #3
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
thank you very much for the code!

why this code have error ?

as I remember, the "parse error" belongs to the parenthesis but here it seems different. would you please explain a little about this error?

regards,




/************************************************** *******************
UDF that simulates M-source specifying a temperature-
dependent
************************************************** ********************/


#include "udf.h"

#define T_upper 290.8833
#define T_lower 296.7833

DEFINE_SOURCE(cell_source, cell, thread,eqn)
{
real source;
real temp;
static int SRC_ON=1; < --------parse error.
Domain* domain; parse error.
real xc[ND_ND]; parse error.
real xdist = 1.E10; parse error.
cell_t c; parse error.
thread *t; < -------- t: undeclared variable
static cell_t c0;
static thread *t0;
static int FOUND = 0;
if (! FOUND) {
FOUND = 1;
domain = Get_Domain(1);
thread_loop_c(t, domain) {

begin_c_loop(c,t)
C_CENTROID(xc, c, t);
if ( NV_MAG(xc) < xdist ) {
xdist = NV_MAG(xc);
c0 = c;
t0 = t;
}
end_c_loop(c,t)

}

}

temp = C_T(c0, t0);

if(temp>=T_upper)
{
SRC_ON = 0;
}

if (temp < T_lower)
{
SRC_ON = 1;
}

if(SRC_ON)
{
source=(-0.02*pow(temp,3.))+(18.131*pow(temp,2.))-(5464.6*pow(temp,1.))+548332;

} else {
source = 0.
}



return source;
}
ahvz is offline   Reply With Quote

Old   May 23, 2013, 06:40
Default
  #4
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
Some minor syntax error exist in the last post. I have corrected those errors so that the following should be complied.

Code:
#include "udf.h"

#define T_upper 290.8833
#define T_lower 296.7833

DEFINE_SOURCE(cell_source, cell, thread, dS, eqn)
{
    real source;
    real temp;
    static int SRC_ON=1;
    Domain* domain;
    real xc[ND_ND];
    real xdist = 1.E10;
    cell_t  c;
    Thread *t;
    static cell_t c0;
    static Thread *t0;
    static int FOUND = 0;
    if (! FOUND) {
        FOUND = 1;
        domain = Get_Domain(1);
        thread_loop_c(t, domain) {

            begin_c_loop(c,t)
                C_CENTROID(xc, c, t);
             if ( NV_MAG(xc) < xdist ) {
                 xdist = NV_MAG(xc);
                 c0 = c;
                 t0 = t;
             }
             end_c_loop(c,t)

        }

    }

    temp = C_T(c0, t0);

    if(temp>=T_upper)
    {
        SRC_ON = 0;
    }

    if (temp < T_lower)
    {
        SRC_ON = 1;
    }

    if(SRC_ON)
    {
        source=(-0.02*pow(temp,3.))+(18.131*pow(temp,2.))-(5464.6*pow(temp,1.))+548332;

    } else {
        source = 0.;
    }

    dS[eqn] = 0.;



    return source;
}
blackmask is offline   Reply With Quote

Old   May 23, 2013, 07:19
Default
  #5
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
still same error appear (parse error) when I interrupting the code for the below lines of the code.



real source; parse error
real temp; parse error
static int SRC_ON=1; parse error
Domain* domain; parse error
real xc[ND_ND]; parse error
real xdist = 1.E10; parse error
cell_t c; parse error
Thread *t; parse error
static cell_t c0; parse error
static Thread *t0; parse error
static int FOUND = 0; FOUND: undeclared variable


when/why parse error usually appear ?

regards,
ahvz is offline   Reply With Quote

Old   May 23, 2013, 07:30
Default
  #6
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
Attach you udf file, please.
blackmask is offline   Reply With Quote

Old   May 23, 2013, 07:32
Default
  #7
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Please find the attached file.

regards,
Attached Files
File Type: c new 2.C (1.7 KB, 11 views)
ahvz is offline   Reply With Quote

Old   May 23, 2013, 07:35
Default
  #8
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
Remove the comments and try again.
blackmask is offline   Reply With Quote

Old   May 23, 2013, 07:39
Default
  #9
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
I did, but still same errors.
Attached Files
File Type: c new 2.C (1.2 KB, 6 views)
ahvz is offline   Reply With Quote

Old   May 23, 2013, 07:51
Default
  #10
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
I noticed that the administrator updated the forum rules and obviously we belong to the group who do not know how to behave in a forum. This will be my last post in this thread if no additional requirement other than syntax correct. I have tested the code in the #4 post. Will you please literally copy the code in #4 post in this thread? That will save us a lot of time.
blackmask is offline   Reply With Quote

Old   May 23, 2013, 08:13
Default
  #11
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
the below code is a copy of the code presented in threat #4, and corresponding errors are highlighted.




Code:
#include "udf.h"

#define T_upper 290.8833
#define T_lower 296.7833

DEFINE_SOURCE(cell_source, cell, thread, dS, eqn)
{
    real source;
    real temp;
    static int SRC_ON=1;         (parse error)
    Domain* domain;(parse error)
    real xc[ND_ND];(parse error)
    real xdist = 1.E10;(parse error)
    cell_t  c;(parse error)
    Thread *t;(parse error)
    static cell_t c0;(parse error)
    static Thread *t0;(parse error)
    static int FOUND = 0;(parse error)
    if (! FOUND) {(FOUND: undeclared variable)
        FOUND = 1;
        domain = Get_Domain(1);
        thread_loop_c(t, domain) {

            begin_c_loop(c,t)
                C_CENTROID(xc, c, t);
             if ( NV_MAG(xc) < xdist ) {
                 xdist = NV_MAG(xc);
                 c0 = c;
                 t0 = t;
             }
             end_c_loop(c,t)

        }

    }

    temp = C_T(c0, t0);

    if(temp>=T_upper)
    {
        SRC_ON = 0;
    }

    if (temp < T_lower)
    {
        SRC_ON = 1;
    }

    if(SRC_ON)
    {
        source=(-0.02*pow(temp,3.))+(18.131*pow(temp,2.))-(5464.6*pow(temp,1.))+548332;

    } else {
        source = 0.;
    }

    dS[eqn] = 0.;



    return source;
}
ahvz is offline   Reply With Quote

Old   May 23, 2013, 08:42
Default
  #12
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
(1) Compile rather than interpret the udf source file.
(2) Post the message displayed in fluent tui / terminal / log file. Do not try to interpret the error/warning message yourself. It could be misleading.
ahvz likes this.
blackmask is offline   Reply With Quote

Old   May 23, 2013, 20:12
Default
  #13
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
According to your recommendation, the code was add into compiler but it can't be "load" its impossible to attach the .log file regard to the error appearance.


As the file can not be attach to this threat (the reason is not clear to me) anyway, I just copy/paste the content of the file here :

HTML Code:
Error [cortex] [time 5/23/13 23:49:25] The UDF library you are trying to load (C:\Users\Mohammad\Desktop\Solidwork-ANSYS-FLUENT\3Dbox-workbench_files\dp0\FFF-10\Fluent\Solidwork-ANSYS-FLUENT) is not compiled for 3d on the current platform (win64).

The system cannot find the path specified.


C:\Users\Mohammad\Desktop\Solidwork-ANSYS-FLUENT\3Dbox-workbench_files\dp0\FFF-10\Fluent\C:\Users\Mohammad\Desktop\Solidwork-ANSYS-FLUENT\3Dbox-workbench_files\dp0\FFF-10\Fluent\Solidwork-ANSYS-FLUENT\win64\3d\libudf.dll
regards,
ahvz is offline   Reply With Quote

Old   May 23, 2013, 21:26
Default
  #14
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 22
blackmask will become famous soon enough
You can find some clue from this thread(http://www.cfd-online.com/Forums/flu...amic-mesh.html). I do not know windows much so I am not be able to help you. The wired thing I heard from one thread is that they also invoke the 'sed' command from the 'makefile' for windows distribution. If you find 'sed' in the libudf/src directory, then maybe you need to install the 'sed.exe' utility. Now I am a bit concerned whether you have compiled your udf successfully or not.
blackmask is offline   Reply With Quote

Old   May 24, 2013, 01:20
Default
  #15
Member
 
Shashank
Join Date: Apr 2011
Posts: 74
Rep Power: 15
shashank312 is on a distinguished road
I think the above problem occurs if you haven't installed Microsoft Visual C++.
shashank312 is offline   Reply With Quote

Old   May 28, 2013, 06:59
Default
  #16
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Quote:
Originally Posted by shashank312 View Post
I think the above problem occurs if you haven't installed Microsoft Visual C++.
I have installed it. but I still have problem to compile UDF...
ahvz is offline   Reply With Quote

Old   May 28, 2013, 10:34
Default
  #17
Member
 
Shashank
Join Date: Apr 2011
Posts: 74
Rep Power: 15
shashank312 is on a distinguished road
Are your path variables properly set?
shashank312 is offline   Reply With Quote

Old   May 28, 2013, 11:50
Default
  #18
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
As I tried many proposals and now I am not sure if I have every things correctly.

would you please explain more how to do that properly ?

for now, my error belongs to the link problem :attached file (I change the type to .txt regarding to attach problem file)

LINK : fatal error LNK1181: cannot open input file 'm.C'


regards,
Attached Files
File Type: txt log.txt (392 Bytes, 5 views)
ahvz is offline   Reply With Quote

Old   May 29, 2013, 13:46
Default
  #19
Senior Member
 
Moha
Join Date: Mar 2013
Location: EU
Posts: 103
Rep Power: 0
ahvz is on a distinguished road
Quote:
Originally Posted by blackmask View Post
You can find some clue from this thread(http://www.cfd-online.com/Forums/flu...amic-mesh.html). I do not know windows much so I am not be able to help you. The wired thing I heard from one thread is that they also invoke the 'sed' command from the 'makefile' for windows distribution. If you find 'sed' in the libudf/src directory, then maybe you need to install the 'sed.exe' utility. Now I am a bit concerned whether you have compiled your udf successfully or not.
thank you for the supports

Finally, the .c file compiled and loaded !

as I tried so many proposals, I have to bring the workable method here (even though its for specific OS)

win 7 x64 bit


first the UDF file should be saved as (name).c =====.>(important not capital c)

then with only SDK command prompt (preferred Install a Software Development Kit (SKD) for 64bit systems. This may be the difference between 32bit and 64bit systems. I have used the .NET Framework 2.0 Software Development Kit (SDK) (x64) from 2006 [5] ) in my PC other versions 7.0 and 7.1 even work.

Start FLUENT from the SDK command prompt. Do not use the Visual Studio command prompt, use the SDK command prompt! Go to the directory your case is in and type 'fluent'.



regards,
ahvz 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
UDF for energy source term engloly Fluent UDF and Scheme Programming 11 June 25, 2017 07:05
pisoFoam compiling error with OF 1.7.1 on MAC OSX Greg Givogue OpenFOAM Programming & Development 3 March 4, 2011 18:18
UDF Source Term Christian FLUENT 4 August 1, 2009 06:53
The source term of UDF summer FLUENT 0 August 24, 2006 18:44
UDFs for Scalar Eqn - Fluid/Solid HT Greg Perkins FLUENT 0 October 11, 2000 04:43


All times are GMT -4. The time now is 18:54.