# Why so many nodes in output file?

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 May 22, 2020, 02:57 Why so many nodes in output file? #1 New Member   Ma qiyu Join Date: Dec 2018 Posts: 8 Rep Power: 3 I found that when using udf to output the mesh node coordinates, the number of the nodes were incredibly large. I don't know what makes this wrong, so I put the udf below and hope someone can give a reasonable explanation. Code: ```#include"udf.h" #define PLATE_ID 5 DEFINE_EXECUTE_AT_END(Coordinate) { Domain *d = Get_Domain(1); Thread *tf = Lookup_Thread(d, PLATE_ID); face_t f; FILE *NX, *NY, *Num; int n, count = 0; Node *v; real x, y; begin_f_loop(f, tf) { f_node_loop(f, tf, n) { v = F_NODE(f, tf, n); x = NODE_X(v); y = NODE_Y(v); NX = fopen("node_x.txt", "at+"); fprintf(NX, "%f,", x); fclose(NX); NY = fopen("node_y.txt", "at+"); fprintf(NY, "%f,", y); fclose(NY); ++count; } } end_f_loop(f, tf); Num = fopen("Num_nodes.txt", "at+"); fprintf(Num, "Num of nodes=%d", count); fclose(Num); }``` In my case, the real number of nodes on the plate is 2036, but that is 4072 in the Num_nodes.txt, exactly two times of the real one.

 May 22, 2020, 05:36 Nodes #2 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,553 Blog Entries: 1 Rep Power: 28 The nodes are not unique for each face but are shared. The number of faces sharing a node depends on the type of mesh. Therefore, many nodes are visited multiple times and the count goes wrong. __________________ Regards, Vinerm PM to be used if and only if you do not want something to be shared on the Forum

May 22, 2020, 06:31
#3
New Member

Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 3
Quote:
 Originally Posted by vinerm The nodes are not unique for each face but are shared. The number of faces sharing a node depends on the type of mesh. Therefore, many nodes are visited multiple times and the count goes wrong.
Thank you very much for the explanation of the mechanism. I need to use the coordinates to control the dynamic mesh deformation in a special way, although I found that the udf(another one) could work well in serial processing which could not be used in parallel processing. So I guess it is the output-coordinates that causes the problem.

 May 24, 2020, 06:48 Output Coordinates #4 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,553 Blog Entries: 1 Rep Power: 28 What do you mean by output coordinates? There is no problem here except that the nodes are being visited multiple times. __________________ Regards, Vinerm PM to be used if and only if you do not want something to be shared on the Forum

May 24, 2020, 08:02
#5
New Member

Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 3
Quote:
 Originally Posted by vinerm What do you mean by output coordinates? There is no problem here except that the nodes are being visited multiple times.
I need the coordinates of two adjacent nodes to calculate the distance between them， the udf macro NODE_X(v) could not be used as NODE_X(v+1) so I have to output the coordinates. But there is another problem that the order of the coordinates is messy.

 May 25, 2020, 10:22 Nodes #6 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,553 Blog Entries: 1 Rep Power: 28 v and v+1 may or may not be adjacent. Try using v->next, though I am not clear about the structure but node structure most likely is based on linked list and you should be able to access next node using next. But even with that, it is not guaranteed that next node is also adjacent node. So, the fool proof method is to compare the coordinates. __________________ Regards, Vinerm PM to be used if and only if you do not want something to be shared on the Forum

May 28, 2020, 04:48
#7
New Member

Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 3
Quote:
 Originally Posted by vinerm v and v+1 may or may not be adjacent. Try using v->next, though I am not clear about the structure but node structure most likely is based on linked list and you should be able to access next node using next. But even with that, it is not guaranteed that next node is also adjacent node. So, the fool proof method is to compare the coordinates.
I found another interesting issue if I add the if(n==0) before the node_loop, the nodes will be visited only one time. But why?

Code:
```begin_f_loop(f, tf)
{
f_node_loop(f, tf, n)
{
if ( n==0 )
{
F_AREA(A, f, tf);
v=F_NODE(f, tf, n);
ve = F_V(f, tf);

NV_VS(pl,=,A,*,F_P(f,tf));
NV_VS(pl,=,pl,*,ve);
NV_V(pl_tot, +=,pl);

}
}
}
end_f_loop(f,tf);```

 May 28, 2020, 04:55 Logic #8 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,553 Blog Entries: 1 Rep Power: 28 That's because the loop goes over values of n. With If condition, you are constraining the loop to one instance, only when n = 0. So, the loop is executed only once. __________________ Regards, Vinerm PM to be used if and only if you do not want something to be shared on the Forum

May 28, 2020, 05:05
#9
New Member

Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 3
Quote:
 Originally Posted by vinerm That's because the loop goes over values of n. With If condition, you are constraining the loop to one instance, only when n = 0. So, the loop is executed only once.
And one more question, are there any side effects if I use the if-condition to constrain the node_loop?

 May 28, 2020, 05:12 Effects #10 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,553 Blog Entries: 1 Rep Power: 28 There are no side-effects, just the effects. The parts of the code within the confines of the If condition will be executed only if the condition is true. If you are thinking of using If to control the number of loops, then the logic wrong. The loop goes over all the nodes only once, there is no problem with that. The issue you are facing is because nodes are not unique to the cells or the faces. Each node is shared. __________________ Regards, Vinerm PM to be used if and only if you do not want something to be shared on the Forum

 Tags node, udf

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 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 OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Jabo OpenFOAM Running, Solving & CFD 25 December 30, 2019 06:53 [swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 11 November 1, 2016 06:43 keepfit ParaView 60 September 18, 2013 03:23 [swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 05:18 jakaranda OpenFOAM Installation 3 October 27, 2008 11:46

All times are GMT -4. The time now is 08:40.

 Contact Us - CFD Online - Privacy Statement - Top