CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   source term UDF- gettnig "error" (https://www.cfd-online.com/Forums/fluent-udf/118201-source-term-udf-gettnig-error.html)

ahvz May 22, 2013 14:18

source term UDF- gettnig "error"
 
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;
}

blackmask May 22, 2013 22:05

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;
}


ahvz May 23, 2013 04:46

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;
}

blackmask May 23, 2013 05:40

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;
}


ahvz May 23, 2013 06:19

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,

blackmask May 23, 2013 06:30

Attach you udf file, please.

ahvz May 23, 2013 06:32

1 Attachment(s)
Please find the attached file.

regards,

blackmask May 23, 2013 06:35

Remove the comments and try again.

ahvz May 23, 2013 06:39

1 Attachment(s)
I did, but still same errors.

blackmask May 23, 2013 06:51

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.

ahvz May 23, 2013 07:13

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;
}


blackmask May 23, 2013 07:42

(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 May 23, 2013 19:12

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,

blackmask May 23, 2013 20:26

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.

shashank312 May 24, 2013 00:20

I think the above problem occurs if you haven't installed Microsoft Visual C++.

ahvz May 28, 2013 05:59

Quote:

Originally Posted by shashank312 (Post 429674)
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...

shashank312 May 28, 2013 09:34

Are your path variables properly set?

ahvz May 28, 2013 10:50

1 Attachment(s)
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,

ahvz May 29, 2013 12:46

Quote:

Originally Posted by blackmask (Post 429649)
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,


All times are GMT -4. The time now is 23:07.