|
[Sponsors] |
Looping over all parcels to check if they are located inside a cell-zone |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 28, 2021, 15:27 |
Looping over all parcels to check if they are located inside a cell-zone
|
#1 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hey everybody, I do have a simulation ongoing in which I evaporate h2o2-h2o droplets almost at a relative saturation of 90 % (maximum = 93% as the droplets do have 12 mass-% h2o2 and 88 mass-% h2o -> this lead to 0.93 mole of h2o and hence maximum 93 %). However, the system gets filled up with a lot of parcels and I don't have any air that is flushing the room. Hence, I would like too loop through all parcels and check if they are inside a cell zone (far away from the area of interest). If they are inside, I want to remove them from the system by calling the appropriate makro (MARK_TP).
I would like to do that by using a EXECUTE_ON_DEMAND (after each flow time step). I have the following code right now. I get the material first and take all cells from the cell zone of cell id = 50. After that I loop over all cells of these cell zone and loop over all parcels if there are some inside the cell. At the end I want to remove the parcel but for that purpose I need to have the "Tracked_Particle" pointer and I don't know how to get it. Code:
DEFINE_ON_DEMAND(removeParcels) { // Fluid domain Domain *domain = Get_Domain(1); // Cell zone id int Cell_Zone_ID = 50; cell_t c; Thread *t = Lookup_Thread(domain, Cell_Zone_ID); // Particle Particle *p; int particleId = 0; // Looping over all cells of the cell zone begin_c_loop(c, t) { // Loop over all parcels in the coresponding cell begin_particle_cell_loop(p, c, t) { // If we are here, the parcel is inside the cell that is inside // the cell zone - hence we can remove it // Need to get the tracked parcel pointer --> how Tracked_Particle *tp; // Remove the parcel MARK_TP(tp, P_FL_REMOVED); // this sthould not work: // MARK_TP(p, P_FL_REMOVED); } } end_c_loop(c,t) }
__________________
Keep foaming, Tobias Holzmann |
|
July 28, 2021, 16:13 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
I have the solution:
Code:
DEFINE_DPM_SCALAR_UPDATE(parcelRemoval, c, t, initialize, tp) { if (initialize) { // Fluid domain Domain *domain = Get_Domain(1); // Cell zone id int Cell_Zone_ID = 598; cell_t cCZ; Thread *tCZ = Lookup_Thread(domain, Cell_Zone_ID); // Looping over all cells of the cell zone begin_c_loop(cCZ, tCZ) { // Check if cCZ == c -> parcel inside if (cCZ == c) { MARK_TP(tp, P_FL_REMOVED); } } end_c_loop(cCZ, tCZ) } } The only thing that is missing is to set the cell-zone-id via TUI rather than hard-code it.
__________________
Keep foaming, Tobias Holzmann |
|
July 29, 2021, 01:28 |
|
#3 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
to get the ID from TUI you may use rpvars
1. execute following script in fluent console, or put it inside the journal or scheme and run Code:
(ti-menu-load-string (format #f "(define (make-new-rpvar name default type)(rp-var-define name default type #f))")) (ti-menu-load-string (format #f "(make-new-rpvar 'tui_cell_zone_id 598 'int)")) 2. read it in UDF Code:
DEFINE_DPM_SCALAR_UPDATE(parcelRemoval, c, t, initialize, tp) { if (initialize) { // Fluid domain Domain *domain = Get_Domain(1); // Cell zone id int Cell_Zone_ID = 111; cell_t cCZ; #if !RP_NODE if (RP_Variable_Exists_P("tui_cell_zone_id")) Cell_Zone_ID = RP_Get_Integer("tui_cell_zone_id"); Message("Cell_Zone_ID on host-> %d\n",Cell_Zone_ID); #endif host_to_node_int_1(Cell_Zone_ID); Message0("DEBUG: Cell_Zone_ID on nodes-> %d\n",Cell_Zone_ID); Thread *tCZ = Lookup_Thread(domain, Cell_Zone_ID); // Looping over all cells of the cell zone begin_c_loop(cCZ, tCZ) { // Check if cCZ == c -> parcel inside if (cCZ == c) { MARK_TP(tp, P_FL_REMOVED); } } end_c_loop(cCZ, tCZ) } } 3. Actually, I will be more efficient to rad rpvar outside DEFINE_DPM_SCALAR_UPDATE macro as it is executed on each cell/thread
__________________
best regards ****************************** press LIKE if this message was helpful |
|
July 29, 2021, 04:14 |
|
#4 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hey,
I can make the cellZoneId a global variable and read it via an execute-on-demand or via the execute-on-loading. One last question, as you are using the commands for nodes and hosts. The following code works perfectly, but I get for each node the Message regarding the removed parcels. So to simplify the output, it would be great to sum the nRemovedParcels from all nodes to the host and only show the host messages using Message0(). However, I am not sure how to get the other node values and sum it to the host guy to finally get the overall removed parcels. Any idea? Code:
DEFINE_DPM_SCALAR_UPDATE(parcelRemoval, c, t, initialize, tp) { if (initialize) { // Check if the time is equal to the one we set real currentFlowTime = CURRENT_TIME; // Cell zone id int cellZoneId = 598; // New time step if (currentFlowTime > flowTime) { flowTime = currentFlowTime; if (nRemovedParcels != 0) { // Output how much parcels were removed in the last time step // For each node that removes parcels, this guy is outputted // Hence, we can have more outputs Message ( "In the last time-step, %i parcels were removed from " "the set cell-zone (id = %i)\n", nRemovedParcels, cellZoneId ); // Reset the nRemovedParcels nRemovedParcels = 0; } } // Fluid domain Domain *domain = Get_Domain(1); cell_t cCZ; Thread *tCZ = Lookup_Thread(domain, cellZoneId); // Looping over all cells of the cell zone begin_c_loop(cCZ, tCZ) { // Check if cCZ == c -> parcel inside if (cCZ == c) { MARK_TP(tp, P_FL_REMOVED); nRemovedParcels++; } } end_c_loop(cCZ, tCZ) } }
__________________
Keep foaming, Tobias Holzmann |
|
July 29, 2021, 04:37 |
|
#5 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you may try the following code
cause you are using summation of variable over all nodes, you need global summation, which is executed on nodes Message0 is data from node0, not from host Code:
DEFINE_DPM_SCALAR_UPDATE(parcelRemoval, c, t, initialize, tp) { if (initialize) { // Check if the time is equal to the one we set real currentFlowTime = CURRENT_TIME; // Cell zone id int cellZoneId = 598; // New time step if (currentFlowTime > flowTime) { flowTime = currentFlowTime; if (nRemovedParcels != 0) { // Output how much parcels were removed in the last time step // For each node that removes parcels, this guy is outputted // Hence, we can have more outputs Message0 ( "In the last time-step, %i parcels were removed from " "the set cell-zone (id = %i)\n", nRemovedParcels, cellZoneId ); // Reset the nRemovedParcels nRemovedParcels = 0; } } // Fluid domain Domain *domain = Get_Domain(1); cell_t cCZ; Thread *tCZ = Lookup_Thread(domain, cellZoneId); // Looping over all cells of the cell zone begin_c_loop(cCZ, tCZ) { // Check if cCZ == c -> parcel inside if (cCZ == c) { MARK_TP(tp, P_FL_REMOVED); nRemovedParcels++; } } end_c_loop(cCZ, tCZ) #if RP_NODE nRemovedParcels = PRF_GISUM1(nRemovedParcels); #endif /*RP_NODE*/ } }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
July 29, 2021, 05:24 |
|
#6 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hey Alexander,
thank you very much for your reply. You are a great support. First off all, the TUI command is: Code:
> (make-new-rpvar 'cell_zone_id_remove_parcels <ID> 'integer #f)
__________________
Keep foaming, Tobias Holzmann |
|
July 29, 2021, 07:32 |
|
#7 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hey Alex,
for any reason my code works not correctly... It removes cells from the other cell zone and I don't know why this happens. Any suggestion? Bildschirmfoto von 2021-07-29 12-28-40.jpg
__________________
Keep foaming, Tobias Holzmann |
|
July 29, 2021, 07:49 |
|
#8 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Okay anything is completely wrong here. I checked the cell position coming from the function and also the cell-zone position. Both are zero. Furthermore, I took the parcel pointer to get the cell position again and everything is zero even though, I can see a lot of parcels.
Code:
// Looping over all cells of the cell zone begin_c_loop(cCZ, tCZ) { // Check if cCZ == c -> parcel inside if (cCZ == c) { cell_t cParcel = TP_CELL(tp); Thread *tcParcel = TP_CELL_THREAD(tp); int pos[3]; int posParcel[3]; int posParcel2[3]; C_CENTROID(pos, cCZ, tCZ); C_CENTROID(posParcel, c, t); C_CENTROID(posParcel2, cParcel, tcParcel); Message("CellZone-Cell == cell of parcel >> %d == %d\n", cCZ, c); Message("CellZone-Cell pos (x|y|z) = (%f | %f | %f)\n", pos[0], pos[1], pos[2]); Message("Parcel -Cell pos (x|y|z) = (%f | %f | %f)\n", posParcel[0], posParcel[1], posParcel[2]); Message("Parcel -Cell pos (x|y|z) = (%f | %f | %f)\n", posParcel2[0], posParcel2[1], posParcel2[2]); // Mark parcels as vanished MARK_TP(tp, P_FL_REMOVED); // Increment counter nRemovedParcels++; } } end_c_loop(cCZ, tCZ) Code:
CellZone-Cell == cell of parcel >> 161 == 161 CellZone-Cell pos (x|y|z) = (0.000000 | 0.000000 | 0.000000) Parcel -Cell pos (x|y|z) = (0.000000 | 0.000000 | 0.000000) Parcel -Cell pos (x|y|z) = (0.000000 | 0.000000 | 0.000000) CellZone-Cell == cell of parcel >> 168 == 168 CellZone-Cell pos (x|y|z) = (0.000000 | 0.000000 | 0.000000) Parcel -Cell pos (x|y|z) = (0.000000 | 0.000000 | 0.000000) Parcel -Cell pos (x|y|z) = (0.000000 | 0.000000 | 0.000000) Code:
begin_c_loop(cCZ, tCZ) { Message("Cell %d\n", cCZ); } end_c_loop(cCZ, tCZ)
__________________
Keep foaming, Tobias Holzmann |
|
July 30, 2021, 02:36 |
|
#9 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you have zeroes because of wrong type of variables
Code:
real pos[3]; real posParcel[3]; real posParcel2[3]; Code:
begin_c_loop(cCZ, tCZ) { Message("Cell %d\n", cCZ); } end_c_loop(cCZ, tCZ) about number of vanished particles.... Unfortunately, I don't see any reason for that
__________________
best regards ****************************** press LIKE if this message was helpful |
|
August 2, 2021, 04:17 |
|
#10 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hey Alex,
for any reason this piece of code is not correct: Code:
cell_t cCZ; Thread *tCZ = Lookup_Thread(domain, Cell_Zone_ID); begin_c_loop(cCZ, tCZ) { // Do something } end_c_loop(cCZ, tCZ) Code:
if (THREAD_ID(t) == Cell_Zone_ID) { //Remove the parcel and do other stuff } And sure ... my fault ... the position is not an integer
__________________
Keep foaming, Tobias Holzmann |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fluent Mesh Check Fail | aunmhd | FLUENT | 1 | August 9, 2020 07:23 |
Fluent UDF wrong number of cells in parallel - correct in serial | dralexpe | Fluent UDF and Scheme Programming | 7 | May 17, 2018 09:26 |
[Commercial meshers] Mesh conversion problem (fluent3DMeshToFoam) | Aadhavan | OpenFOAM Meshing & Mesh Conversion | 2 | March 8, 2018 02:47 |
critical error during installation of openfoam | Fabio88 | OpenFOAM Installation | 21 | June 2, 2010 04:01 |
Problems in compiling paraview in Suse 10.3 platform | chiven | OpenFOAM Installation | 3 | December 1, 2009 08:21 |