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

Define_grid_motion udf

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By `e`
  • 1 Post By `e`
  • 1 Post By `e`
  • 1 Post By `e`

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 2, 2015, 14:05
Default Define_grid_motion udf
  #1
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
Hi
I have a UDF written for sinusoidal grid motion of a channel wall. It is compiled successfully but there is no motion on channel wall. I need someone who can identify the mistakes in my UDF.
I am really in need of some useful suggestions.
thank you
Code:
#include "udf.h"
#include "dynamesh_tools.h"
#include <stdlib.h>
#include <math.h>
#define AH 0.1 // Average Height of Channel
#define XL 2.0 // Length
#define WA 15 // Wave Amplitude
#define PI 3.1415925 
#define C 0.1 //Wave Speed
#define Lambda 0.5 // wavelength
#define XStep 0.01
#define XSize XL/XStep
#define HStep 0.0038
#define HSize AH/HStep

DEFINE_GRID_MOTION(peristaltic, domain, dt, time, dtime)
{

	Thread *tf = DT_THREAD(dt) ;
	int counter, i;

	face_t f ;
	float curr_time = CURRENT_TIME ; 
	float tmpv = 0;
	float sint = 0;
	float xVec[1001] ; 
	float hVec[1001] ; 
	xVec[0] = 0 ;

	for (counter = 1 ; counter < XSize ; counter++) 
	{
		xVec[counter] = xVec[counter - 1] + XStep; 
	}

	i = 1;
	begin_f_loop(f,tf)
	{
		curr_time = CURRENT_TIME;
		sint = sin(2 * PI/Lambda * (xVec[i]));	
		hVec[i] = AH + (WA * sint);		
		i = i  + 1;
	}
	end_f_loop(f,tf)

}
Attached Images
File Type: png channel image.png (8.1 KB, 64 views)
engrmansoor2534 is offline   Reply With Quote

Old   November 2, 2015, 16:22
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
You need to set the neighboring boundaries and interior zone as deforming (as well as apply your user-defined grid motion to the channel wall). A quick way to set the interior zone as deforming is within the UDF:

Code:
Thread *tf = DT_THREAD((Dynamic_Thread *)dt);
SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));
You may also need to apply deformation to the inlet and outlet if the motion is applied at the ends. For a 3-D case, the sides of the channel will also need to be set as deforming.

Perhaps to check your UDF and MDM settings, move the channel wall outwards with a linear motion (if this case works fine then the problem is with your sinusoidal code).
engrmansoor2534 likes this.
`e` is offline   Reply With Quote

Old   November 3, 2015, 02:41
Default
  #3
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
Thank you 'e' for your useful guidance as usual. As I mentioned earlier I don't have much knowledge about writing UDF's. Can you kindly write all the changes required in the UDF. you are right I need inlet, outlet and interior as deforming.
Best Regards
engrmansoor2534 is offline   Reply With Quote

Old   November 3, 2015, 03:50
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
An example of adding the code as I mentioned above (for the interior zone):

Code:
#include "udf.h"
#include "dynamesh_tools.h"
#include <stdlib.h>
#include <math.h>
#define AH 0.1 // Average Height of Channel
#define XL 2.0 // Length
#define WA 15 // Wave Amplitude
#define PI 3.1415925 
#define C 0.1 //Wave Speed
#define Lambda 0.5 // wavelength
#define XStep 0.01
#define XSize XL/XStep
#define HStep 0.0038
#define HSize AH/HStep

