CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums

Getting ANSYS 14 Fluent, Windows 8.1 and VS2013 to compile UDFs

Register Blogs Community New Posts Updated Threads Search

Rating: 9 votes, 5.00 average.

Getting ANSYS 14 Fluent, Windows 8.1 and VS2013 to compile UDFs

Posted October 27, 2013 at 18:00 by trollreign

1. Goal

I am a beginner at Fluent, and even more so concerning UDF's. I am facing a problem where I have to use a velocity profile at my inlet boundary and later I would like to write code to model an actuator disk. After reading the corresponding sections of the Fluent 14 UDF Manual I felt like I am ready to face the task.

Things didn't go half as smooth as I expected and in the end I spent a weekend getting it to work.


2. Software

First of all, my system consists of the following:
- Microsoft Windows 8.1 x64
- ANSYS Fluent 14.0 x64
- Microsoft Visual Studio 2013 Express
- Windows Software Development Kit 8.1
- Microsoft .NET Framework 4.5.1


3. Loading a UDF into Fluent

So in this section I describe quickly how easy it is (in theory) to use a UDF in Fluent 14.
0. Write your UDF and make sure you save it to your working directory where your case & data files are.
1. Open your mesh or case, and then go through the following
Define --> User-Defined --> Functions --> Compiled.
2. In the window that appears just add your source files (.c) on the left and your header files (.h) on the right.
3. Click 'Build'
4. Select your source files in the list and click Load.



There are several points where this can go wrong, I would like to write about some of these.

4.1 Problem with 'nmake'

According to the manual, I wrote a C code, saved it in my working folder, added it, clicked Build... and then I saw this:

(system "copy "C:\PROGRA~1\ANSYSI~1\v140\fluent"\fluent14.0.0\sr c\makefile_nt.udf "example\win64\2d\makefile" ")
1 file(s) copied.
(chdir "example")()
(chdir "win64\2d")()
'nmake' is not recognized as an internal or external command,
operable program or batch file.
'nmake' is not recognized as an internal or external command,
operable program or batch file.

Done.



4.2 Solution to the 'nmake' problem

Without any detail, the problem is caused because nmake.exe cannot be found. The solution is to start Fluent from the x64 version of the Visual Studio 2013 Command Prompt:

