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/)
-   -   Determining the cell neighbours for a given node (https://www.cfd-online.com/Forums/fluent-udf/212590-determining-cell-neighbours-given-node.html)

t4leung December 4, 2018 15:39

Determining the cell neighbours for a given node
 
I was wondering, is there a fluent macro for looping over all the cells adjacent to a given node? Thanks in advance

AlexanderZ December 4, 2018 21:10

how do you know the node?

lets imagine, you know it, so you may make a loop over all cells and find, where your node is located. If nodes matches this is your node.

From Ansys Fluent Customization manual
Code:

/* Store the mesh node coordinates in user-defined node memory */
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
c_node_loop (c,t,n)
{
v = C_NODE(c,t,n);
N_UDMI(v,0) = NODE_X(v);
N_UDMI(v,1) = NODE_Y(v);
#if RP_3D
N_UDMI(v,2) = NODE_Z(v);
#endif
}
}
end_c_loop (c,t)
}

best regards

t4leung December 4, 2018 22:38

I guess what I would like to do is the opposite of c_node_loop(c,t,n). For a given cell, c_node_loop will loop over all the common nodes with that cell. For a given node, is there an easy way to identify all the cells that are common to that node?

t4leung December 4, 2018 22:53

One idea I had was to define a structure that stored the adjacent cell IDs. I would have an array of these structs and I could use the cell and node loops to identify which cells were associated with each node. However, for a given node ID, I want to know the adjacent cell IDs and I can't see how I can do this with my approach.

typedef struct NODE_ADJACENT{
Node *v;
cell_t c_adj[4];
int total_adj;
} node_cellneighbour;

node_cellneighbour n1[count];

#if RP_NODE
int i = 0;
thread_loop_c(t,d)
{
begin_c_loop_int(c,t)
{
c_node_loop(c,t,n)
{
n1[i].v = C_NODE(c,t,n);
n1[i].c_adj[n1[i].total_adj] = c;
n1[i].total_adj = n1[i].total_adj + 1;

i++;
}

}
end_c_loop_int(c,t)
}
#endif

AlexanderZ December 6, 2018 22:45

This code is not working? that looks good.
What data is stored in your array?
Try to debug on single core first, if you are using fluent version less than 19.0
also begin_c_loop_int macro is very specific, you should check is it suitable for your case or not.

Use Ansys Fluent Customization manual for for information

best regards

Antech October 19, 2020 09:37

The code above will just collect arrays of Node structure pointers for each cell's neighbor nodes. It will not identify nodes. I googled for the topic and found that there is no solution on the Internet. I can propose the simple "dirty" method of finding node IDs, don't know if they are local for current thread (mesh partition) or for the entire domain. If we look at Fluent's user header files we'll find that node_struct is declared in mem_grid.h and there are cxindex id and int idx fields in this struct. I didn't further into cxindex struct, but idx is not just "1, 2, 3" but looks node index or ID. Strange that there is no macro for this, so you can use it, but it's not guaranteed to work in all Fluent versions. We use old 14 and 16 versions, so may not work in newer versions. And don't forget to check what happens in parallel mode. (Node ID or index will be just v->idx with this method)

Antech October 20, 2020 04:09

Checked for the idx if it's global or for current partition. It's for current partition, so it changes from 0 to some value around NumberOfCells/NumberOfPartitions. For Fluent release 16.


All times are GMT -4. The time now is 10:34.