DEFINE_GRID_MOTION(peristaltic, domain, dt, time, dtime)
{

	Thread *tf = DT_THREAD(dt) ;
	int counter, i;

	face_t f ;
	float curr_time = CURRENT_TIME ; 
	float tmpv = 0;
	float sint = 0;
	float xVec[1001] ; 
	float hVec[1001] ; 
	xVec[0] = 0 ;

	SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));

	for (counter = 1 ; counter < XSize ; counter++) 
	{
		xVec[counter] = xVec[counter - 1] + XStep; 
	}

	i = 1;
	begin_f_loop(f,tf)
	{
		curr_time = CURRENT_TIME;
		sint = sin(2 * PI/Lambda * (xVec[i]));	
		hVec[i] = AH + (WA * sint);		
		i = i  + 1;
	}
	end_f_loop(f,tf)

}
Note that you'll still need to set the other boundaries as deforming via the GUI (the interior zone can also be specified in this way as well if you don't want to modify the UDF).
engrmansoor2534 likes this.
`e` is offline   Reply With Quote

Old   November 4, 2015, 00:20
Default
  #5
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
thank you 'e'. I will try this code along with your suggestions and will get back to you.
Best Regards
engrmansoor2534 is offline   Reply With Quote

Old   November 7, 2015, 03:54
Default
  #6
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
Quote:
Originally Posted by `e` View Post
You need to set the neighboring boundaries and interior zone as deforming (as well as apply your user-defined grid motion to the channel wall). A quick way to set the interior zone as deforming is within the UDF:

Code:
Thread *tf = DT_THREAD((Dynamic_Thread *)dt);
SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));
You may also need to apply deformation to the inlet and outlet if the motion is applied at the ends. For a 3-D case, the sides of the channel will also need to be set as deforming.

Perhaps to check your UDF and MDM settings, move the channel wall outwards with a linear motion (if this case works fine then the problem is with your sinusoidal code).
Dear 'e' I have done some changes to the UDF and also set the interior zone as deforming.
but instead of producing a sinusoidal deformation on the wall it only displaces by a certain amount.
I have given the full details in the links
https://www.dropbox.com/s/8blln9jxqz...image.png?dl=0
https://www.dropbox.com/s/o51wl5o2sb...nal_UDF.c?dl=0
https://www.dropbox.com/s/ke5pbl930d...annel.msh?dl=0
https://www.dropbox.com/s/jjn5rk7urx...annel.out?dl=0
whats wrong in my UDF? kindly help me out!!!
engrmansoor2534 is offline   Reply With Quote

Old   November 7, 2015, 07:01
Default
  #7
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The links you have provided are broken.

The x-position of each node can be retrieved using the NODE_X macro; instead of manually using an array ("xVec").

You've not moved any node positions in your UDF, and you should loop through the nodes of each face with "f_node_loop(f,tf,n)". Have a look at the examples in the UDF manual.
`e` is offline   Reply With Quote

Old   November 7, 2015, 11:42
Default Define_grid_motion UDF
  #8
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
Thank you 'e' for your quick response. Sorry for the broken links. I have given the links again below.
kindly take a look at them. also the image on order to view the current deformation produced in the channel.
https://www.dropbox.com/s/ke5pbl930d...annel.msh?dl=0
https://www.dropbox.com/s/jjn5rk7urx...annel.out?dl=0
https://www.dropbox.com/s/o51wl5o2sb...nal_UDF.c?dl=0
https://www.dropbox.com/s/8blln9jxqz...image.png?dl=0
I will also refer to the UDF manual. can you kindly give which specific version of UDF manual does contain an example like mine. can you share a link
Best regards
engrmansoor2534 is offline   Reply With Quote

Old   November 7, 2015, 17:53
Default
  #9
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
For reference, the UDF you're currently using is copied below. This new version includes the f_node_loop and should be deforming the mesh boundary. Any version of the UDF manual should be fine to read an example from, but preferably use the same version number as your Fluent installation. Have a read of the DEFINE_GRID_MOTION section: it won't have your exact case (sinusoidal deformation) but has the required tools.

It's unclear why you're scanning an output file ("channel.out") to read in the node positions (use the NODE_X, NODE_Y and NODE_Z macros instead). You've set the variable "x=3;" on line 47 and then used this value for your sine function, giving a constant value for all nodes (regardless of their actual x-position).

