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

ACCESS_VIOLATION error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 25, 2010, 06:10
Default ACCESS_VIOLATION error
  #1
New Member
 
Emily
Join Date: Aug 2010
Posts: 5
Rep Power: 16
whelk123 is on a distinguished road
Hello, I am trying to model the heat transfer within a hydrogen fuel cell and I keep getting the message ACCESS_VIOLATION when I try applying my UDF.
#include "udf.h"
DEFINE_INIT(init_func,d)
{
Domain *d;
Thread *t;
real sum_diss=0.;
cell_t c;
d = Get_Domain(1);
}
DEFINE_SOURCE(sink_mass, c, t, dS, eqn)
{
real sink_mass;
sink_mass=-C_UDMI(c,t,0)*rau0*0.0166*(1-poros);
return sink_mass;

}
DEFINE_SOURCE(energy_source, c, t, dS, eqn)
{
real energy_source;
energy_source=-C_UDMI(c,t,0)*rau0*0.0166*(1-poros)*deltah/mh2;
return energy_source;
}
DEFINE_EXECUTE_AT_END(execute_at_end)
{
real step =RP_Get_Real("physical-time-step");
Domain *domain = Get_Domain(1);
int ID=2;
Thread *t =Lookup_Thread(domain, ID);
cell_t c;
begin_c_loop(c,t)
{
double temper,P,hsmp,lnpeq,Peq, dxdt;
temper=C_T(c,t);
P=(C_R(c,t)*rgp*C_T(c,t)/mh2)*0.00001;


hsmp= C_UDMI(c,t, 1 )*(HsMmaxprim-hsurm)+hsurm;
lnpeq=A-B/temper+C*hsmp+D*pow(tan(pi*hsmp/2.0/HsMmaxprim),n)+E*pow(tan(pi*hsmp/2.0/HsMmaxprim),(-m));
Peq=exp(lnpeq);
C_UDMI(c,t,0)=mh2*Ca*exp(Ea/(rgp*temper))*log(P/Peq)/0.0166;
C_UDMI(c,t,1 )=C_UDMI(c,t,1 )+C_UDMI(c,t,0)*step;
}
end_c_loop(c,t)
}

I have defined things but didnt think that was important. Can anyone please tell me what is wrong with this code!! It is fairly urgent!
Thank you for any help
whelk123 is offline   Reply With Quote

Old   August 25, 2010, 07:04
Default
  #2
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
You have to check if the pointers are valid and if you have enough user defined memory allocated:
Code:
 
...
if (N_UDM > 0)
  sink_mass=-C_UDMI(c,t,0)*rau0*0.0166*(1-poros); 
else
  Error("Not enough UDM's defined!\n");
return sink_mass; 
 
} 
...
if (N_UDM > 0)
  energy_source=-C_UDMI(c,t,0)*rau0*0.0166*(1-poros)/mh2;
else
  Error("Not enough UDM's defined!\n")
return energy_source; 
...
int ID=2; 
Thread *t =Lookup_Thread(domain, ID); 
cell_t c; 
if(NULL == t)
  Error("No such thread!\n");
...  
if (N_UDM < 2)
  Error("Not enough UDM's defined!\n")
C_UDMI(c,t,0)=mh2*Ca*exp(Ea/(rgp*temper))*log(P/Peq)/0.0166; 
C_UDMI(c,t,1 )=C_UDMI(c,t,1 )+C_UDMI(c,t,0)*step; 
...
dmoroian is offline   Reply With Quote

Old   August 25, 2010, 07:24
Default
  #3
New Member
 
Emily
Join Date: Aug 2010
Posts: 5
Rep Power: 16
whelk123 is on a distinguished road
Thanks for your help. I seem to have fixed the code but when I try and hook the function into the model, the sources do not appear in the hooking function box. Any ideas?
Thanks again!
whelk123 is offline   Reply With Quote

Old   August 27, 2010, 03:01
Default
  #4
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Quote:
Originally Posted by whelk123 View Post
...
when I try and hook the function into the model, the sources do not appear in the hooking function box.
...
Which "hooking function box" are you talking about?
I suspect you're looking in the wrong place. Check section 6.2.19 in the User Defined Function Manual to see how sources are hooked in fluent.
dmoroian is offline   Reply With Quote

Old   August 27, 2010, 04:16
Default
  #5
New Member
 
Emily
Join Date: Aug 2010
Posts: 5
Rep Power: 16
whelk123 is on a distinguished road
I have been following the instructions, but when going into the assigning hooks where you assign inital_func etc not all of my functions are there. The heat source appears but the energy source does not.
whelk123 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
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM Community Contributions 300 October 29, 2014 19:00
Errors running allwmake in OpenFOAM141dev with WM_COMPILE_OPTION%3ddebug unoder OpenFOAM Installation 11 January 30, 2008 21:30
[Netgen] Compiling Netgen on Fedora Core is driving me crazy jango OpenFOAM Meshing & Mesh Conversion 3 November 9, 2007 14:29
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51
user defined function cfduser CFX 0 April 29, 2006 11:58


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