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.

UDF for reinjecting particles

    • dseong
      Subscriber

      Hi all,

      I am working on creating a UDF to track particles hitting the outlet boundary. The setup involved in an air purifier in a small chamber, and I aim to set the purifier's efficiency at 95%. (95% of the particles that reach the outlet will escape, while 5% will be reinjected from a reinjection point)

      From my understanding:
      return PATH_END is used for considering particles escaped from the domain and
      return PATH_ACTIVE is for continuously tracking particles

      I would like to set up the system so that 5% of particles are reinjected from the reinjection point and continue being tracked. While PATH_END seems to work as expected, PATH_ACTIVE does not. In the console, particles are being aborted.

      I have revised my code several times and attempted different solutions, but I am currently out of ideas.

      Would anyone be able to help me solve this issue or suggest any possible approaches? I would greatly appreciate your insights.

      Thank you in advance!

      Best regards,
      Dahae

      --------------------------------------------------------------
      Here is my code FYI:

      #include "udf.h"
      #include "dpm.h"

      #define REINJECT_POSITION_X 2.0 // Set the x-coordinate of the reinjection point
      #define REINJECT_POSITION_Y 0.425 // Set the y-coordinate of the reinjection point
      #define REINJECT_POSITION_Z 0.18 // Set the z-coordinate of the reinjection point

      /* Global variables */
      int particle_count = 0;
      int escaped_count = 0;
      int reinjected_count = 0;

      DEFINE_DPM_BC(udf_outlet, tp, t, f, f_normal, dim)
      {
      particle_count++;

      if (particle_count <= 95)
      {
      /* Mark as escaped */
      escaped_count++;

      return PATH_END;

      }

      if (particle_count > 95)
      {
      /* Mark as reinjected */
      reinjected_count++;

      /* Move particle to specific point */
      P_POS(tp)[0] = REINJECT_POSITION_X; // Specific X position
      P_POS(tp)[1] = REINJECT_POSITION_Y; // Specific Y position
      P_POS(tp)[2] = REINJECT_POSITION_Z; // Specific Z position

      return PATH_ACTIVE;
      }

      /* Reset the counter after 100 particles */
      if (particle_count > 100)
      {
      particle_count = 0;
      escaped_count = 0;
      reinjected_count = 0;
      }

      return PATH_ACTIVE;
      }

    • Rob
      Forum Moderator

      Are you applying the UDF to the outlet boundary? What fate did you set on the boundary? 

      • dseong
        Subscriber

        Hi Rob, thanks for your response.

        Yes. I am applying the UDF to my outlet boundary (pressure outlet). This is what I set on the boundary.

    • Rob
      Forum Moderator

      How far into the domain is the injection?

      • dseong
        Subscriber

         

        I injected around 10,000 particles uniformly all around the domain (the size of the domain is 3 m by 4 m by 2.5 m).  And I wanted to set the 5% of particles passing the pressure outlet to be reinjected from the inlet. So, I specified the reinjection point in front of the inlet. 

         

    • Rob
      Forum Moderator

      But you're not sending 5% back you're sending count-95 back. Or would be if it worked. 

      • dseong
        Subscriber

        From my understanding, 'return PATH_END' means that particles escaped from the domain. So, I thought my code said that the particle count of less than 95 escaped. Could you please correct my code? 

        if (particle_count <= 95)
        {
        /* Mark as escaped */
        escaped_count++;

        return PATH_END;

        }

        if (particle_count > 95)
        {
        /* Mark as reinjected */
        reinjected_count++;

        /* Move particle to specific point */
        P_POS(tp)[0] = REINJECT_POSITION_X; // Specific X position
        P_POS(tp)[1] = REINJECT_POSITION_Y; // Specific Y position
        P_POS(tp)[2] = REINJECT_POSITION_Z; // Specific Z position

        return PATH_ACTIVE;
        }

    • Rob
      Forum Moderator

      I'm not debugging, the problem is if (particle_count > 95) I think. 

      • dseong
        Subscriber

        Thanks for your reply, Rob

        I am sorry but I am having trouble understanding the issue. If the problem lies with particle_count>95, how should I relocate particles from 96th to 100th that are hitting the outlet? I would greatly appreciate your answer. 

    • Rob
      Forum Moderator

      If you have 100 parcels you'll have the last 5 be reinjected. But... with 1000 particles you'll have 905 reinjected. So a random number function may be better. 

      Now, for the actual return part. If a parcel hits the outlet does it leave the domain before the UDF triggers? If you put a surface at a few cells into the domain (porous jump are really useful for this) does behaviour change?

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