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

UDF "Define_On_Demand" error: "Segmentation Violation"

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By pakk
  • 1 Post By upeksa
  • 1 Post By upeksa
  • 1 Post By upeksa

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 3, 2015, 03:23
Default UDF "Define_On_Demand" error: "Segmentation Violation"
  #1
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Hi, Fluent UDF user,

This is the same question as previous thread: Hooking On_Demand error.
I re-wrote new code, the compiler and loading UDF is OK. But when the code hooked, It showed the proplem as in the picture below (pic.12 is the compiler successful, pic.11 is the error).

Could you please help me solve this problem??

Thank you very much.

#include "udf.h"
#include "math.h"

DEFINE_ON_DEMAND(contour)
{
Domain *d;
Thread *t;
cell_t c;
Node *v;
d=Get_Domain(1);
int i,j,k,n,m;
real dx,dy,dz,delta,Cdes=0.65,Lt,Ldes;
thread_loop_c(t,d) /*loops over all cell threads in domain*/
{
begin_c_loop(c,t) /* loops over cells in a cell thread */
{
c_node_loop(c,t,n) /* loops over node in a cell thread */
{
v=C_NODE(c,t,n);
NODE_MARK(v)=0;
}
}
end_c_loop(c,t)

begin_c_loop(c,t) /* loops over cells in a cell thread */
{
k=C_NNODES(c,t);
real x[k],y[k],z[k];
real delx1=0,dely1=0,delz1=0;
for (m=0;m<=k;m++)
{
c_node_loop(c,t,n) /* loops over node in a cell thread */
{
v=C_NODE(c,t,n);
x[m]=NODE_X(v);
y[m]=NODE_Y(v);
z[m]=NODE_Z(v);
if (NODE_MARK(v)==0)
NODE_MARK(v)=1;
}
}
for (i=0;i<=k;i++)
{
for (j=0;j<=k;j++)
{
dx=MAX(delx1,fabs(x[i]-x[j]));
dy=MAX(dely1,fabs(y[i]-y[j]));
dz=MAX(delz1,fabs(z[i]-z[j]));
delta=MAX(dx,dy);
delta=MAX(delta,dz);
}
}
Lt=sqrt(C_K(c,t))/0.09/C_O(c,t);
Ldes=Cdes*delta;
if(Lt>Ldes)
{
C_UDMI(c,t,1)=1;
}
if(Lt<=Ldes)
{
C_UDMI(c,t,1)=0;
}
}
end_c_loop(c,t)
}
}
Attached Images
File Type: jpg 11.jpg (28.6 KB, 12 views)
File Type: jpg 12.jpg (32.4 KB, 12 views)
dinhanh is offline   Reply With Quote

Old   February 3, 2015, 03:36
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
I would suggest to comment out some parts, so you can determine where in the code the problem is. (Like this.)
dinhanh likes this.
pakk is offline   Reply With Quote

Old   February 3, 2015, 07:05
Default
  #3
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Thank you, Pakk,

But I could not get your answer, Please help, this one very importance for me!!!
dinhanh is offline   Reply With Quote

Old   February 3, 2015, 07:23
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Your code has a mistake. Remove half of the code, and see if you still get an error. If you get the error, then the mistake is in the remaining code. If you don't get an error, the mistake is in the part you removed.

Repeat this until you found the error.
pakk is offline   Reply With Quote

Old   February 3, 2015, 09:46
Default
  #5
Member
 
Join Date: Jul 2013
Posts: 80
Rep Power: 12
upeksa is on a distinguished road
I don't really know what are you trying, you have a lot of useless code here.

It works now anyway.

#include "udf.h"
#include "math.h"

DEFINE_ON_DEMAND(contour)
{
Domain *d=Get_Domain(1);
Thread *t;
cell_t c;
Node *v;
int i,j,k,n,m;
real dx,dy,dz,delta,Cdes=0.65,Lt,Ldes;
real *x, *y, *z;
real delx1=0.,dely1=0.,delz1=0.;

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
c_node_loop(c,t,n)
{
v=C_NODE(c,t,n);
CLEAR_NODE_VISITED(v);
}
}
end_c_loop(c,t)

