|
[Sponsors] |
Calculating a variable based on the data from two different cell zones |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 21, 2019, 13:47 |
Calculating a variable based on the data from two different cell zones
|
#1 |
New Member
Jason FANG
Join Date: Aug 2019
Posts: 6
Rep Power: 7 |
Hi, everyone!
I woulk like to kindly ask for some help with a UDF that I am trying to write. I am modelling the membrane permeation. I want to calculate the flux near the solid-liquid interface based on the pressure difference. However, can the pressure difference be gotten by direct subtraction, and how to guarantee the one-to-one correspondence of two subtracted cell value? Last edited by Jasonf; August 22, 2019 at 22:36. |
|
August 22, 2019, 01:34 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Code:
begin_f_loop(f1,ft1) { c01=F_C0(f1,ft1); t01=F_C0_THREAD(f1,ft1); p1=C_P(c01,t01); } end_f_loop(f1,ft1) So I suggest you to use UDMs to store pressure Code:
DEFINE_ADJUST(adjust_flux,domain) { Domain *domain=Get_Domain(1); real p1, p2, flux; face_t f1, f2; Thread *t,*ft1=Lookup_Thread(domain,8); Thread *ft2=Lookup_Thread(domain,6); cell_t c,c01, c02; Thread *t01, t02; begin_f_loop(f1,ft1) { c01=F_C0(f1,ft1); t01=F_C0_THREAD(f1,ft1); C_UDMI(c01,t01,0)=C_P(c01,t01); } end_f_loop(f1,ft1) begin_f_loop(f2,ft2) { c02=F_C0(f2,ft2); t02=F_C0_THREAD(f2,ft2); C_UDMI(c02,t02,1)=C_P(c02,t02); } end_f_loop(f2,ft2) begin_c_loop(c, t) { C_UDMI(c,t,2)=C_UDMI(c,t,0)-C_UDMI(c,t,1); //flux=p1-p2; } end_f_loop(c,t) } |
|
August 22, 2019, 02:04 |
|
#3 |
New Member
Jason FANG
Join Date: Aug 2019
Posts: 6
Rep Power: 7 |
@AlexanderZ,thank you! Your help is very helpful to me, and I will try it.
|
|
September 1, 2019, 12:03 |
|
#4 | |
New Member
Jason FANG
Join Date: Aug 2019
Posts: 6
Rep Power: 7 |
Quote:
Code:
DEFINE_INIT(UDM,domain) { cell_t c; Thread *t; thread_loop_c(t,domain} { begin_c_loop_all(c,t) { C_UDMI(c,t,0)=1.e3; C_UDMI(c,t,1)=200.; C_UDMI(c,t,2)=0.; } end_c_loop_all(c,t) } } DEFINE_ADJUST(adjust_flux,domain) { real p1, p2, flux; face_t f1, f2; Thread *t,*ft1=Lookup_Thread(domain,8); Thread *ft2=Lookup_Thread(domain,6); cell_t c,c01, c02; Thread *t01, t02; begin_f_loop(f1,ft1) { c01=F_C0(f1,ft1); t01=F_C0_THREAD(f1,ft1); C_UDMI(c01,t01,0)=C_P(c01,t01); } end_f_loop(f1,ft1) begin_f_loop(f2,ft2) { c02=F_C0(f2,ft2); t02=F_C0_THREAD(f2,ft2); C_UDMI(c02,t02,1)=C_P(c02,t02); } end_f_loop(f2,ft2) thread_loop_c(t,domain) { begin_c_loop(c, t) { C_UDMI(c,t,2)=C_UDMI(c,t,0)-C_UDMI(c,t,1); //transmembrane pressure=p1-p2; } end_c_loop(c,t) } As shown in the attached FIG, a) the pressures on the left side of membrane are stored into 4th layer cells of C_UDMI(c,t,0), and the ones on the right side are stored into 7th layer of C_UDMI(c,t,1)? b) the formula C_UDMI(c,t,2)=C_UDMI(c,t,0)-C_UDMI(c,t,1) can achieve the subtraction of 4th layer and 7th layer cells? c) if not, how to achieve this aim? Maybe my understanding is wrong, so hope your suggestions. Thanks for any help! |
||
September 2, 2019, 02:46 |
|
#5 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
my bad, you are right, you can't compare udm_0 with udm_1 because they have data in different cells
may be you can make your own arrays and compare them directly: Code:
#include "udf.h" DEFINE_INIT(my_init_func,d) { cell_t c; Thread *t; /* loop over all cell threads in the domain */ thread_loop_c(t,d) { /* loop over all cells */ begin_c_loop_all(c,t) { C_UDMI(c,t,0)=1.e3; C_UDMI(c,t,1)=200.; C_UDMI(c,t,2)=0.; C_UDMI(c,t,3)=0.; C_UDMI(c,t,4)=0.; } end_c_loop_all(c,t) } } DEFINE_ADJUST(adjust_flux,domain) { real p1, p2, flux; face_t f1, f2; Thread *t,*ft1=Lookup_Thread(domain,8); Thread *ft2=Lookup_Thread(domain,6); cell_t c,c01, c02; Thread *t01, *t02; real *c0_array,*c1_array; int n; n=0; begin_f_loop(f1,ft1) { c01=F_C0(f1,ft1); t01=F_C0_THREAD(f1,ft1); C_UDMI(c01,t01,0)=C_P(c01,t01); c0_array[n] = C_P(c01,t01); n++; } end_f_loop(f1,ft1) n=0; begin_f_loop(f2,ft2) { c02=F_C0(f2,ft2); t02=F_C0_THREAD(f2,ft2); C_UDMI(c02,t02,1)=C_P(c02,t02); c1_array[n] = C_P(c01,t01); n++; } end_f_loop(f2,ft2) if ((sizeof(c0_array) / sizeof(c0_array[0])) != (sizeof(c1_array) / sizeof(c1_array[0]))) Message0("ERROR ********* size of face 6 is not equal to size of face 8 ********* \n"); n=0; // You may check order in array and in cell/thread loop thread_loop_c(t,domain) { begin_c_loop(c, t) { C_UDMI(c,t,2)= c0_array[n] - c1_array[n]; //transmembrane pressure=p1-p2; // Start -> You may check order in array and in cell/thread loop | compare C_UDMI(c,t,0) with C_UDMI(c,t,3) and C_UDMI(c,t,1) with C_UDMI(c,t,4) C_UDMI(c,t,3)= c0_array[n]; //transmembrane pressure=p1-p2; C_UDMI(c,t,4)= c1_array[n]; //transmembrane pressure=p1-p2; // End -> You may check order in array and in cell/thread loop n++; } end_c_loop(c,t) } } |
|
September 3, 2019, 00:53 |
|
#6 | |
New Member
Jason FANG
Join Date: Aug 2019
Posts: 6
Rep Power: 7 |
Quote:
Code:
face_t f1, f2; Thread *t,*ft1=Lookup_Thread(domain,8); Thread *ft2=Lookup_Thread(domain,6); cell_t c01, c02; Thread *t01, *t02; int n=0; begin_f_loop(f1,ft1) { n++; } end_f_loop(f1,ft1) real c0_array[n]={0}; n=0; begin_f_loop(f1,ft1) { c01=F_C0(f1,ft1); t01=F_C0_THREAD(f1,ft1); C_UDMI(c01,t01,0)=C_P(c01,t01); c0_array[n] = C_P(c01,t01); n++; } end_f_loop(f1,ft1) ...... Last edited by Jasonf; September 3, 2019 at 04:40. |
||
September 3, 2019, 05:17 |
|
#7 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
variable should be defined in the top of function, before other instructions
try this Code:
#include "udf.h" DEFINE_INIT(my_init_func,d) { cell_t c; Thread *t; /* loop over all cell threads in the domain */ thread_loop_c(t,d) { /* loop over all cells */ begin_c_loop_all(c,t) { C_UDMI(c,t,0)=1.e3; C_UDMI(c,t,1)=200.; C_UDMI(c,t,2)=0.; C_UDMI(c,t,3)=0.; C_UDMI(c,t,4)=0.; } end_c_loop_all(c,t) } } DEFINE_ADJUST(adjust_flux,domain) { real p1, p2, flux; face_t f1, f2; Thread *t,*ft1=Lookup_Thread(domain,8); Thread *ft2=Lookup_Thread(domain,6); cell_t c,c01, c02; Thread *t01, *t02; int n; real c0_array[100000],c1_array[100000]; n=0; begin_f_loop(f1,ft1) { c01=F_C0(f1,ft1); t01=F_C0_THREAD(f1,ft1); C_UDMI(c01,t01,0)=C_P(c01,t01); c0_array[n] = C_P(c01,t01); n++; } end_f_loop(f1,ft1) n=0; begin_f_loop(f2,ft2) { c02=F_C0(f2,ft2); t02=F_C0_THREAD(f2,ft2); C_UDMI(c02,t02,1)=C_P(c02,t02); c1_array[n] = C_P(c01,t01); n++; } end_f_loop(f2,ft2) if ((sizeof(c0_array) / sizeof(c0_array[0])) != (sizeof(c1_array) / sizeof(c1_array[0]))) Message0("ERROR ********* size of face 6 is not equal to size of face 8 ********* \n"); n=0; // You may check order in array and in cell/thread loop thread_loop_c(t,domain) { begin_c_loop(c, t) { C_UDMI(c,t,2)= c0_array[n] - c1_array[n]; //transmembrane pressure=p1-p2; // Start -> You may check order in array and in cell/thread loop | compare C_UDMI(c,t,0) with C_UDMI(c,t,3) and C_UDMI(c,t,1) with C_UDMI(c,t,4) C_UDMI(c,t,3)= c0_array[n]; //transmembrane pressure=p1-p2; C_UDMI(c,t,4)= c1_array[n]; //transmembrane pressure=p1-p2; // End -> You may check order in array and in cell/thread loop n++; } end_c_loop(c,t) } } |
|
August 22, 2022, 12:21 |
|
#8 | |
New Member
Manish Bhendura
Join Date: Apr 2018
Posts: 3
Rep Power: 8 |
Quote:
I am solving the same problem. I tried this approach and was able to store saturation pressure (function of temperature) in my arrays. However, the sequence of storing values in each array is different from each other. Thus a direct comparison is not helpful. my code: thread_loop_c(t,d) { begin_c_loop(c,t) { C_CENTROID(x,c,t); if (x[1] < 0.001001 && x[1] > 0.001){ psc[i] = exp(25.317-5144/C_T(c,t)); i++; }} end_c_loop(c,t) i=0; begin_c_loop(c,t) { C_CENTROID(x,c,t); if (x[1] > 0.00123 && x[1] < 0.00124){ psh[i] = exp(25.317-5144/C_T(c,t)); C_UDMI(c,t,1) = psh[i]; i++; }} end_c_loop(c,t) I printed the values of the x-coordinate(x[0]) for both c-loops to see the sequence of storing values. A sample (initial 5 values) for both loops are : i = 0,1,2,3,4,...... loop 1: 22.783333, 22.816667, 15.05, 22.85, 15.083333,........ loop 2: 84.916667, 84.883333, 26.516667, 84.85, 118.25,.... In my understanding, these two loops should return the same values to get the correct pressure difference at each cell. Thank you |
||
August 24, 2022, 02:11 |
|
#9 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
check this thread, the way to get link between cells is described there:
Writing a UDF for species mass transfer
__________________
best regards ****************************** press LIKE if this message was helpful |
|
September 2, 2022, 08:38 |
|
#10 |
New Member
Manish Bhendura
Join Date: Apr 2018
Posts: 3
Rep Power: 8 |
Dear Alexander
Thank you so much. Your suggestion worked. Can you suggest any reference for CX_Find_Cell_With_Point() function for more clarity? It is not available in the ANSYS UDF manual. Last edited by mbhendura; September 5, 2022 at 01:56. |
|
Tags |
adjacent cell layer, define_adjust, multiple cell zones |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] refineWallLayer Error | Yuby | OpenFOAM Meshing & Mesh Conversion | 2 | November 11, 2021 12:04 |
Creatin macros for multiple data sets and assigning multiple zones | Skyler | Tecplot | 0 | January 24, 2019 13:24 |
paraview - cell data or point data on plot over line | bye bye my blue | OpenFOAM | 0 | December 13, 2016 07:07 |
Exporting data (cell values, ascii) and obtaining more data than cells! | TfG | FLUENT | 3 | April 3, 2015 01:18 |
[OpenFOAM] Cell Data to Point Data Issues | mcintoshjamie | ParaView | 2 | November 19, 2009 04:55 |