Compiling UDF with ANSYS 16 and Visual Studio 2015

Compiling UDF with ANSYS 16 and Visual Studio 2015

To compile User Defined Functions (UDF) with ANSYS you need to install a C++ compiler. ANSYS recommends Visual C++ which is freely available in form of Visual Studio Community.

In this article I will only consider the case of x64 ANSYS.

1. Update udf.bat

Go to C:\Program Files\ANSYS Inc\v162\fluent\ntbin\win64 and back up the file udf.bat. We need to modify this file to add support for Visual C++ 2015. To this end, add below set MSVC_VERSION=0 the following lines

echo trying to find MS C compiler, version 140....
set MSVC_DEFAULT=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0
if exist "%MSVC_DEFAULT%\VC\vcvarsall.bat" set MSVC=%MSVC_DEFAULT%
if not "%MSVC%" == "" goto msvc_env140

Moreover, add above :msvc_env71 the following lines

call "%MSVC%\VC\vcvarsall.bat" x64
goto ms_c_end

Save the file udf.bat and you are good to go.

2. Compile your UDF

  • Make sure your code, header, mesh and fluent files are contained in a single folder (project folder).
  • Open ANSYS fluent and select the project folder as the current working directory.
  • In ANSYS' main window select Define -> User Defined Function -> Compile

X. Hint

Make sure in your UDF file's DEFINE statements are not spaces between brackets.


DEFINE_PROFILE (current_dens,t,i)



Additional spaces may lead to erratic behavior of the makefile script so that defined SOURCES, PROFILES, or DIFFUSIVITIES do not show in Fluent.

How to create a local copy of our wordpress site for testing

In this post I will briefly describe how to install wordpress on your windows machine and what to consider, when restoring the data of your live wordpress site to your local installation. This procedure can be useful to test wordpress (plugin/theme) updates locally before applying them to the life site.

Note: I assume that you are running wordpress against a MySql database and use a Windows machine for local testing.

0. Create a backup of your wordpress site

There are plenty of ways to create backups. The most convenient one is probably to use a plugin like one of these which takes care of everything. If you have direct access to the server, you may also just create a copy of the wp-content folder and your wp-config.php. You also have to copy the mysql database - refer to this Wordpress Wiki for detailed instructions.

