Sample, shown below, will access IDS data and print it on console.
Warning | ||
---|---|---|
| ||
Source code for this sample can be found at following location
Note that workflow is running such way it reads data from pulse file of user |
Info |
---|
Make sure to initialise your environment. Follow the steps here: 00. Initial setup or here: 05.3. IMAS - basic topics - environment set-up(POZ'19Oct) |
Info | ||
---|---|---|
Make sure to initialise test database - it will be used for temporary files
|
Preparing the FC2K project
Main purpose of FC2K is to embed native code inside Kepler workflow. This way, you are able to connect various, physics based, calculations into chain of execution. There are few rules you have to follow while embedding native code inside Kepler:
- your routine signature must be exactly the same as one suggested by FC2K
- in order to access IDSes, you have to use IMAS based modules inside your Fortran code
- you can pass data into and outside of the code in the form of:
- primitive types
- IDSes
- code parameters
- you should avoid accessing external files unless it's really impossible to run the simulation without external source of data
- all physics related information should be exchanged only via IDSes
In this tutorial, I will show show you how to build simple native code and plug it inside Kepler using FC2K.
Sample, shown below, will access IDS data and print it on console.
...
First of all, we need simple code that will read data. In this sample, we will use very simple code that reads distribution IDS, shows some info, and output scalar value
...
When you talk about actor, most important is the interface. It's API defines how actor interacts with other actors in the workflow.
What interface should I provide
Info |
---|
You can always start with FC2K in order to make sure how native interface should be implemented like. |
...
Defining interface to user code
First of all, let's add two ports into actor. Input port - IDS, and output port - integer.
Now, let's take a look how the native code should look like in order to provide correct implementation of the actor's API.
Now, once we know how our interface looks like, we can start developing the code
Source code of the actor
In our case, we can start with providing very basic implementation
Code Block |
---|
subroutine distributiondisp(distributionin, output)
use ids_schemas
implicit none
type (ids_distribution_sources) :: distributionin
integer, intent(out) :: output
output = 1
return
end subroutine |
As you can see, we don't even access input data, yet. All we have, so far, is the API of the native code.
Creating library with native code
As you recall from previous session (dedicated to FC2K) we have to have library that contains native code we are supposed to run.
Let's prepare it. We will do it, by creating Makefile
project - library will be called libdistribution_disp.a
...
In
...
Once we run make
we can use library inside the project
...
this example we will use library libdistribution_disp.a
prepared previously
Describing the actor
When we fill information regarding actor, we make it possible to create a bridge between Kepler (actor) and native code (in this case Fortran based library). I will fill the table following way
Field | Value | Description |
---|---|---|
Project | IMAS | This is the name of the project you will see later on inside Kepler - in the actor browser |
Name | distributiondisp | This is the name of the actor in Kepler. Once you place it on canvas this is what you will see. |
Version | 1.0 | This is the version of actor - you are in charge of it. It is supposed to help people know what version of your actor they are using. |
Subroutine | distributiondisp | This is the name of routine in your native code (take a look at sources above) |
Now, go ahed and take a look at Interface again. You can observe that now, interface is complete and perfectly matches your code (can you spot the difference?).
Choosing compiler
The only thing that is left is to set proper values for the compiler. Make sure we are using Fortran and the vendor is set to Intel
We have all we need to build our first, IMAS based, actor. Press Generate.
...
Now it's time to put all the things together. Start your Kepler and create following workflow.
Now we can run it.
As you can see, the result is exactly the same as we have expected. Now, let's try to get some check data coming from the IDS.
Code Block |
---|
> idsdumppath g2michal test 3 92436 1 distribution_sources "time(0)"
Type: <class 'numpy.float64'>
----------------------------------------------
----------------------------------------------
49.005001068115234 |