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

pls help. UDF in DEFINE_SR_RATE

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Sixkillers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 25, 2011, 17:21
Question pls help. UDF in DEFINE_SR_RATE
  #1
New Member
 
golshadi
Join Date: Sep 2011
Posts: 14
Rep Power: 15
golshadi is on a distinguished road
I have a rate of surface reaction:
-rM=(ks*KM^2*(CM^2-CW*CD/K)/(1+2*(KM*CM)^0.5+(KW*CW)))

and have written this UDF for it:
#include "udf.h"
#define KEQ 7
#define KS 11.7
#define KM 884.6
#define KW 418.4
#define CH3OCH3 0
#define H2O 1
#define CH3OH 2
real reaction_rate(cell_t c, Thread *cthread,real mw[],real yi[])
{
real concenCH3OCH3 = C_R(c,cthread) * yi[CH3OCH3] / mw[CH3OCH3];
real concenH2O = C_R(c,cthread) * yi[H2O] / mw[H2O];
real concenCH3OH = C_R(c,cthread) * yi[CH3OH] / mw[CH3OH];
real kcm= KM * concenCH3OH;
real den=1+(2 * sqrt(kcm))+(KW * concenH2O);
return -1*(KS *1000* pow(KM,2)) * (pow(concenCH3OH,2)-(concenH2O * concenCH3OCH3/KEQ))/(pow(den,4));
}
DEFINE_SR_RATE(rate1,f,fthread,r,mw,yi,rr)
{
*rr = reaction_rate(F_C0(f,fthread),THREAD_T0(fthread),m w,yi);
}


I Compile and load and Hook it in (Define/User Defined/Function Hook/surface reaction rate). But in the menu of reaction I dont look it. and after iterating , 'FlUENT' writes this :

Deleted old libudfrate\ntx86\2ddp\libudf.dll
1 file(s) copied.
(system "copy c:\fluent6.3\fluent\fluent6.3.26\src\makefile_nt.u df libudfrate\ntx86\2ddp\makefile")
1 file(s) copied.
(chdir "libudfrate")()
(chdir "ntx86\2ddp")()
my_rate1.c
c:\fluent6.3\fluent\fluent6.3.26\src\machine.h(114 ) : warning C4005: 'stdout' : macro redefinition
D:\C++\VC\INCLUDE\stdio.h(161) : see previous definition of 'stdout'
c:\fluent6.3\fluent\fluent6.3.26\src\machine.h(115 ) : warning C4005: 'stderr' : macro redefinition
D:\C++\VC\INCLUDE\stdio.h(162) : see previous definition of 'stderr'
c:\fluent6.3\fluent\fluent6.3.26\src\machine.h(116 ) : warning C4005: 'stdin' : macro redefinition
D:\C++\VC\INCLUDE\stdio.h(160) : see previous definition of 'stdin'
# Generating udf_names.c because of makefile my_rate1.obj
udf_names.c
c:\fluent6.3\fluent\fluent6.3.26\src\machine.h(114 ) : warning C4005: 'stdout' : macro redefinition
D:\C++\VC\INCLUDE\stdio.h(161) : see previous definition of 'stdout'
c:\fluent6.3\fluent\fluent6.3.26\src\machine.h(115 ) : warning C4005: 'stderr' : macro redefinition
D:\C++\VC\INCLUDE\stdio.h(162) : see previous definition of 'stderr'
c:\fluent6.3\fluent\fluent6.3.26\src\machine.h(116 ) : warning C4005: 'stdin' : macro redefinition
D:\C++\VC\INCLUDE\stdio.h(160) : see previous definition of 'stdin'
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj my_rate1.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.
"D:/guess"

Opening library "libudfrate"...
Library "libudfrate\ntx86\2ddp\libudf.dll" opened
rate1
Done.

iter continuity x-velocity y-velocity energy ch3och3 h2o time/iter

reversed flow in 40 faces on outflow 5.

Error:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: ()


pls Help me to solve this problem.
golshadi is offline   Reply With Quote

Old   December 25, 2011, 17:48
Default
  #2
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 15
Sixkillers is on a distinguished road
It looks like array indexing is messed up. You should try to place several Message methods into your code to see, where it is exactly failing.
Sixkillers is offline   Reply With Quote

Old   December 26, 2011, 03:41
Default
  #3
New Member
 
golshadi
Join Date: Sep 2011
Posts: 14
Rep Power: 15
golshadi is on a distinguished road
Quote:
Originally Posted by Sixkillers View Post
It looks like array indexing is messed up. You should try to place several Message methods into your code to see, where it is exactly failing.
Hi my friend Sixkillers
I'm amateur in C coding. pls explain more.
FLUENT is giving below error:

