12.10.2013 Views

Creating an Example IFM Module with FEFLOW 5.4 and Microsoft ...

Creating an Example IFM Module with FEFLOW 5.4 and Microsoft ...

Creating an Example IFM Module with FEFLOW 5.4 and Microsoft ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

<strong>Creating</strong> <strong>an</strong> <strong>Example</strong> <strong>IFM</strong> <strong>Module</strong> <strong>with</strong><br />

<strong>FEFLOW</strong> <strong>5.4</strong><br />

<strong>an</strong>d<br />

<strong>Microsoft</strong> Visual Studio 2008<br />

(St<strong>an</strong>dard/Professional or Express Edition)<br />

1 Introduction<br />

The following introduction is a guide to the setup of a first own <strong>IFM</strong> module.<br />

The example is based on <strong>Microsoft</strong> Visual Studio 2008 St<strong>an</strong>dard/Professional<br />

Edition <strong>an</strong>d the free <strong>Microsoft</strong> Visual Studio 2008 Express Edition. The<br />

approach slightly differs for older versions of <strong>Microsoft</strong> Visual Studio. In case<br />

of <strong>an</strong>y problems, please contact the DHI-WASY support team (support@dhiwasy.de).<br />

Before starting the module development, the following items have to be<br />

installed:<br />

• <strong>FEFLOW</strong> <strong>IFM</strong> Development Kit (the respective package in the <strong>FEFLOW</strong><br />

setup has to be selected)<br />

• <strong>Microsoft</strong> Visual Studio 2008 St<strong>an</strong>dard/Professional <strong>with</strong> C++ support<br />

or<br />

• <strong>Microsoft</strong> Visual Studio 2008 Express Edition <strong>with</strong> C++ support<br />

(free download available from http://www.microsoft.com/express/)<br />

Figure 1-1: Installing the X64 compilers<br />

1<br />

Only for users of the 64-Bit<br />

Edition of <strong>FEFLOW</strong>:<br />

To create <strong>IFM</strong> modules for the<br />

usage <strong>with</strong> the 64-bit Edition<br />

of <strong>FEFLOW</strong>, it is necessary to<br />

include the X64 Compilers <strong>an</strong>d<br />

Tools in the installation of<br />

Visual Studio 2008 as shown<br />

in Figure 1-1).


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

2 Create your own module<br />

2.1 Open <strong>FEFLOW</strong> <strong>an</strong>d select the <strong>IFM</strong> | Configure menu entry (<strong>IFM</strong>-<br />

Configure…)<br />

Figure 2-1: <strong>FEFLOW</strong> <strong>IFM</strong> - Configure menu entry<br />

2.2 Choose the interface Simulation <strong>an</strong>d press the New <strong>Module</strong> button<br />

to create a new module<br />

Figure 2-2: Interface M<strong>an</strong>ager<br />

The additional columns <strong>Module</strong>s <strong>an</strong>d Callbacks are not used at this point.<br />

2


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 2-3: <strong>IFM</strong> menu Step 1<br />

2.3 Specify a name for the new module <strong>an</strong>d a base directory for the<br />

module files (typically <strong>with</strong> the same name). By default, <strong>FEFLOW</strong> will<br />

store new modules in My documents\<strong>FEFLOW</strong> <strong>IFM</strong> Projects.<br />

2.4 Define the module properties (L<strong>an</strong>guage, GUI support, <strong>an</strong>d the<br />

description). The names <strong>an</strong>d Register procedure are set<br />

automatically.<br />

3


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 2-4: <strong>IFM</strong> menu Step 2<br />

Figure 2-5: <strong>IFM</strong> menu Step 3<br />

2.5 Decline to edit the copyright file now. A default copyright text file<br />

will be generated for your module.<br />

4


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 2-6: Alert Box<br />

2.6 Read the information about the following file generation carefully.<br />

You c<strong>an</strong> make ch<strong>an</strong>ges by going back <strong>with</strong> the Prev button.<br />

Figure 2-7: <strong>IFM</strong> menu Step 4<br />

