|
[Sponsors] |
May 22, 2020, 03:57 |
Why so many nodes in output file?
|
#1 |
New Member
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7 |
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); } |
|
May 22, 2020, 06:36 |
Nodes
|
#2 |
Senior Member
|
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. |
|
May 22, 2020, 07:31 |
|
#3 |
New Member
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7 |
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, 07:48 |
Output Coordinates
|
#4 |
Senior Member
|
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. |
|
May 24, 2020, 09:02 |
|
#5 |
New Member
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7 |
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, 11:22 |
Nodes
|
#6 |
Senior Member
|
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. |
|
May 28, 2020, 05:48 |
|
#7 | |
New Member
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7 |
Quote:
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, 05:55 |
Logic
|
#8 |
Senior Member
|
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. |
|
May 28, 2020, 06:05 |
|
#9 |
New Member
Ma qiyu
Join Date: Dec 2018
Posts: 8
Rep Power: 7 |
And one more question, are there any side effects if I use the if-condition to constrain the node_loop?
|
|
May 28, 2020, 06:12 |
Effects
|
#10 |
Senior Member
|
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. |
|
Tags |
node, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using PengRobinsonGas EoS with sprayFoam | Jabo | OpenFOAM Running, Solving & CFD | 36 | July 16, 2024 04:52 |
[swak4Foam] funkyDoCalc with OF2.3 massflow | NiFl | OpenFOAM Community Contributions | 14 | November 25, 2020 04:30 |
[OpenFOAM] Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 | keepfit | ParaView | 60 | September 18, 2013 04:23 |
[swak4Foam] funkySetFields compilation error | tayo | OpenFOAM Community Contributions | 39 | December 3, 2012 06:18 |
ParaView Compilation | jakaranda | OpenFOAM Installation | 3 | October 27, 2008 12:46 |