1. Install Wordpress on your machine

  • Go ahead to the Microsoft Web Platform Site for Wordpress and hit the button Install Wordpress
  • The site will prompt you to download a tool called Web Platfrom Installer, or WebPI for short, which will take care of all the technical things like installing IIS, installing PHP, installing MySql, installing wordpress, and setting everything up.
  • You can find step by step instructions for the installation with WebPI here.
  • When your setup is complete, write down the precise url under which your local wordpress installation is available (e.g. http://localhost/wordpress/)

2. Restore your live site to your local machine

  • Restore the mysql database copied from your live site to your local mysql server. My recommendation is to leave the wordpress database created by WebPI as is and to restore your backup to a database with a different name, say wordpress-restored.
  • Overwrite the contents of your local wp-content folder with the ones of your live site.
  • Edit the local wp-config.php from your live site and enter the login data of your local mysql server and point it to your restored mysql database wordpress-restored.
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress-restored');
/** MySQL database username */
define('DB_USER', 'wp-restored-user');
/** MySQL database password */
define('DB_PASSWORD', 'wp-restored-pw');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
  • Find the section of your live site's wp-config.php containing the authorization keys and salts and insert the ones of your live site.
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');
  • Open the wp-login.php and find this line:
require( dirname(__FILE__) . '/wp-load.php' );

insert the following lines below

//FIXME: do comment/remove these hack lines. (once the database is updated)
update_option('siteurl', 'http://localhost/wordpress' );
update_option('home', 'http://localhost/wordpress' );
  • If you installed a newer wordpress version locally than the one running on your live site, head to the admin portal to initiate a database update.
  • That's it!

Plot3D with RegionFunction equivalent in MATLAB

Suppose you want to plot a function g depending on two variables x, y over a range where y depends on x.

Using Mathematica this can be done in essentially one line (not counting the definition of the function g and the lower and upper bounds f1 and f2).

f1[y_] := y^3 - 1
f2[y_] := y^3 + 1
g[x_, y_] := x^2 + y^2
Plot3D[g[x, y], {x, -2, 2}, {y, -2, 2},
 RegionFunction -> Function[{x, y, z}, f1[x] < y < f2[x]]]

The output will be like this.

Mathematica output

I am not aware of an equivalent function built directly into MATLAB. However, the same functionality can be achieved with some manual coding.

The essential idea is to create a surface in 3D space and plot this using MATLAB's surf function. I put the code in a gist, which you can find/fork/comment here.

The output looks like this.

MATLAB output

WOL with Realteak NICs on Windows 10


To restore WOL functionality disable Fast Start and install the Realtek device driver from here.

Long Story

After upgrading several machines from Windows 7 / 8.1 to Windows 10, I noticed that it was no longer possible to wake them over the network using the Wake on LAN magic packet.

Fast Start

One reason is that Windows 10 (as 8.1) due to its fast start feature shuts down the computer in the System Power State S4 instead of S5. In S4 all connected devices are powered off including the NIC. Therefore, the system is unable to receive the WOL Magic Packet for wakeup. When starting up from S4, on the other hand, the system can load a hibernation image from disk which eliminates the need to initialize hardware and dramatically cuts startup speed.

At a later time, the device manufactors may update their drivers and/or BIOS/UEFI firmware to allow WOL also from shut down state S4. For now, however, one has to disable shutting down to S4 to be able to use WOL.

To do this, right click Start, go to Energy Options and then select Select what the power button does. Elevate and then disable Fast Start.


A second issue is that the Realtek device driver which is currently installed from Windows Update seems to have a bug which avoids proper configuration of the machine to wake up after shutdown; wakeup from Sleep works, however.

The device driver available from the Realtek website seems to have this bug fixed. You can find it here.

Posted von Jan-Cornelius Molnar | mit no comments
Abgelegt unter: , , ,

Team City

This post has the intention to ease future Team City installations for me and hopefully also other people out there. For the moment I will not be very specific in how to perform all the steps involved to get everything up and running. Instead I will just give a list of references and hints. I may extend this post in the future. Since I am a .NET guy, I will focus on installing stuff to build and package .NET applications.

0. State of the art

  • TeamCity Version to install = 9.1
  • Server = Windows Server 2012 R2
  • Database = Sql Server 2014
  • .NET Version = 4.6
  • VS Version = 2015

1. Install Team City

Start with the obvious. Grab the Team City installation files from JetBrains here and run the installer.

If you want to use Microsoft SQL Server for the database backend, you also need the sqljdbc driver which can be obtained here. The driver has to be placed in TeamCity Data Directory/lib/jdbc where on my system TeamCity Data Directory = C:\ProgramData\JetBrains\TeamCity -- see also here for further information.

Note: The Professional Server license is free and allows up to 3 build agents and 20 build configurations. Of course, both limits can be extended by purchasing additional licenses.

1.1 Build Agent User Configuration

The user running the build agents need several additional permissions -- see

In particular, the user needs the permissions

  • Logon as a service
  • Reboot the machine
  • Start/Stop TCBuildAgent service

The first two can be configured using the Local Security Policy, while for the third one it is convenient to use the tool SubInACL provided by Microsoft here.

   .\subinacl /service TCBuildAgent /grant=YOURMACHINE\YOURUSER=top

The default installation path is C:\Program Files (x86)\Windows Resource Kits\Tools\

2. Install MS Build Tools

See also for further details.

3. Install additional MS Build targets

You may encounter the following error when building web applications

  The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\ Microsoft.WebApplication.targets" was not found.

You can easily fix this by copying the C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0 from your machine to the TeamCity build agent.

4. Install Nuget

To be able to use nuget package restore during your build, follow the instructions here. You can also setup your TC Server to serve a Nuget feed of your builds.

5. Install Git

If you want to have TC check out source code from your git repositories, you need to install Git for Windows.

6. Install Visual Studio Test Agents

Install MSTest.exe to allow TeamCity to run Unit Tests designed using the Microsoft Testing Framework.

7. Connect with Visual Studio Online

8. GitVersionTask

If you want to use GitVersionTask Version 2.x, then there are several issues with Team City. One is that the whole git repository has to be checked out to perform the build and not just the branch you are building. To do that go to Project Settings -> Build -> Edit -> Version Control Settings -> VCS checkout mode: Automatically on agent. Doing so requires the agent to have access to the git repository. One possibility to achieve this is to store the git credentials in the environment variables of the user running the build agent.

!! This may introduce serve security issues especially when you are using the same build agent for different clients !!

See also

9. Code Contracts

If you want to use code contracts, install the latest version of them on your build agent.

You may also want to alter your project files to run code contracts as a build step.

<Project xmlns="">
  <!-- Begin CodeTools: CodeContracts: After -->
    <CodeContractsInstallDir Condition="'$(CodeContractsInstallDir)'==''">C:\Program Files (x86)\Microsoft\Contracts\</CodeContractsInstallDir>
  <Import Condition="'$(CodeContractsImported)' != 'true' AND '$(DontImportCodeContracts)' != 'true'" Project="$(CodeContractsInstallDir)MsBuild\v12.0\Microsoft.CodeContracts.targets" />
  <!-- End CodeTools: CodeContracts: After -->

X. What is missing

The possibilities to use TeamCity to automate your build process are endless and therefore this manual is far from complete. Any questions, comments, and suggestions to extend it are welcome.

SP324098: Your browser could not complete the operation

After having changed the password of my Visual Studio Online account, Visual Studio greeted me by asking to reenter my credentials. So I clicked on the Sign In button but instead of being redirected to the Sign In page I simply got the error message "SP324098: Your browser could not complete the operation".

Visual Studio Error Dialog

I tried several things like setting IE to be my default browser, deleting the browser history, and resetting IE to factory settings. I also installed the most recent version of Newtonsofts Json library to my GAC without having success on the Sing In page.

Finally, I found the answer on Stackoverflow.
My computer is joined to a domain network but I tried to do the sign in from home without a VPN connection established. The Visual Studio Identity provider thus could not reach my domain controller and gave the cryptic error message instead of the Sign In page.

The solution was quite simple: Establish a VPN connection such that Visual Studio can reach the domain controller and everything is fine again.

Visual Studio Login Dialog

Posted von Jan-Cornelius Molnar | mit no comments
Abgelegt unter: ,

Delete Team Projects from Hosted TFS Servies

When the TFS Services preview went live, I started moving my on premise projects to the hosted tfs services.

At some point I wanted to delete a team project created in the hosted services. For now, the web interface does not provide an option for that. However, the commandline tool tfsdeleteproject works fine.


tfsdeleteproject /force /collection:https://[yourname] [yourproject]

Warning: This operation cannot be undone!

Posted von Jan-Cornelius Molnar | mit no comments
Abgelegt unter:

WebDay - Part II (02. Juli 2010)

10:00-11:20        WCF & Silverlight
11:40-13:00        Sql Server

Fortsetzung mit Microsoft Surface am 16. Juli 2010 um 10:00

WCF Developer Center
Sql Server Developer Center

WCF Slides

Sql Server Slides

CanAddNew und generische Listen mehrerer Parameter

Das WPF ListCollectionView unterstützt das Hinzufügen von Elementen bei generischen Listen in einem Parameter, wie List<T> oder ObservableCollection<T>.

Erstellt man jedoch ein View zu einer Collection der Bauart MyCollection<T,S>, unterstützt ListCollectionView lediglich ReadOnly Operationen, denn CanAddNew evaluiert zu “False”. Nach einigen Nachforschungen stellt man fest, dass CanCunstructItem zu “False” evaluiert und folglich auch CanAddNew.

Man folgendem dirty code lässt sich das Problem umgehen. In der Implementierung von ListCollectionView in .NET 4 tritt das Problem nicht auf.

public class TypedListCollectionView : ListCollectionView
        public TypedListCollectionView(IList items, Type itemType)
            : base(items) {

            var itemConstructor = itemType.GetConstructor(Type.EmptyTypes);

            Type type = typeof(ListCollectionView);

            var itemConstructorField =
            type.GetField("_itemConstructor", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var isItemConstructorValidField =
            type.GetField("_isItemConstructorValid", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

            itemConstructorField.SetValue(this, itemConstructor);
            isItemConstructorValidField.SetValue(this, true);

WebDay – Part I (18. Juni 2010)

In einem Tag zum .NET Webentwickler. Wir zeigen dir alles was du brauchst, von ASP.NET und Silverlight über WCF WebServices bis hin zur Datenbank Sql Server 2008.

10:00-11:20        Einführung in ASP .NET
11:40-13:00        Silverlight

Fortsetzung mit WCF WebServices und Sql Server am 02. Juli 2010 um 10:00

Ressourcen – ASP.NET HowTo Videos, Tutorials, uvm. – Ajax Control Kit



Sql Database nach Sql Azure migrieren

1. Datenbank einrichten

Die Dantebank erstellt man über das WebInterface zu finden auf


Anschließend muss die Firewall so konfiguriert werden, dass man vom lokalen Computer Zugriff auf die Datenbank hat. Soll die Sql Azure Datenbank außerdem von einem Windows Azure Service verwendet werden, dann muss auch “Allow Microsoft Services” aktiviert werden.


1. Sql Server 2008 R2 CTP

Um bequem auf die Sql Azure Datenbanken zuzugreifen ist Sql Server 2008 R2 nötig, das Management Studio der “normalen” 2008er Version hat leider keinen Zugriff.

Die CTP steht hier zum Download (kostenlos)

2. Datenbank Skripte generieren

Der einfachste Weg, die lokale Datenbank mit oder ohne Daten in die Cloud zu bekommen ist mittels Sql Skripten. Sql 2008 R2 bringt dazu auch gleich die nötigen Wizards mit. Einfach die Datenbank auswählen –> Tasks –> Generate Scripts. Dann im Wizard Sql Azure auswählen. Das ist wichtig, da Sql Azure nicht alle Befehle des Sql Servers 2008 unterstützt, der Wizard generiert dann automatisch “bereinigte” Skripte.

image image

Ich empfehle zunächst ein Skript für das Schema zu erstellen (Schema only) und dieses auszuführen. Ging alles glatt, kann man anschließend die Daten hinterherschicken (mittels Data only Skript).

Verwendet man eine ASP.NET 3.5 Membership Datenbank ist ein kleiner Fix bei den Stored Procedures notwendig. Ich habe folgenden verwendet (ohne Gewähr)

CREATE PROCEDURE [aspnet_Membership_GetNumberOfUsersOnline]
    @ApplicationName [nvarchar](256),
    @MinutesSinceLastInActive [int],
    @CurrentTimeUtc [datetime]
    DECLARE @DateActive datetime
    SELECT  @DateActive = DATEADD(minute,  -(@MinutesSinceLastInActive), @CurrentTimeUtc)

    DECLARE @NumOnline int
    SELECT  @NumOnline = COUNT(*)
    FROM    dbo.aspnet_Users u,
            dbo.aspnet_Applications a,
            dbo.aspnet_Membership m
    WHERE   u.ApplicationId = a.ApplicationId                  AND
            LastActivityDate > @DateActive                     AND
            a.LoweredApplicationName = LOWER(@ApplicationName) AND
            u.UserId = m.UserId

3. User anlegen

Nachdem die Datenbankstruktur samt Daten nun in der Cloud sind, wollen wir wieder darauf zugreifen.

Dazu mit dem Management Studio in die master Datenbank von Sql Azure einloggen und einen login erstellen.


Anschließend muss der login auf einen Datenbankuser gemapped werden. Dazu loggt man sich wieder in der Sql Azure Datenbank ein und führt folgenden Befehl aus.

Die Rechteverwaltung in Sql Azure ist analog zu der im Sql Server. Für die meisten Anwendungen genügen Lese- und Schreibrechte, diese kann man so vergeben.
EXEC sp_addrolemember N'db_datareader', N'MyCloudUser'
EXEC sp_addrolemember N'db_datawriter', N'MyCloudUser'

Sind außerdem Stored Procedures im Spiel, will man auch auf diese den Zugriff erlauben. Will man gleich alle Stored Procedures auf einmal freischalten, empfielht sich die Erstellung einer Rolle und mit den entsprechenden Rechten.

CREATE ROLE db_executor
GRANT EXECUTE TO db_executor

Nun müssen lediglich alle Benutzer, die alle Stored Procedures ausführen dürfen sollen zu dieser Rolle hinzugefügt werden

EXEC sp_addrolemember N'db_executor', N'MyCloudUser'
!! Nur wenn es absolut unabdingbar ist, sollten dem Anwendungsbenutzer auch dbo-Rechte verliehen werden!!

-- only if you need dbo access:
EXEC sp_addrolemember N'db_owner', N'MyCloudUser'

4. Anwendung testen

Jetzt ist die Sql Azure Datenbank bereit für den ersten Anwendungszugriff.

Hinweis: Damit Sql Azure Zugriff gewähren kann, muss aus dem connectionstring der ServerName ausgelesen werden. Viele Provider senden, diesen jedoch nicht, daher sollte der Benutzername im Format user@server angegeben werden.

AjaxMin – JavaScript und CSS Dateien automatisch schrumpfen

Während der Entwicklung von Web-Anwendungen ist man meist über gut dokumentierte JavaScripts und CSS Stylesheets, die viel Whitespace zur Strukturierung enthalten, dankbar. Geht es jedoch ans Deployment, möchte man diese Dateien möglichst klein halten, um den Seitenaufbau im Browser zu beschleunigen. Im Web findet man zahlreiche Tools sogenannte “Minifier”, die die Dateien verkleinern, indem Kommentare und Whitespace entfernt werden. In großen Projekten mit vielen Skripts und Styles ist dieser Vorgang jedoch sehr mühsam und nach jeder Änderung müssen die Dateien neu “minifiziert” werden.

Abhilfe schaft “AjaxMin” eine Visual Studio Erweiterung von Microsoft, die diese Arbeit automatisch durchführt. AjaxMin definiert einen Build-Taks, der sich in jedes Projekt einbinden lässt und bei jedem Compile-Vorgang automatisch alle Skripte und Style minifiziert und mit der Endung “min.js” bzw. “min.cs” neben die bestehenden Dateien legt. Damit reduziert sich der Aufwand für die Minifizierung auf Null :)

Übersicht über AjaxMin

Download von AjaxMin

Ankh über Proxy Server

Surft man über einen Proxy Server und will auf seine SVN Repositories über Ankh zugreifen, genügen die globalen Einstellungen des InternetExplorers nicht.

Dennoch verfügt Ankh über die Möglichkeit einen Proxy Server zu verwenden. Dazu muss die folgende Datei editiert werden:


Dazu müssen die Elemente http-proxy-host usw. auskommentiert werden.

http-proxy-host =
http-proxy-port = 80

Windows 7 RTM ab dem 13. August in der MSDN AA

Ich habe soeben folgende Nachricht erhalten:

Wir freuen uns Ihnen mitteilen zu können, dass “Windows 7 Professional ” ab dem 13. August 2009 in ELMS erhältlich ist.

  • Windows 7 Professional (32 bit ) and (64 bit )
  • Microsoft CCR and DSS Toolkit 2008 R2
  • Microsoft Robotics Developer Studio 2008 R2
  • Expression Studio 3
  • Surface SDK

(Bitte beachten Sie: “Windows 7 Professional” ist nur in englisch erhältlich)

Mehr Beiträge Nächste Seite »