Fluids

Fluids

UDF program for calculating the pressure

    • vighnesh
      Subscriber

      Hello there,


      can anyone help me in writing a UDF program ??


      I need to calculate Change in pressure and with change in inlet velocity at given time interval in a pipe.Pipe description is as mention in this link. (https://forum.ansys.com/forums/topic/calculate-pressure-difference/?order=all#comment-22db4f04-ee3b-48ba-b8bb-aa8800b2b566).


      @abenhadj and rwoolhou, as you people suggested, i got expected result. Which was like..


      Once done with the geometry and meshing,in setup create the point P1 and P2. in models,materials,cell zone conditions and boundry conditions do the necessary changes.In solution-->report definations for P1 and P2 and then in monitors,generate report files as explained the above link.


      In this solution i was manually changing the inlet velocity and calculating P1-P2 everytime after required time step for say 'T' sec.


      What I need is how can i write a UDF program so that all the variable parameters are addressed in one program i.e calculate p1-p2 with varieing inlet velocity for regular interval of time say for first 100 sec velocity is v1 next 100 sec velocity is v2 and so on for 2000sec.


      any comments or data materials will help..


       


      Thanks.

    • DrAmine
      Ansys Employee

      You need to use DEFINE_PROFILE to change the boundary value at your inlet. If the profile is only dependent on time you can use profile file. If you are using actual versions you can use Fluent Expression to change the value at the boundary.


      The pressure difference is via Report so I guess you do not need to do anything. Only if you want to have that on demand via UDF. But is this really required.


       


      All above is documented.

    • Rob
      Ansys Employee

      You don't need a UDF to calculate the pressure. If you use the reporting features (as you've done) for the pressure drop you then only need a profile or expression (or simple boundary UDF) to alter the velocity with time.  The latter can be done using a couple of example UDFs in the manual: start with DEFINE_PROFILE


       

    • vighnesh
      Subscriber

      Thank you..will go through both the suggestions.


      Please find the attachment below.


      Fig 1 is the graph what i am getting now using Ansys fluent. Fig 2 is what i need to get.


      Any thoughts??Graph


      Thanks.

    • DrAmine
      Ansys Employee

      See my suggestions above thanks.

    • vighnesh
      Subscriber


      Hi abenhadj,rwoolhou,


      I dont understand where to start with. Im litrally new to programming. Please help. I had gone through the Ansys UDF manual. Should i write a c code or TUI commands and journal files will do the trick?? 


       


      regards,

    • Rob
      Ansys Employee

      Right, start off with what you need to know:


      For a given velocity (that changes with time) you want the pressure loss. 


       


      So, input is the velocity profile. If you can ignore the higher frequency noise    velocity = coefficient * time     Now read the DEFINE_PROFILE example in the UDF manual, and look for examples where solution time has been used.  If velocity is a stair-step you'll need to use an IF function and figure out the logic. 


      The output is the pressure loss or value. For a velocity inlet & pressure outlet, the pressure on the outlet is fixed, and varies on the inlet to force the flow into the domain.  Using a Report you can plot & save this value to a file (read up on monitor points). 


      Plot the input you give the UDF and Pressure monitor (remember to add time into the export) to get what you're after. 


       


      As an aside: please use one thread per problem. Posting elsewhere won't get you a faster answer and will result in other topics being locked. As I have a finite amount of time it'll also mean I don't answer other threads. 

    • vighnesh
      Subscriber

      Thanks rwoolhou,


      Attached a image file of UDF, please comment if anything to be added into that. I am able to compile the program but not able to get the expected graph.


    • vighnesh
      Subscriber

      How to export velocity values (0.03 to 1.95) to the report file??

    • Rob
      Ansys Employee

      You can set a second report and then combine the files, or add in the data manually: you're setting the velocity. Check you can't add multiple reports to one file (can't remember if they need to have the same units). 


      Re the UDF, if time is greater than 1000s it's also greater than 900s (and 800s etc): what value should the solver use? 

    • vighnesh
      Subscriber

      hi rwoolhou,


      1. As written in UDF,  as far as my understanding solver uses value in between the timestamp as mention. E.g : After 1000s and till 1100, v=1.5m/s and if >900 and less than 1000,v=1.35.


      Please correct me if i am wrong.


      2. I get some negative Delta p values,as velocity step increases. Any suggestions??


      Velocity is lower at P1 and higher at P2 as expected but Pressure is not stable.


       

    • DrAmine
      Ansys Employee
      1/yes
      2/ Perhaps it requires more iterations and or smaller time steps especially at transition.

      Why not using transient profile or Expressions.
    • vighnesh
      Subscriber

      Hi Amine,


      Why not using transient profile or Expressions..


      Can you please elaborate..? 

    • DrAmine
      Ansys Employee

      Transient Profile is another alternative instead of writing UDFs. The same is with Fluent Expressions. But now you are using UDF: that is okay.

    • vighnesh
      Subscriber

      Thank you. Will try increasing iterations(already done for 20 iterations) and also smaller time steps.


      lately i have been doing this for every 100sec,increase v at steps of 0.05m/s.


      is that okay?


      Regards,


      Vighnesh

    • DrAmine
      Ansys Employee

      That is your application: I don't know if this is okay as I do not know the application. If your application and reality require this ramp-up then you should try to do that.

    • vighnesh
      Subscriber

      Hi Amine,


      smaller time steps especially at transition...


      Do u mean..


      a. Should I try calculating Delta P for every 0.25 sec rather than 1sec.


      b. Should i try this for lesser duration time/change in velocity (lately i have been doing this for every 100sec,increase v at steps of 0.05m/s)

    • DrAmine
      Ansys Employee

      Just try and report. I was meaning using smaller time steps in general and more iteration during each time step (set it to 20 max and report interval to 5 to enforce 5 iterations every time step).

    • vighnesh
      Subscriber

      Hi Amine,rwoolhou,


      Can I know how Ansys calculates the pressure,velocity etc. (back end code on which equation/formula it uses). I have theoretically calculated Delta P which is not close to the value I got from Ansys. I need to know how does Ansys calculate those values.


      regards,


      Vighnesh

    • Rob
      Ansys Employee

      The equations are all in the theory guide: we calculate values at each cell and iterate to a solution.  Differences to theory can be due to limitations in the theory (eg assumptions in the equations), insufficient mesh/resolution, user error etc so there's no one reason for a discrepancy. 

    • vighnesh
      Subscriber

      Thanks rwoolhou!!!


       

    • vighnesh
      Subscriber

      Hi people,


      How can i add temperature parameter at the inlet along with the velocity (already mentioned in above UDF) to the attached UDF program.


      Regards,


      Vighnesh

    • DrAmine
      Ansys Employee

      That is with the parameter "i" passed to the UDF. You need to identifiy which "i" matches velocity magnitude and temperature then. Better to start with a dummy and say provide dummy but eye catcher values like if i== 3, 111, if i==4 333, ....


      Alternative to use another DEFINE_PROFILE.

    • vighnesh
      Subscriber

      Can i do all in one program?? what i mean is for


      time>=0 to time<100 having velocity 0.03 m/s all the way til time>=3900 to time<4000 having velocity 1.21 m/s ( total 40 time steps) with individual temperature value 30,40,50,60 degree C for all 40 time steps in one go i.e total 40*4=160 readings.


      Regards,


      Vighnesh

    • DrAmine
      Ansys Employee

      Yes you can do it within a single DEFINE_PROFILE. i is just the placeholder where the udf is hooked. So the value will change based on where you are hooking the UDF profile. But you need to test with dummy UDF to know which i a certain place is associated with.

    • vighnesh
      Subscriber

      Hi abenhadj,


      Can u please elaborate.i need to run entire udf for 30degree first then for 40 degree moving on till 70degree. how can i hook it to this UDF. Have done some modification below hope you have some good suggestion. 


       


      #include "udf.h"


      DEFINE_PROFILE(velocity_magnitude,t,temp)


      {


      real velocity;


      real the_current_time;


      face_t f;


      For(real temp=30; temp<=70;temp+=10)


      {


      the_current_time = CURRENT_TIME;


      if ((the_current_time>=0) && (the_current_time<100))


      {


      velocity=0.03;


      }


      .


      .


      .


      .


      .


      if ((the_current_time>=3900) && (the_current_time<4000))


      {


      velocity=1.21;


      }


      }


      begin_f_loop(f,t)


      {


      F_PROFILE(f,t,temp) = velocity;


      }


      end_f_loop(f,t)


      }

    • DrAmine
      Ansys Employee
      I don't understand your UDF.
    • vighnesh
      Subscriber

      Hello abenhadj,


      sorry for the inconvenience.


      I need to run entire UDF for 30 degree first then for 40 degree moving on till 70 degree. How can i hook it to this UDF. Present UDF gives the inlet velocity for an assigned time say 0.03 m/s for 0-99 sec,0.06 m/s  for 100-199 sec till 1.21 m/s for 3899-3999 sec so total 40 inlet velocities at 0.03 individual increment. I need this inlet velocity for given inlet temperature i.e. for 0 to 3999 sec i need to vary my inlet velocity as well as inlet temperature.


      Please find the attached image file.


      Regards,


      Vighnesh


       

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