CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

How to read from file?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 26, 2014, 08:53
Default How to read from file?
  #1
New Member
 
Tom
Join Date: Mar 2014
Posts: 19
Rep Power: 12
blowback is on a distinguished road
Hello,

I'd like to create UDF that assigns over 30 different values contained in one matrix to variable which appears in DEFINE_PROFILE function.

In this example I tried to do this only for 2 different q values. I don't want to do it by hand, because I'd like to have easy possibilites to change q values which are contained in .txt file

After compiling, assigning boundary conditions and performing simulation 0 heat flux values are shown on faces.

#include "udf.h"
#include <math.h>
#include <stdio.h>
float q[2];
FILE *file;
DEFINE_EXECUTE_ON_LOADING(udf, libname)
{
int i;
file = fopen("power.txt", "r");
for (i=0;i<2;i++)
{
fscanf(file, "%g", &q[i]);
}
fclose(file);
}
DEFINE_PROFILE(p11,ft, var)
{
real x[3];
real z;
face_t f;
real q0 = q[0];
begin_f_loop(f,ft)
{
F_CENTROID(x,f,ft);
z = x[2];
F_PROFILE(f,ft,var)= (2/M_PI)*q0*sin(((z-0.287)/0.01)*M_PI);
}
end_f_loop(f,ft)
}
DEFINE_PROFILE(p12,ft, var)
{
real x[3];
real z;
face_t f;
real q0 = q[1];
begin_f_loop(f,ft)
{
F_CENTROID(x,f,ft);
z = x[2];
F_PROFILE(f,ft,var)= (2/M_PI)*q0*sin(((z-0.287)/0.01)*M_PI);
}
end_f_loop(f,ft)
}
blowback is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to calculate mass flow rate on patches and summation of that during the run? immortality OpenFOAM Post-Processing 104 February 16, 2021 09:46
[swak4Foam] Swak4FOAM 0.2.3 / OF2.2.x installation error FerdiFuchs OpenFOAM Community Contributions 27 April 16, 2014 16:14
[swak4Foam] swak4Foam-groovyBC build problem zxj160 OpenFOAM Community Contributions 18 July 30, 2013 14:14
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 11:57
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 15:00


All times are GMT -4. The time now is 18:09.