Fluids

Fluids

Turbulent Viscosity UDF?

    • vedama
      Subscriber
      Hello,nnI am trying to write a UDF to calculate turbulent viscosity based on Prandtl's mixing layer model (mu_t = a*delta) to use with the Spalart-Allmaras model. I performed the simulation using the default values first so I have a solution blueprint and then compiled the UDF, changed the Turbulent Viscosity in the Viscous dialog box to the udf value. However, I am now getting floating point exception in the first iteration itself. Could someone check my code, please? Not sure why I'm getting that error.nnI'm running a 2D second-order, pressure-based solver with Coupled scheme.n#include udf.hDEFINE_TURBULENT_VISCOSITY(mu_t1,c,t)n{ntreal a_const = 0.1;ntreal rho = C_R(c,t);ntreal dudy = C_DUDY(c,t);ntreal del = .000125;ntreal lm = a_const*del;ntreal mu_t = dudy*SQR(lm);ntntreturn mu_t;nn
    • Karthik R
      Administrator
      Hello,nHave you attempted to run the model without the UDF? Does it work?nAlso, I'd strongly recommend that you print the values of mu_t in your UDF. Use the Message statements. This will do two things: nIs the UDF working properly?nIs the magnitude of mu_t correct?nI don't see anything wrong with the UDF straightaway. I'm worried about the magnitude though (if it is too large or small depending on your initial conditions). nAlso, check your overall mesh quality and make sure that you have a good mesh.nKarthikn
    • vedama
      Subscriber
      Hi Karthik,nnThanks for your response. You were right, the magnitude is rather large. I scaled it down by 3 orders of magnitude and it seems to work fine now. I'm relatively new to the world of UDFs, if you don't mind answering, why does a large magnitude cause it to fail? Would it not just give you a (horribly) wrong answer? My understanding of floating point exceptions is that it tries to divide by zero. How or where is the zero popping up, if the mu_t is off by a large magnitude? Thanks for your help!n
    • YasserSelima
      Subscriber
      The way the solver works is by iterations ... having initial guess, and using it to calculate the residuals which is used to modify the guess ... by repeating this process, the values of the residuals keeps decreasing and the solution converges. However, if the initial guess is too far from the solution, the the 2nd guess might be further away ... and as iterations proceed, the values become too large and/or too small ... for example velocity = 1e+35 ... n
Viewing 3 reply threads
  • You must be logged in to reply to this topic.