Code:
#include "udf.h"
#include "dynamesh_tools.h"
FILE *fout;
DEFINE_GRID_MOTION(peristaltic, domain, dt, time, dtime)
{
 
    Thread *tf= DT_THREAD(dt);
 
    face_t f;
    Node *v;
    real NV_VEC(A);
    real NV_VEC(dx);
    real previous_time;
    real AH;  
    real WA; 
    real PI; 
    real c;
    real x;
    real Lambda; 
    real sint;
    real hVec;
int n;
float f1;
float f2;
    float npx[301] ; 
    float npy[301] ; 
int v1;
int i;
char buffer[100];
fout = fopen("channel.out", "r");
fgets(buffer,100,fout);
while(feof(fout)==0)
{
fscanf(fout, "%d %f %f\n", &v1, &f1, &f2);
npx[v1]=f1;
npy[v1]=f2;
}
fclose(fout);
i = 1;
begin_f_loop(f,tf)
 {
    previous_time =PREVIOUS_TIME;
F_AREA(A,f,tf);
PI = 3.1415925;
Lambda = 0.5;
c= 0.5;
x=3;
AH = 0.5;
WA = 0.2;
    sint = sin(2 * PI/Lambda)*(x - c*time); 
    hVec = AH - (WA * sint);        
dx[0] = (A[0]/NV_MAG(A)*hVec);
dx[1] = (A[1]/NV_MAG(A)*hVec);
     
    f_node_loop(f,tf,n)
{
v = F_NODE(f,tf,n);
/* update node if the current node has not been previously */
/* visited when looping through previous faces */
if ( NODE_POS_NEED_UPDATE (v))
{
/* indicate that node position has been update */
/*so that it's not updated more than once */
    NODE_POS_UPDATED(v);
    NODE_COORD(v)[0]=dx[0]+npx[i];
    NODE_COORD(v)[1]=dx[1]+npy[i];
        i=i+1;
        }
    }
}
end_f_loop(f,tf);
}
engrmansoor2534 likes this.
`e` is offline   Reply With Quote

Old   November 8, 2015, 06:43
Default
  #10
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
Dear 'e' I have used the .out file concept from an example similar to mine. I have studied the example given in UDF manual. but I can not understand neither find the meaning of the syntax used. can you kindly explain a bit.
Code:
* node motion based on simple beam deflection equation
 * compiled UDF
 *
 **********************************************************/
#include "udf.h"

DEFINE_GRID_MOTION(beam, domain, dt, time, dtime)
{
  Thread *tf = DT_THREAD (dt);
  face_t f;
  Node *v;
  real NV_VEC (omega), NV_VEC (axis), NV_VEC (dx);
  real NV_VEC (origin), NV_VEC (rvec);
  real sign;
  int n;
  
  /* set deforming flag on adjacent cell zone */
  SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));

  sign = -5.0 * sin (26.178 * time);
  
  Message ("time = %f, omega = %f\n", time, sign);
  
  NV_S (omega, =, 0.0);
  NV_D (axis, =, 0.0, 1.0, 0.0);
  NV_D (origin, =, 0.0, 0.0, 0.152);
  
  begin_f_loop (f, tf)
    {
      f_node_loop (f, tf, n)
        {
          v = F_NODE (f, tf, n);

          /* update node if x position is greater than 0.02
             and that the current node has not been previously
             visited when looping through previous faces */
          if (NODE_X (v) > 0.020 && NODE_POS_NEED_UPDATE (v))
            {
              /* indicate that node position has been update
                 so that it's not updated more than once */
              NODE_POS_UPDATED (v);

              omega[1] = sign * pow (NODE_X (v)/0.230, 0.5);
              NV_VV (rvec, =, NODE_COORD (v), -, origin);
              NV_CROSS (dx, omega, rvec);
              NV_S (dx, *=, dtime);
              NV_V (NODE_COORD (v), +=, dx);
            }
        }
    }
  end_f_loop (f, tf);
}
specially the bold lines
thank you for your time
engrmansoor2534 is offline   Reply With Quote

