How to calculate the correct net mass flux for a cell?
User wants to compute net flux through all faces in a given cell. I created a 2d test case where all interior face velocities are set to 1 by patching. The printout from udf shows that two cells have non-zero net flux. On these cells, it seems that opposite faces have face normals that point in the same direction thereby causing a net flux (which should be zero). I have attached the printout below. The last two cells show the right net value of 0.0. ======================================= cell 0, n 0, cell flux 0.000000 cell 0, n 1, cell flux 1.225000 cell 0, n 2, cell flux 0.000000 cell 0, n 3, cell flux 1.225000 Net cell flux = 2.450000 cell 1, n 0, cell flux 1.225000 cell 1, n 1, cell flux 0.000000 cell 1, n 2, cell flux 1.225000 cell 1, n 3, cell flux 0.000000 Net cell flux = 2.450000 cell 2, n 0, cell flux 0.000000 cell 2, n 1, cell flux -1.225000 cell 2, n 2, cell flux 0.000000 cell 2, n 3, cell flux 1.225000 Net cell flux = 0.000000 cell 3, n 0, cell flux 1.225000 cell 3, n 1, cell flux 0.000000 cell 3, n 2, cell flux -1.225000 cell 3, n 3, cell flux 0.000000 Net cell flux = 0.000000 ===================================== A workaround was found. I included a check (using F_C0 macro) if the current cell is c0. If it is then i simply reverse the sign on F_FLUX. I checked this on my test case and it works. The udf is attached below: #include "udf.h" #define TARGET_THREAD_ID 3 /* set correct thread id */ DEFINE_ON_DEMAND(porous_loop) { Domain *d=Get_Domain(1); FILE *output; face_t f; cell_t c; Thread *t; Thread *tf; int n; real cflux = 0.0; real myflux; output = fopen("debug.out","w"); thread_loop_c(t,d) { if (THREAD_ID(t) == TARGET_THREAD_ID) { begin_c_loop(c,t) { c_face_loop(c,t,n) { f=C_FACE(c,t,n); tf=C_FACE_THREAD(c,t,n); myflux = F_FLUX(f,tf); if (F_C0(f,tf) == c) {myflux=-myflux;} fprintf(output, "cell %i, n %i, cell flux %fn",c,n,myflux); cflux += myflux; } fprintf(output, "n Net cell flux = %fn n",cflux); cflux=0.0; } end_c_loop(c,t) fclose(output); } } } |
||
![]()
|