CFD Online Logo CFD Online URL
Home > Forums > Fluent UDF and Scheme Programming

UDF: How to load data from an external file into a vector

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Display Modes
Old   June 16, 2016, 07:18
Default UDF: How to load data from an external file into a vector
New Member
Join Date: Aug 2015
Posts: 10
Rep Power: 4
EmiS is on a distinguished road

I would like to impose inlet velocity values for unsteady flow by a udf. I have 2 files, one containing a single column of time values, and the other containing a column of corresponding velocity values (let's assume that at given time, velocity is uniform across the inlet surface).

I managed to make this work by creating two large arrays with time and velocity values hard-coded directly in the udf source code. Now I'm trying to have the data read from an external file, and I'm stuck. Ideally, I would like to read the values only once at startup, and then keep them in memory. Can this be done?
I'm trying to use the macro DEFINE_EXECUTE_ON_LOADING(name, libname), but unfortunately I have no idea what 'libname' should be.
I aslo thought about using a macro DEFINE_RW_FILE (from UDF docuemntation) but I don't manage to store the data from my external file into a vector "visible" for all the other macros of the UDF (especially the DEFINE_PROFILE)

I pasted a piece of my UDF, which returns to me that the "symbol velocityExp is not defined".

On a more general note, does Fluent and the UDF system support linking to external libraries? Suppose I have my own code written in C/C++ which is fairly large and does some complex computation to obtain boundary values. Is there a way of compiling this separately and then linking it to udf which would only call one high-level function (something like (get_my_bc(time, x, y, z) ....)?

Any working example code to load files on startup would be greatly appreciated.

Thank you very much for your help.


/* UDF code - Exctract */
/* */

extern real velocityExp[90];

void read_data_velocity(FILE *ptr_velfile)
int i;

ptr_velfile = fopen("ExpData.txt", "r");
printf(":%s:\n", "Read input file for Velocity!");

for (i=0;i<90;i++)
fscanf (ptr_velfile, "%lf", &velocityExp[i]);

printf ( "%lu\n", sizeof velocityExp );
printf(":%s:\n", "Close input file for Velocity!");


DEFINE_RW_FILE(reader_velocity, ptr_velfile)

Message0("Reading UDF data from data file...\n");


host_to_node_real(velocityExp, 90);

EmiS is offline   Reply With Quote


boundary condition u, global vector, load text file, udf

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use finite area method in official OpenFOAM 2.2.0? Detian Liu OpenFOAM Meshing & Mesh Conversion 4 November 3, 2015 04:04
Problem installing swak_2.x for OpenFoam-2.4.0 towanda OpenFOAM Installation 6 September 5, 2015 21:03
Trouble compiling utilities using source-built OpenFOAM Artur OpenFOAM Programming & Development 14 October 29, 2013 11:59
Error bulding swak4Foam sfigato OpenFOAM Installation 18 August 22, 2013 12:41
Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Native Meshers: blockMesh 10 April 2, 2007 14:00

All times are GMT -4. The time now is 02:25.