|
[Sponsors] |
December 5, 2016, 13:32 |
Avoid negative scalar values (UDS)
|
#1 |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 |
Hello everyone,
I have a mixture gaseous phase in fluent and I am simulating a second phase (liquid water) as a scalar defined by a UDS. Nevertheless, I am facing a negative volume fraction in the liquid water phase. I've been through this topic http://www.cfd-online.com/Forums/flu...ds-values.html , but I tried the code and it did not worked. Basically, what I need is one way of limiting my scalar withing 0.0 and 1.0. My source term (evaporation/condensation) is defined as: Code:
double mass_source_vap_to_liq(cell_t c,Thread *ct) /* vapour - liquid phase change source term function (condensation/evaporation) */ { double S_vl, rho_h2o, rho_sat; rho_h2o = C_Y_H2O(c,ct)*C_R(c,ct); rho_sat = MW_H2O*SATURATION_CONCENTRATION(c,ct); if (rho_h2o > rho_sat) S_vl = POROSITY(ct) * CONDENSATION_RATE * (rho_h2o - rho_sat) * (1.0 - MAX(MIN(0.9999,C_LIQ_H2O(c,ct)),0.0)); else if (rho_h2o < rho_sat) S_vl = POROSITY(ct) * EVAPORATION_RATE * (rho_h2o - rho_sat) * MAX(MIN(0.9999,C_LIQ_H2O(c,ct)),0.0); else S_vl = POROSITY(ct) * EVAPORATION_RATE * (rho_h2o - rho_sat) * MAX(MIN(0.9999,C_LIQ_H2O(c,ct)),0.0); return S_vl; } Thanks in advanced. |
|
December 5, 2016, 17:04 |
|
#2 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
You could enforce the range limit at each iteration by looping over all cells and faces after solving the transport equations (DEFINE_EXECUTE_AT_END) and applying value=MAX(value,0.); etc. However, care should be taken with how the scalars are extending beyond this range because if you artificially restrict on [0,1] then you may not converge your solution (high residuals).
|
|
December 9, 2016, 07:25 |
|
#3 | |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 |
Quote:
I've tried the approach you suggested, but it still gives a negative value to the scalar. Does anything else comes to your mind? |
||
December 9, 2016, 11:27 |
|
#4 |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 |
I have a convective term in my udf for this equation, which I had implemented as a source.
It is defined as Code:
C_H2O_LIQ_CONVECTIVE_SRC(c,ct) = - LIQUID_WATER_DENSITY * (C_MU_L(c,ct)*LIQUID_RELATIVE_PERMEABILITY(c,ct) / (DYNAMIC_VISCOSITY_LIQUID_H2O(T0)*GAS_RELATIVE_PERMEABILITY(c,ct))) * (C_DUDX(c,ct) + C_DVDY(c,ct) + C_DWDZ(c,ct)); Code:
DEFINE_UDS_FLUX(my_uds_flux,f,t,i) { cell_t c0, c1 = -1; Thread *t0, *t1 = NULL; real NV_VEC(psi_vec), NV_VEC(A), flux = 0.0; real constant0, constant1; c0 = F_C0(f,t); t0 = F_C0_THREAD(f,t); F_AREA(A, f, t); /* If face lies at domain boundary, use face values; */ /* If face lies IN the domain, use average of adjacent cells. */ if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/ { real dens; /* Depending on its BC, density may not be set on face thread*/ if (NNULLP(THREAD_STORAGE(t,SV_DENSITY))) dens = DENSITY IN THE FACE; /* Set dens to face value if available */ else dens = LIQUID_WATER_DENSITY * (C_MU_L(c0,t0)*LIQUID_RELATIVE_PERMEABILITY(c0,t0) / (DYNAMIC_VISCOSITY_LIQUID_H2O(T0)*GAS_RELATIVE_PERMEABILITY(c0,t0))); /* else, set dens to cell value */ NV_DS(psi_vec, =, F_U(f,t), F_V(f,t), F_W(f,t), *, dens); flux = NV_DOT(psi_vec, A); /* flux through Face */ } else { c1 = F_C1(f,t); /* Get cell on other side of face */ t1 = F_C1_THREAD(f,t); constant0 = LIQUID_WATER_DENSITY * (C_MU_L(c0,t0)*LIQUID_RELATIVE_PERMEABILITY(c0,t0) / (DYNAMIC_VISCOSITY_LIQUID_H2O(T0)*GAS_RELATIVE_PERMEABILITY(c0,t0))); constant1 = LIQUID_WATER_DENSITY * (C_MU_L(c1,t1)*LIQUID_RELATIVE_PERMEABILITY(c1,t1) / (DYNAMIC_VISCOSITY_LIQUID_H2O(T0)*GAS_RELATIVE_PERMEABILITY(c1,t1))); NV_DS(psi_vec, =, C_U(c0,t0),C_V(c0,t0),C_W(c0,t0),*,constant0); NV_DS(psi_vec, +=, C_U(c1,t1),C_V(c1,t1),C_W(c1,t1),*,constant1); flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */ } /* ANSYS FLUENT will multiply the returned value by phi_f (the scalar's value at the face) to get the "complete'' advective term. */ return flux; } |
|
December 9, 2016, 17:22 |
|
#5 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Are you sure? What code are you using to set the UDS to zero? How are you checking the values? Are you plotting by node or cell values (shouldn't matter, but perhaps the interpolated node values aren't updated -- shouldn't affect the next iteration since the transport equations use cell values). You could loop through all cells and check which ones are outside of [0,1] with a define on demand macro.
|
|
December 12, 2016, 07:40 |
|
#6 | |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 |
Quote:
Do you have experience in this macro? As I mentioned before, I have 1 function which is defined in the cell. I think the cell bit I've done correctly, but I do not know how to get the values in the face. Could you please help me? |
||
December 12, 2016, 18:14 |
|
#7 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
I haven't used DEFINE_UDS_FLUX or read through in detail, but it seems strange that if you're restricting the scalar to [0,1] at the end of each iteration, that it's going beyond this range at all.
|
|
December 13, 2016, 08:10 |
|
#8 | |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 |
N
Quote:
Nevertheless I should focus in the FLUX macro. |
||
November 8, 2023, 21:19 |
|
#9 |
New Member
Join Date: Nov 2023
Posts: 1
Rep Power: 0 |
Hello bruno~ I am suffering the same problem as you, I wonder have you solved the problem? could you share the solution to this problem?
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
problem during mpi in server: expected Scalar, found on line 0 the word 'nan' | muth | OpenFOAM Running, Solving & CFD | 3 | August 27, 2018 05:18 |
[blockMesh] Errors during blockMesh meshing | Madeleine P. Vincent | OpenFOAM Meshing & Mesh Conversion | 51 | May 30, 2016 11:51 |
[General] Visualizing Scalar Values at Gauss Points | FasTom | ParaView | 0 | October 17, 2012 19:27 |
Raise pressure level in simulation to avoid negative pressures | solimcfd | CFX | 3 | June 13, 2012 08:28 |
negative uds value despite zero bc | Elmar Riesmeier | FLUENT | 3 | June 11, 2001 22:22 |