Saarland University
Lehrstuhl fr Automatisierungstechnik

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Implement C external functions, Id like to implement a C external function not available in any C sta
David Elixmann
post Jul 27 2011, 06:35 PM
Post #1


Newbie
*

Group: Members
Posts: 5
Joined: 26-July 11
Member No.: 582,252



QUOTE(f.perrone @ Apr 11 2011, 02:35 PM) *

Hello everyone,

Im trying to engender a 3D wind field and to do so I need to make use of the fast fourier transform.
On Internet there thousands of external C library that allow to get a fft.I have one of those and I would like to implement that in Dymola in order to call the function fft and get the transform of my starting values vector.
Please enclosed you might find the file Im talking about.
I actually hope to get some hints as soon as possible.
Regards,

Francesco


Hi Francesco,

I don't understand the details of what you are trying to do, but it sounds like you just want to have a function in your Modelica model which computes some values using a routine that you have implemented in C?

If so, then it is fairly easy to do (I think). There's an explanation of how to do it in Peter Fritzson's book, in the chapter 9.4.

I can show you how I included a DLL library into my model:

You need to create an interface function in the Modelica model, like this:

CODE

function InflowData0 "Modelica external function"
  input String filename "Name of table file";
  input Real timet "Time (in days)";
  input Integer nData "Number of data columns (not time!) in the table";
  output Real data[nData] "inflow data";
  external "C" InflowData0(filename, timet, data) annotation(Include="#include <externalLib/InflowData0.c>",
    Library={"externalLib/myExternalLib0"});
end InflowData0;


In the Dymola working directory there's a subdirectory called "externalLib" in which I have the following files:
  • InflowData0.c which contains the following:
    CODE

    // file to be used for the compilation of the Modelica model


    #ifndef INFLOWDATA0_C
    #define INFLOWDATA0_C
    #include <stdlib.h>
    #include "externalLib/myExternalLib0.h"

    // also include the myExternalLib library in the compiler --> do this in Modelica

    void InflowData0(const char* filename, double time, double *value) // (double time, double* value)
    {
        int c_column;
        
        /* DEBUGGING
        printf(filename);
        fflush(1);  
        system("Pause");
        */

        if (time == 0)
        {
            c_column = file_read0(filename); //("data_inflow.txt");
        }
        interpolateValue0(time, value);

    }
    #endif
  • myExternalLib0.h which contains the headers of functions included in my DLL library
  • myExternalLib0.dll which is the DLL library that contains the functions "interpolateValue0" and "file_read0" that you see in the code above
  • myExternalLib0.lib which I had to include in this directory, too, for incomprehensible reasons.

The Dymola compiler is, in my experience, terrible at finding files at their specified locations, so I also included duplicates of all the above files also in the Dymola working directory itself. Redundant, I know, but I could not figure out how to make the compiler work correctly otherwise.

I hope this can help you? Your case seems less complicated than mine (you have all your functions in C code already, rather than in a compiled library like me) so maybe you can do it in a less cumbersome way.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
f.perrone
post Apr 11 2011, 12:35 PM
Post #2


Newbie
*

Group: Members
Posts: 9
Joined: 14-March 11
Member No.: 266,812



Hello everyone,

Im trying to engender a 3D wind field and to do so I need to make use of the fast fourier transform.
On Internet there thousands of external C library that allow to get a fft.I have one of those and I would like to implement that in Dymola in order to call the function fft and get the transform of my starting values vector.
Please enclosed you might find the file Im talking about.
I actually hope to get some hints as soon as possible.
Regards,

Francesco


Attached File(s)
Attached File  kiss_fft.h ( 3.24k ) Number of downloads: 463
Attached File  kiss_fft.c ( 12.36k ) Number of downloads: 447
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 18th August 2019 - 04:36 AM