Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

 

 

1. What code wrapper actually does?

The code wrapper intermediates between Kepler actor and user code:

  • Passes variables of language built-in types (int, char, etc) from actor to the code
  • Reads IDS(es) from UAL and passes data to user code
  • Passes input code parameters (XML/XSD files) to user code
  • Calls user subroutine/function
  • Saves output IDS(es)

2. Development of Fortran codes

2.1 Subroutine syntax

subroutine name ( <in/out arguments list> [,code_parameters] [,diagnostic_info] )

...

4.2.1. Changes

CHEAT SHEET
ITMIMAS
use euitm_schemas
use ids_schemas
use euitm_routines
use ids_routines
type(type_<cpo_name>) :: cpo 
type (ids_<ids_name>) :: ids 
type(type_<cpo_name>), pointer :: cpoArray(:) <= ARRAY !!
type (ids_<ids_name>) :: ids <== SINGLE OBJ !!!
eval-pkg-config
pkg-config 
eval-pkg-config --cflags --libs ual-ifort
pkg-config --cflags --libs imas-ifort
eval-pkg-config --cflags --libs ual-gfortran
pkg-config --cflags --libs imas-gfortran
type(type_param) :: XML_params
type(ids_parameters_input ) :: XML_params
type type_param    
... :: parameters  
   ... :: default_param     
   ... :: schema 
endtype
type ids_parameters_input     
    ... :: parameters_value   
    ... :: parameters_default        
    ... :: schema      
 endtype
use euitm_xml_parser
use imas_xml_parser
call euitm_xml_parse(code_params, nparm, param_list)
call imas_xml_parse(code_params, nparm, param_list)
eval-pkg-config 
pkg-config 
eval-pkg-config --cflags ual-ifort
pkg-config --cflags imas-ifort
eval-pkg-config --cflags ual-gfortran
pkg-config --cflags imas-gfortran

 

 

4.2.2 Examples

Examples of interface between wrapper and user code
ITM

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**** Fortran intrinsic data types ***/

...

2.2. Arguments list

...

integer :: input
character(50) :: charstring
integer,dimension(4) :: tabint

...

 
/**** Single slice ***/
type (type_equilibrium)

...

:: cpo
 
/**** Array of slices ***/
type (type_

...

equilibrium),pointer ::

...

cpoArray(:)

...

...

  • Always describe IDS as an array. In case of time slice, the size of the input IDS is 1 (!)
  • Do not forget to add: use imas_schemas, while playing with IDSes
  • Please use intent(in), intent(out) to point in/out parameters

2.3. Code parameters

...

Argument of type: type_param

/**** Code XML parameters ***/
 type(type_param), intent(in) :: codeparam
 
/**** Arbitrary diagnostic info ***/
integer    ::     outputFlag
character(len=

...

:), pointer   ::

...

    

...

  • parameters - Actual value of the code parameters (instance of coparam/parameters in XML format).
  • default_param - Default value of the code parameters (instance of coparam/parameters in XML format).
  • schema - Code parameters schema.

