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

UDF reading files from a directory

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By Mohammad74
  • 1 Post By pakk
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By Mohammad74

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 28, 2021, 10:09
Smile UDF reading files from a directory
  #1
Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 30
Rep Power: 7
Mohammad74 is on a distinguished road
Hi,

I have written a udf using "dirent.h" header to read a bunch of text files from an specified directory and import them into Ansys Fluent. However after building the code in Fluent, it gives me this error:

..\..\src\data_import.c(2) : fatal error C1083: Cannot open include file: 'dirent.h': Invalid argument

What can I do now? It seems like Ansys does not support "dirent.h" header?
Is there any way to read a directory using Ansys UDFs?

Thank you!
Krite2002 likes this.
Mohammad74 is offline   Reply With Quote

Old   June 29, 2021, 01:02
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
We can't see how you tried to use that header file, so it is impossible for us to say if you made a mistake and how to fix it...
Mohammad74 likes this.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   June 29, 2021, 03:57
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
How to use a non-standard C library in a UDF
Mohammad74 likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   July 1, 2021, 09:17
Default
  #4
Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 30
Rep Power: 7
Mohammad74 is on a distinguished road
Hello and thank you for your responses.

Quote:
Originally Posted by AlexanderZ View Post
I read this post and also read the UDF guide on how to "Link Precompiled Object Files From Non-ANSYS Fluent Sources", but since I am a newbie and not familiar with how .obj files work and how to make them, I preferred not to try this.

Anyhow, I solved my issue by using my code to read the data outside fluent and write them into 2 new files which can be read easier using a fluent UDF with standard C headers (no "dirent.h").

But now I have another question:
How can I use this data in other UDFs with different source files? In other words how to share variables between different UDFs?
Mohammad74 is offline   Reply With Quote

Old   July 1, 2021, 21:22
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you may use UDMs (user-defined memory) to do that,
however, UDMs contains the variable value on each cell/face of the domain. It is array. So it could be not efficient to use UDM to store single values, but it's the simplest approach.

also you may write/read variable to file.

the third option is rpvars. These are variable created in fluent cortex (not UDF) using scheme language. rpvars could be read/written in UDF as well. rpvars could be of different typres: integer, double, array, strings, so on.
Read Ansys Fluent Customization manual.
Mohammad74 likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   July 2, 2021, 06:32
Default
  #6
Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 30
Rep Power: 7
Mohammad74 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
you may use UDMs (user-defined memory) to do that,
however, UDMs contains the variable value on each cell/face of the domain. It is array. So it could be not efficient to use UDM to store single values, but it's the simplest approach.
The UDM guide says you can define a maximum number of 500 UDMs but I want to store two matrices and one of them is a 2*361*11 matrix and the other one is 15*3. Should I define a UDM for each of their elements individually (which will exceed 500 UDMs.) or I can define 1 UDM for each matrix.

Also as you said, UDMs store variables of Cells/Faces or nodes but the data that I'm trying to store do not belong to any of these and I'm reading them from text files. So what should i do with the input arguments of F_UDMI macro (i.e. face and thread identifiers) ?

Thanks for assistance!
Mohammad74 is offline   Reply With Quote

Old   July 3, 2021, 14:44
Lightbulb
  #7
Member
 
Mohammad Shafiee
Join Date: Apr 2021
Posts: 30
Rep Power: 7
Mohammad74 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
you may use UDMs (user-defined memory) to do that,
however, UDMs contains the variable value on each cell/face of the domain. It is array. So it could be not efficient to use UDM to store single values, but it's the simplest approach.

also you may write/read variable to file.

the third option is rpvars. These are variable created in fluent cortex (not UDF) using scheme language. rpvars could be read/written in UDF as well. rpvars could be of different typres: integer, double, array, strings, so on.
Read Ansys Fluent Customization manual.

Hello,

So thanks to Ansys UDF manual, I managed to share my desired variables between different UDF source codes in a much simpler way than the methods mentioned above. Sharing it here so others might find it helpful:

Lets say you want to use the values of 2 matrices like: a[5][5] and b[5][5] that you have defined in a UDF called "Code1.c", in the UDF called "Code2.c".

1.First you must define these two matrices in one of the source codes as Global Variables which means they have to be defined outside the macro definition:

Code:
#include "udf.h"

real a[5][5] , b[5][5] ;

DEFINE_WHATEVER_MACRO(arg1,arg2,...)
{
    // Your macro code that uses a and b goes here.
}
2. Then you have to make a header file like "Extvar.h" in which you define the variables that you want to share as External, like this:

Code:
extern real a[5][5] , b[5][5] ;
3. Now you can include this header file in all the other UDF source codes (like "Code2.c" ) that are going to use a & b variables. Like this:

Code:
#include "udf.h"
#include "Extvar.h"

DEFINE_WHATEVER_MACRO(arg1,arg2,...)
{
    // Your code that uses a and b goes here.
}
4. This method works only for compiled UDFs. It is also important to note that when you are trying to compile the "Code1.c" and "Code2.c" source codes, you should also include the "Extvar.h" header file in the "Compiled UDFs" dialogue box.


I tested this and it worked just fine.
pakk likes this.
Mohammad74 is offline   Reply With Quote

Reply

Tags
udf and programming, udf code, udf compilation


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
[openSmoke] LaminarSMOKE compilation error mdhfiz OpenFOAM Community Contributions 7 October 4, 2022 13:57
SU2 7.0.7 Built on CentOS 7, parallel computation pyscript mpi exit error? EternalSeekerX SU2 3 October 9, 2020 18:28
1.7.x Environment Variables on Linux 10.04 rasma OpenFOAM Installation 9 July 30, 2010 04:43
critical error during installation of openfoam Fabio88 OpenFOAM Installation 21 June 2, 2010 03:01
Problems in compiling paraview in Suse 10.3 platform chiven OpenFOAM Installation 3 December 1, 2009 07:21


All times are GMT -4. The time now is 01:28.