Fluids

Fluids

Need a bit support regarding UDF’s in Fluent

    • Holzmann
      Subscriber

      Hey everybody, I was in contact with the FLUENT support today regarding the evaporation of H2O2/H2O droplets. As stated in the theory guide, the liquid droplets/phase are assumed to be ideal which means that the activity coefficient is set to one. However, based on the customer, we know that the equilibrium to an ideal assumption is far away and hence, we need to incorporate the activity coefficient in the DPM model.

      We can use an already defined UDF for manipulating the concentration / partial pressure of each phase. The makro is given here: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v211/en/flu_udf/flu_udf_sec_define_dpm_vp_equilib.html

      So, I just want to discuss the part I need to modify:

         for (is = 0; is < nc; is++) {

          /* gas species index of vaporization */

          int gas_index = TP_COMPONENT_INDEX_I(tp,is);

          if(gas_index >= 0)

            {

             /* condensed material */

             Material * cond_c = MIXTURE_COMPONENT(cond_mix, is);

             /* condensed component molefraction */

             real xi_cond = TP_COMPONENT_I(tp,is)/(molwt[gas_index]*molwt_cond);

             /* particle saturation pressure */

             real p_saturation = DPM_vapor_pressure(tp, cond_c, Tp);

             if (p_saturation < 0.0)

               p_saturation = 0.0;

             /* vapor pressure over the surface, this is the actual Raoult law */

             cvap_surf[is] = xi_cond * p_saturation * activity / UNIVERSAL_GAS_CONSTANT / Tp;

            }

         }

      The last line includes a new variable named activity which is not given in the original Makro (so it is the field I need to calculate to incorporate real-gas-effects). The activity variable is a field such as «p_saturation» (in each parcel different). Based on the species we look at the moment, I have to call two functions different functions. I need something like that:


      if (species[i] == "h2o")

      {

      activity = activityH2O(temperature, mole-fraction-h2o)

      }

      else if (species[i] == "h2o2")

      {

      activity = activityH2O2(temperature, mole-fraction-h2o)

      }


      As I never programmed in fluent, it is a bit overwhelming right now (I am programming c++ mostly in QT and OpenFOAM). However, I have no clue how to access the fields of fluent and how to define the two different functions. So I would like to have some support from you. I guess I need something like this:

      double activityH2O(const class temperature, const class mole-fraction)

      {

      double temp = 1;

      temp = exp(232*temperature) * moleFraction * some other things

      }


      However, as I never did something similar in Fluent I have no glue. Mostly, people use pre-defined Makros so I don't even know the Makro name for defining a function such as:

      DEFINE_FUNCTION(activityH2O, ....)


      What I get out of the code is that

      • the Temperature of the parcel is Tp
      • the mole fraction of component I is given by xi_cond

      So the function should look somehow as:

      double activityH2O(double Tp, double xi_cond)

      {

      double tmp;

      // Calc tmp based on the droplet temperature Tp and h2o molefraction xi_cond

      return tmp;

      }


      But still, I am not sure which class I need to for the objects Tp and xi_cond and if the definition of the function would be fine. I used "double" here in that example, but I am not sure if this is valid? I guess it is «real» as given in the UDF example above (probably it is «real»). However, I am not sure how to compare strings in fluent and how to get the actual name of the species we are looking at. The line

      Material * cond_c = MIXTURE_COMPONENT(cond_mix, is);

      Gives me the idea that I could use the cond_c pointer to call (maybe) the name of the species such das:

      string nameOfSpecies = cond_c->name();

      Finally the last question. How can I be sure that this UDF is used later on?


      Thank you very much for your support.

      Tobi

    • Holzmann
      Subscriber
Viewing 1 reply thread
  • You must be logged in to reply to this topic.