maximum y-position of nodes of a face
hello all.
i want to shrink a circle.i define a udf code on the wall of circle(moving wall).this code is below.my circle reduce radius and comes down.i define begin_f_loop and f_node_loop that get all node of the wall and move it.i need max y-position of node of face each time for create center of circle.how can i? my code: #include "udf.h" DEFINE_GRID_MOTION(gridmotion,domain,dt,time,dtime ) { Thread *tf = DT_THREAD(dt); face_t f; Node *v; double NV_VEC(dx),NV_VEC(a),c,d; int n; real r=0.1*time; SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf)); begin_f_loop(f,tf) { f_node_loop(f,tf,n) { v = F_NODE(f,tf,n); c = NODE_Y(v); d = MAx(c); >>>>>>>>>>>>>this is not correct.how can i? if (NODE_POS_NEED_UPDATE (v)) { NODE_POS_UPDATED(v); a[0]=0; a[1]=(d*0.5); dx[0]=-r*(NODE_COORD(v)[0]-a[0]); dx[1]=-r*((NODE_COORD(v)[1]-a[1])+(d*0.5)); NV_V(NODE_COORD(v), +=, dx); } } end_f_loop(f,tf); } } |
make a loop over all faces using F_CENTROID(x,f,t) macros
and find min/max value of coordinate in y direction Best regards |
tanx
i dont understand.i want y-position of uppermost node of my circle each time. for example a for-loop that get all node y-position and get maximum |
You can use PRF_GRHIGH1 macros. Check help for how to use them. Using them in parallel mode is requires lots of modification in udf so keep that in mind.
|
Hi Ali_Karimi,
There is a function MAX(a,b), as defined in global.h, which does what you would expect. It is difficult to work out what you are aiming for, but I suspect that you need one loop (or set of loops) to calculate the maximum y-coordinate, and then a separate loop (or set of loops) to use that to move the nodes. So, the first set of loops could look like this: Code:
#define VERY_NEGATIVE -0.99e38 I really cannot work out what you are intending to do in the calculations leading up to "NV_V(NODE_COORD(v), +=, dx);". I suspect that your current code is wrong. (For example, it looks like all the nodes collapse onto the same coordinate. And do you really want r to be zero at time zero?) You need to work this out for yourself, and I would advise you to do this outside of DEFINE_GRID_MOTION, which is a difficult UDF to debug. Best regards, Ed. |
Quote:
I was hoping if you can explain MAX function a little bit more. #define MAX(a,b)((b)>(a)?(b):(a)) This is how it is defined in global.h but it is very confusing to me and it is never explained in anywhere. Not in help or online I checked it a lot. So it means if the "array b" has any bigger number than "a", "a" becomes maximum number in the "array b" ? |
No, MAX(a,b) is just the maximum of numbers a and b.
So: MAX(3,10) is the same as 10 MAX(5,1) is the same as 5 MAX(2,2) is the same as 2 MAX(-1,1) is the same as 1 and so on. |
(Thanks for the examples, pakk.)
The reason this is not explained in the Fluent manuals is because it is standard C programming language. (Specifically, the "#define" part is a preprocessor macro, and the "(X ? Y : Z)" part is a conditional operator.) See for example https://stackoverflow.com/questions/...n-and-max-in-c, where they also propose more complicated but more secure versions. |
Quote:
Thank you. I can not use this function, but I found another way. I defined a loop that gets maximized before each step. first c=0 begin_f_loop(f,tf) { f_node_loop(f,tf,n) { v = F_NODE(f,tf,n); if(NODE_Y(v)>c) c=NODE_Y(v); } } end_f_loop(f,tf); |
Quote:
Thanks for your attention, Yes. I need one loop to calculate the maximum y-coordinate, and then a separate loop to use that to move the nodes. I found a way to get the maximum, but it's just right in the serial mode.Speed is important to me and does not recognize the maximum in the parallel state. This is first loop of my code: Code:
#include "udf.h" |
"max-y" is not a good variable name. You can not have a minus sign inside a variable name. Try "max_y" instead.
|
Pakk is correct about "max-y" (in fact, too restrained -- it is worse than "not a good variable name"). Also, ", int n" should be "; int n" (probably with a newline after ";", to be readable).
Your version of the first loop is basically the same as the one that I proposed, except that yours will never return a negative value of max_y, which could be an error, and I showed you how to use PRF_GRHIGH1. |
Quote:
yes.Sorry I have put these values correct in the my code. Here it is wrong. i change code to: Code:
#include "udf.h" Error: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64). The system cannot find the file specified. Where's the mistake? How do I compile a parallel udf? |
That is not the error that you get when you try to compile the udf, but the error that you get when you try to load the udf.
Please look at the error that you get after clicking 'build'. |
Quote:
ew 1.c to libudf3\src Creating user_nt.udf file for 2ddp ... (system "copy "C:\PROGRA~1\ANSYSI~1\v150\fluent"\fluent15.0.0\sr c\makefile_nt.udf "libudf3\win64\2ddp\makefile" ") 1 file(s) copied. (chdir "libudf3")(chdir "win64\2ddp") Done. |
Thank you ED and pakk
The problem was solved.i changed my code to: Code:
#include "udf.h" |
Find and store maximum value at initial condition
Hello guys, I am facing the same problem. However, I want to loop over the domain before my first time step, in other words before I change the values of the nodes and extract the maximum and minimum as parameters for the entire simulation.
Would you help me with some advice how do I manage the loop function? should I create a function, use another macro? Thank you for the advice, Code:
DEFINE_GRID_MOTION(motion, domain, dt, time, dtime) |
use macro DEFINE_ON_DEMAND to calculate something before first iteration
|
All times are GMT -4. The time now is 19:39. |