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

Why so many nodes in output file?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 22, 2020, 02:57
Question Why so many nodes in output file?
  #1
New Member
 
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7
Sunmax is on a distinguished road
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.
Sunmax is offline   Reply With Quote

Old   May 22, 2020, 05:36
Default Nodes
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
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 publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 22, 2020, 06:31
Thumbs up
  #3
New Member
 
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7
Sunmax is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
Sunmax is offline   Reply With Quote

Old   May 24, 2020, 06:48
Default Output Coordinates
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
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 publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 24, 2020, 08:02
Default
  #5
New Member
 
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7
Sunmax is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
Sunmax is offline   Reply With Quote

Old   May 25, 2020, 10:22
Default Nodes
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
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 publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 28, 2020, 04:48
Default
  #7
New Member
 
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7
Sunmax is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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);
Sunmax is offline   Reply With Quote

Old   May 28, 2020, 04:55
Default Logic
  #8
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
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 publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 28, 2020, 05:05
Default
  #9
New Member
 
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7
Sunmax is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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?
Sunmax is offline   Reply With Quote

Old   May 28, 2020, 05:12
Default Effects
  #10
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
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 publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Reply

Tags
node, udf


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
Using PengRobinsonGas EoS with sprayFoam Jabo OpenFOAM Running, Solving & CFD 35 April 29, 2022 15:35
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 03:30
[OpenFOAM] Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 keepfit ParaView 60 September 18, 2013 03:23
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 05:18
ParaView Compilation jakaranda OpenFOAM Installation 3 October 27, 2008 11:46


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