CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Setting BC for each cell on face (https://www.cfd-online.com/Forums/fluent-udf/77649-setting-bc-each-cell-face.html)

Geisel June 29, 2010 15:39

Setting BC for each cell on face
 
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.

dmoroian July 1, 2010 06:15

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 [mhttp://www.cfd-online.com/Forums/vbL...587345c3-1.gif], 0.8 - area of the whole inlet surface [mhttp://www.cfd-online.com/Forums/vbL...587345c3-1.gif], 10 - desired magnitude of the mass flow
The idea is that e.g. we have 200 cells on that BC surface
http://www.cfd-online.com/Forums/vbL...fb720d82-1.gifhttp://www.cfd-online.com/Forums/vbL...df468663-1.gifhttp://www.cfd-online.com/Forums/vbL...7023d9db-1.gif  desired magnitude = desired magnitude */
  }
  end_f_loop(f, thread)
}

This should by a workable udf (although not very elegant).

Geisel July 2, 2010 02:22

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

dmoroian July 2, 2010 02:52

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)
...



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