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

[UDF] Find and save the cells in a region

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By gearboy

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 30, 2019, 23:57
Unhappy [UDF] Find and save the cells in a region
  #1
New Member
 
zacTee
Join Date: Jan 2019
Posts: 2
Rep Power: 0
waveandwind is on a distinguished road
Hi everyone. I have a problem in the udf (FLUENT) and dont know how to start it.
I want to find a particular group of cells, i.e. located by coordinates in a cylinder region, and save these cells' index (or threads?) for further uses.
Now I think I am surposed to use:




begin_c_loop_int(cc,tc)
C_CENTROID(xrc,cc,tc);
if xrc<=...
{
Record cc. How to record all the cells in a variable?

}
end_c_loop_int(cc,tc)


Moreover, if I have the cell group cc, how can I get the thread of these recorded cells?

So I can allocate memory and define sources to these cells...


Thank you in advance!
waveandwind is offline   Reply With Quote

Old   January 31, 2019, 01:56
Default
  #2
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
gearboy is on a distinguished road
Quote:
Originally Posted by waveandwind View Post
Hi everyone. I have a problem in the udf (FLUENT) and dont know how to start it.
I want to find a particular group of cells, i.e. located by coordinates in a cylinder region, and save these cells' index (or threads?) for further uses.
Now I think I am surposed to use:




begin_c_loop_int(cc,tc)
C_CENTROID(xrc,cc,tc);
if xrc<=...
{
Record cc. How to record all the cells in a variable?

}
end_c_loop_int(cc,tc)


Moreover, if I have the cell group cc, how can I get the thread of these recorded cells?

So I can allocate memory and define sources to these cells...


Thank you in advance!
You can allocate a dynamic dimension to store these cell number.

cell_t *DimensionToStore=NULL;
int total_cells=0, cell_index;
begin_c_loop_int(cc,tc)
C_CENTROID(xrc,cc,tc);
if xrc<=...
{
total_cells++;
}
end_c_loop_int(cc,tc)

DimensionToStore=(cell_t*)malloc(total_cells*sizeo f(cell_t));

cell_index=0;
begin_c_loop_int(cc,tc)
C_CENTROID(xrc,cc,tc);
if xrc<=...
{
DimensionToStore[cell_index]=cc;
cell_index++;
}
end_c_loop_int(cc,tc)

Now DimensionToStore is ready for use. Do not forget to free it since it is a dynamic dimension, otherwise memory leakage will occur.
bhwcs likes this.
gearboy is offline   Reply With Quote

Old   January 31, 2019, 02:03
Default
  #3
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
gearboy is on a distinguished road
Quote:
Originally Posted by gearboy View Post
You can allocate a dynamic dimension to store these cell number.

cell_t *DimensionToStore=NULL;
int total_cells=0, cell_index;
begin_c_loop_int(cc,tc)
C_CENTROID(xrc,cc,tc);
if xrc<=...
{
total_cells++;
}
end_c_loop_int(cc,tc)

DimensionToStore=(cell_t*)malloc(total_cells*sizeo f(cell_t));

cell_index=0;
begin_c_loop_int(cc,tc)
C_CENTROID(xrc,cc,tc);
if xrc<=...
{
DimensionToStore[cell_index]=cc;
cell_index++;
}
end_c_loop_int(cc,tc)

Now DimensionToStore is ready for use. Do not forget to free it since it is a dynamic dimension, otherwise memory leakage will occur.
If you use UDF compling/debugging tool VcUdfStudio (https://vcudfstudio.bitbucket.io/), you also can use C++ "new"/"delete" operator to allocate dynamic dimensions.

DimensionToStore=new cell_t[total_cells];

...
delete[] imensionToStore;
gearboy is offline   Reply With Quote

Old   January 31, 2019, 03:19
Default
  #4
New Member
 
zacTee
Join Date: Jan 2019
Posts: 2
Rep Power: 0
waveandwind is on a distinguished road
Quote:
Originally Posted by gearboy View Post
You can allocate a dynamic dimension to store these cell number.

cell_t *DimensionToStore=NULL;
int total_cells=0, cell_index;
begin_c_loop_int(cc,tc)
C_CENTROID(xrc,cc,tc);
if xrc<=...
{
total_cells++;
}
end_c_loop_int(cc,tc)

DimensionToStore=(cell_t*)malloc(total_cells*sizeo f(cell_t));

cell_index=0;
begin_c_loop_int(cc,tc)
C_CENTROID(xrc,cc,tc);
if xrc<=...
{
DimensionToStore[cell_index]=cc;
cell_index++;
}
end_c_loop_int(cc,tc)

Now DimensionToStore is ready for use. Do not forget to free it since it is a dynamic dimension, otherwise memory leakage will occur.

Thank you Gearboy! Thats really helpful.
Now given the DimensionToStore which stores the cell index, can I use any loop macro to loop on all these cells?

Something like:
begin_c_loop_int(DimensionToStore)
...

end_c_loop_int(DimensionToStore)
waveandwind is offline   Reply With Quote

Reply

Tags
fluent;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
[Other] preserveFaceZones constraint on a multi region mesh ViktorKL OpenFOAM Meshing & Mesh Conversion 5 May 21, 2019 12:45


All times are GMT -4. The time now is 18:54.