You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

In this tutorial

  • how can you integrate your code with UAL
  • how can you access data via UAL

Accessing data from UAL requires some modification to your code. In this part of tutorial, we will take a closer look on how to access IDS via UAL.

 

 

Warning

Stop here for a moment. Make sure you have followed the configuration setup before proceeding any further!

Configuration related tutorial is here -> Click me! <-

 

1.1.1. 3.1 Accessing data using Python

 

shell> python ./put_ids_array.py
shell> python ./put_ids_slices.py

 

 

4. Open example file

 put()
ITM
#system libraries
import sys
from pylab import * 

#ual library
import ual

# Create a new instance of database
itm_obj = ual.itm(13,3)
itm_obj.create()

ids.equilibriumArray.resize(10)
cpoArray = ids.equilibriumArray

#First fill fields which are not time-dependent.
cpoArray[0].datainfo.dataprovider = 'MKO'
cpoArray[0].datainfo.putdate = '20/09/2016'



# ---- a loop ----
for i in range(0, 10):
      #Fill time-dependent fields 
      cpoArray[i].eqgeometry.boundary.resize(1)
      cpoArray[i].eqgeometry.boundary[0].r = 1/float(100-i)
    
	  #Do not forget time!!
      cpoArray.array[i].time = i
# ---- a loop ----

#Save data in the database
equi.put() # <= Called outside the loop

#close the pulse file
ids.close()
IMAS
#system libraries
import sys
import numpy

#ual library
import imas

# Create a new instance of database
imas_obj = imas.ids(11, 22)
imas_obj.create()

ids = imas_obj.core_profiles
# allocate the ids fie
ids.global_quantities.ip.resize(10)
ids.time.resize(10))
# Mandatory to define this property
ids.ids_properties.homogeneous_time = 0
#First fill fields which are not time-dependent.
# Fillthe ids fields with data
ids.ids_properties.comment = 'A test ids created by PUT'

# ---- a loop ----
for i in range(0,10):
      #Fill time-dependent fields
      ids.global_quantities.ip[i] = i * 10
	  
      #Do not forget time!!
      ids.time[i] = i
# ---- a loop ----

#Save data in the database
ids.put() # <= Called outside the loop
imas_obj.close()
VI related notice
I will use VI in every place where text files are modified. If you have any other text file editor of your choice - fell free to use it instead.
Handling IDSes: put() vs. putSlice()
$TUTORIAL_DIR/ids_basics/python/put_ids_array.py
import sys
from pylab import * 
import ual

ids = ual.itm(13,3)
ids.create()

if not ids.isConnected():
    print 'error during itmdb entry creation'
    sys.exit(1)

ids.equilibriumArray.resize(10)
equi = ids.equilibriumArray

#First fill fields which are not time-dependent.
equi.array[0].datainfo.dataprovider = 'MKO'
equi.array[0].datainfo.putdate = '20/09/2016'
equi.array[0].codeparam.parameters = 'param'



