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

How does connectivity macros work for cell zones

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By obscureed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 23, 2017, 08:29
Default How does connectivity macros work for cell zones
  #1
New Member
 
Doruk Yelkenci
Join Date: Apr 2017
Posts: 20
Rep Power: 9
doruk is on a distinguished road
Hello everyone,

I am trying to find values of the adjacent cells of a cell and then use these values for the cell. I have found F_C0 and F_C1 macros from the help but using these macros are not explained clearly.

For example if a cellzone with only hex elements, C1 is the index for all the cells around C0 so it must consist of 6 cells. So if i use C_T(c1,t), from which of these cell it takes its value? or just finds the average of all C1 cells ?
doruk is offline   Reply With Quote

Old   January 12, 2018, 07:35
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Doruk,

F_C0 and THREAD_T0 look up the cell adjacent to a *face*, not a cell. For an interior face, there is also a cell on the other side, F_C1 and THREAD_T1. So, if you want to look up all the cells that lie adjacent to a specific cell, you need to loop over all faces of that cell, and for each face work out whether (c0,t0) or (c1,t1) is the neighbour. Remember that some faces of some cells will be boundary faces, with no neighbouring cell; and some neighbouring cells might be solid cells, which do not have fluid-style data

Fluent has many capabilities, and this can lead to difficult cases: hanging nodes, dynamic mesh, adaption, non-conformal interfaces, etc. When you start looking at neighbouring cells, it is difficult to write UDFs that can deal with all these capabilities, and you should probably try to deal with only the ones relevant to your case -- just be aware that your UDFs will work on a restricted feature set.

The most frequent complication is running in parallel. This will mean that some neighbours of a cell might "belong" to different partitions, perhaps on physically separate computers. The good news is that one layer of neighbours is copied over from these other partitions. So, looking at neighbours is safe in parallel -- so long as you only loop over interior cells. Look for documentation of the "interior cell looping macro" begin_c_loop_int. It is extremely difficult to look at neighbours-of-neighbours in parallel.

So, here's a skeleton of the code you might want:
Code:
  Thread *t,*tf,*t0,*t1,*tn;
  cell_t c,c0,c1,cn;
  face_t f;
  int n;

  ... here find the cell-thread t that you want to work on

  begin_c_loop_int(c,t)
  {
    c_face_loop(c,t,n)
    {
      f = C_FACE(c,t,n);
      tf = C_FACE_THREAD(c,t,n);
      c0 = F_C0(f,tf);
      t0 = F_C0_THREAD(f,tf);
      c1 = F_C1(f,tf);
      t1 = F_C1_THREAD(f,tf);

      tn = NULL;
      if(t0 != NULL &&
          (c != c0 || THREAD_ID(t0) != THREAD_ID(t))) {
        /* ... (c0,t0) is a neighbouring cell   */
        tn = t0;
        cn = c0;
      }
      else if(t1 != NULL &&
          (c != c1 || THREAD_ID(t1) != THREAD_ID(t))) {
        /* ... (c1,t1) is a neighbouring cell  */
        tn = t1;
        cn = c1;
      }
      if(tn != NULL) {
        ... do something with the neighbour (cn,tn) here ...
          (not forgetting to check, for example, solid cell zones)
      }
    }
  }
  end_c_loop_int(c,t)
I have not actually compiled this code, and it might have some inefficiencies: t0 should never be NULL, given the way that we have found it. I'm not sure whether cells in different cell-threads are guaranteed to have different cell numbers -- if so, we could detect a different cell simply by (c!=c0) and not bother comparing thread pointers or their THREAD_ID.
Best regards,
Ed
mamama797979 likes this.
obscureed is offline   Reply With Quote

Old   March 2, 2018, 10:15
Default
  #3
New Member
 
Doruk Yelkenci
Join Date: Apr 2017
Posts: 20
Rep Power: 9
doruk is on a distinguished road
Hi Ed,
Thanks for taking time to explain.

I think I understand now. An interior face is between 2 cells. Such as 1223th face is between 7987th cell and 3435th cell c1 and c0 respectively. 3435th cell has 6 faces, 1223th face 2345th face, .... etc. and C1 varies for each face.

For a simple case where all the cell elements are cube with same dimensions, Lets say if i want to find the neighboring cell at the top of a cell, I should just find the face at the top of c0 by coordinates of face compared to c0, then ask for c1. In code;

