UDF "Define_On_Demand" error: "Segmentation Violation"
2 Attachment(s)
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) } } |
I would suggest to comment out some parts, so you can determine where in the code the problem is. (Like this.)
|
Thank you, Pakk,
But I could not get your answer, Please help, this one very importance for me!!! |
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. |
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) } } |
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. |
Quote:
|
Quote:
|
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) } } |
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) } } |
Do you have two two user defined memories (UDMS) defined in Fluent?
|
1 Attachment(s)
Quote:
What do you mean? |
I think something is wrong with C_O(c,t).
I have change it for C_T(c,t) for example and it worked. |
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 |
You haven't reserved UDF memories:
Define -> User-Defined -> Memory... Number of User-Defined Memory Locations =2 It will work |
Quote:
It work now. So the problem is the number of memory location. How can we determine how many memory location will be needed? |
Quote:
|
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? |
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. |
All times are GMT -4. The time now is 09:39. |