|
[Sponsors] |
UDF "Define_On_Demand" error: "Segmentation Violation" |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 3, 2015, 04:23 |
UDF "Define_On_Demand" error: "Segmentation Violation"
|
#1 |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
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) } } |
|
February 3, 2015, 04:36 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
I would suggest to comment out some parts, so you can determine where in the code the problem is. (Like this.)
|
|
February 3, 2015, 08:05 |
|
#3 |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
Thank you, Pakk,
But I could not get your answer, Please help, this one very importance for me!!! |
|
February 3, 2015, 08:23 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
February 3, 2015, 10:46 |
|
#5 |
Member
Join Date: Jul 2013
Posts: 80
Rep Power: 13 |
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) } } |
|
February 3, 2015, 11:09 |
|
#6 |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
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. |
|
February 3, 2015, 11:28 |
|
#7 | |
Member
Join Date: Jul 2013
Posts: 80
Rep Power: 13 |
Quote:
|
||
February 3, 2015, 11:32 |
|
#8 |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
||
February 3, 2015, 23:01 |
|
#9 | |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
Quote:
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) } } |
||
February 4, 2015, 03:13 |
|
#10 |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
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) } } |
|
February 4, 2015, 05:24 |
|
#11 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Do you have two two user defined memories (UDMS) defined in Fluent?
|
|
February 4, 2015, 05:49 |
|
#12 | |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
Quote:
What do you mean? |
||
February 4, 2015, 06:28 |
|
#13 |
Member
Join Date: Jul 2013
Posts: 80
Rep Power: 13 |
I think something is wrong with C_O(c,t).
I have change it for C_T(c,t) for example and it worked. |
|
February 4, 2015, 07:01 |
|
#14 | |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
Quote:
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 |
||
February 4, 2015, 08:31 |
|
#15 |
Member
Join Date: Jul 2013
Posts: 80
Rep Power: 13 |
You haven't reserved UDF memories:
Define -> User-Defined -> Memory... Number of User-Defined Memory Locations =2 It will work |
|
February 4, 2015, 10:34 |
|
#16 | |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
Quote:
It work now. So the problem is the number of memory location. How can we determine how many memory location will be needed? |
||
February 4, 2015, 10:37 |
|
#17 |
Member
Join Date: Jul 2013
Posts: 80
Rep Power: 13 |
||
February 4, 2015, 10:41 |
|
#18 |
Member
Anh
Join Date: Sep 2014
Posts: 72
Rep Power: 12 |
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? |
|
February 4, 2015, 10:55 |
|
#19 | |
Member
Join Date: Jul 2013
Posts: 80
Rep Power: 13 |
Quote:
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. |
||
|
|
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 08:29 |
UDF for Mass Flow at the Outlet: ERROR ACCESS VIOLATION | I-mech | Fluent UDF and Scheme Programming | 1 | May 23, 2014 13:37 |
udf segmentation violation when hooked | jjchristophe | Fluent UDF and Scheme Programming | 9 | June 25, 2012 06:46 |
udf error : access violation | butterfly007 | Fluent UDF and Scheme Programming | 2 | June 1, 2012 12:01 |
UDF Access violation | therandomestname | FLUENT | 0 | April 15, 2011 18:31 |