|
[Sponsors] |
December 20, 2017, 19:55 |
maximum y-position of nodes of a face
|
#1 |
New Member
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9 |
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); } } |
|
December 20, 2017, 21:14 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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 |
|
December 21, 2017, 06:28 |
|
#3 |
New Member
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9 |
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 |
|
December 22, 2017, 05:29 |
|
#4 |
New Member
Doruk Yelkenci
Join Date: Apr 2017
Posts: 20
Rep Power: 9 |
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.
|
|
January 3, 2018, 06:40 |
|
#5 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
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 real max_y = VERY_NEGATIVE; begin_f_loop(f,tf) { f_node_loop(f,tf,n) { v = F_NODE(f,tf,n); max_y = MAX(max_y,NODE_Y(v)); } }end_f_loop(f,tf) #if RP_NODE max_y = PRF_GRHIGH1(max_y); #endif 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. |
|
January 3, 2018, 08:05 |
|
#6 | |
New Member
Doruk Yelkenci
Join Date: Apr 2017
Posts: 20
Rep Power: 9 |
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" ? |
||
January 3, 2018, 09:59 |
|
#7 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
January 3, 2018, 16:00 |
|
#8 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
(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. |
|
January 17, 2018, 02:19 |
|
#9 | |
New Member
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9 |
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); |
||
January 17, 2018, 02:41 |
|
#10 | |
New Member
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9 |
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" DEFINE_GRID_MOTION(gridmotion,domain,dt,time,dtime) { Thread *tf = DT_THREAD(dt); face_t f; Node *v; Double max-y=0,int n; begin_f_loop(f,tf) { f_node_loop(f,tf,n) { v = F_NODE(f,tf,n); if(NODE_Y(v)>max-y) max-y=NODE_Y(v); } } end_f_loop(f,tf); |
||
January 17, 2018, 04:18 |
|
#11 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
"max-y" is not a good variable name. You can not have a minus sign inside a variable name. Try "max_y" instead.
|
|
January 17, 2018, 06:15 |
|
#12 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
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. |
|
January 17, 2018, 11:56 |
|
#13 | |
New Member
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9 |
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" DEFINE_GRID_MOTION(gridmotion,domain,dt,time,dtime) { #if !RP_HOST Thread *tf = DT_THREAD(dt); face_t f; Node *v; double max_y; int n; begin_f_loop(f,tf) { f_node_loop(f,tf,n) { v = F_NODE(f,tf,n); if(NODE_Y(v)>max_y) max_y=NODE_Y(v); } } end_f_loop(f,tf); #if PARALLEL max_y=PRF_GRHIGH1(max_y); #endif #endif 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? |
||
January 18, 2018, 04:53 |
|
#14 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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'. |
|
January 18, 2018, 11:32 |
|
#15 | |
New Member
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9 |
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. |
||
January 18, 2018, 12:10 |
|
#16 |
New Member
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9 |
Thank you ED and pakk
The problem was solved.i changed my code to: Code:
#include "udf.h" DEFINE_GRID_MOTION(gridmotion,domain,dt,time,dtime) { Thread *tf = DT_THREAD(dt); face_t f; Node *v; double c=-1; int n; begin_f_loop(f,tf) { f_node_loop(f,tf,n) { v = F_NODE(f,tf,n); c = MAX(c,NODE_Y(v)); } } end_f_loop(f,tf) #if RP_NODE c = PRF_GRHIGH1(c); #endif |
|
February 9, 2021, 12:21 |
Find and store maximum value at initial condition
|
#17 |
New Member
Marcelo Ruiz
Join Date: Feb 2021
Location: Italy
Posts: 17
Rep Power: 5 |
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) { Thread* tf = DT_THREAD(dt); face_t f; Node* v; double xprev, yprev, hprev, d, h; int n; double x_max, x_min; x_max = -0.99e38; x_min = 0.99e38; begin_f_loop(f, tf) // I used this loop to find the maximum and minimum and maximum but it broke my entire code { f_node_loop(f, tf,n) { v = F_NODE(f,tf, n); x_max = MAX(x_max, NODE_X(v)); x_min = MIN(x_min, NODE_X(v)); } }end_f_loop(f, tf) #if RP_NODE x_max = PRF_GRHIGH1(x_max); x_min = PRF_GRHIGH1(x_min); #endif SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf)); begin_f_loop(f, tf) { f_node_loop(f, tf, n) { v = F_NODE(f, tf, n); if (NODE_POS_NEED_UPDATE(v)) { NODE_POS_UPDATED(v); if (CURRENT_TIME > 0.0) { xprev = NODE_X(v); yprev = NODE_Y(v); hprev = kinematics(xprev, PREVIOUS_TIME,x_max,x_min); d = yprev; h = kinematics(xprev, CURRENT_TIME, x_max, x_min); NODE_Y(v) = d+hprev-h; } } } } end_f_loop(f,tf) } |
|
March 9, 2021, 00:59 |
|
#18 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
use macro DEFINE_ON_DEMAND to calculate something before first iteration
__________________
best regards ****************************** press LIKE if this message was helpful |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to set periodic boundary conditions | Ganesh | FLUENT | 15 | November 18, 2020 07:09 |
snappyhexmesh remove blockmesh geometry | philipp1 | OpenFOAM Running, Solving & CFD | 2 | December 12, 2014 11:58 |
[Gmsh] Import problem | ARC | OpenFOAM Meshing & Mesh Conversion | 0 | February 27, 2010 11:56 |
Looping Over All Nodes DISTINCTLY in a Face | rockymountai | FLUENT | 0 | October 27, 2009 17:29 |
fluent add additional zones for the mesh file | SSL | FLUENT | 2 | January 26, 2008 12:55 |