Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

How to do a UDF to simulate the opening and closing of compressor valves?

    • sebastiancg26
      Subscriber

      How to do a UDF to simulate the opening and closing of compressor valves, wich depends on the pressure?

    • Rob
      Forum Moderator
      It depends on how you want to mimic the valve closure. More details would be helpful.
    • sebastiancg26
      Subscriber
      It could be as an orifice with constant area or as a reed valve. What is really important is that these valves open or close according to a certain pressure. IÔÇÖd aprecciate very much your help!

    • Rob
      Forum Moderator
      That would be an FSI problem. Because the motion is relatively large you'll need to use System Coupling to link to Mechanical and full remeshing in Fluent. Don't think you'll need UDFs in this case.
    • sebastiancg26
      Subscriber
      Can you help me with that? It would be very helpful
    • Rob
      Forum Moderator
      Other than point you at the tutorials, no. If you read the rules we can offer hints and "simple" answers only. Click on "Help" and have a look at Mechanical, Fluent and System Coupling.
    • YasserSelima
      Subscriber
      You can define your valve as a porous zone and use a UDF to change the properties
    • sebastiancg26
      Subscriber
      Wich parameter should I change? viscous resistance profile or porous resistance direction vector? and how could I change? so that it varies with pressure..
    • YasserSelima
      Subscriber
      permeability
    • sebastiancg26
      Subscriber
      I have read the UDF User guide, but I didn't find any information about how to change the permeability.. could you tell me how I can change the permeability based on pressure? how can I write the code? I'd really aprecciate your help, solving this problem is really important..
    • Rob
      Forum Moderator
      You will need to change alpha and C2, which are coefficients linked to how permeable the porous media is. In your case they will be found by obtaining the valve pressure loss at different flow rates and open fractions.
      Note, this will mimic the valve effect but won't provide any useful details on flow in the actual valve.
    • sebastiancg26
      Subscriber

      Thanks Rob!
      Do you know where I can find some information about how to change this properties based on pressure in UDF? I didn't find something similar like that in the UDF user's guide..
    • YasserSelima
      Subscriber
      First, you need to use DEFINE_ADJUST to check the difference .. the Macro C_P or F_P can give you the pressure of a cell or face. Then use DEFINE_PROPERTY to set the permeability
    • sebastiancg26
      Subscriber
      Dear Yasser.
      I'm very grateful to you. Finally, I have an idea of how I can start the code, I'm rookie in this topics but I'll continue studying the UDF user guide. If it's not too much to ask, could yo give me a way to contact us? In case I need any other help..
    • YasserSelima
      Subscriber
      you can message me here on the forum or mention me in a comment
    • Rob
      Forum Moderator
      The porous model uses DEFINE_PROFILE (I think!), the rest you'll need to work out with help from the community.
    • sebastiancg26
      Subscriber

      Hi Yasser! I've found a UDF of "viscous resistance profile" in the UDF user guide. But, this UDF is a function of "y".. How can I change that? How can I write the same code but based on pressure? I need the outlet valve closes at 600 kPa and the inlet valve opens at 100 kPa (those pressures are the outlet and intlet boundary conditions, respectively).. here, I'm going to paste the code that I found.
      #include "udf.h"
      DEFINE_PROFILE(vis_res,t,i)
      {
      real x[ND_ND];
      real a;
      cell_t c;
      begin_c_loop(c,t)
      {
      C_CENTROID(x,c,t);
      if(x[1] < (x[0]-0.01))
      a = 1e9;
      else
      a = 1.0;
      F_PROFILE(c,t,i) = a;
      }
      end_c_loop(c,t)
      }

      In a nutshell, I need something like these..
      if (P>100)
      a=1E12;
      else
      a=1;
      Yasser, thank you very much for your cooperation!!
    • YasserSelima
      Subscriber
      Thanks for clarification.
      Using DEFINE_ADJUST
      Define_adjust is called before every iterations. You can check the condition at the valve and then change an integer variable between 0 and 1 ... then in the DEFINE_PROFILE check if the variable is 1 or 0.
      I believe in your case, you need to close the valve based on the pressure in the last time step .. so, you need to check the pressure only one time before the time step. In the manual, there is an example that lists some commands to be done at iteration 1 only.
    • sebastiancg26
      Subscriber
      and right now I've something like this.. but what else do I need?

    • YasserSelima
      Subscriber
      "Define adjust" and "define profile" are two different functions. Go to the manual and look for examples on define-adjust
    • Emperor
      Subscriber
      hi to all,
      I've been working on the same problem for a while and I still don't have a solution. why do we always have to use an udf? is the use of 6-dof in the GUI not relevant?


    • Rob
      Forum Moderator
      6DOF tends to be used for free moving objects, which generally don't deform. They also don't hit anything. You want to model a valve closing so need to fix the motion and figure out when to stop the motion so the valve doesn't fully close. As it's a reed valve (so the valve deflects, or at least in the type I've seen they do) you can't just assume a motion.
    • sebastiancg26
      Subscriber
      if I understood you correclty.. I wrote two codes, both for DEFINE_ADJUST and DEFINE_PROFILE, but I still can't get it, could you help me?
      This is the DEFINE_ADJUST code..
      #include "udf.h"
      DEFINE_ADJUST(outvalve,d)
      {
      Thread *t;
      cell_t c;
      real P=0.;
      thread_loop_c(t,d)
      {
      begin_c_loop(c,t)
      P = C_P(c,t);
      end_c_loop(c,t)
      }
      printf("Pressure: %g\n", P);
      }

      .. and this is the DEFINE_PROFILE code
      #include "udf.h"
      DEFINE_PROFILE(outletvalve,t,i)
      {
      real P = C_P(c,t); /*pressure*/
      real a; /*viscous resistance = 1/permeability*/
      begin_c_loop(c,t)
      {
      if(P > 500000)
      a = 1.0;
      else
      a = 1e12;
      F_PROFILE(c,t,i) = a;
      }
      end_c_loop(c,t)
      }

    • YasserSelima
      Subscriber
      Assuming your code is right .. you need to put them below each other in the same file and remove #include "udf.h" from in between.
      Second, you need to define a global variable at the top, you set its value in define adjust, then use it in define profile ... something like this
      #include "udf.h"
      int my_variable;
      DEFINE_ADJUST(outvalve,d)
      {
      /* Loop and check the condition */
      if( condition ) {
      my_variable = 1;
      } else {
      my_variable = 0;
      }
      }

      DEFINE_PROFILE(outletvalve,t,i)
      {
      real P = C_P(c,t); /*pressure*/
      real a; /*viscous resistance = 1/permeability*/
      begin_c_loop(c,t)
      {
      if( my_variable == 1)
      a = 1.0;
      else
      a = 1e12;
      F_PROFILE(c,t,i) = a;
      }
      end_c_loop(c,t)
      }


    • YasserSelima
      Subscriber
      If you want the valve to open\close at certain pressure without knowing the valve mechanism, mass or spring stiffness, you will need to go through trial and error which would take months of simulations.
    • sebastiancg26
      Subscriber
      finally, this is my code..

      /*UDF that simulates the opening and closing of the inlet valve based on pressure*/

      #include "udf.h"

      intmy_variable;
      cell_t c;
      Thread *t;

      DEFINE_ADJUST(invalve,d)
      {
      real P; /*pressure*/

      P = C_P(c,t);

      /* Loop and check the condition */

      if( P < 100000 ) {
      my_variable = 1; /*OPEN VALVE*/

      }else{
      my_variable = 0; /*CLOSE VALVE*/
      }
      }

      DEFINE_PROFILE(inletvalve,t,i)
      {

      real a; /*viscous resistance = 1/permeability*/

      begin_c_loop(c,t)
      {
      if( my_variable == 1)
      a = 1.0;
      else
      a = 1e12;
      F_PROFILE(c,t,i) = a;
      }
      end_c_loop(c,t)

      }

      but I don't know if there are errors.. what do you think?
    • Emperor
      Subscriber
      if we know all the characteristics of our valve, i.e. spring stiffness, mass... we can use the interface then?
    • YasserSelima
      Subscriber
      You need to find the pressure inside define_adjust ... P is the pressure of which cell ... is it average? Are you going to change the value of my_variable each iteration? I guess no .. should be only first iteration of each time step.

      I guess yes you can use SDOF in this case and treat the valve gate as a moving object under spring force. However, depending on the complex of your geometry you might need to use a UDF to move your gate
    • Emperor
      Subscriber
      thank you for your answers. But then the pressure at the inlet just can't move the valve?
    • YasserSelima
      Subscriber
      Not immediately ... the pressure would cause a fluid forces on the valve which moves the valve with some time lag. I believe this is more realistic simulation of an actual valve but it comes at a cost. If you are interested in valve design/optimisation, you have to do this ... if the valve is not your interest or you have a solenoid that is controlled by a signal, you can do some assumptions to simplify your simulation.
    • Emperor
      Subscriber
      can you please come into this discussion and tell me what you think? I will be very pleased. We patched the pressure during the initialization, but during the deforming mesh other complications appear. I am interested in any hypothesis to make (I am still trying to consolidate my knowledge in fluid simulation)
    • sebastiancg26
      Subscriber
      I have made this based on the manual..
      #include "udf.h"


      static int last_ts = -1; /* Global variable. Time step is never <0 */


      DEFINE_ADJUST(first_iter_only, domain)


      {
      int curr_ts;
      int my_variable;
      face_t f;
      Thread *t;


      curr_ts = N_TIME;

      if (last_ts != curr_ts)
      {
      last_ts = curr_ts;

      {
      real P; /*pressure*/

      P = F_P(f,t);

      /* Loop and check the condition */

      if( P > 1000000 ) {
      my_variable = 1; /*OPEN VALVE*/

      } else {
      my_variable = 0; /*CLOSE VALVE*/
      }

      }
      }
      }


      DEFINE_PROFILE(outletvalve,t,i)

      {
      real a; /*viscous resistance = 1/permeability*/
      begin_f_loop(f,t)
      {
      if( my_variable == 1)
      a = 1.0;
      else
      a = 1e12;
      F_PROFILE(f,t,i) = a;
      }
      end_f_loop(f,t)

      }

      what do you think?
    • YasserSelima
      Subscriber
      P = F_P(f,t);
      Which face f, and which thread t?
    • sebastiancg26
      Subscriber
      #include "udf.h"

      static int last_ts = -1; /* Global variable. Time step is never <0 */

      DEFINE_ADJUST(first_iter_only, domain)

      {
      int curr_ts;

      curr_ts = N_TIME;

      if (last_ts != curr_ts)
      {
      last_ts = curr_ts;

      {
      intmy_variable;
      cell_t c;
      Thread *t;
      real P; /*pressure*/

      P = C_P(c,t);

      /* Loop and check the condition */

      if( P > 1000000 ) {
      my_variable = 1;/*OPEN VALVE*/

      }else{
      my_variable = 0;/*CLOSE VALVE*/
      }

      }
      }
      }

      DEFINE_PROFILE(outletvalve,t,i)

      {
      real a; /*viscous resistance = 1/permeability*/
      begin_c_loop(c,t)
      {
      if( my_variable == 1)
      a = 1.0;
      else
      a = 1e12;
      F_PROFILE(c,t,i) = a;
      }
      end_c_loop(c,t)

      }

      that's how it is?
      in the manual, there is an example wich allows me to calculate only in the first iteration, the code is...
      /**********************************************************************
      Example UDF that uses N_TIME
      ***********************************************************************/
      static int last_ts = -1; /* Global variable. Time step is never <0 */

      DEFINE_ADJUST(first_iter_only, domain)
      {
      int curr_ts;
      curr_ts = N_TIME;
      if (last_ts != curr_ts)
      {
      last_ts = curr_ts;
      /* things to be done only on first iteration of each time step
      can be put here */
      }
      }
    • sebastiancg26
      Subscriber
      after many attempts, I think I managed to do the UDF to calculate the value of "my_variable" for each time step (only in the first iteration). But, but now the problem is that I don't know how to include the UDF in ansys fluent, I have to put it in "Functions hook" or in the cell zone task manager or both .. could you help me please?
    • Rob
      Forum Moderator
      Have a look at the macro in the UDF manual, it'll explain where to hook it up. You then need a separate section of code to do whatever you want it to once the Adjust function is called, that's hooked into it's own part of the code (again the manual will generally say where it goes). For porous values it'll be either the Porous Jump boundary or porous media cell zone.
Viewing 35 reply threads
  • The topic ‘How to do a UDF to simulate the opening and closing of compressor valves?’ is closed to new replies.