begin_c_loop_int(c,t)
{
c_face_loop(c,t,n)
{
f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);
c0 = F_C0(f,tf);
t0 = F_C0_THREAD(f,tf);
c1 = F_C1(f,tf);
t1 = F_C1_THREAD(f,tf);
C_CENTROID(xc,c0,t0);
F_CENTROID(xf,f,tf);
if(xf[2]>xc[2])
{
C_UDMI(c,t,1)=C_T(c1,t1);
}


We can make a workaround in parallel by giving all the necessary data to the node-zero then making calculations only for node zero and after that sending the data to all other nodes. I have done something like this when global reduction macros was bugged for my case and there is an example of it in user guide. It can make simulation very slow for some cases(when element number is very high or using super computer with 100 cores) but it works nonetheless.

Best Regards,
Doruk
doruk is offline   Reply With Quote

Old   June 12, 2020, 00:47
Default
  #4
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 207
Rep Power: 16
arunraj is on a distinguished road
Hello guys, I have a similar problem as yours. I would like to apply DEFINE_SOURCE only on the interior face. Is there any way you can help me with the UDF?
arunraj is offline   Reply With Quote

Old   June 15, 2020, 04:55
Default Source
  #5
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Sources are volumetric and a source for a face is nothing but a flux. So, either apply a flux or apply sources in the cells adjacent to the faces.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 15, 2020, 05:33
Default
  #6
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 207
Rep Power: 16
arunraj is on a distinguished road
Dear Vinerm, Thank you for your reply. How to apply sources to the cells adjacent to the interior or wall. I have made the source term as below. I did based on ID.

#include "udf.h"
#include "math.h"

#define M 18.015
#define hfg 2600000.0
#define R 8314.0
#define pi 3.141592
#define pref 101325
#define Tref 373.15
#define pv 15828.0
#define Tv 343.0

DEFINE_SOURCE(massliqcond,c,t,dS,eqn)
{
real source, pv_eq, Tlv, vol;
Domain *d=Get_Domain(1);
int ID=11;
Thread *t_int=Lookup_Thread(d, ID);
face_t f;
real A[ND_ND];
real area = 0.0;
{
begin_c_loop(c,t)
{
int i = 0;
f=C_FACE(c,t,i);
F_AREA(A,f,t_int);
area = 2*pi*NV_MAG(A);
Tlv = C_T(c,t);
vol = C_VOLUME(c,t);
pv_eq = pref * exp(((M*hfg)/R) * ((1/Tref)-(1/Tlv)));
source = 0.857142857 * (area/vol) * (1/pow(M/2*pi*R, 0.5)) * ((pv_eq/pow(Tlv, 0.5)) - (pv/pow(Tv, 0.5)));
dS[eqn] = 0.857142857 * (area/vol) * (1/pow(M/2*pi*R, 0.5)) * (pref * exp((M*hfg)/R) * (-((1/Tref) * (0.5/pow(Tlv, 1.5))) + (1.5/pow(Tlv, 2.5))));
}
end_c_loop(c,t)
}
return source;
}
arunraj is offline   Reply With Quote

Old   June 15, 2020, 06:13
Default Source Terms
  #7
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
It has to be done in two parts

First, identify the cells where source needs to be added, such as, all the cells adjacent to a particular boundary. If these cells are fixed, i.e., their number and identification, then you can also separate those out as a separate cell zone. If you do not want to do that, then run a DEFINE_ON_DEMAND function that goes over the face loop of the boundary. While going over each face, identify the cell adjacent to each face, i.e., F_C0 and THREAD_T0. Using return values of these two function, assign a value of 1 to UDMs in these cells.

In DEFINE_SOURCE, multiply the source with these UDMs. Now, source will be applied only in those cells that have UDM of 1. For all other cells, UDM should be initialized to 0.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 15, 2020, 06:30
Default
  #8
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 207
Rep Power: 16
arunraj is on a distinguished road
Thank you so much. This is what I am expecting as I don't have much idea about UDF development. May I know in which scenario we need to use DEFINE_DEMAND and DEFINE_ADJUST.
arunraj is offline   Reply With Quote

Old   June 15, 2020, 06:36
Default Define_
  #9
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
DEMAND is based on user demand, whenver user wants to execute it. This can done using GUI or by giving a command in the text user interface or under Execute Commands. In other words, DEFINE_DEMAND is not executed by Fluent if user does not demand for it at specific intervals or at specific instant. On the other hand, DEFINE_PROFILE needs to be hooked to a physical zone, such as, a boundary or a cell zone. Fluent will execute it every iteration or based on the profile update interval chosen by the user under Run Calculation.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 15, 2020, 06:54
Default
  #10
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 207
Rep Power: 16
arunraj is on a distinguished road
I want to know about DEFINE_ADJUST. Thank you
arunraj is offline   Reply With Quote

Old   June 15, 2020, 06:56
Default _adjust
  #11
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
DEFINE_ADJUST is executed at the beginning of every iteration, before the fields are solved.

Refer the documentation for the details of all the DEFINE_ macros.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 15, 2020, 06:58
Default
  #12
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 207
Rep Power: 16
arunraj is on a distinguished road
Thanks a lot. I got it now.
arunraj 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
Building problems with cell zones when reopening Fluent MJ2017 FLUENT 0 October 14, 2017 09:11
how to work on parallel computing in openfoam.. Machine to machine connectivity Thomas Renald OpenFOAM Running, Solving & CFD 0 October 21, 2016 06:31
First order in fvSchemes does not seem to work gerritgroot OpenFOAM Running, Solving & CFD 0 September 30, 2015 21:06
[Gmsh] Cell to node connectivity after 'gmshToFoam' Jibran OpenFOAM Meshing & Mesh Conversion 1 June 8, 2015 10:09
ATTENTION! Reliability problems in CFX 5.7 Joseph CFX 14 April 20, 2010 16:45


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