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

UDF issue

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 17, 2010, 01:52
Default UDF issue
  #1
Senior Member
 
MASOUD
Join Date: Mar 2009
Posts: 102
Rep Power: 17
MASOUD is on a distinguished road
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???
MASOUD is offline   Reply With Quote

Old   March 17, 2010, 02:36
Default
  #2
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
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
coglione is offline   Reply With Quote

Old   March 17, 2010, 17:44
Default UDF Compilation issue
  #3
Senior Member
 
MASOUD
Join Date: Mar 2009
Posts: 102
Rep Power: 17
MASOUD is on a distinguished road
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
MASOUD is offline   Reply With Quote

Old   March 18, 2010, 08:25
Default
  #4
Senior Member
 
Micael
Join Date: Mar 2009
Location: Canada
Posts: 156
Rep Power: 18
Micael is on a distinguished road
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
Micael is offline   Reply With Quote

Old   March 21, 2010, 00:34
Default
  #5
Senior Member
 
MASOUD
Join Date: Mar 2009
Posts: 102
Rep Power: 17
MASOUD is on a distinguished road
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
MASOUD is offline   Reply With Quote

Old   March 21, 2010, 19:27
Default
  #6
Senior Member
 
Micael
Join Date: Mar 2009
Location: Canada
Posts: 156
Rep Power: 18
Micael is on a distinguished road
You are so closed.

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

Old   March 22, 2010, 01:04
Default
  #7
Senior Member
 
MASOUD
Join Date: Mar 2009
Posts: 102
Rep Power: 17
MASOUD is on a distinguished road
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???
MASOUD is offline   Reply With Quote

Old   March 22, 2010, 08:12
Default
  #8
Senior Member
 
Micael
Join Date: Mar 2009
Location: Canada
Posts: 156
Rep Power: 18
Micael is on a distinguished road
It looks unusual. Do your UDFs work?
Micael is offline   Reply With Quote

Old   March 22, 2010, 14:40
Default
  #9
Senior Member
 
MASOUD
Join Date: Mar 2009
Posts: 102
Rep Power: 17
MASOUD is on a distinguished road
No, don't work...that means I can't find them in the related drop-down lists.
MASOUD is offline   Reply With Quote

Old   March 22, 2010, 15:23
Default
  #10
Senior Member
 
MASOUD
Join Date: Mar 2009
Posts: 102
Rep Power: 17
MASOUD is on a distinguished road
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.
MASOUD is offline   Reply With Quote

Old   March 23, 2010, 15:24
Default
  #11
Senior Member
 
Micael
Join Date: Mar 2009
Location: Canada
Posts: 156
Rep Power: 18
Micael is on a distinguished road
That solved your problem ?

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.
Micael is offline   Reply With Quote

Old   March 23, 2010, 15:31
Default
  #12
Senior Member
 
MASOUD
Join Date: Mar 2009
Posts: 102
Rep Power: 17
MASOUD is on a distinguished road
yes, solved!

As far as I know from the UDF manual, the names must be the same.
MASOUD is offline   Reply With Quote

Old   March 23, 2010, 15:46
Default
  #13
Senior Member
 
Micael
Join Date: Mar 2009
Location: Canada
Posts: 156
Rep Power: 18
Micael is on a distinguished road
Where did you see that? I see the opposite in the manual (I just verified it).
Micael is offline   Reply With Quote

Old   March 24, 2010, 10:31
Default
  #14
Senior Member
 
MASOUD
Join Date: Mar 2009
Posts: 102
Rep Power: 17
MASOUD is on a distinguished road
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.
MASOUD is offline   Reply With Quote

Old   December 6, 2012, 13:39
Default define_source UDF for 2d
  #15
New Member
 
ali m
Join Date: Oct 2012
Posts: 8
Rep Power: 13
ali_mehrabi69 is on a distinguished road
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???
ali_mehrabi69 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
Dynamic Mesh UDF Qureshi FLUENT 7 March 23, 2017 07:37
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 22:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 21:38
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 04:03
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 04:01


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