- **Fluent UDF and Scheme Programming**
(*https://www.cfd-online.com/Forums/fluent-udf/*)

- - **Applying pressure on a boundary**
(*https://www.cfd-online.com/Forums/fluent-udf/86532-applying-pressure-boundary.html*)

Applying pressure on a boundaryHello Everyone,
Been a regular visitor to this site. Recently started playing with UDFs. I am stuck at this one. I have to model a pressure boundary condition similar to a hydrostatic pressure at the inlet. My problem is that I am not able to get the pressure already available at the first time step at every face of the inlet thread (I use a steady state solution as my initial condition for the unsteady case) and then compute its average. I have to store this as the initial pressure. Then I have to decrease the initially calculated volume Q0 at the inlet with the volume flux and compute pressure P1 using the new remaining volume Q1 to be stored in a user defined memory location (MEM2) and use it in the next time step. Can anyone take a look and help me out here. Thanks, Pranab #include "udf.h" DEFINE_PROFILE(pv1, t, index) { face_t f; int n = N_TIME; /*no. of time steps*/ real P1; real P_sum=0; real P_avg=0; real Q0, Q1; real vol_out; real mass_flux=0; real mass_flux_tot=0; real MEM1, MEM2, MEM3; Thread *t1; int d; int Zone_ID = 22; /*look up the id from the boundary conditions panel*/ d=Get_Domain(1); /*domain*/ t1=Lookup_Thread(d,Zone_ID); /**Initialize UDM to face-pressure at the first time-step**/ if(n==1) {printf("\nFirst timestep\n"); begin_f_loop(f,t1) { P_sum = P_sum + F_P(f,t1); P_avg = P_sum / 7; F_UDMI(f,t1,0) = P_avg; /*constant for all iterations*/ Q0 = (P_avg * 10000)/(0.6679 * 9.81); /*initial volume*/ F_UDMI(f,t1,1) = Q0; F_UDMI(f,t1,2) = Q0; /*constant for all iterations*/ }end_f_loop(f,t1) } /**Assign all UDM's to a variable to be used later**/ MEM1 = F_UDMI(f,t1,0); MEM2 = F_UDMI(f,t1,1); MEM3 = F_UDMI(f,t1,2); / begin_f_loop(f,t1) { mass_flux = mass_flux + F_FLUX(f,t1); }end_f_loop(f,t1) mass_flux_tot = mass_flux; vol_out = 0.0001* mass_flux_tot/0.6679; /**Calculate remaining volume & new pressure**/ Q1 = MEM2 - vol_out; /**new volume**/ P1 = Q1 * MEM1 / MEM3; /**new pressure**/ printf("New Pressure = %f\n", P1); begin_f_loop(f,t1) { /**Apply new pressure on the face**/ F_PROFILE(f,t1,index) = P1; }end_f_loop(f,t1) /**Update the udm with new Q1**/ F_UDMI(f,t1,1) = Q1; } |

Hello All,
I am still stuck at the problem... so I decided to narrow down to the place that I was stuck. I am having issues with the UDM here. I used a small UDF to check. Here it is: #include "udf.h" DEFINE_EXECUTE_AT_END(abcd) { face_t f; Thread *t1; int d; int Zone_ID = 22; d = Get_Domain(1); t1 = Lookup_Thread(d,Zone_ID); begin_f_loop(f,t1) { F_UDMI(f,t1,0) = F_P(f,t1); } end_f_loop(f,t1) printf("memory = %f\n", F_UDMI(f,t1,0)); } But I always get the value of the UDM as 0 when I plot it every iteration. Can anyone suggest anything. What is it that I am overlooking? Also, in steady state calculations, the UDM never gets printed to the console while in the unsteady calculations it does. This is also bothering me. |

Hi,
these changes may help you. (just a suggestion, I didn't check that before) Code:
`#include "udf.h"` |

Hi Amir,
Thanks for the reply. My code that I posted earlier did compile after I made some changes: begin_f_loop(f,t1) { Message("test"); val += F_P(f,t1); F_UDMI(f,t1,0) = val; val1 = F_UDMI(f,t1,0); printf("\nmemory = %f\n", val1); } end_f_loop(f,t1) The modified code that you gave me, which utilizes the adjacent cell thread funda also ran, and both gave me the same result. But that did not solve my problem. My problem is that the pressure on the boundary in my case file is actually 20 Pa. But what returns from the function for each cell is completely different (values like 14 Pa, 10 Pa, 12 Pa, 5 Pa, -3 Pa, etc.) which is wrong. I need the variable (in this case pressure) on the boundary face thread as applied to the boundary in fluent and store the average of all the cell faces in a UDM. (I have not included the averaging process in the above code). Any suggestions/comments? Thanks again for the earlier code. |

Hi All,
Continuing my discussion here, I would like to ask if somebody has had a problem like this before: When I use the F_FLUX(f,t) macro to get the value of total pressure on a face thread, I get a value that is not consistent with the mass flow rate that I get from the Report -> Fluxes -> Mass Flow Rate menu. What can be the reason for this? My model is a "2D axisymmetric" one. Is it because I am missing a factor of 2*pi or something like that in my UDF? I noticed that the difference is a factor of about 6, F_FLUX gives me the lesser value. Any suggestions? |

From the udf-Manuel:
C-side calculations for axisymmetric models in ANSYS FLUENT are made on a 1 radian basis. Therefore, when you are utilizing certain data access macros (e.g., F_AREA or F_FLUX) for axisymmetric flows, your UDF will need to multiply the result by 2*PI (utilizing the macro M_PI) to get the desired value. cheers |

Thanks Max,
I should have read the manual more carefully. |

All times are GMT -4. The time now is 17:12. |