# ---- a loop ----
for i in range(0, 10):
    #Fill time-dependent fields 
    equi.array[i].eqgeometry.boundary.resize(1)
    equi.array[i].eqgeometry.boundary[0].r = sin(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
    equi.array[i].eqgeometry.boundary[0].z = cos(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
    
	#Do not forget time!!
    equi.array[i].time = i
# ---- a loop ----

#Save data in the database
equi.put() # <= Called outside the loop

#close the pulse file
ids.close()
$TUTORIAL_DIR/ids_basics/python/put_ids_slices.py
import sys
from pylab import * 
import ual

ids = ual.itm(14,4)
ids.create()

if not ids.isConnected():
    print 'error during itmdb entry creation'
    sys.exit(1)

equi = ids.equilibrium


#First fill fields which are not time-dependent.
equi.datainfo.dataprovider = 'MKO'
equi.datainfo.putdate = '20/09/2016'
equi.codeparam.parameters = 'param'

#Save time independent fields
equi.putNonTimed()
# ---- a loop ----
for i in range(0, 10):
	#Fill time-dependent fields 
	equi.eqgeometry.boundary.resize(1)
    equi.eqgeometry.boundary[0].r = sin(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
    equi.eqgeometry.boundary[0].z = cos(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
    
    #Do not forget time!!
    equi.time = i 
    
    #Append this slice in the database
    equi.putSlice() # <= Called inside the loop
# ---- a loop ----

#close the pulse file
ids.close()

 

vi $TUTORIAL_DIR/ids_basics/python/put_ids.py

What you can see here is a simple code that stores particular IDS into MDSPlus database using UAL.

 

 

Let's check how to read these data in Fortran.

1.1.2. 3.2 Accessing data using Fortran

Exercise no. 4 - After this exercise you will:

  • know how to connect to UAL
  • know how to retrieve data from UAL
  • know how to prepare Makefile for your Fortran code

Exercise no. 4 (approx. 15 min)

In this exercise you will read IDS and print some data stored inside.

1. source ITMv1 script by invoking

source $ITMSCRIPTDIR/ITMv1 kepler test 4.10b > /dev/null

2. Change directory to a demo location for this exercise

cd $TUTORIAL_DIR/ids_basics/fortran
 
Handling IDSes: get() vs. getSlice()
$TUTORIAL_DIR/ids_basics/fortran/get_ids_array.f90
program diagnostic
    use imas_schemas
    use imas_routines
    implicit none

    integer :: idx, i, arraySize
    type (type_equilibrium), pointer :: eqArray(:) ! <= Array !!!



    call imas_open('IDS', 14, 4, idx)
    
    call imas_get(idx, 'equilibrium', eqArray)
    arraySize = size(eqArray)
    write (*,*) "Number of slices: ", arraySize
    
	do i=1, arraySize
    	write (*,*) "Time: ", eqArray(i)%time
        write (*,*) "Value of r: ", eqArray(i)%eqgeometry%boundary(1)%r(1)
        write (*,*) "Value of z: ", eqArray(i)%eqgeometry%boundary(1)%z(1)
    enddo
    call imas_close(idx)
end program
$TUTORIAL_DIR/ids_basics/fortran/get_ids_slices.f90
program diagnostic
    use imas_schemas
    use imas_routines  
    implicit none

    integer :: idx, i, arraySize 
    type (type_equilibrium) :: equilibrium
    real(IMAS_R8), pointer :: timeVector(:)
    real(IMAS_R8) :: time

    call imas_open('IDS', 14, 4, idx)
    
    call imas_get_times(idx, 'equilibrium',timeVector)
    
    arraySize = size(timeVector)
    write (*,*) "Number of slices: ", arraySize
    write (*,*) "Time vector: ", timeVector
    
	do i = 1, arraySize
        time = timeVector(i)
        call imas_get_slice(idx, 'equilibrium', equilibrium, time, 1)
            
    	write (*,*) "Time [", time, "]: ",  equilibrium%time
        write (*,*) "Value of r: ", equilibrium%eqgeometry%boundary(1)%r(1)
        write (*,*) "Value of z: ", equilibrium%eqgeometry%boundary(1)%z(1)
    enddo
    
	call imas_close(idx)
end program

 

4. Compile the code
 
shell> make clean
shell> make

5. Run the code

shell> ./get_ids_array.exe
shell> ./get_ids_slices.exe

 

 

6. You should see values that we have stored using Python based code.

1.2. 4. FC2K - Fortran Code to Kepler

It is possible to encapsulate Fortran/C++ code with Java code that represents Kepler actor. This way, you can easily incorporate your Fortran code with existing Kepler workflow. In order to make it happen you will have to:

  1. Prepare Fortran code that has a subroutine to be called and is compiled as a library
  2. Prepare FC2K based description of the actor
  3. Recompile Kepler with newly created actor

After these steps are performed, you will have an access to Kepler actor that encapsulates your Fortran code.

All these topics will be covered in separate tutorial: 1.4 Using FC2K for embedding Fortran code into Kepler

 

  • No labels