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

Setting BC for each cell on face

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 29, 2010, 16:39
Default Setting BC for each cell on face
  #1
New Member
 
Luk
Join Date: Jun 2009
Posts: 24
Rep Power: 17
Geisel is on a distinguished road
Dear all

I am trying to do something completely new for me, and my UDF skills do not permit me to prepare this. I would be grateful for any help.

The problem is to set a BC (mass flow inlet) in that way that each cell would have different magnitude (accordingly to its area) and the sum of it for all cells would be my total mass flow inlet.

I have tried to use both C_VOLUME and F_AREA macros but nothing worked. I thought that the result is compared with one of them.


My code cannot work unless I fill it with proper macros or function, but put there some of my thoughts how this should work in my opinion.
If that changes anything, the case is 3D x,y - horizontal coords z-vertical coord

Code:
#include "udf.h"
DEFINE_PROFILE(xyz, thread, position)
{
real x[ND_ND];
real A[ND_ND];
real area, vol; /*area for F_AREA, vol for C_VOLUME*/

face_t f;

begin_f_loop(f, thread) /* I understand that f_loop macro need to be set on face only*/
{
F_CENTROID(x,f,thread); /*this will keep centroid coordinates of each cell*/
area=F_AREA(A,f,thread);/*this did not work/*
vol=C_VOLUME(c,thread);/*this either*/
/*of course, according to used macros (area or vol) the variables will differ/*
F_PROFILE(f, thread, position)= (area/0.8)*10; 
/* area - cell area [m^{2}], 0.8 - area of the whole inlet surface [m^{2}], 10 - desired magnitude of the mass flow
The idea is that e.g. we have 200 cells on that BC surface 
\sum\frac{area-of-cell}{total-area-of-surface}\times  desired magnitude = desired magnitude */
}
end_f_loop(f, thread)
}
I hope someone can help me, and please do not be trenchant if the problem is easy to solve

Regards.
__________________
*******************************
Geisel is offline   Reply With Quote

Old   July 1, 2010, 07:15
Default
  #2
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Code:
#include "udf.h"
DEFINE_PROFILE(xyz, thread, position)
{
   real A[ND_ND];
   real area; /*area for F_AREA*/

   face_t f;

   begin_f_loop(f, thread)
   {
      F_AREA(A,f,thread);
      area = NV_MAG(A);
      F_PROFILE(f, thread, position)= (area/0.8)*10; 
/* area - cell area [m], 0.8 - area of the whole inlet surface [m], 10 - desired magnitude of the mass flow
The idea is that e.g. we have 200 cells on that BC surface 
  desired magnitude = desired magnitude */
   }
   end_f_loop(f, thread)
}
This should by a workable udf (although not very elegant).
dmoroian is offline   Reply With Quote

Old   July 2, 2010, 03:22
Default
  #3
New Member
 
Luk
Join Date: Jun 2009
Posts: 24
Rep Power: 17
Geisel is on a distinguished road
Thank you dmoroian very much for you attention and help.

I have put your code into my case, but unfortunatelly the results are not desired one. I will prepare 4-cell face and thoroughly test it. Perhaps this fixed magnitude 0.8 is a problem.


Maybe you or someone else could help or advice me in another matter.
These two codes (mass flow and this one) will be eventually in one code.

I have prepared code:
Code:
#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, position)
{
real x[ND_ND];
face_t f;

begin_f_loop(f, thread)
{
F_CENTROID(x, f, thread);
if (x[1]<x[0] && x[0]<-x[1])
{
F_PROFILE(f, thread, position)= 10.; /* mass flow = magnitude related to area of all cells, for now is fixed*/
/*}
else
{
F_PROFILE(f, thread, position)= 0; /* mass flow = 0 */
/*}
end_f_loop(f, thread)
}}
The main purpose of it is to create a virtual obstacle on BC. The face is a circle and the obstacles or openings are sectors of the circle. It is working for steady analysis.


And now I would like to set it on transient case. The obstacles or openings are rotating around the center.
Code:
#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, position)
{
real x[ND_ND];
real t=CURRENT_TIME;
double angle,angle2,sinangle,cosangle;
face_t f;
begin_f_loop(f, thread)
{
angle=6*t; /* assumption: each second --> 6 grad of rotation*/
angle2=angle+90
sinangle=sin(angle2);
cosangle=cos(angle);
F_CENTROID(x, f, thread);
/* 0.5 --> radius */
if (x[1]<0.5*cosangle && x[0]<0.5*sinangle)
{
F_PROFILE(f, thread, position)= 10; /* mass flow = magnitude related to area of all cells, for now is fixed */
}
else
{
F_PROFILE(f, thread, position)= 0; /* mass flow = 0 */
}
end_f_loop(f, thread)
}}
It is only for one quadrant of cartesian coordinates system, formulas for x and y has been converted from polar coordinate. Probably I will have to use atan2 function to achive the correct values in each quadrant.

Maybe someone created something like that and could provide me with the code or help me to understand the C++ syntax in that case? I assume there will be loop in the loop.

Regards
__________________
*******************************
Geisel is offline   Reply With Quote

Old   July 2, 2010, 03:52
Default
  #4
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
My point with "this should be a workable udf" was that is clean and you should start from here, not use it as it is.
One thing that you have to modify is the hardcoded value of the total area. This should be computed using a loop over all faces:
Code:
...
   float totalArea = 0;
 
   begin_f_loop(f, thread)
   {
      F_AREA(A,f,thread);
      totalArea += NV_MAG(A);
   }
   end_f_loop(f, thread)
...
dmoroian 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
Cells with t below lower limit Purushothama Siemens 2 May 31, 2010 22:58
[blockMesh] BlockMeshmergePatchPairs hjasak OpenFOAM Meshing & Mesh Conversion 11 August 15, 2008 08:36
fluent add additional zones for the mesh file SSL FLUENT 2 January 26, 2008 12:55
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 05:15
Warning 097- AB Siemens 6 November 15, 2004 05:41


All times are GMT -4. The time now is 03:39.