Creating an Example IFM Module with FEFLOW 5.4 and Microsoft Visual Studio 2008 (Standard/Professional or Express Edition) 1 Introduction The following introduction is a guide to the setup of a first own IFM module. The example is based on Microsoft Visual Studio 2008 Standard/Professional Edition and the free Microsoft Visual Studio 2008 Express Edition. The approach slightly differs for older versions of Microsoft Visual Studio. In case of any problems, please contact the DHI-WASY support team (support@dhiwasy.de). Before starting the module development, the following items have to be installed: FEFLOW IFM Development Kit (the respective package in the FEFLOW setup has to be selected) Microsoft Visual Studio 2008 Standard/Professional with C++ support or Microsoft Visual Studio 2008 Express Edition with C++ support (free download available from http://www.microsoft.com/express/) Only for users of the 64-Bit Edition of FEFLOW: To create IFM modules for the usage with the 64-bit Edition of FEFLOW, it is necessary to include the X64 Compilers and Tools in the installation of Visual Studio 2008 as shown in Figure 1-1). Figure 1-1: Installing the X64 compilers 1
2 Create your own module 2.1 Open FEFLOW and select the IFM Configure menu entry (IFM- Configure ) Figure 2-1: FEFLOW IFM - Configure menu entry 2.2 Choose the interface Simulation and press the New Module button to create a new module Figure 2-2: Interface Manager The additional columns Modules and Callbacks are not used at this point. 2
Figure 2-3: IFM menu Step 1 2.3 Specify a name for the new module and a base directory for the module files (typically with the same name). By default, FEFLOW will store new modules in My documents\feflow IFM Projects. 2.4 Define the module properties (Language, GUI support, and the description). The names and Register procedure are set automatically. 3
Figure 2-4: IFM menu Step 2 Figure 2-5: IFM menu Step 3 2.5 Decline to edit the copyright file now. A default copyright text file will be generated for your module. 4
Figure 2-6: Alert Box 2.6 Read the information about the following file generation carefully. You can make changes by going back with the Prev button. Figure 2-7: IFM menu Step 4 2.7 Press Finish to close the dialog 5
2.8 Click close in the information box Figure 2-8: Information about IFM project generation The source code and the related files of the module are created. The new module (HelloWorld) appears in the column Modules. Figure 2-9: Interface Manager 2.9 Close the dialog by hitting Close 6
3 Add the generated files to a new Visual C++ project Open Visual Studio and add the generated files to a new project. 3.1 Select File New New project From Existing Code 3.2 Choose the type of your project (Visual C++) and click Next Figure 3-1: Definition of the project file location 3.3 Define the project file location (see chapter 2.7, in our example G:\Development\HelloWorld ), type in the Project name HelloWorld and click Next 7
Figure 3-2: Definition of the project type 3.4 Define the Dynamically linked library (DLL) project as Project type. 3.5 Press Finish (The next two pages are accepted without changes). Figure 3-3: Add Existing Project 8
Figure 3-4: Add the ifm project 3.6 Select File Add Existing project and add the prepared IFM library project (<FEFLOW User Files>\sdk\lib\vc9\ifm.vcproj) to the Visual Studio project. You will commonly find the <FEFLOW User Files> under C:\Documents and Settings\All Users\ Shared Documents\WASY FEFLOW 5.4\ (Windows XP) or C:\Users\Public\Documents\WASY FEFLOW 5.4\ (Windows Vista). Depending on the system language, these paths may be slightly different. Adding the ifm library source code to the solution ensures that the library is always up-to-date and allows the use of Microsoft s IntelliSense for IFM functions. If using Visual Studio 2005, use <FEFLOW User Files>\sdk\lib\vc8\ifm.vcproj instead. 9
4 Define solution and project settings 4.1 In the Solution Explorer, click on your project with the right mouse button ( HelloWorld ) and select Project dependencies. Figure 4-1: Select project dependencies Activate the dependency for your project HelloWorld on the ifm project. Figure 4-2: Definition of the project dependencies 10
4.2 Open the project properties (right mouse click on the project HelloWorld). Open the Configuration Properties C/C++ General and add the following folders to the list of Additional Include Directories - <FEFLOW User Files>\sdk\ifm\include - <FEFLOW User Files>\sdk\ifm\include\xdk Figure 4-3: Adding of include directories 4.3 In Configuration Properties Debugging define the debug executable (<FEFLOW Root Folder>\bin32\feflow.exe) and define ifmdebug as Command Arguments. This will tell Visual Studio to start FEFLOW in debug-mode to test your module. Use <FEFLOW Root Folder>\bin64\feflow.exe if using the 64-bit Edition of FEFLOW. 11
Figure 4-4: Command and Command arguments definition 4.4 Define Multi-threaded Debug (/Mtd) as runtime library in C/C++ Code generation Figure 4-1: Runtime library definition 12
4.5 Switch to release configuration and repeat the steps 4.2 and 4.4 for the release configuration if you want to build release versions of your module Figure 4-5: Switching Configurations 4.6 For users of the 64-bit Edition of FEFLOW only: Right-click on Solution and choose Configuration manager from the context menu. Choose <New...> from the Active solution platform dropdown menu. Figure 4-2: Configuration manager Confirm the upcoming dialog (Figure 4-3) with OK and exit the configuration manager with close. You can now switch between the Win32 (x86) and x64 platform as shown in Figure 4-4. Figure 4-3: New solution platform Figure 4-4: Switching the target platform 13
5 Compile the module 5.1 Compile the module by hitting F7 or using menu Build 5.2 Start debugging hitting F5 or opening the menu Debug Start debugging 5.3 Open IFM Configure 5.4 Define a Callback (OnEditDocument) to be used by clicking on the corresponding entry in the Callbacks column and hitting Add (or double-click the list entry). A plus is shown, indicating that the OnEditDocument callback is used in the HelloWorld module. Close the dialog. Figure 5-1: IFM dialog 5.5 Close FEFLOW. 5.6 Go back to the Visual C++ solution and accept reloading the file. The source code of the module has been changed by FEFLOW, adding the callback. 5.7 Add your own code in the callback function OnEditDocument, replacing the entire comment TODO: Add your own code here: IfmInfo(pDoc, Hello World... ); 14
Figure 5-2: Microsoft Visual C++ 5.8 Build the module (F7) and start debugging again (F5) 5.9 Open the IFM Configure menu and select the module (Hello Word) 5.10 Press Properties and define the path of the created debug dll as Target(debug). Close the dialog with Okay. 15
Figure 5-3: Definition of the module path 5.11 Close FEFLOW and accept reloading the source file in VC++ 5.12 Compile (F7) and start debugging again (F5) 5.13 Load an arbitrary fem file (e.g., <FEFLOW User Data>\demo\exercise\femdata\demo_flow_3d.fem) 16
Figure 5-4: FEFLOW fem file 5.14 Open the Problem Editor IFM modules Manage modules 5.15 Load the IFM module and close the dialog Figure 5-5: Loading of the IFM module 5.16 Click on the module button in the lower left corner. The IFM information should appear in the Log Messages box. 17
Figure 5-6: FEFLOW Problem Editor For programming more complex modules, please see Appendix B of the FEFLOW Online Help for a complete list of all available IFM API functions. You might also wish to have a look at the description of all available callbacks in the IFM dialog to see where you can add your own code. In case of any problems or questions, please do not hesitate to contact the FEFLOW support staff (support@dhi-wasy.de). 18