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

maximum y-position of nodes of a face

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 1 Post By AlexanderZ
  • 1 Post By doruk
  • 1 Post By obscureed
  • 1 Post By pakk
  • 1 Post By obscureed
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 20, 2017, 19:55
Smile maximum y-position of nodes of a face
  #1
New Member
 
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9
ali_karimi is on a distinguished road
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);
}
}
ali_karimi is offline   Reply With Quote

Old   December 20, 2017, 21:14
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
ali_karimi likes this.
AlexanderZ is offline   Reply With Quote

Old   December 21, 2017, 06:28
Default
  #3
New Member
 
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9
ali_karimi is on a distinguished road
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
ali_karimi is offline   Reply With Quote

Old   December 22, 2017, 05:29
Default
  #4
New Member
 
Doruk Yelkenci
Join Date: Apr 2017
Posts: 20
Rep Power: 9
doruk is on a distinguished road
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.
ali_karimi likes this.
doruk is offline   Reply With Quote

Old   January 3, 2018, 06:40
Default
  #5
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
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
Note that "begin_f_loop(f,tf){" has to be balanced at the end by "}end_f_loop(f,tf)" -- note this includes "}"! The code you posted gets this wrong and is therefore very confusing. (Note also there is no final ";", which in my opinion is inconvenient.) As doruk pointed out, you need PRF_GRHIGH1 if you running in parallel.

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.
ali_karimi likes this.
obscureed is offline   Reply With Quote

Old   January 3, 2018, 08:05
Default
  #6
New Member
 
Doruk Yelkenci
Join Date: Apr 2017
Posts: 20
Rep Power: 9
doruk is on a distinguished road
Quote:
Originally Posted by obscureed View Post

There is a function MAX(a,b), as defined in global.h, which does what you would expect.
Hi Ed,

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" ?
doruk is offline   Reply With Quote

Old   January 3, 2018, 09:59
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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.
pakk is offline   Reply With Quote

Old   January 3, 2018, 16:00
Default
  #8
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
(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.
obscureed is offline   Reply With Quote

Old   January 17, 2018, 02:19
Default
  #9
New Member
 
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9
ali_karimi is on a distinguished road
Quote:
Originally Posted by doruk View Post
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.

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);
ali_karimi is offline   Reply With Quote

Old   January 17, 2018, 02:41
Default
  #10
New Member
 
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9
ali_karimi is on a distinguished road
Quote:
Originally Posted by obscureed View Post
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
Note that "begin_f_loop(f,tf){" has to be balanced at the end by "}end_f_loop(f,tf)" -- note this includes "}"! The code you posted gets this wrong and is therefore very confusing. (Note also there is no final ";", which in my opinion is inconvenient.) As doruk pointed out, you need PRF_GRHIGH1 if you running in parallel.

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.
Hi ED,
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);
Yes, I have to use the PRF_GRHIGH1 function, but I do not know how. Tell me please?
ali_karimi is offline   Reply With Quote

Old   January 17, 2018, 04:18
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
"max-y" is not a good variable name. You can not have a minus sign inside a variable name. Try "max_y" instead.
ali_karimi likes this.
pakk is offline   Reply With Quote

Old   January 17, 2018, 06:15
Default
  #12
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
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.
ali_karimi likes this.
obscureed is offline   Reply With Quote

Old   January 17, 2018, 11:56
Default
  #13
New Member
 
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9
ali_karimi is on a distinguished road
Quote:
Originally Posted by obscureed View Post
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.
tanx pakk and Ed,
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
but see this error when compile the udf:
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?
ali_karimi is offline   Reply With Quote

Old   January 18, 2018, 04:53
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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'.
ali_karimi likes this.
pakk is offline   Reply With Quote

Old   January 18, 2018, 11:32
Default
  #15
New Member
 
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9
ali_karimi is on a distinguished road
Quote:
Originally Posted by pakk View Post
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'.
yes.thats error is this:

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.
ali_karimi is offline   Reply With Quote

Old   January 18, 2018, 12:10
Smile
  #16
New Member
 
ali karimi
Join Date: Dec 2017
Posts: 7
Rep Power: 9
ali_karimi is on a distinguished road
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
ali_karimi is offline   Reply With Quote

Old   February 9, 2021, 12:21
Default Find and store maximum value at initial condition
  #17
New Member
 
Marcelo Ruiz
Join Date: Feb 2021
Location: Italy
Posts: 17
Rep Power: 5
CFDavatar is on a distinguished road
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)
}
CFDavatar is offline   Reply With Quote

Old   March 9, 2021, 00:59
Default
  #18
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
use macro DEFINE_ON_DEMAND to calculate something before first iteration
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ 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
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


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