Error:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: ()

I added a message above the *rr=... line, and it is shown in console fluent but after that the error is appeared.
thanks
golshadi is offline   Reply With Quote

Old   December 26, 2011, 18:48
Default
  #4
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 15
Sixkillers is on a distinguished road
ACCESS_VIOLATION can be caused by two things:
1) A pointer is pointing to a memory, which doesn't belong to running process and it is dereferenced.
2) An array index is out of bounds.

I have modified your code to help you see what is going on

PHP Code:
#include "udf.h"
#define KEQ 7
#define KS 11.7
#define KM 884.6
#define KW 418.4
#define CH3OCH3 0
#define H2O 1
#define CH3OH 2

real reaction_rate(cell_t cThread *cthread,real mw[],real yi[])
{
    
real concenCH3OCH3 C_R(c,cthread) * yi[CH3OCH3] / mw[CH3OCH3];

    
Message("concenCH3OCH3...OK!\n");

    
real concenH2O C_R(c,cthread) * yi[H2O] / mw[H2O];

    
Message("concenH2O...OK!\n");

    
real concenCH3OH C_R(c,cthread) * yi[CH3OH] / mw[CH3OH];

    
Message("concenCH3OH...OK!\n");

    
real kcmKM concenCH3OH;
    
real den=1+(sqrt(kcm))+(KW concenH2O);

    return -
1*(KS *1000pow(KM,2)) * (pow(concenCH3OH,2)-(concenH2O concenCH3OCH3/KEQ))/(pow(den,4));
}

DEFINE_SR_RATE(rate1,f,fthread,r,mw,yi,rr)
{
    
Threadt0;

    if(
fthread == NULL)
    {
        
Message("fthread is NULL!\n");
        
abort();
    }

    
t0 THREAD_T0(fthread);

    if(
t0 == NULL)
    {
        
Message("t0 is NULL!\n");
        
abort();
    }

    *
rr reaction_rate(F_C0(f,fthread),t0,mw,yi);

Sixkillers is offline   Reply With Quote

Old   December 27, 2011, 15:45
Default
  #5
New Member
 
golshadi
Join Date: Sep 2011
Posts: 14
Rep Power: 15
golshadi is on a distinguished road
thanks a lot my friend , Sixkillers .
I discover my problem.
because my c source file is written to access face type thread but I use it in a porous media, and the media is a volume cell, so : "t0 is NULL" is shown by it. so I used this source in a wall boundary of another case, and Fluent didn't show any error(for time-saving in c source I transformed Message lines to comment lines). in this try the mass fractions of species didn't change and it looks the reaction does not exist.

so my problem is in two category:
1- why don't mass fractions of species change after correctly compiling & Hooking my UDF in second case?
2- for applying the UDF in porous media what changes should I do?

I hope to help me.

Last edited by golshadi; December 27, 2011 at 15:52. Reason: I made a mistake
golshadi is offline   Reply With Quote

Old   December 28, 2011, 18:09
Default
  #6
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 15
Sixkillers is on a distinguished road
1) I have no idea why it doesn't work, but you might want to try write several values from your method to a file (example how to do it: http://www.cfd-online.com/Forums/flu...avitation.html).

2) I am afraid that you will really have to use macro DEFINE_VR for porous media. In addition be sure that your rate law is in units [kmol/(m^3 * s)].
golshadi likes this.
Sixkillers is offline   Reply With Quote

Old   December 30, 2011, 15:08
Default
  #7
New Member
 
golshadi
Join Date: Sep 2011
Posts: 14
Rep Power: 15
golshadi is on a distinguished road
By your suggestions my problems , in this stage of my work, almost are solved.
1- I checked carefully any part of my UDF in the way you said. I found that the fluent did not pass any mass fraction to my UDF so I correct it.
2- I used DEFINE_VR, but I don't know the result of my simulation will be correct.
I want to say "YOU ARE KING OF UDF WRITTING" and thanks a lot.
I'm sincerely grateful for your help.
golshadi 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
pls Help!...can't interpret UDF X3mZ Fluent UDF and Scheme Programming 1 December 12, 2010 13:05
udf problem.... pls help anant FLUENT 2 January 11, 2007 07:01
Error pls HELP on UDF .... CFD USER FLUENT 1 October 26, 2006 15:49
pls help with udf file Arif FLUENT 1 February 7, 2006 12:10
pls help : udf & cell temp. A. H. Jaberi FLUENT 0 December 16, 2004 06:33


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