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 Members List Search Today's Posts Mark Forums Read

Rating: 3 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:	8581
Size:	6.8 KB
ID:	188  
Posted in Uncategorized
Views 13252 Comments 16 Edit Tags Email Blog Entry
« Prev     Main     Next »
Total Comments 16

Comments

  1. Old Comment
    Dear trollreign,

    Thank you very much for detailed description!
    Could you please specify how to "Start Fluent with "C:\Program Files\ANSYS Inc\v140\ fluent\fluent14.0.0\launcher\win64"". "win64" is a folder, how could i start fluent with it?
    permalink
    Posted December 3, 2013 at 10:40 by MichaelVS MichaelVS is offline
  2. Old Comment
    Dear Trollreign,
    Thanx for your help.
    I followed all the steps until 6.2, but when I start fluent again and i try to compile my UDF I get this message: "fatal error LNK1104: cannot open file 'LIBCMT.lib' ".
    Do you have any idea how to solve this issue?
    permalink
    Posted January 19, 2014 at 11:51 by giovanni.el giovanni.el is offline
  3. Old Comment
    Quote:
    Originally Posted by giovanni.el View Comment
    Dear Trollreign,
    Thanx for your help.
    I followed all the steps until 6.2, but when I start fluent again and i try to compile my UDF I get this message: "fatal error LNK1104: cannot open file 'LIBCMT.lib' ".
    Do you have any idea how to solve this issue?
    I followed all these steps and now I get another error, similar to yours:
    LNK2019: unresolved external symbol

    Any suggestions?
    permalink
    Posted January 24, 2014 at 14:41 by nenazarian nenazarian is offline
  4. Old Comment
    Hi Trollreign,

    I am facing the x64 system problem. I have Fluent 14, win 7 and Visual Studio from 2008 to 2012.

    I have tried to start Fluent from the VS2012 Cross Tools command prompt and it didn't work. Then I decided to update the environment variables as Messi indicated in the post http://www.cfd-online.com/Forums/flu...tml#post471365
    I've used SDK v7.1A and visual studio 11 (I don't know why I haven't got a Visual Studio 2012 folder) instead of v6.0A and 9.
    This hasn't solved my problem either.
    Now I'm having this message:

    Code:
    c:\program files\ansys inc\v140\fluent\fluent14.0.0\src\global.h(10) : fatal error C1083: Cannot open the include archive: 'stdio.h': Invalid argument
    And then the former error:

    Code:
    Opening library "c:\users\<working directory>libudf"...
    Error: The UDF library you are trying to load (C:\Users\<working directory>\libudf) is not compiled for 3d on the curent platform (win64).
    What should I try next?

    Any comment would be highly appreciated.

    Thanks a lot!
    permalink
    Posted January 28, 2014 at 05:58 by Bollonga Bollonga is offline
  5. Old Comment
    Hi,
    Thanks a lot for your guide. I've been trying to get UDFs til work for some time now.
    I am getting an error:

    LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib2

    Does anyone have any suggestions on how to fix it?

    (windows 8.1, installed visual studio express 2013, visual studio 2010 (to get the old math.h), Microsoft .NET Framework 4.5.1, Windows Software Development Kit 8, and ANSYS Fluent v15 x64)

    Best regards,
    Jakob
    permalink
    Posted February 18, 2014 at 07:35 by hrvig hrvig is offline
  6. Old Comment
    Quote:
    Originally Posted by nenazarian View Comment
    I followed all these steps and now I get another error, similar to yours:
    LNK2019: unresolved external symbol

    Any suggestions?
    Did you solve it?
    permalink
    Posted February 18, 2014 at 07:40 by hrvig hrvig is offline
  7. Old Comment
    Me too, at some point, I got the error "fatal error LNK1104: cannot open file 'libcmt.lib'."

    Then I found out that libcmt.lib is only present in the Microsoft Visual C++ 2010 Express (C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib).

    So I started to just use Microsoft Visual C++ 2010 Express, i.e. start Fluent from the Visual Studio Command Prompt (2010).

    My udf compiled flawlessly! I'm halfway there...

    But then when I try to load it, I got the following error:
    Opening library "my working directory\libudf"...
    Error: Error code: 193

    And I'm stuck... Anybody knows what to do with this error?

    Thanks.
    permalink
    Posted April 23, 2014 at 19:06 by macfly macfly is offline
  8. Old Comment
    Quote:
    Originally Posted by macfly View Comment
    Me too, at some point, I got the error "fatal error LNK1104: cannot open file 'libcmt.lib'."

    Then I found out that libcmt.lib is only present in the Microsoft Visual C++ 2010 Express (C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib).

    So I started to just use Microsoft Visual C++ 2010 Express, i.e. start Fluent from the Visual Studio Command Prompt (2010).

    My udf compiled flawlessly! I'm halfway there...

    But then when I try to load it, I got the following error:
    Opening library "my working directory\libudf"...
    Error: Error code: 193

    And I'm stuck... Anybody knows what to do with this error?

    Thanks.
    Same problem here. Help please!
    permalink
    Posted April 29, 2014 at 05:49 by warrior warrior is offline
  9. Old Comment
    In the end, I uninstalled Microsoft Visual Studio Express 2010 and 2013. I installed Microsoft Visual Studio 2010 Ultimate and everything works!
    permalink
    Posted April 29, 2014 at 07:40 by macfly macfly is offline
  10. Old Comment
    I encountered the below error, followed the step 1-5 and resolved it

    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
    #----------------------------------------------------------

    Step-1 : Enable visualization technology in the BIOS setting in Windows 8 or 7

    Step-2 : install Microsoft visual studio 2012 express

    Step-3 : open VS2012 X64 Cross tools Command Prompt, change directory to working folder , where you have the *.c file

    Step-4 : open Fluent V14.5 through step-3 command prompt window, make sure you open with appropriate 2D or 3D double precision options

    Step-5 : compile the UDF
    permalink
    Posted June 4, 2014 at 22:53 by jthiakz jthiakz is offline
  11. Old Comment
    For anyone who don't have VS2010, there is a simple way solve the math.h problem:
    find the line as:

    _CRTIMP double __cdecl cbrt(_In_ double _X);

    delete or comment it.
    In VS 2013, it is located at Line 482.
    permalink
    Posted July 29, 2014 at 12:38 by p36288 p36288 is offline
  12. Old Comment
    Quote:
    Originally Posted by MichaelVS View Comment
    Dear trollreign,

    Thank you very much for detailed description!
    Could you please specify how to "Start Fluent with "C:\Program Files\ANSYS Inc\v140\ fluent\fluent14.0.0\launcher\win64"". "win64" is a folder, how could i start fluent with it?
    I think it represents something like:
    "C:\Program Files\ANSYS Inc\v140\fluent\ fluent14.0.0\launcher\win64\launcher1.exe"
    or
    "C:\Program Files\ANSYS Inc\v140\fluent\ntbin\win64\fluent.exe" -r14.0.0 -shortcut
    that starts the Fluent Launcher panel, click OK you will enter Fluent, then load your case.
    permalink
    Posted July 29, 2014 at 23:07 by p36288 p36288 is offline
    Updated July 30, 2014 at 03:27 by p36288
  13. Old Comment
    Hi all,

    I encountered the same problem:
    LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib2

    The solution came when I added the following line in the path variable (see p.7 of the present post):

    ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin;C:\Program Files\ANSYS Inc\v120\fluent\ntbin\win64
    permalink
    Posted January 14, 2015 at 10:59 by MichaelVS MichaelVS is offline
  14. Old Comment
    hi trollreign,

    this was a fantastic post. you saved me a lot of time!

    thanks
    ak
    permalink
    Posted July 10, 2015 at 03:43 by ak6g08 ak6g08 is offline
  15. Old Comment
    Hi all,

    thanks dear Trollreign for your detailed explanation.
    unfortunately I have done all he same procedure mentioned but I couldn't compile the UDF.

    The system I am using:
    windows 8.1 x64
    visual studio 2013 ultimate
    visual studio 2010 ultimate
    Ansys fluent version 2015

    problem of "nmake" solved by installing both fluent and visual studios in the C:\ root. before installing in the same root I got that error.

    I still get the error
    The UDF library you are trying to load (libudf) is not compiled for 2d on the curent platform (win64).

    I am not an expert fluent user and the purpose of posting was only to share my experience. (failure experience )

    any comments would be appreciated.

    Best regards,
    Parham
    permalink
    Posted July 17, 2015 at 04:38 by Parham Vatankhah Parham Vatankhah is offline
  16. Old Comment
    I am experiencing the error LINK : fatal error LNK1104: cannot open file 'LIBCMT.LIB. I have tried Michael's method but i failed to make it work.

    Anyone has any other solutions to this?
    permalink
    Posted August 23, 2015 at 03:38 by tsaget tsaget is offline
 

All times are GMT -4. The time now is 23:57.