2.7 Press Finish to close the dialog<br />

5


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

2.8 Click close in the information box<br />

Figure 2-8: Information about <strong>IFM</strong> project generation<br />

The source code <strong>an</strong>d the related files of the module are created.<br />

The new module (HelloWorld) appears in the column <strong>Module</strong>s.<br />

Figure 2-9: Interface M<strong>an</strong>ager<br />

2.9 Close the dialog by hitting Close<br />

6


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

3 Add the generated files to a new Visual C++<br />

project<br />

Open Visual Studio <strong>an</strong>d add the generated files to a new project.<br />

3.1 Select File |New | New project From Existing Code…<br />

3.2 Choose the type of your project (Visual C++) <strong>an</strong>d click Next<br />

Figure 3-1: Definition of the project file location<br />

3.3 Define the project file location (see chapter 2.7, in our example<br />

“G:\Development\HelloWorld”), type in the Project name<br />

HelloWorld <strong>an</strong>d click Next<br />

7


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 3-2: Definition of the project type<br />

3.4 Define the Dynamically linked library (DLL) project as Project<br />

type.<br />

3.5 Press Finish (The next two pages are accepted <strong>with</strong>out ch<strong>an</strong>ges).<br />

Figure 3-3: Add Existing Project<br />

8


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 3-4: Add the ifm project<br />

3.6 Select File | Add | Existing project <strong>an</strong>d add the prepared <strong>IFM</strong><br />

library project (\sdk\lib\vc9\ifm.vcproj) to<br />

the Visual Studio project.<br />

You will commonly find the under<br />

C:\Documents <strong>an</strong>d Settings\All Users\<br />

Shared Documents\WASY <strong>FEFLOW</strong> <strong>5.4</strong>\ (Windows XP) or<br />

C:\Users\Public\Documents\WASY <strong>FEFLOW</strong> <strong>5.4</strong>\ (Windows Vista).<br />

Depending on the system l<strong>an</strong>guage, these paths may be slightly<br />

different.<br />

Adding the ifm library source code to the solution ensures that the<br />

library is always up-to-date <strong>an</strong>d allows the use of <strong>Microsoft</strong>’s<br />

IntelliSense for <strong>IFM</strong> functions.<br />

If using Visual Studio 2005, use \sdk\lib\vc8\ifm.vcproj instead.<br />

9


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

4 Define solution <strong>an</strong>d project settings<br />

4.1 In the Solution Explorer, click on your project <strong>with</strong> the right mouse<br />

button (“HelloWorld”) <strong>an</strong>d select Project dependencies<br />

.<br />

Figure 4-1: Select project dependencies<br />

Activate the dependency for your project “HelloWorld” on the ifm project.<br />

Figure 4-2: Definition of the project dependencies<br />

10


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

4.2 Open the project properties (right mouse click on the project<br />

HelloWorld). Open the Configuration Properties | C/C++ | General<br />

<strong>an</strong>d add the following folders to the list of Additional Include<br />

Directories<br />

- \sdk\ifm\include<br />

- \sdk\ifm\include\xdk<br />

Figure 4-3: Adding of include directories<br />

4.3 In Configuration Properties | Debugging define the debug executable<br />

(\bin32\feflow.exe) <strong>an</strong>d define –ifmdebug<br />

as Comm<strong>an</strong>d Arguments. This will tell Visual Studio to start <strong>FEFLOW</strong><br />

in debug-mode to test your module.<br />

Use \bin64\feflow.exe if using the 64-bit<br />

Edition of <strong>FEFLOW</strong>.<br />

11


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 4-4: Comm<strong>an</strong>d <strong>an</strong>d Comm<strong>an</strong>d arguments definition<br />

4.4 Define Multi-threaded Debug (/Mtd) as runtime library in C/C++<br />

| Code generation<br />

Figure 4-1: Runtime library definition<br />

12


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

4.5 Switch to release configuration <strong>an</strong>d repeat the steps 4.2 <strong>an</strong>d 4.4 for<br />

