Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

UDF not getting compiled

    • ashch
      Subscriber
      I am trying to execute a UDF to adapt specific heat in one of my materials, however it is not getting compiled. nHere's the code -nDEFINE_SPECIFIC_HEAT(SpecificHeat, T, Tref, h, yi)n{nreal cp;n{n if (T > 1458. && T < 2000.)n cp = 850.0e-0;n else if (T >= 1418. && T <= 1457.)n cp = 1803.0e-0;n else if (T >= 1373. && T <= 1417.)n cp = 5190.0e-0n elsen cp = 850.0;n}nreturn cp;n}nnAny comments/suggestions to rectify this ?nThanks,nAshishn
    • Keyur Kanade
      Ansys Employee
      Are you getting any error? Which version you are using? Do you have any compiler installed? nWe may not help you to debug udfs. Please check help at nnYou may search this forum which has many posts about udf. nRegards,nKeyurnHow to access Ansys Online Help DocumentnHow to show full resolution imagenGuidelines on the Student CommunitynHow to use Google to search within Ansys Student Communityn
    • Keyur Kanade
      Ansys Employee
    • ashch
      Subscriber
      Version - 2020R1nCompiler- Visual Studio (Other UDF's are getting compiled)nError messages - ..\..\src\Cp.c(7): error C2065: 'real:undeclared identifiern..\..\src\Cp.c(7): error C2146: syntax error: missing ';' before identifier 'cp'n..\..\src\Cp.c(7): error C2065: 'cp:undeclared identifiern..\..\src\Cp.c(14): error C2065: 'cp:undeclared identifiern..\..\src\Cp.c(19): error C2065: 'cp:undeclared identifiern..\..\src\Cp.c(22): error C2065: 'cp:undeclared identifiern..\..\src\Cp.c(25): error C2065: 'cp:undeclared identifiern..\..\src\Cp.c(31): error C2065: 'cp:undeclared identifiern
    • YasserSelima
      Subscriber
      you must have this at the topn#include udf.hnnnand this before return cp;n*h = cp*(T-Tref);n
    • YasserSelima
      Subscriber
      #include udf.hnDEFINE_SPECIFIC_HEAT(SpecificHeat, T, Tref, h, yi)n{nreal cp;nn if (T > 1458. && T < 2000.)n   cp = 850.0e-0;n else if (T >= 1418. && T <= 1457.)n   cp = 1803.0e-0;n else if (T >= 1373. && T <= 1417.)n   cp = 5190.0e-0;n elsen   cp = 850.0;nn*h = cp*(T-Tref);nreturn cp;n}n
    • ashch
      Subscriber
      Hi Array nThanks for your reply. nYes, it works now. However, for it says it shows a warning message invalid cp at certain temperatures. Do you have any comments on this?WARNING: Invalid cp (0.000000e+00 J/kgK) for melt at temperature 1371.553061 KnnThanks,nAshishn
    • Rob
      Forum Moderator
      Try without the e-0 for the two cp values, my C coding is rusty so it's an educated guess. I'd also check the logic, what is cp at 1457.5K? Easy oversight, and remember the Ansys staff have either seen or made most errors you'll see on here: there are lots of us and collectively we have centuries of experience. n
    • YasserSelima
      Subscriber
      nAs pointed out, you have gabs in the if statements ... This would cause discontinuity in the Cp values ... like at 1457.5K nHowever, this gab won't cause this problem. You should get Cp = 850 at 1371.55nnDid you get this warning at the first iteration or after some iterations? n
    • ashch
      Subscriber
      Hi Array and ArraynThank you for the comments. nYes I have checked the logic for the if statements. There are no gaps in temperature, and as Array pointed out even if there is gap it should execute the else statementnof Cp 850 J/kgK. It is strange for me. nI get a warning in all the iterations (total 500 iterations) and the warning is also at different temperatures. Since I was testing this UDF, my mesh is very coarse and hence very low residuals. I hope this is not an issue.Let me know nThanks,nAshishn
    • YasserSelima
      Subscriber
      Did you hookup the function to your materials? make sure you didnIf you are still using the curly brackets after real cp; and before return cp; , remove themnif the error still there after doing the above, add this line before return cp;n#if RP_HOSTnif (cp != 0) {nMessage(Temperature = %f , Cp = %f, T, cp);n}n#endifnThese lines will print lots of lines ... so probably the computer will get slower and the solver will print lots of messages ... but this is to know if the function works for some cells or it is not read at alln
    • ashch
      Subscriber
      Hi ArraynThank you for the comments.nYes, I did hook it up. Checked twice nIt seems to me the UDF is NOT getting read-only. It's because after having included the code lines, still the same warning messages are being displayed and the message Message(Temperature = %f , Cp = %f, T, cp);is not being displayed even once.  nNOTE - It shows NO ERROR while getting compiled nWARNING: Invalid cp (0.000000e+00 J/kgK) for melt at temperature 1370.089680 KnnHere's the UDF again- n #include udf.hn DEFINE_SPECIFIC_HEAT(my_user_cp, T, Tref, h, yi)n {n  real cp;n/* Specific Heat of Liquid Melt above T-liquidus(above 1185 deg C)*/n if (T > 1458. && T < 2000.)n   cp = 850.0e-0;n/* Specific Heat of Liquid Melt in between T-liquidus and T-eutectic-start (>1185 & <1145 deg C) (0.0170239*T*T) - (35.0263*T) + 18651.1 + 850.0*/n else if (T <= 1458. && T > 1418.)n   cp = 1890.0;n/* Specific Heat of Liquid Melt in between T-eutectic-start and T-solidus(>1100 & <1145 deg C) (1.264730168e-7*T*T) + (42.6196*T) - 43600 + 850.0;*/n else if (T >1373. && T <= 1418.)n   cp = 4262.0;n/* Specific Heat of Liquid Melt in below T-solidus(<1100 deg C) */n elsen   850.0e-0;n #if RP_HOSTntif (cp != 0) tnt{tMessage(Temperature = %f , Cp = %f, T, cp); }n#endiftn  *h = cp*(T-Tref);n  return cp;n }nnThanks,nAshishn
    • YasserSelima
      Subscriber
      Remove the #if RP_HOST and #endif and try againn
    • YasserSelima
      Subscriber
      because you removed cp = from last linenelse n cp = 850;nn
    • ashch
      Subscriber
      Hi ArraynThank you for the comments. It works nicely nAshishn
    • YasserSelima
      Subscriber
      My pleasure!n
Viewing 15 reply threads
  • The topic ‘UDF not getting compiled’ is closed to new replies.