begin_c_loop(c,t)
{
k=C_NNODES(c,t);
x=(real *)malloc(k*sizeof(real));
y=(real *)malloc(k*sizeof(real));
z=(real *)malloc(k*sizeof(real));

c_node_loop(c,t,n)
{
v=C_NODE(c,t,n);
x[n]=NODE_X(v);
y[n]=NODE_Y(v);
z[n]=NODE_Z(v);
if (!(NODE_IS_VISITED(v)))
SET_NODE_VISITED(v);
}

for (i=0;i<=k;i++)
{
for (j=0;j<=k;j++)
{
dx=MAX(delx1,fabs(x[i]-x[j]));
dy=MAX(dely1,fabs(y[i]-y[j]));
dz=MAX(delz1,fabs(z[i]-z[j]));
delta=MAX(dx,dy);
delta=MAX(delta,dz);
}
}

Lt=sqrt(C_K(c,t))/0.09/C_O(c,t);
Ldes=Cdes*delta;

if(Lt>Ldes)
C_UDMI(c,t,1)=1;

if(Lt<=Ldes)
C_UDMI(c,t,1)=0;
free(x);
free(y);
free(z);
}
end_c_loop(c,t)
}
}
dinhanh likes this.
upeksa is offline   Reply With Quote

Old   February 3, 2015, 10:09
Default
  #6
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Thank you so much, upeksa,

I am trying to plot the contour in which the region of LES will be 0 and the region of RAN will be 1. I am using DES turbulence model. So in order to do thay, I need to calculate the max grid size of each cell, and compear that one to lenght scale of k-omega model. That is what I am doing now.
dinhanh is offline   Reply With Quote

Old   February 3, 2015, 10:28
Default
  #7
Member
 
Join Date: Jul 2013
Posts: 80
Rep Power: 12
upeksa is on a distinguished road
Quote:
Originally Posted by dinhanh View Post
Thank you so much, upeksa,

I am trying to plot the contour in which the region of LES will be 0 and the region of RAN will be 1. I am using DES turbulence model. So in order to do thay, I need to calculate the max grid size of each cell, and compear that one to lenght scale of k-omega model. That is what I am doing now.
Did you know that you can use the macro C_VOLUME(c,t) to check the cell volume of each cell?
upeksa is offline   Reply With Quote

Old   February 3, 2015, 10:32
Default
  #8
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Quote:
Originally Posted by upeksa View Post
Did you know that you can use the macro C_VOLUME(c,t) to check the cell volume of each cell?
Yes, I known. But what I need here is the max grid size, not the the vollume of cell. I mean, at each cell, I need to find delta=max(dx,dy,dz)
dinhanh is offline   Reply With Quote

Old   February 3, 2015, 22:01
Default
  #9
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Quote:
Originally Posted by upeksa View Post
I don't really know what are you trying, you have a lot of useless code here.

It works now anyway.

#include "udf.h"
#include "math.h"

DEFINE_ON_DEMAND(contour)
{
Domain *d=Get_Domain(1);
Thread *t;
cell_t c;
Node *v;
int i,j,k,n,m;
real dx,dy,dz,delta,Cdes=0.65,Lt,Ldes;
real *x, *y, *z;
real delx1=0.,dely1=0.,delz1=0.;

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
c_node_loop(c,t,n)
{
v=C_NODE(c,t,n);
CLEAR_NODE_VISITED(v);
}
}
end_c_loop(c,t)

