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

Periodic BC in ANSYS DDPM, UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 7, 2016, 23:58
Default
  #21
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
Friend, now UDF is working fine and created .txt file (when particle touch outlet boundary). My problem, UDF is creating Lacs of rows and one column. I am taking only 1042 particles. After analyze, I saw particles are not recycling. All is fine, but particle after reach to outlet boundary remains there as it is. This is the main problem. Pls tell, why particle not recycle even i made outlet diameter in such a way that only one one-one particle reach to outlet boundary.
Thanks a lot
roopesh99 is offline   Reply With Quote

Old   February 9, 2016, 00:52
Default
  #22
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The UDF is only called at the outlet when particles reach the outlet boundary (and are recycled back to the inlet at x = 0 m); then and only then are the particle positions written to the text file.

Considering you have a number of lines of text in the file suggests particles have been recycled. There is no end state for the particles (they will loop from outlet to inlet unless they escape elsewhere) and therefore the number of recycled particles could exceed the number of injected particles (1042).
`e` is offline   Reply With Quote

Old   February 9, 2016, 02:27
Default
  #23
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
Thanks a lot, but my problem is particles not recycling even i tried the PATH_ACTIVE, PATH_END, PATH_BREAK, PATH_STOP as well as PATH_ABORT, also tried P_POS(p)[0] = 0.0 and P_POS(p)[0] = 0.15
Thanking You

Last edited by roopesh99; February 9, 2016 at 07:45.
roopesh99 is offline   Reply With Quote

Old   February 9, 2016, 18:51
Default
  #24
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
I've investigated this problem and there's a couple of tricks:
  • The P_POS macro doesn't modify the particle position from DEFINE_DPM_BC calls
  • The P_POS macro doesn't modify the particle position for steady tracking (use unsteady tracking instead)

My test case was a 1 m cube domain centred about (0.5,0,0) with an inlet velocity of 1 m/s (left), pressure outlet (right) and the side walls were of type symmetry. The mesh had 12 elements in each direction (each cell length was 0.08333... m).

Use the DEFINE_DPM_BC macro to keep the particle tracked at the outlet boundary and use the DEFINE_DPM_SCALAR_UPDATE macro to shift the particle from the outlet (beyond some critical x position) to the inlet. See below for my UDF, you'll need to enable two user-defined scalars for the particles (Define > Models... > Discrete Phase > UDF > User Variables). The first UDS is for counting the number of times a parcel has recycled and the second UDS is for a fix (the scalar macro is sometimes called a couple of times when the parcel reaches the outlet).

Code:
#include "udf.h"

DEFINE_DPM_BC(continue_tracking,p,t,f,f_normal,dim)
{
	return PATH_ACTIVE;
}