1. Open the Start screen (press Windows button on your keyboard)
2. Type 'Visual Studio Tools', click the folder.
3. In the folder click and start 'VS2013 x64 Cross Tools Command Prompt'
4. Navigate to your working folder, i.e. the folder where your case and data files are (.cas & .dat).
5. Start Fluent with "C:\Program Files\ANSYS Inc\v140\fluent\fluent14.0.0\launcher\win64" (quotation signs included, in case of standard installation"
6. Make sure that on the Environment tab 'Setup Compilation Environment for UDF' is ticked. The default address is fine.

Starting Fluent this way should solve the 'nmake' problem and the compilation message should look like this:

(system "copy "C:\PROGRA~1\ANSYSI~1\v140\fluent"\fluent14.0.0\sr c\makefile_nt.udf "exex\win64\2d\makefile" ")
1 file(s) copied.
(chdir "exex")()
(chdir "win64\2d")()
# Generating ud_io1.h
velocity_profile.c
# Generating udf_names.c because of makefile velocity_profile.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj velocity_profile.obj
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library libudf.lib and object libudf.exp

Done.



5.1 Problem with x64 system

In case you do not have Microsoft Visual Studio 2013 Express then likely you tried starting Fluent from the 'Visual Studio Command Prompt (2010)' or any other previous version of VS command prompt. It is likely that you encountered a problem when clicking Load, specifically this one:

The UDF library you are trying to load (libudf) is not compiled for 2d on the curent platform (win64).
The system cannot find the file specified.

X:\<your working folder>libudf\win64\2d\libudf.dll


The reason of this error is that previous versions of Visual Studio are 32bit and do not work with your x64 version of Fluent. You probably googled the problem and found advice to start Fluent from the command promt of the SDK (Software Development Kit) 7.0/7.1 instead, or from the command prompt of the .NET Framework. Unfortunately, as Microsoft states on their website at the Windows SDK 8.1 download page:
"The Windows SDK no longer ships with a complete command-line build environment. You must install a compiler and build environment separately. If you require a complete development environment that includes compilers and a build environment, you can download Visual Studio 2013, which includes the appropriate components of the Windows SDK."
Older versions of the .NET Framework and SDK do not seem to work properly on Windows 8.1 ([citation needed], just my experience ). I also found out that with a working x64 SDK installed you can start the simple windows command prompt (cmd.exe) with the proper environmental variables using a cmd.exe /k "<environmental variables>" command, which I failed to get to work.


5.2 Solution to the problem of x64 system

The solution to this is to start Fluent from the x64 command prompt 'VS2013 x64 Cross Tools Command Prompt' as described in (4.1) instead of previous versions of VS or SDK/.NET command prompts.


6.1 Problem with math.h

Another problem occurred even after I had everything set up. This problem was reported by cfd-online user KITetima as well in this forum topic.
The very simple c code to initialize the velocity on the inlet boundary to a given velocity profile did not compile, and the following error message appeared:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(482) : error C2059: syntax error : ','
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(482) : error C2143: syntax error : missing ')' before 'constant'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(482) : error C2143: syntax error : missing '{' before 'constant'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(482) : error C2059: syntax error : 'constant'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(482) : error C2059: syntax error : ')'

Done.


I could not figure out exactly what is the problem, but it seems that the header file math.h provided by VS2013 has some mistakes, or somehow isn't compatible with Fluent 14 (and Fluent 14.5).
First I tried to give the math.h header file for the UDF myself in the Header section (see Figure above), however, the compiler still used the math.h file that is located in C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include.


6.2 Solution to the problem with math.h

1. Keep the software installed on your computer, but also install Microsoft Visual C++ 2010 Express
2. Go to the following folder:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include
3. From this folder copy the math.h file to
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include
4. Start Fluent as described above in (4.2). Now you will be using VS2013 as compiler but the math.h file from VS2010, which worked fine for me.


7. Setting the Environmental Variables

Many pages that you find dealing with the problem give suggestions like "make sure your environmental variables are set". However, it is not clear how to do that. I succeeded finally at making it work, however, before that I managed to ruin my Windows and I needed a network registry operation to fix it, so first of all:
0. DO NOT DELETE OR MODIFY WHAT IS ALREADY IN THE 'PATH' VARIABLE.
1. Right click on 'My computer'/'This PC' and click 'Properties'
2. On the left side of the screen click 'Advanced system settings'
3. On the bottom click 'Environmental variables'
4. In the bottom box look for the Variable named 'Path', select it and click 'Edit'
5. Be careful not to modify anything that is already there.
6. At the end, put a semicolon ( ; ) and after that paste the address of your Fluent executable, i.e. add to the end of the Path variable
;C:\<your Fluent executable folder>
7. Add to the end the folder where the 'vcvarsx86_amd64.bat' file of your Visual Studio 12 is found. By default this is:
;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64
8. Click OK and OK your way out of the My computer properties. You are all set hopefully.

This will enable you to start fluent by simply typing the command "fluent" in your command prompt. You can also add the 2D and 3D executables separately to the Path variable.

8. Remarks and disclaimer
I would like to emphasize that I am in no way an expert in CFD/C++/UDFs/Windows SDK, only a beginner user. I do not take any responsibility for anything described or suggested on this page, or any damage caused by following these steps. This is merely a summary of my experiences with my system, and I cannot guarantee that the solutions will work in any other setup (or with this setup on other systems).

However, I do hope that some will find it useful and some people will save many hours of searching for the solutions.
Kind regards,
L. Arany
Attached Thumbnails
Click image for larger version

Name:	001.PNG
Views:	42925
Size:	6.8 KB
ID:	188  
Posted in Uncategorized
Views 73365 Comments 23 Edit Tags Email Blog Entry
« Prev     Main     Next »
Total Comments 23

Comments

  1. Old Comment
    Thank you trollreign. It was very useful. you have saved a lot of times of people. Just wanted to update and share my experience and help others who feel like a beginner like myself . I am using Workbench v18.1. I was trying to model 3ddp parallel a 2 stroke scavenging which ansys has a tutorial for. To make the story short the udf file which was created in 2006 didn't work with 64bit error and as it was recommended, I installed free version of visual studio community 17 from Microsoft (before starting installation I checked all the boxes which were relevant, and installing space was about 30 GB). I didn't change any environmental variable. In my start menu I followed "Visual Studio 17 > Visual Studio Tools > VC > x86_x64 cross tool Command Prompt". In the VC folder, there were 3 other cmd options which didn't work. make sure you select x86_x64. then in the cmd window I navigated to my working folder and copied the fluent luncher address after it. the command line looked like this which the "new run with sdk" is my working folder: E:\Ansys files\2 stroke\Fluent\new run with sdk>"C:\Program Files\ANSYS Inc\v181
    \fluent\fluent18.1.0\launcher\win64\launcher1.exe" . In the launcher, I selected 3d, double precision, and 10 cores, started fluent, compiled the default .c udf file (which was in the same working folder), built the library and finally it was loaded successfully. Even better, in cmd window I started my workbench project file (which contain my fluent component). The workbench opened and started the fluent from there like always and I could successfully load the library. I hope it works for you too.
    permalink
    Posted February 14, 2018 at 18:56 by nima_nzm nima_nzm is offline
  2. Old Comment
    it worked! thank you so much!
    permalink
    Posted July 10, 2019 at 12:09 by prayash prayash is offline
  3. Old Comment
    I am very disturbed due to this error. I want to simulate the Pure Yaw Motion using following UDF but i ge this error
    (Error: The UDF library you are trying to load (libudf) is not compiled for 3d on the current platform (win64).\n\nThe system cannot find the file specified.
    \n\nC:\Users\enaz8\Desktop\Try1\libudf\win64\3d\li budf.dll
    Error Object: #f)

    anybody please tell me.
    My udf
    #include "udf.h"
    #include "dynamesh_tools.h"

    real a0, w, u0;

    DEFINE_CG_MOTION(motion, dt, vel, omega, time, dtime)
    {
    Thread *t;
    NV_S(vel, = 0.0);
    NV_S(omega, = 0.0);
    if (!Data_Valid_P())
    {
    Message("Wrong\n");
    return;
    }
    t = DT_THREAD((Dynamic_Thread *)dt);
    a0 = 0.1;
    w = 2.513; // frequency
    vel[0] = 0.0; // x-component of velocity
    vel[1] = -a0 * w * cos(w * time); // y-component of velocity
    vel[2] = 0.0; // z-component of velocity
    omega[0] = 0.0;
    omega[1] = 0.0;
    omega[2] = 0.0;
    Message("time:%f vely:%f\n", time, vel[1]);
    }
    permalink
    Posted February 14, 2024 at 14:46 by Nazir Ahmed Nazir Ahmed is offline
 

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