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

distance between two cells

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 27, 2018, 01:56
Default distance between two cells
  #1
Member
 
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 9
annan is on a distinguished road
Hello everyone,

I want to compute the distance between cells in order to get dx and dy, so I thought I could use :

C_CENTROID(x0,c0,t0);
C_CENTROID(x1,c1,t1);

real dx = x1[0]-x0[0];
real dy = x1[1]-x0[1];

But it doesn't give me the right values I should get. I also tried using connectivity macros like INTERIOR_FACE_GEOMETRY(f,t,A,ds,es,A_by_es,dr0,dr1 ) to get ds, but still don't get the right values.

Thank you in advance for your help.
annan is offline   Reply With Quote

Old   February 27, 2018, 02:21
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
how do you define c0,t0,c1,t1 here?

Best regards
AlexanderZ is offline   Reply With Quote

Old   February 27, 2018, 02:31
Default
  #3
Member
 
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 9
annan is on a distinguished road
Thank you AlexanderZ for your reply.

I define them like the following :

t0 = THREAD_T0(t);
c0 = F_C0(f,t);

if (THREAD_TYPE(t)==THREAD_F_INTERIOR)
{
t1 = THREAD_T1(t);
c1 = F_C1(f,t);

... <the code I wrote in the first message is in here>

}

The overall is within a face loop.
annan is offline   Reply With Quote

Old   February 27, 2018, 02:41
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
in chapter 2.7.3.3. Example from UDF manual you can find something that can be used for your case
Code:
/**********************************************************************/
/* UDF that implements a simplified advective term in the */
/* scalar transport equation */
/**********************************************************************/
#include "udf.h"
DEFINE_UDS_FLUX(my_uds_flux,f,t,i)
{
cell_t c0, c1 = -1;
Thread *t0, *t1 = NULL;
real NV_VEC(psi_vec), NV_VEC(A), flux = 0.0;
c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);
F_AREA(A, f, t);
/* If face lies at domain boundary, use face values; */
/* If face lies IN the domain, use average of adjacent cells. */
if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/
{
real dens;
/* Depending on its BC, density may not be set on face thread*/
if (NNULLP(THREAD_STORAGE(t,SV_DENSITY)))
dens = F_R(f,t); /* Set dens to face value if available */
else
dens = C_R(c0,t0); /* else, set dens to cell value */
NV_DS(psi_vec, =, F_U(f,t), F_V(f,t), F_W(f,t), *, dens);
flux = NV_DOT(psi_vec, A); /* flux through Face */ }
else
{
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = F_C1_THREAD(f,t);
NV_DS(psi_vec, =, C_U(c0,t0),C_V(c0,t0),C_W(c0,t0),*,C_R(c0,t0));
NV_DS(psi_vec, +=, C_U(c1,t1),C_V(c1,t1),C_W(c1,t1),*,C_R(c1,t1));
flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */
}
/* ANSYS Fluent will multiply the returned value by phi_f (the scalar’s
value at the face) to get the ‘‘complete’’ advective term. */
return flux;
}
Here t0 and t1 are defined in other way
Code:
t0 = F_C0_THREAD(f,t);
t1 = F_C1_THREAD(f,t);
You may try to use this approach

Unfortunatelly, I can't test it

Best regards
AlexanderZ is offline   Reply With Quote

Old   February 27, 2018, 03:03
Default
  #5
Member
 
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 9
annan is on a distinguished road
Thank’s for your answer. I’ve tried to implement your suggestion, but it didn’t change anything to the obtained values...

Best regards
annan is offline   Reply With Quote

Old   February 27, 2018, 04:08
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
try this code
Code:
#include "udf.h"

DEFINE_ON_DEMAND(calc_distance)
{
	Thread *t,*t0, *t1 = NULL;
	cell_t c0, c1 = -1;
	face_t f;
	Domain *domain;
	real x0[ND_ND];
	real x1[ND_ND];
	int n = 0;
	real dx = 0.0, dy = 0.0;
	domain = Get_Domain(1);
	Message("Start on demand calc_distance\n");
	n = 0;
	thread_loop_f(t,domain)
	{
		begin_f_loop (f,t)
		{
			c0 = F_C0(f,t);
			t0 = F_C0_THREAD(f,t);
			if (BOUNDARY_FACE_THREAD_P(t))
				{}
			else
				{
				n+=1;
				t1 = F_C1_THREAD(f,t);
				c1 = F_C1(f,t);
				C_CENTROID(x0,c0,t0);
				C_CENTROID(x1,c1,t1);
				dx = x1[0]-x0[0];
				dy = x1[1]-x0[1];
				Message("dx = %f, dy = %f, number of pairs = %d\n",dx,dy,n);
				}
		}
		end_f_loop (f,t)
	}
	Message("End on demand calc_distance\n");
}
Best regards
AlexanderZ is offline   Reply With Quote

Old   February 27, 2018, 07:01
Default
  #7
Member
 
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 9
annan is on a distinguished road
Thank you very much for taking the time to write the code
I just tried to run it, I get the right dx. However the dy is not right ... i get some few points right but the other values are equal to zero (everywhere)
My grid is quad, uniform in the x direction (dx=constant) and variable in the y direction ( dy increases gradually). It’s an easy case normally
annan is offline   Reply With Quote

Reply

Tags
fluent - udf, fluent - udf - parallel, mesh 2d


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
[snappyHexMesh] SnappyHexMesh running killed! Mark JIN OpenFOAM Meshing & Mesh Conversion 7 June 14, 2022 01:37
Problem with divergence TDK FLUENT 13 December 14, 2018 06:00
[snappyHexMesh] Problem: after snappyHexMesh, the cells size are not the same kanes OpenFOAM Meshing & Mesh Conversion 0 January 25, 2016 08:06
[snappyHexMesh] snappyHexMesh matches wrong cells to CellZone Siegunn OpenFOAM Meshing & Mesh Conversion 4 July 31, 2015 05:10
snappyHexMesh in parallel - FOAM Fatal IO Error mturcios777 OpenFOAM Running, Solving & CFD 4 August 10, 2012 19:18


All times are GMT -4. The time now is 21:54.