the release configuration if you w<strong>an</strong>t to build release versions of<br />

your module<br />

Figure 4-5: Switching Configurations<br />

4.6 For users of the 64-bit Edition of <strong>FEFLOW</strong> only:<br />

Right-click on Solution <strong>an</strong>d choose Configuration m<strong>an</strong>ager from the<br />

context menu.<br />

Choose from the Active solution platform dropdown menu.<br />

Figure 4-2: Configuration m<strong>an</strong>ager<br />

Confirm the upcoming dialog (Figure 4-3) <strong>with</strong> OK <strong>an</strong>d exit the<br />

configuration m<strong>an</strong>ager <strong>with</strong> close. You c<strong>an</strong> now switch between the<br />

Win32 (x86) <strong>an</strong>d x64 platform as shown in Figure 4-4.<br />

Figure 4-3: New solution platform<br />

Figure 4-4: Switching the target platform<br />

13


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

5 Compile the module<br />

5.1 Compile the module by hitting F7 or using menu Build<br />

5.2 Start debugging hitting F5 or opening the menu Debug | Start<br />

debugging<br />

5.3 Open <strong>IFM</strong>|Configure<br />

<strong>5.4</strong> Define a Callback (OnEditDocument) to be used by clicking on the<br />

corresponding entry in the Callbacks column <strong>an</strong>d hitting Add (or<br />

double-click the list entry). A plus is shown, indicating that the<br />

OnEditDocument callback is used in the HelloWorld module. Close<br />

the dialog.<br />

Figure 5-1: <strong>IFM</strong> dialog<br />

5.5 Close <strong>FEFLOW</strong>.<br />

5.6 Go back to the Visual C++ solution <strong>an</strong>d accept reloading the file.<br />

The source code of the module has been ch<strong>an</strong>ged by <strong>FEFLOW</strong>,<br />

adding the callback.<br />

5.7 Add your own code in the callback function OnEditDocument,<br />

replacing the entire comment TODO: Add your own code here:<br />

IfmInfo(pDoc,”Hello World...”);<br />

14


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 5-2: <strong>Microsoft</strong> Visual C++<br />

5.8 Build the module (F7) <strong>an</strong>d start debugging again (F5)<br />

5.9 Open the <strong>IFM</strong> Configure menu <strong>an</strong>d select the module (Hello Word)<br />

5.10 Press Properties <strong>an</strong>d define the path of the created debug dll as<br />

Target(debug). Close the dialog <strong>with</strong> Okay.<br />

15


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 5-3: Definition of the module path<br />

5.11 Close <strong>FEFLOW</strong> <strong>an</strong>d accept reloading the source file in VC++<br />

5.12 Compile (F7) <strong>an</strong>d start debugging again (F5)<br />

5.13 Load <strong>an</strong> arbitrary fem file (e.g.,<br />

\demo\exercise\femdata\demo_flow_3d.fem)<br />

16


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 5-4: <strong>FEFLOW</strong> fem file<br />

5.14 Open the Problem Editor | <strong>IFM</strong> modules | M<strong>an</strong>age modules…<br />

5.15 Load the <strong>IFM</strong> module <strong>an</strong>d close the dialog<br />

Figure 5-5: Loading of the <strong>IFM</strong> module<br />

5.16 Click on the module button in the lower left corner. The <strong>IFM</strong><br />

information should appear in the Log Messages box.<br />

17


<strong>Example</strong> <strong>IFM</strong> module using MS Visual Studio 2008<br />

Figure 5-6: <strong>FEFLOW</strong> Problem Editor<br />

For programming more complex modules, please see Appendix B of the<br />

<strong>FEFLOW</strong> Online Help for a complete list of all available <strong>IFM</strong> API functions. You<br />

might also wish to have a look at the description of all available callbacks in<br />

the <strong>IFM</strong> dialog to see where you c<strong>an</strong> add your own code. In case of <strong>an</strong>y<br />

problems or questions, please do not hesitate to contact the <strong>FEFLOW</strong> support<br />

staff (support@dhi-wasy.de).<br />

18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!