Old   November 8, 2015, 17:39
Default
  #11
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
First, instead of using vectors it might be clearer (and simpler) to specify values on a component basis. For example, use dx, dy and dz for displacements instead of a single vector (dx).

The vector operations below match the equations in the manual.

Code:
real NV_VEC (omega), NV_VEC (axis), NV_VEC (dx);
real NV_VEC (origin), NV_VEC (rvec);
Declaring vectors omega, axis, dx, origin and rvec. A vector has a scalar value in each direction. For example, x, y and z in 3-D Cartesian coordinates.

Code:
Message ("time = %f, omega = %f\n", time, sign);
Prints the current simulation time and current omega value (their example is of the deflection on a cantilever beam).

Code:
NV_S (omega, =, 0.0);
NV_D (axis, =, 0.0, 1.0, 0.0);
NV_D (origin, =, 0.0, 0.0, 0.152);
Initialises the vectors. NV_S for uniform values and NV_D for non-uniform values.

Code:
omega[1] = sign * pow (NODE_X (v)/0.230, 0.5);
Evaluates omega in the y-direction (array entries start from zero).

Code:
NV_VV (rvec, =, NODE_COORD (v), -, origin);
Vector operation such that rvec yields the displacement vector between the node and origin.

Code:
NV_CROSS (dx, omega, rvec);
Cross product: dx = omega x rvec.

Code:
NV_S (dx, *=, dtime);
Scalar multiplication: dx = dx*dtime (dtime is the deforming mesh time step; a scalar value).

Code:
NV_V (NODE_COORD (v), +=, dx);
Vector addition for updating node coordinates: NODE_COORD = NODE_COORD + dx.
engrmansoor2534 likes this.
`e` is offline   Reply With Quote

Old   November 9, 2015, 12:33
Default
  #12
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
thanks alot 'e'. I am trying to modify the UDF according to your suggestions. I hope it will fulfill my requirements.
I will be in touch with you.
Best Regards
engrmansoor2534 is offline   Reply With Quote

Old   January 18, 2016, 10:34
Default
  #13
New Member
 
giulia
Join Date: Jan 2016
Posts: 2
Rep Power: 0
Cinnamon is on a distinguished road
hello, i'm wondering how the file "channel.out" is organised! Thank you !
Cinnamon is offline   Reply With Quote

Old   January 18, 2016, 17:13
Default
  #14
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The file "channel.out" includes a column for the node number, x-coordinate and y-coordinate. This file is posted above and I've copied the first few lines below:

Code:
nodenumber     x-coordinate     y-coordinate 
         1  3.000000000E+00  5.000000000E-01 
         2  2.990000010E+00  5.000000000E-01 
         3  2.980000019E+00  5.000000000E-01 
         4  2.970000029E+00  5.000000000E-01 
         5  2.960000038E+00  5.000000000E-01
However, you should be able to calculate the new nodal positions within the UDF instead of opening an external file.
`e` is offline   Reply With Quote

Old   January 19, 2016, 01:55
Default
  #15
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
If you are interested in obtaining channel.out file. click on export solution data in file menu. there you can export a number of parameters including the nodal positions.
engrmansoor2534 is offline   Reply With Quote

Old   January 19, 2016, 06:25
Default
  #16
New Member
 
giulia
Join Date: Jan 2016
Posts: 2
Rep Power: 0
Cinnamon is on a distinguished road
Thank you! i'm traying to export the displacements of structures nodes from LS-Dyna in a file.txt, which will be the opening file in the UDF- Grid motion. I have some hesitations about the difference of numeration of nodes from LSDyna and Fluent and the corrispondence of these nodes.
Cinnamon 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
WILLING TO PAY/ FREELANCER REQUIRED / small UDF coding force loads over body / 6DOF acasas CFD Freelancers 1 January 23, 2015 08:26
Source Term UDF VS Porous Media Model pchoopanya Fluent UDF and Scheme Programming 1 August 28, 2013 07:12
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 22:38
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01


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