begin_c_loop(c,t)
{
k=C_NNODES(c,t);
x=(real *)malloc(k*sizeof(real));
y=(real *)malloc(k*sizeof(real));
z=(real *)malloc(k*sizeof(real));

c_node_loop(c,t,n)
{
v=C_NODE(c,t,n);
x[n]=NODE_X(v);
y[n]=NODE_Y(v);
z[n]=NODE_Z(v);
if (!(NODE_IS_VISITED(v)))
SET_NODE_VISITED(v);
}

for (i=0;i<=k;i++)
{
for (j=0;j<=k;j++)
{
dx=MAX(delx1,fabs(x[i]-x[j]));
dy=MAX(dely1,fabs(y[i]-y[j]));
dz=MAX(delz1,fabs(z[i]-z[j]));
delta=MAX(dx,dy);
delta=MAX(delta,dz);
}
}

Lt=sqrt(C_K(c,t))/0.09/C_O(c,t);
Ldes=Cdes*delta;

if(Lt>Ldes)
C_UDMI(c,t,1)=1;

if(Lt<=Ldes)
C_UDMI(c,t,1)=0;
free(x);
free(y);
free(z);
}
end_c_loop(c,t)
}
}
Dear upeksa,
I Tried to use your code and modified a little. But It still did not work. The same error appeared. I dont know why It have no error in your case

#include "udf.h"
#include "math.h"

DEFINE_ON_DEMAND(contour)
{
Domain *d=Get_Domain(1);
Thread *t;
cell_t c;
Node *v;
int i,j,k,n;
real delta,Cdes=0.65,Lt,Ldes;
real *x, *y, *z;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
c_node_loop(c,t,n)
{
v=C_NODE(c,t,n);
CLEAR_NODE_VISITED(v);
}
}
end_c_loop(c,t)

begin_c_loop(c,t)
{
k=C_NNODES(c,t);
x=(real *)malloc(k*sizeof(real));
y=(real *)malloc(k*sizeof(real));
z=(real *)malloc(k*sizeof(real));
real dx=0.,dy=0.,dz=0.;
c_node_loop(c,t,n)
{
v=C_NODE(c,t,n);
x[n]=NODE_X(v);
y[n]=NODE_Y(v);
z[n]=NODE_Z(v);
if (!(NODE_IS_VISITED(v)))
SET_NODE_VISITED(v);
}

for (i=0;i<=k;i++)
{
for (j=0;j<=k;j++)
{
dx=MAX(dx,fabs(x[i]-x[j]));
dy=MAX(dy,fabs(y[i]-y[j]));
dz=MAX(dz,fabs(z[i]-z[j]));
delta=MAX(dx,dy);
delta=MAX(delta,dz);
}
}

Lt=sqrt(C_K(c,t))/0.09/C_O(c,t);
Ldes=Cdes*delta;

if(Lt>Ldes)
C_UDMI(c,t,1)=1;
if(Lt<=Ldes)
C_UDMI(c,t,1)=0;
free(x);
free(y);
free(z);
}
end_c_loop(c,t)
}
}
dinhanh is offline   Reply With Quote

Old   February 4, 2015, 02:13
Default
  #10
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
I also tried with the more simple code, But still got same error.
So I dont know what happened

#include "udf.h"
#include "math.h"
#include "stdlib.h"
#include "malloc.h"

DEFINE_ON_DEMAND(contour)
{
Domain *d=Get_Domain(1);
Thread *t;
cell_t c;
real delta,Cdes=0.65,Lt,Ldes;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
delta=pow(C_VOLUME(c,t),1./3);
Lt=sqrt(C_K(c,t))/0.09/C_O(c,t);
Ldes=Cdes*delta;

if(Lt>Ldes)
C_UDMI(c,t,1)=1;
if(Lt<=Ldes)
C_UDMI(c,t,1)=0;
}
end_c_loop(c,t)
}
}
dinhanh is offline   Reply With Quote

Old   February 4, 2015, 04:24
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Do you have two two user defined memories (UDMS) defined in Fluent?
pakk is offline   Reply With Quote

Old   February 4, 2015, 04:49
Default
  #12
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Quote:
Originally Posted by pakk View Post
Do you have two two user defined memories (UDMS) defined in Fluent?
Thank, pakk,

