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/)
-   -   UDF issue (https://www.cfd-online.com/Forums/fluent-udf/73787-udf-issue.html)

MASOUD March 17, 2010 01:52

UDF issue
 
I'm trying to compile the following code for energy equation source term:

---------------------------------
#include "udf.h"
#include "mem.h"
static real ACT_AREA=1;
static real REF_EXCH_CURR_A=1;
static real MW_H2=1;
static real REF_CONC=1;
static real BETA=1;
static real ALPHA=1;
static real NO_ELEC=1;
static real EQU_POT_A=1;
static real FARADAY=1;
static real UNI_GAS_CONS=1;
static real STOCH=1;
static real RXN_RATE_A;
static real Z;
static real ZZ;
static real ZZZ;
static real ELEC_COND=1;
static real CARB_COND=1;
static real OVERPOT_A;
static real SOURCE_1;
static real SOURCE_2;
static real SOURCE_3;
static real SOURCE;
static real A;
static real B;
DEFINE_SOURCE(ENERGY_SOURCE_ANODE,c,t,dS,eqn)
{
A=C_UDSI_G(c,t,0);
B=C_UDSI_G(c,t,1);

SOURCE_1=pow((A/ELEC_COND),2)/ELEC_COND;

SOURCE_2=pow((B/CARB_COND),2)/CARB_COND;

Z=ACT_AREA*REF_EXCH_CURR_A*pow(((C_YI(c,t,1)*C_R(c ,t)/MW_H2)/REF_CONC),BETA);

ZZ=exp((ALPHA*NO_ELEC*FARADAY*(C_UDSI(c,t,0)-EQU_POT_A))/(UNI_GAS_CONS*C_T(c,t)));

ZZZ=exp((1-ALPHA)*NO_ELEC*FARADAY*(EQU_POT_A-C_UDSI(c,t,0))/(UNI_GAS_CONS*C_T(c,t)));

RXN_RATE_A=Z*(ZZ-ZZZ);

OVERPOT_A=C_UDSI(c,t,0)-REF_EXCH_CURR_A;

SOURCE_3=RXN_RATE_A*OVERPOT_A;

SOURCE=SOURCE_1+SOURCE_2+SOURCE_3;

dS[eqn]=0;

return SOURCE;
}
-------------------------------

But I came across the following error:

..\..\src\ENERGY_SOURCE-ANODE.c(32) : error C2440: '=' : cannot convert from 'real *' to 'real'
..\..\src\ENERGY_SOURCE-ANODE.c(34) : error C2440: '=' : cannot convert from 'real *' to 'real'
Generating Code...

Any idea???

coglione March 17, 2010 02:36

C_UDSI_G returns a vector with spatial derivatives of your scalar as components. Your variables Source_1, Source_2 are defined as scalar quantities which causes the error you get from the compiler when it evaluates e.g. SOURCE_1=pow((A/ELEC_COND),2)/ELEC_COND;
Maybe you actually want the magnitude of the gradient-vector which can be obtained using NV_MAG(vector).
cheers

MASOUD March 17, 2010 17:44

UDF Compilation issue
 
Great answer! Thank you so much.

Actually I have 12 UDFs and could compile the majority of them successfully.

Here is the report for the 9th UDF compilation process:

-------------------------
...

Deleted old libudf\ntx86\2d\libudf.dll
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
(system "copy "C:\PROGRA~1\ANSYSI~1\v120\fluent"\fluent12.0.16\s rc\makefile_nt.udf libudf\ntx86\2d\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "ntx86\2d")()
# Generating ud_io1.h
CARBONATE_CHARGE_UDS.c
CO2_SOURCE_ANODE.c
CO2_SOURCE_CATHODE.c
ELECT_CHARGE_UDS.c
ENERGY_SOURCE-ANODE.c
ENERGY_SOURCE-CATHODE.c
ENERGY_SOURCE-ELECTROLYTE.c
H2_SOURCE_ANODE.c
H2O_SOURCE_ANODE.c
Generating Code...
# Generating udf_names.c because of makefile CARBONATE_CHARGE_UDS.obj CO2_SOURCE_ANODE.obj CO2_SOURCE_CATHODE.obj ELECT_CHARGE_UDS.obj ENERGY_SOURCE-ANODE.obj ENERGY_SOURCE-CATHODE.obj ENERGY_SOURCE-ELECTROLYTE.obj H2_SOURCE_ANODE.obj H2O_SOURCE_ANODE.o
j
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj CARBONATE_CHARGE_UDS.obj CO2_SOURCE_ANODE.obj CO2_SOURCE_CATHODE.obj ELECT_CHARGE_UDS.obj ENERGY_SOURCE-ANODE.obj ENERGY_SOURCE-CATHODE.obj ENERGY_SOURCE-ELECTROLYTE.obj H2_SOURCE_ANODE.
bj H2O_SOURCE_ANODE.obj
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library libudf.lib and object libudf.exp

Done.

-----------------------

As you see everything is alright so far. But when I tried to compile the 10th UDF, I didn't get the same report format. Here is the report:

-----------------------


Deleted old libudf\ntx86\2d\libudf.dll
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
(system "copy "C:\PROGRA~1\ANSYSI~1\v120\fluent"\fluent12.0.16\s rc\makefile_nt.udf libudf\ntx86\2d\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "ntx86\2d")()

Done.

----------------------

And this one is for 11th UDF:

----------------------

Deleted old libudf\ntx86\2d\libudf.dll
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
(system "copy "C:\PROGRA~1\ANSYSI~1\v120\fluent"\fluent12.0.16\s rc\makefile_nt.udf libudf\ntx86\2d\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "ntx86\2d")()

Done.
----------------------

And the 12th:


----------------------

Deleted old libudf\ntx86\2d\libudf.dll
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
(system "copy "C:\PROGRA~1\ANSYSI~1\v120\fluent"\fluent12.0.16\s rc\makefile_nt.udf libudf\ntx86\2d\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "ntx86\2d")()

Done.

-------------------------

So is there any problem with my UDFs?

I tried to compile the UDFs one by one. Then when I'm done with compilation, will LOAD the library, is it correct?
Do you suggest any other procedure?

Many thanks,
Masoud

Micael March 18, 2010 08:25

The BUILD process is actually a COMPILE then LINK process. Do the build only once with every source files. You are likely to have trouble if you build one by one.

Keep us in touch of the progress.

Have a good day

Micaël Boulet

MASOUD March 21, 2010 00:34

Thanks Michael;

But I don't know how too hook-up these 12 UDFs. What I did is:

DEFINE->USER-DEFINED->FUNCTIONS->COMPILED->ADD and then select the first UDF and then press BUILD botton.
And repeat this process for the other 11 UDFs and then press LOAD.

But as I mentioned above, I came across a problem for 10th, 11th and 12th UDFs: it's like a copy only, not compilation.

Another method is to select all 12 UDF, and press COMPILE botton. But again the same problem come-up: just copy, not compilation.

Please advice.

Masoud

Micael March 21, 2010 19:27

You are so closed.

DEFINE->USER-DEFINED->FUNCTIONS->COMPILED->ADD
then select every *.c files, just click on each one. Then do the build.

MASOUD March 22, 2010 01:04

Micael,

I did what you said, and here is the report from Fluent:

--------------------------------
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
(system "copy "C:\PROGRA~1\ANSYSI~1\v120\fluent"\fluent12.0.16\s rc\makefile_nt.udf libudf\ntx86\2d\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "ntx86\2d")()

Done.
---------------------------------

As you see, Fluent has copied my UDFs but has not compiled them. Is there something wrong???

Micael March 22, 2010 08:12

It looks unusual. Do your UDFs work?

MASOUD March 22, 2010 14:40

No, don't work...that means I can't find them in the related drop-down lists.

MASOUD March 22, 2010 15:23

Oh man! I figured-out what was the problem!!!

The name of the UDF file was not exactly the name which I was referring to (in the macro, as a argument)!!!

Anyway thanks for your advices.

Micael March 23, 2010 15:24

That solved your problem ?:confused:

When I do not use the same name for the file and the function name (the argument of the macro) everything is still fine. No problem with it.

MASOUD March 23, 2010 15:31

yes, solved!

As far as I know from the UDF manual, the names must be the same.

Micael March 23, 2010 15:46

Where did you see that? I see the opposite in the manual (I just verified it).

MASOUD March 24, 2010 10:31

Not exactly the same sentence. But according to the DEFINE macros description, in this case DEFINE_SOURCE,:
------------------------------------
DEFINE SOURCE(name,c,t,dS,eqn)
Argument Type Description
symbol name UDF name.
------------------------------------

Ii shows that the first argument is the UDF file name (But it can be just a name for UDF as well!!!!).

I have a separate file for each UDF and didn't put all of them in just a file.

Maybe in case you want to put all UDFs in one file, you should use different name (argument and file name).

Anyway I could hook them up successfully with my method. Now I'm trying to get some results and figure out whether this method works or not.

ali_mehrabi69 December 6, 2012 13:39

define_source UDF for 2d
 
hi
i wrote a code for define a source in 2D, but when i compile it in fluent this error appear:
"The UDF library you are trying to load (C:\Users\N43SN\Desktop\3\libudf7) is not compiled for 2d on the curent platform (win64).
The system cannot find the file specified."

Any idea???


All times are GMT -4. The time now is 13:49.