...

  • (type_param) :: codeparam{{

2.4. Diagnostic info

...

output / optional

...

diagInfo
IMAS

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**** Fortran intrinsic data types ***/
integer :: input
character(50) :: charstring
integer,dimension(4) :: tabint
 
/**** Single slice ***/
type (ids_equilibrium) :: cpo
 
/**** Array of slices ***/
type (ids_equilibrium) :: ids <== SINGLE OBJ !!!
 
/**** Code XML parameters ***/
type(ids_parameters_input), intent(in) :: codeparam
 
/**** Arbitrary diagnostic info ***/
integer    ::     

...

outputFlag

...

character(len=:), pointer

...

   

...

::    

...

diagInfo

...

 

...

  • outpuflag = 0    - SUCCESS, no action is taken

  • outputFlag > 0  - WARNING, a warning message is displayed, workflow continuue execution

  • outputFlag < 0 - ERROR, actor throws an exception, workflow stops

...

diagnosticInfo - an arbitrary string

2.5. Examples

...

titleExample 1 Simple in/out argument types

...

4.2.2 XML Parsing


Code Block
 use imas_xml_parser
 
  type(ids_Parameters_Input),intent(in)   :: code_parameters
  integer, intent(out)                    ::

...

 

 

...

titleExample 2 A IDS array as a subroutine argument

...

 return_status
  type(tree)             :: parameter_list
  type(element), pointer :: 

...

temp_pointer
 

...

 integer(

...

itm_

...

i4)        :: 

...

 

 

...

titleExample 3 Usage of code input parameters

...

i, nparm, n_values,j
  character(len = 132)   :: cname
!...  initialisations
  nparm         = 0
  n_values      = 0
  return_status = 0      ! no error
  j             = 0
!-- parse xml-string code_parameters%parameters using W3C XML schema in
!   code_parameters%schema
  call imas_xml_parse(code_parameters, nparm, parameter_list)
!-- assign variables
  temp_pointer => parameter_list%first
  outer: do
   

...

 

...

cname = char2str(temp_pointer%cname)   ! necessary for AIX
    select case (cname)
!--   parameters overall
      case ("parameters")
        temp_pointer => temp_pointer%child
        cycle      
!--   parameter classes
!--   individual 

...

parameters
  

...

 

...

 

...

  

...

case 

...

(

...

3 Development of C++ codes

3.1 Function syntax

void name ( <in/out arguments list> [,code_parameters] [,diagnostic_info] )

  • name - function name
  • code_parameters - optional - user defined input parameters
  • diagnostic_info -  arbitrary output diagnostic information

3.2 Arguments list

  • in/out arguments list
  •  mandatory
  • a list of input and output function arguments including:
    • CPP intrisic data types, eg:
      • int &x
      • double &y
    • IDSes, eg:
      • ItmNs::Itm::antennas & ant
      • ItmNs::Itm::equilibriumArray & eq

3.3 Code parameters

...

Argument of type: ItmNs::codeparam_t &

...

languagecpp

...

"tokamak")
        if (allocated(temp_pointer%cvalue)) &
         call char2num(temp_pointer%cvalue, tokamak)

      case default
        write(0, *) 'ERROR: invalid parameter', cname
        return_status = 1
        exit
    end select
    do
      if (associated(temp_pointer%sibling)) then
       

...

 temp_pointer => temp_pointer%sibling
        

...

exit
      end if
     

...

 if (associated(temp_pointer%parent, parameter_list%first )) &
        exit outer
      if (associated(temp_pointer%parent)) then
        temp_pointer => temp_pointer%parent
      else
        write(0, *) 'ERROR: broken list.'
        return
      end if
    end do
  end do outer

 

4.2.3

 

 

...

  • parameters - Actual value of the code parameters (instance of coparam/parameters in XML format).
  • default_param - Default value of the code parameters (instance of coparam/parameters in XML format).
  • schema - Code parameters schema.

...

3.4 Diagnostic info

  • arbitrary output diagnostic information
  • output / optional

    Code Block
    languagecpp
     void name(...., int* output_flag, char** diagnostic_info)
  • output_flag - indicates if user subroutine was successfully executed

    • output_flag = 0  - SUCCESS, no action is taken

    • output_flag > 0  - WARNING, a warning message is displayed, workflow continuue execution

    • output_flag < 0  - ERROR, actor throws an exception, workflow stops

  • diagnostic_info - an arbitrary string

Warning

Required header

Do not forget to add #include "UALClasses.h" while playing with IDSes!

 

 

3.5 Examples

 

 

Code Block
languagecpp
titleExample 4. Simple in/out argument types
void simplecppactornoids(double &x, double &y)
Code Block
languagecpp
title Example 5. A IDS array as a function argument
void simplecppactor(ItmNs::Itm::equilibriumArray &eq, double &x, double &y)
Code Block
languagecpp
titleExample 6. Usage of init function and code input parameters
void mycppfunctionbis_init();

void mycppfunction(ItmNs::Itm::summary& sum, ItmNs::Itm::equilibriumArray& eq, int& x, ItmNs::Itm::coreimpur& cor,  double&  y, ItmNs::codeparam_t& codeparam)
Info

Initialization

If user function needs any pre-initialization, an additional function <name>_init could be defined.

 

 

...

Delivery of the user code

The user code should be delivered as a static library.
Please find examples of the simple "

...

Makefile" below:

 

 

CXX=g++ CXXFLAGS= -g -fPIC CXXINCLUDES= ${shell eval-pkg-config --cflags ual-cpp-gnu} all: libsimplecppactor.a libsimplecppactor.a: simplecppactor.o ar -rvs $@ $^ simplecppactor.o: simplecppactor.cpp $(CXX) $(CXXFLAGS) $(CXXINCLUDES) -c -o $@ $^ clean: rm *.a *.o
Code Block
languagebash
titleExample 6. Building of Fortran code
F90 = $(ITM_INTEL_FC)ifort
COPTS = -g -O0 -assume no2underscore -fPIC -shared-intel

INCLUDES = $(shell eval-pkg-config --cflags ual-$(ITM_INTEL_OBJECTCODE))imas-ifort)

all: equilibrium2distsource.o libequilibrium2distsource

libequilibrium2distsource: equilibrium2distsource.o
        ar -rvs libequilibrium2distsource.a equilibrium2distsource.o

equilibrium2distsource.o: equilibrium2distsource.f90
        $(F90) $(COPTS) -c -o $@ $^ ${INCLUDES} 

clean:
        rm -f *.o *.a
Code Block
titleExample 7. Building of C++ code

 


 

 

Tip

Recomendations

  • Please use eval-pkg-config to get UAL flags and not hard coded references.
  • The usage of environment variables for identifying compilers and versions of the pkg-config is recommended.