CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF to write interp files (https://www.cfd-online.com/Forums/fluent/29286-udf-write-interp-files.html)

Karl January 28, 2002 12:23

UDF to write interp files
 
Hello,

I am trying to write a UDF so that I can save an interpolation file containing velocity and TKE data every few time steps for only the stationary zone of a two zone sliding mesh. This doesn't seem to be possible using a journal file or macro as the text interface doesn't provide capablility to write these files for only a single zone (although the GUI interface does).

I am having a deal of difficulty understanding how to write these UDF's, even though I know C. Does anyone have a skeleton of a similar UDF I could use or suggestions in getting started. Your advice is very much appreciated. Thanks.

Karl

Greg Perkins January 31, 2002 17:49

Re: UDF to write interp files
 
Have you searched the archives for a sample udf? I've posted quite a few over the past year or so.

The udf manual also has some code for looping pver threads/cells in the domain - you can use that.

Basically I would do something like:

Domain *domain;

DEFINE_ON_DEMAND(EXEC_Write_Interpolate) {

/* --- here define outfile and open file using

usual C code.... */

/* --- loop over all cells in domain - you

can restict to particular threads using

additional code. */

thread_loop_c(thread, domain)

{

begin_c_loop_int(cell,thread)

{

/* --- can access cell data */

/* --- eg. write temp */

fprintf(outfile,"%f",C_T(cell,thread));

/*--- write other data....*/

}

end_c_loop_int(cell,thread)

}

fclose(outfile); }

NOTE: I don't know the format of the interpolation file. Its probaly quite complex, so it will be easier for you to write your own file, and then write another udf to read this file into a new grid and perform the interpolation yourself. Perhaps Fluent can help.

The required code snippets, commands for doing complex things isn't documented by Fluent, so I think you'll find it easier to do it yourself than try writing your macro to produce a generic interpolation file which Fluent can understand.

Lu Hu February 4, 2002 19:02

Re: UDF to write interp files
 
Thanks for you udf file. Actually I wrote a similar one today following some examples. If I write " extern Domain *domain;", the compiler will return the following error messages:

Creating library libudf.lib and object libudf.exp esource.obj : error LNK2001: unresolved external symbol _domain libudf.dll : fatal error LNK1120: 1 unresolved externals NMAKE : fatal error U1077: 'link' : return code '0x460' Stop.

If I get rid of "extern" like what you did, everything's fine. I haven't run the dll yet( the cas file is missing :( ) and don't know if it works. Could you tell me why I can't use "extern" here? Thanks!

Lu

Greg Perkins February 4, 2002 19:39

Re: UDF to write interp files
 
Its a good question. To be honest I'm not sure - it may be to do with how Domain type is defined. The above works, and since I'm a bit pressed for time, I'm not going to spend any time to find out the details.

Let me know, if you work it out.

Greg

Lu Hu February 5, 2002 23:05

Re: UDF to write interp files
 
I guess you used compiled udf. I can compile the file and get a dll file. But when I tried to run the udf in Fluent, it gave the error message: Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: ()

I tried to debug the program and simplified it as:

#include "udf.h"

Domain* domain;

DEFINE_ON_DEMAND(test) {

Thread *t;

cell_t c;

thread_loop_c(t,domain)

{

begin_c_loop(c,t)

{

}

end_c_loop(c,t)

} }

The error still exists. Seems I cannot use thread_loop_c. The operation system is Win2000 Professional. Could you give me some suggestions? Thanks a lot.

Lu

Greg Perkins February 5, 2002 23:27

Re: UDF to write interp files
 
Actually I had another look a my source code, I do in fact use

extern Domain* domain;

as the declaration.....

Also I use unix - and all my code has worked on several platforms, HP-UX, IRIX6r10 etc. I don't use Windows - I'm not a big fan of this OS for Fluent, since they develop on unix boxes and when they port to Windows, some strange things have occurred in the past - acces to some variables is limited and the setup to compile is a bit different. Also, scripting etc in Windows is not standard, whereas on unix I can use the same scripts etc on a HP, an SGI or whatever - so this make things a lot easier, at least for me.

So can't really help much with detailed Win2k questions, sorry.

Greg


Lu Hu February 7, 2002 12:10

Re: UDF to write interp files
 
Anyway, thanks for your help. I am kind of hooked to win2000 and it is not easy to change to another system. I agree with you. Sometimes windows OS is rather confusing.


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