DEFINE_DPM_SCALAR_UPDATE(recycle_particles,c,t,initialize,p)
{
	FILE *fp;

	if (P_POS(p)[0]<0.08333)
	{
		P_USER_REAL(p,1) = 0.;
	}
	
	if (P_POS(p)[0]>0.91667 && P_USER_REAL(p,1) == 0.)
	{
		// save particle position to a text file
		fp=fopen("recycleparticles.txt", "a"); // x, y, z particle positions [m], particle ID [#] and time [s]
		fprintf(fp,"%e %e %e %d %e\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],p->part_id,P_TIME(p));
		fclose(fp);

		// save the number of times this particle has been recycled
		P_USER_REAL(p,0) = P_USER_REAL(p,0) + 1.;
		P_USER_REAL(p,1) = 1.;

		// send particle to the inlet boundary
		P_POS(p)[0] = 0.;
		P_POS(p)[1] = P_POS(p)[1] + 0.0833;
	}
}
The first attachment shows the particles gradually moving up through the domain (I've displaced the particles when they've reached the outlet by one cell height to show they have recycled) and are coloured by the number of recycled times. The second attachment is a side view of the same simulation.
Attached Images
File Type: png recycledparticles.png (58.7 KB, 65 views)
File Type: png recycledparticles2.png (11.3 KB, 43 views)
FarzinD likes this.
`e` is offline   Reply With Quote

Old   February 10, 2016, 00:24
Default
  #25
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
you udf is not compiling. i made cube 1m with center (0,0,0), x-y in hz and z-vertical. Inlet from bottom and outlet from top. what is the problem with that. it will be good if send case file so that i can analyze the given udf my case point of view.
Thank you

Last edited by roopesh99; February 11, 2016 at 03:03.
roopesh99 is offline   Reply With Quote

Old   February 11, 2016, 05:06
Default
  #26
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
My UDF compiled fine on my system, what error are you getting while compiling? If you have a different domain then you'll need to modify the UDF to reflect those changes. The main difference with your case (inlet at the bottom, outlet at the top and the centre at the origin) can be customised for by modifying which particle positions are used. Note that these positions are available as macros in the x (P_POS(p)[0]), y (P_POS(p)[1] and z (P_POS(p)[2]) directions.
`e` is offline   Reply With Quote

Old   February 11, 2016, 06:25
Default
  #27
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
Thanks friend, now udf is compiling. But I am confuse in your udf which axis is inlet. I am taking z axis as inlet and outlet. x and y as wall. My center is at the bottom vertex of z.
roopesh99 is offline   Reply With Quote

Old   February 11, 2016, 06:28
Default
  #28
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
My inlet was on the left side of the cube in the YZ plane (x = 0 m, y and z both ranged from -0.5 m to +0.5 m).
`e` is offline   Reply With Quote

Old   February 11, 2016, 13:51
Default
  #29
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
Dear friend,
i tried one example case same 1m cube with yz plane as velocity inlet as well as pressure outlet, still problem same as before as well as recycleparticles.txt not generated. [In my actual case inlet will be in x-y plan and z axis will be in vertical direction and origin (0,0,0)]
Attached Files
File Type: zip example.zip (149.7 KB, 17 views)
roopesh99 is offline   Reply With Quote

Old   February 12, 2016, 00:31
Default
  #30
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The text file is saved to the local Fluent working directory because a relative (instead of absolute) directory location was provided. For example:

Code:
...\DPMrecycle\DPMrecycle_files\dp0\FFF\Fluent\recycleparticles.txt
`e` is offline   Reply With Quote

Old   February 12, 2016, 03:12
Default
  #31
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
see the attached jpg run file. Also in the working folder no recycleparticles.txt. I want also where the command execute "fprintf(fp,"%e %e %e %d %e\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],p->part_id,P_TIME(p));"
Attached Images
File Type: jpg Picture1.jpg (107.5 KB, 30 views)
roopesh99 is offline   Reply With Quote

Old   February 12, 2016, 03:37
Default
  #32
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Where have you saved your Workbench project and does Fluent have access to writing files there? Try saving the text file to an external hard drive or anywhere outside the Program Files folder or My Documents.
`e` is offline   Reply With Quote

Old   February 29, 2016, 01:36
Default
  #33
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
Dear Friend,
check the attached case and UDF. Send me one case with udf and i will understand that and try to modify for my vertical direction outlet case. Also pls tell what is the means of P_USER_REAL(p,1) and P_USER_REAL(p,0) in the udf.
Thanks.
Attached Files
File Type: zip pls check.zip (149.7 KB, 15 views)

Last edited by roopesh99; February 29, 2016 at 12:13.
roopesh99 is offline   Reply With Quote

Old   February 29, 2016, 19:31
Default
  #34
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
You hadn't enabled the scalar update macro, via: Define > Models > Discrete Phase > UDF > User-Defined Functions > Scalar Update. Note: you need to define two user-defined scalars (under user variables of the same dialog box).
`e` is offline   Reply With Quote

