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

UDF with data-output to file

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By Deepblack
  • 1 Post By pakk

 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old   January 14, 2014, 13:11
Question UDF with data-output to file
  #1
New Member
 
-
Join Date: Nov 2013
Posts: 11
Rep Power: 12
Deepblack is on a distinguished road
Hello everyone,

I am writing a UFD to simulate a dynamic mesh in Fluent.
The function itself works fine. But I want to include a data output, so I can work with the values (e.g. in Matlab). Besides, it's important for me to have a feedback what the function does because I'm still learning C / UDFs and need to understand the language.

Here is my UDF:

//==================================

#include "udf.h"
#include <stdio.h>

DEFINE_CG_MOTION(movement,dt,vel,omega,time,dtime)
{
real t = CURRENT_TIME;
real a,w;
a=1.6;
w=1.5;
NV_S(vel, =, 0.0);
if (!Data_Valid_P())
return;

vel[0]=1;
vel[1] = a * sin(w*t);

printf("x-Vel: %f, y-Vel: %f",vel[0],vel[1]);

// Works till here!
// Data output:

FILE *str;
str = fopen ("Output.txt","w");

if(str==NULL)
{
printf("Error\n");
}

fprintf (str,"x-vel: %f , y-vel: %f \n", vel[0], vel[1]);
fclose (str);
}

//============================

The last part SHOULD create a "Output.txt" file and save all the velocities line by line in it. I hoped that the \n would work but it doesn't.
The file appears and the LAST velocity entry is in line one.

Here is my question: How can I make this UDF write each entry in a new line?

I really hope you guys can help me.
soheil_r7 likes this.
Deepblack is offline   Reply With Quote

 

Tags
data extract, data file, output data, udf exporting variable


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
patch error OF v2.2.2 mac hewei OpenFOAM Installation 4 November 30, 2013 16:55
Trouble compiling utilities using source-built OpenFOAM Artur OpenFOAM Programming & Development 14 October 29, 2013 10:59
[swak4Foam] swak4Foam-groovyBC build problem zxj160 OpenFOAM Community Contributions 18 July 30, 2013 13:14
ParaView Compilation jakaranda OpenFOAM Installation 3 October 27, 2008 11:46
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 01:24


All times are GMT -4. The time now is 07:58.