CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Avoid negative scalar values (UDS) (https://www.cfd-online.com/Forums/fluent-udf/181035-avoid-negative-scalar-values-uds.html)

Bruno Machado December 5, 2016 12:32

Avoid negative scalar values (UDS)
 
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;
}

Does anyone have an idea how to limit the scalar?

Thanks in advanced.

`e` December 5, 2016 16:04

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).

Bruno Machado December 9, 2016 06:25

Quote:

Originally Posted by `e` (Post 628424)
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).

Hi `e`

I've tried the approach you suggested, but it still gives a negative value to the scalar. Does anything else comes to your mind?

Bruno Machado December 9, 2016 10:27

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));
I tried to implement it using the DEFINE_UDS_FLUX macro, nevertheless, the functions GAS_RELATIVE_PERMEABILITY and LIQUID_RELATIVE_PERMEABILITY are defined in the cell, not in the faces. If you have any idea how to make this work, I'd appreciate any insight. The whole function that define the density of the scalar is defined in dens variable.

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;
}


`e` December 9, 2016 16:22

Quote:

Originally Posted by Bruno Machado (Post 628927)
Hi `e`

I've tried the approach you suggested, but it still gives a negative value to the scalar. Does anything else comes to your mind?

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.

Bruno Machado December 12, 2016 06:40

Quote:

Originally Posted by `e` (Post 628987)
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.

Yes, I checked both node and cell values. Nevertheless, I found that when I do not consider the convective term (previous post), it stays within 0 and 1. In that case, I think my focus should be in fix the DEFINE_UDS_FLUX.

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?

`e` December 12, 2016 17:14

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.

Bruno Machado December 13, 2016 07:10

N
Quote:

Originally Posted by `e` (Post 629355)
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.

I does limit when I do not consider the convective term that I was adding as a source. I believe it has something to do with the derivative values. Can not think any other possibility.

Nevertheless I should focus in the FLUX macro.

ChengxiYao November 8, 2023 20:19

Quote:

Originally Posted by Bruno Machado (Post 629443)
N

I does limit when I do not consider the convective term that I was adding as a source. I believe it has something to do with the derivative values. Can not think any other possibility.

Nevertheless I should focus in the FLUX macro.

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?


All times are GMT -4. The time now is 02:03.