CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Avoid negative scalar values (UDS)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 5, 2016, 13:32
Default Avoid negative scalar values (UDS)
  #1
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
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.
Bruno Machado is offline   Reply With Quote

Old   December 5, 2016, 17:04
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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).
`e` is offline   Reply With Quote

Old   December 9, 2016, 07:25
Default
  #3
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by `e` View Post
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 is offline   Reply With Quote

Old   December 9, 2016, 11:27
Default
  #4
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
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;
}
Bruno Machado is offline   Reply With Quote

Old   December 9, 2016, 17:22
Default
  #5
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
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.
`e` is offline   Reply With Quote

Old   December 12, 2016, 07:40
Default
  #6
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by `e` View Post
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?
Bruno Machado is offline   Reply With Quote

Old   December 12, 2016, 18:14
Default
  #7
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   December 13, 2016, 08:10
Default
  #8
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
N
Quote:
Originally Posted by `e` View Post
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.
Bruno Machado is offline   Reply With Quote

Old   November 8, 2023, 21:19
Default
  #9
New Member
 
Join Date: Nov 2023
Posts: 1
Rep Power: 0
ChengxiYao is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
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?
ChengxiYao is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 14:53.