What do you mean?
Attached Images
File Type: jpg Untitled.jpg (47.7 KB, 5 views)
dinhanh is offline   Reply With Quote

Old   February 4, 2015, 05:28
Default
  #13
Member
 
Join Date: Jul 2013
Posts: 80
Rep Power: 12
upeksa is on a distinguished road
I think something is wrong with C_O(c,t).

I have change it for C_T(c,t) for example and it worked.
upeksa is offline   Reply With Quote

Old   February 4, 2015, 06:01
Default
  #14
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Quote:
Originally Posted by upeksa View Post
I think something is wrong with C_O(c,t).

I have change it for C_T(c,t) for example and it worked.
For me, even, I changed C_O(c,t) by 5, for example, still got same error.
And in the simple code upper, the same error appeared. But when I compiler UDF for vapor pressure, It ran well, no error.
So it seem to be have problem in my PC. I am using super-comp at University.
If you dont mind, Could you use example Fluent file, and use this UDF code to plot the data?
http://www.filedropper.com/desktop_61

Thank you
dinhanh is offline   Reply With Quote

Old   February 4, 2015, 07:31
Default
  #15
Member
 
Join Date: Jul 2013
Posts: 80
Rep Power: 12
upeksa is on a distinguished road
You haven't reserved UDF memories:

Define -> User-Defined -> Memory... Number of User-Defined Memory Locations =2

It will work
dinhanh likes this.
upeksa is offline   Reply With Quote

Old   February 4, 2015, 09:34
Default
  #16
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Quote:
Originally Posted by upeksa View Post
You haven't reserved UDF memories:

Define -> User-Defined -> Memory... Number of User-Defined Memory Locations =2

It will work
Thank you very much, upeksa,

It work now. So the problem is the number of memory location. How can we determine how many memory location will be needed?
dinhanh is offline   Reply With Quote

Old   February 4, 2015, 09:37
Default
  #17
Member
 
Join Date: Jul 2013
Posts: 80
Rep Power: 12
upeksa is on a distinguished road
Quote:
Originally Posted by dinhanh View Post
Thank you very much, upeksa,

It work now. So the problem is the number of memory location. How can we determine how many memory location will be needed?
You used C_UDMI(c,t,0) and C_UDMI(c,t,1). 2 memory locations.
upeksa is offline   Reply With Quote

Old   February 4, 2015, 09:41
Default
  #18
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
From the UDF code, I used only one memory user define location with If loops
If (a<b) C_UDMI(c,t,1)=1
If (a>b) C_UDMI(c,t,1)=0

So I think only 1 location is required?
dinhanh is offline   Reply With Quote

Old   February 4, 2015, 09:55
Default
  #19
Member
 
Join Date: Jul 2013
Posts: 80
Rep Power: 12
upeksa is on a distinguished road
Quote:
Originally Posted by dinhanh View Post
From the UDF code, I used only one memory user define location with If loops
If (a<b) C_UDMI(c,t,1)=1
If (a>b) C_UDMI(c,t,1)=0

So I think only 1 location is required?
No, you still need 2.

if you only use 1 memory location whose number is, for example 11 (C_UDMI(c,t,11)), you will need in that case 12 memory locations.

If you are going to use only one memory location, use C_UDMI(c,t,0) instead.
dinhanh likes this.
upeksa 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
specified shear at wall - temperature gradient - UDF - access violation error senD Fluent UDF and Scheme Programming 9 September 18, 2014 07:29
UDF for Mass Flow at the Outlet: ERROR ACCESS VIOLATION I-mech Fluent UDF and Scheme Programming 1 May 23, 2014 12:37
udf segmentation violation when hooked jjchristophe Fluent UDF and Scheme Programming 9 June 25, 2012 05:46
udf error : access violation butterfly007 Fluent UDF and Scheme Programming 2 June 1, 2012 11:01
UDF Access violation therandomestname FLUENT 0 April 15, 2011 17:31


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