We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

DEFINE_SOURCE

    • sjohn
      Subscriber
      I am working with a two-phase case, wherein each phase has only one species. Using DEFINE_SOURCE, I can remove mass from one phase. How do I add mass to the other phase? 
       
      Here is a simplified UDF to remove mass from one phase:
       
      [COLOR="DarkRed"]#include "udf.h"
      #include "math.h"
       
      /* Define the source term function */
      DEFINE_SOURCE(species_add_lit3, c, t, dS, eqn)
      {
          real source;
           
          source = 1;
          dS[eqn] = 0;
       
          return source;
      }[/COLOR]
       
      In my actual UDF, the source is not constant but a function.
    • Rob
      Forum Moderator

      You just need two source terms. One is negative for phase-1 and the other positive for phase-2. Ideally the two values will match! Just be wary of density differences as the volume has to go or come from somewhere. 

    • sjohn
      Subscriber

      That's how I have been doing but get large difference in mass flowrate. For example, inlet is 1 g/s but outlet is 0.6 g/s. The mass flowrates were calculated using the built-in Flux Report Definition at inlet and outlet boundaries. 

      Here is UDFs for subtraction. The subtraction UDF is hooked to the liquid phase in Cell Zone Conditions. For addition, I just use negative sign in the UDF and hook it to the gas phase.

      #include "udf.h"
      #include "math.h"
       
      /* Define the source term function */
      DEFINE_SOURCE(species_sub_lit, c, t, dS, eqn)
      {
          real source;
          real massfrac;
          real temperature;
          real k;
          real A = 10;  
          real Ea = 50;  
          real R = 8.314;  
       
          massfrac = C_YI(c, t, 0);
          temperature = C_T(c, t);
          k = A * exp(-Ea / (R * temperature));
          source = -k * massfrac;
          dS[eqn] = -k;
       
          return source;
      }

       

    • Rob
      Forum Moderator

      Are you recalculating the value, or using the value with a negative sign? 

    • sjohn
      Subscriber

      Additionally, I calculated outlet mass flowrate for each phase using my custom defintion.

      liquid phase = MassFlowAve(VelocityMagnitude,['outlet'])*Area(['outlet'])*MassFlowAve(Density(phase='phase-liq'),['outlet']) = 22.6 g/s

      gas phase = MassFlowAve(VelocityMagnitude,['outlet'])*Area(['outlet'])*MassFlowAve(Density(phase='phase-gas'),['outlet']) = 0.3 g/s

      mixture = MassFlowAve(VelocityMagnitude,['outlet'])*Area(['outlet'])*MassFlowAve(Density(phase='mixture'),['outlet'])= 4.3 g/s

      inlet = MassFlowAve(VelocityMagnitude,['inlet'])*Area(['inlet'])*MassFlowAve(Density(phase='mixture'),['inlet']) = 1.2 g/s

      The inlet flowrate obtained using above formula matches with the inlet flowrate obtained using Flux Report Definition. The outlet flowrate obtained using the above formula (for mixture) does not match the outlet flowrate obtained using Flux Report Defintion.

    • Rob
      Forum Moderator

      Use the Flux Report for each phase. 

    • sjohn
      Subscriber

      I am recalculating the values in the addition UDF (used to add mass to gas phase)

      Should I be using the source or k value from subtraction UDF directly in the addition UDF? I don't know how to do that. Currently, they are two separate .c files.

    • sjohn
      Subscriber

      Using Flux Report Defintion,

      Liq phase:
      inlet flowrate = 1.23 g/s

      outlet flowrate = 0.64 g/s

      user mass source = 2.841e-20 g/s

       

      Gas phase:
      inlet flowrate = 0 g/s

      outlet flowrate = 1.56e-3 g/s

      user mass source = 2.841e-20 g/s

    • sjohn
      Subscriber

      So the addition and subtration of masses between the two phases match. So what could be the reason for the outlet flowrate to be so different than the inlet flowrate.

    • Rob
      Forum Moderator

      Is it a transient run? Just wondering if you're accumulating liquid as gas forms and flows out of the domain. 

    • sjohn
      Subscriber

      Steady state

    • Rob
      Forum Moderator

      How does the domain mass monitor look? Ie is it flat or changing? 

    • sjohn
      Subscriber

      Is this some sort of plot to determine mass conservation? How can I plot this?

    • Rob
      Forum Moderator

      There's a mass imbalance value in Residuals but that's on a per cell basis and is usually only useful to find regions where the solver is struggling. 

      If you plot volume integral of phase mass with iteration that's usually a good indicator of what's going on. You can also combine that with mass in & mass out and some maths (change in volume mass / time step) to see how the system is behaving. 

Viewing 13 reply threads
  • You must be logged in to reply to this topic.