Old   March 1, 2016, 22:14
Default
  #35
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
Thanks a lot friend, now code is working and i already run it for 10 no. of particles and i saw particles recycle properly. See the attached generated txt file. In the txt file second last column printing contentiously the same particle 2 to 6 times with millisecond time difference. May be possible, i am using 0.025 m diameter particle (big size particles). But, i want only once reporting time for that i.d. particle in the txt file when that particle cross the outlet boundary or in other word it should not depend on particle size. See the second last column of attached result .txt file.
Also wt is the means of "p->part_id" [Is it used to provide the particle ID?]
[fprintf(fp,"%e %e %e %d %e\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],p->part_id,P_TIME(p));]
And wt is the means of P_USER_REAL(p,0) = P_USER_REAL(p,0) + 1.;
P_USER_REAL(p,1) = 1.; [Is it related with initial and 1st time-step?]
Thanks for guiding and help..
Attached Files
File Type: txt recycleparticles.txt (5.4 KB, 23 views)
File Type: c 31n7.c (883 Bytes, 28 views)

Last edited by roopesh99; March 2, 2016 at 00:41.
roopesh99 is offline   Reply With Quote

Old   March 2, 2016, 16:53
Default
  #36
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by roopesh99 View Post
In the txt file second last column printing contentiously the same particle 2 to 6 times with millisecond time difference. May be possible, i am using 0.025 m diameter particle (big size particles). But, i want only once reporting time for that i.d. particle in the txt file when that particle cross the outlet boundary or in other word it should not depend on particle size. See the second last column of attached result .txt file.
I've tried using the larger particle diameter of 0.025 m and it's still working fine (no repetitions in the text file). I used that second user-defined memory location in the particles to avoid duplicate entries (flags particles when they reach the outlet, and then resets at inlet). Perhaps try running the simulations in serial, otherwise, remove duplicate entries outside of Fluent (manually for small numbers, or MATLAB/similar for automating).

Quote:
Originally Posted by roopesh99 View Post
Also wt is the means of "p->part_id" [Is it used to provide the particle ID?]
[fprintf(fp,"%e %e %e %d %e\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],p->part_id,P_TIME(p));]
Yes.

Quote:
Originally Posted by roopesh99 View Post
And wt is the means of P_USER_REAL(p,0) = P_USER_REAL(p,0) + 1.;
P_USER_REAL(p,1) = 1.; [Is it related with initial and 1st time-step?]
This first user-defined particle value counts the number of times the particle is recycled from the outlet to inlet. I've coloured the particles by this count in my previous post.
`e` is offline   Reply With Quote

Old   March 3, 2016, 00:24
Default
  #37
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
Dear Friend
what is the means of "I used that second user-defined memory location in the particles to avoid duplicate entries (flags particles when they reach the outlet, and then resets at inlet). "
i think it is (P_POS(p)[0]>0.91667 && P_USER_REAL(p,1) == 0.)?
Also pls explain wt is the role of this line "P_POS(p)[0]>0.91667 && P_USER_REAL(p,1) == 0." in the udf?
Thanks a lot
roopesh99 is offline   Reply With Quote

Old   March 3, 2016, 00:46
Default
  #38
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by roopesh99 View Post
what is the means of "I used that second user-defined memory location in the particles to avoid duplicate entries (flags particles when they reach the outlet, and then resets at inlet). "
i think it is (P_POS(p)[0]>0.91667 && P_USER_REAL(p,1) == 0.)?
Yes, the second user-defined memory location corresponds to P_USER_REAL(p,1). In that line of code you've quoted, the code block is only run when P_USER_REAL(p,1) is false ("0"); i.e. when this particle has not yet been marked at the outlet. This code block is skipped if this particle is already flagged (to avoid duplicate entries).

Quote:
Originally Posted by roopesh99 View Post
Also pls explain wt is the role of this line "P_POS(p)[0]>0.91667 && P_USER_REAL(p,1) == 0." in the udf?
As above, and the first portion checks to see if this particle is near the outlet (we've defined it as x > 0.91667 m in this case).
`e` is offline   Reply With Quote

Old   March 3, 2016, 11:53
Default
  #39
Member
 
Rupesh Verma
Join Date: Jun 2013
Posts: 64
Rep Power: 13
roopesh99 is on a distinguished road
Dear Friend
I am trying this for vertical column. But i want to ask that "P_USER_REAL(p,0) and P_USER_REAL(p,1) are represent to axis x and y or UDS 1 and 2? Because now I am trying to modify this where xy is base and z as height.
Thanks a lot

Last edited by roopesh99; March 4, 2016 at 00:41.
roopesh99 is offline   Reply With Quote

Old   March 8, 2016, 18:08
Default
  #40
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by roopesh99 View Post
I am trying this for vertical column. But i want to ask that "P_USER_REAL(p,0) and P_USER_REAL(p,1) are represent to axis x and y or UDS 1 and 2? Because now I am trying to modify this where xy is base and z as height.
To clarify, the setup I've used was a cube with particles entering from the left and 'recycling' on the right (along the x-axis); a 'horizontal column'. If you're now inserting particles along the z-axis, a 'vertical column', then you'll need to update the P_POS macros with the z-direction.

For example, setting the particle position in the z-direction to zero would be done with:

Code:
P_POS(p)[2] = 0.;
The user-defined variables for the particles, P_USER_REAL, are not related to the physical coordinates. These lines of code are unaffected by the orientation of the domain.
`e` 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
UDF for periodic boundary condition Angeline Fluent UDF and Scheme Programming 6 November 7, 2015 01:08
Periodic model for ansys cfx jayendrajpatel CFX 3 January 21, 2015 17:44
Ansys FLUENT UDF - Velocity profile (of known values) across edge / surface emmkell FLUENT 0 October 20, 2011 08:37
Compiling UDF in Ansys Fluent12 Vishu Fluent UDF and Scheme Programming 2 October 5, 2011 10:09
Ansys meshing of two-phase periodic domain kcsmith ANSYS Meshing & Geometry 11 March 9, 2011 22:08


All times are GMT -4. The time now is 18:04.