|
[Sponsors] |
UDF not extracting data from 3D model accurately in Fluent |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 |
New Member
TanmayK
Join Date: Apr 2025
Posts: 1
Rep Power: 0 ![]() |
Hello all,
I'm trying to write a simple UDF to extract the face area magnitude and outlet flow rate for the outlet face of a straight pipe. It is a transient simulation. The problem I'm facing is that the UDF is giving output of 0.0 for both parameters mentioned above, randomly for certain timesteps. I agree that the outlet flow rate value can be zero at certain time steps but the face area magnitude cannot be zero ever, and that's what is puzzling me as to why it is giving a 0.0 value as output. The UDF is executed at the end of every time step. I print the values extracted by the UDF in a text file at every time step. Eventually I want to use these values extracted by the UDF for calculations performed by a 3-element Windkessel model at every time step, and therefore it is important that the UDF extracts correct values at every time step. Pipe diameter = 4cm, length = 30cm Inlet BC: transient velocity profile Outlet BC: transient pressure profile Time step = 0.001 s I have attached photos of the geometry, the inlet and outlet boundary conditions profiles, the UDF code written in C that I'm using, and a photo of the output file which shows the erroneous output values (highlighted in yellow). I would really appreciate if someone can point what is going wrong with the UDF. Following is the UDF I'm using: Code:
#include "udf.h" #include <stdio.h> DEFINE_EXECUTE_AT_END(print_outlet_flow) { Domain *d; Thread *t; face_t f; real area_vec[ND_ND]; real face_area; real vol_flow; real total_area = 0.0; real total_vol_flow = 0.0; static int first = 1; FILE *fp; int outlet_zone_id = 6; /* <<< set this to your outlet face-zone ID */ /* get the domain and the outlet thread */ d = Get_Domain(1); t = Lookup_Thread(d, outlet_zone_id); /* open file once for header, then append thereafter */ if (first) { fp = fopen("outlet_flow.txt", "w"); if (!fp) { Message("Error: could not open outlet_flow.txt for writing\n"); return; } fprintf(fp, "Time\tTotalArea\tTotalVolFlow\n"); first = 0; } else { fp = fopen("outlet_flow.txt", "a"); if (!fp) { Message("Error: could not open outlet_flow.txt for appending\n"); return; } } /* loop over all faces in the outlet thread */ begin_f_loop(f, t) { /* get face‐area vector and magnitude */ F_AREA(area_vec, f, t); face_area = NV_MAG(area_vec); /* get volumetric flux through this face */ vol_flow = F_FLUX(f, t); total_area = total_area + face_area; total_vol_flow = total_vol_flow + vol_flow; } end_f_loop(f, t); /* write time, total area, and total volumetric flow rate */ fprintf(fp, "%e\t%e\t%e\n", CURRENT_TIME, total_area, total_vol_flow); fclose(fp); } Thank you. |
|
![]() |
![]() |
![]() |
Tags |
fluent udfs, output to file, pipe flow, udf and programming, windkessel |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Error: WorkBench Error: Could not handle event: SolutionStatusUpdate | Kieyo | Fluent Multiphase | 0 | November 9, 2022 23:58 |
Integration of a Custom C++ Model into FLUENT | Syed Haider | FLUENT | 2 | March 6, 2018 23:37 |
Integrating data from UDF to Fluent | say2017 | FLUENT | 0 | October 20, 2017 13:50 |
Fluent Radiation/porous media | Schmitt pierre-Louis | FLUENT | 26 | September 1, 2016 10:29 |
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem | Attesz | OpenFOAM Meshing & Mesh Conversion | 12 | May 2, 2013 10:52 |