FORTRAN ROUTINES FOR STORING EIRENE TRIANGULAR GRIDS IN IMAS
Content
- Introduction
- Files provided
- Running a test example
- Structure of EIRENE files
- Presentation of EIRENE grid in GGD
- Module
triangular_grid_modile
- Module
triangular_grid_ids_io
- Template files
save_grid.f90
andrecover_grid.f90
- Things to be done
...
Introduction
The Fortran routines described herein are intended to become a part of interface between the code EIRENE and the IMAS data structure. They take files containing the description of a triangular grid in native EIRENE format and store this grid in an IMAS IDS; on the other hand, they extract a stored grid description from IMAS and provide it in EIRENE format. At present, these routines have been tested only with the IDS edge_profiles
.
...
The files provided are intended to support storing triangular 2D grids in the grid_ggd
structure. In the future (if required), they can be upgraded to support work with 3D grids consisting of a triangular 2D grid in the poloidal plane and a grid in the toroidal direction.
...
Files provided
The files listed below can be found in the public directory ~g2yyakov/public/eirene/0.5.
FILES | CONTENT |
---|---|
triangular_grid_module.f90 | Library that supports reading, writing and processing triangular grids |
triangular_grid_ids_io.f90 | Library that supports communication with IMAS IDS |
save_grid.f90 | Program that takes an EIRENE grid and puts it to IMAS |
recover_grid.f90 | Program that extracts a grid from IMAS, providing it in EIRENE format |
Makefile | Used to compile test examples |
gsl_config.sh | Bash script to facilitate compilation |
soledge3x.npco_char | Triangular grid example received from the EIRENE team |
soledge3x.elemente | Another file of this example |
soledge3x.neighbor | Another file of this example |
README.txt | Brief description of how to compile and run |
user_guide.pdf | PDF version of this document |
...
Running a test example
You need to have installed GSL (GGD Standard Library).
- Open the file
gsl_config.sh
and set the value of the variable HOME to the GSL source directory location. - Type
module load imasenv
- Create the required IMAS entry:
imasdb eirene
- Type
. ./gsl_config.sh
- Now you can compile the examples. Type
make clean
make save
OR type
ifort triangular_grid_module.f90 trangular_grid_ids_io.f90 save_grid.f90 -o save_grid.exe ${PKG_PART
} - Run the program:
./save_grid.exe
The program puts the grid stored in the files soledge3x.* into the IDSedge_profiles
of the IMAS databaseeirene
. - Type
make recover
OR type
ifort triangular_grid_module.f90 trangular_grid_ids_io.f90 recover_grid.f90 -o recover_grid.exe ${PKG_PART
} - Run the program:
./recover_grid.exe
Compare the new fileseirene.*
with the original filessoledge3x.*
.
...
Structure of EIRENE files
There are three files describing the triangular grid used in EIRENE.
...
Here Ni is the index of the neighbouring triangle on side i, Si is the index of this side in the triangle Ni, Mi is the ‘material property’ of the side i, ixtri
and iytri
are not used now (they are zeros in this example). Note that side 1 connects vertices 1 and 2; side 2, vertices 2 and 3; side 3, vertices 3 and 1. The material property (MP) is an index referring to a surface model defined in the main EIRENE file. In particular, MP is 0 for transparent (i.e., internal) grid edges. The MP of boundary edges can have different positive values. In the provides example, there are boundary edges with MP = 1, 2, 3.
...
Presentation of EIRENE grid in GGD
We begin with brief overview of general principles of presentation of grids in the grid_ggd
structure.
...
At present, only items 1-4 of this lists are implemented.
...
Module triangular_grid_module
The module contains a data type for storing the information about all elements of a triangular grid and a library of methods (subroutines and functions). The methods solve the following tasks:
...
The module depends on the IMAS module ids_types
(uses the constant IDS_real
– the kind of real variables in IMAS).
...
Data types provided
The following data types are provided:
...
The type edge_structure
is intended for information about an edge. The integer child array vertex
holds indices of the edge vertices in triangular_grid%vertex
. The leaf material_property
holds the MP of the edge. The child array adjacent
holds the indices of the neighbouring triangles in triangular_grid%triangle
.
...
Methods provided
The module member routines are as follows:
...
Read information about a triangular grid from EIRENE-format files and generate a list of grid edges (using the method build_edges
).
Argument / result | Type | Intent | Description |
---|---|---|---|
grid | type(triangular_grid) | result | Grid structure holding the content of the files |
coord_file | character(len=*) | in | Name of the file holding grid node coordinates |
triangles_file | character(len=*) | in | Name of the file holding indices of triangle vertices |
neighbors_file | character(len=*) | in | Name of the file holding information about neighbours of triangles |
do_tests | logical | in | Turns on/off sanity checks |
io_unit | integer, optional | in | Number of the i/o unit used (equals to 69 by default) |
subroutine write_eirene_grid (grid, coord_file, triangles_file, neighbors_file, do_tests, io_unit)
Write information about a triangular grid into EIRENE-format files;
Argument | Type | Intent | Description |
---|---|---|---|
grid | type(triangular_grid) | in | Grid structure |
coord_file | character(len=*) | in | Name of the file to hold grid node coordinates |
triangles_file | character(len=*) | in | Name of the file to hold indices of triangle vertices |
neighbors_file | character(len=*) | in | Name of the file to hold information about neighbours of triangles |
do_tests | logical | in | Turns on/off sanity checks |
io_unit | integer, optional | in | Number of the i/o unit used (equals to 69 by default) |
subroutine provide_grid_object_lists (grid, coordinates, edge_connect, cell_connect)
...
This subroutine is no longer used in the module triangular_grid_ids_io.f90
.
Argument | Type | Intent | Description |
---|---|---|---|
grid | type(triangular_grid) | in | Grid structure |
coordinates | real(IDS_real), dimension(:,:) | out | Array containing the coordinates of all vertices |
edge_connect | integer, dimension(:,:) | out | Array containing indices of vertices for all edges |
cell_connect | integer, dimension(:,:) | out | Array containing indices of vertices for all triangles |
subroutine arrange_neighbors (grid)
Process a grid structure taken from IMAS, filling up the missing components of grid%triangle
(information about neighbouring edges and triangles).
Argument | Type | Intent | Description |
---|---|---|---|
grid | type(triangular_grid) | inout | Grid structure to be completed |
subroutine build_edges (grid)
Process a grid structure, building the missing substructure grid % edge
. The order of the edges in the substructure is as follows: side 1 of triange 1, side 2 of triange 1, side 3 of triange 1, side 1 of triangle 2 (if not accounted for earlier), side 2 of triangle 2 (if not accounted for earlier), and so on.
Argument | Type | Intent | Description |
---|---|---|---|
grid | type(triangular_grid) | inout | Grid structure to be completed |
function give_edges_with_mat_property (grid, mat_property)
Return a list of edges with a given value of MP.
Argument | Type | Intent | Description |
---|---|---|---|
grid | type(triangular_grid) | in | Grid structure |
mat_property | integer | in | MP value |
result | integer, allocatable, dimension(:) | result | List of edge indices in grid % edge |
subroutine deallocate_grid (grid)
Deallocate all grid components.
Argument | Type | Intent | Description |
---|---|---|---|
grid | type(triangular_grid) | in | Grid structure |
For description of service routines (some of them are no longer used), see comments in the module file.
...
Module triangular_grid_ids_io
The module contains routines that support writing a grid having the type(triangular_grid)
form to IMAS IDS and, vice versa, reading a grid from IMAS and putting it into the type(triangular_grid)
form. It depends on the module triangular_grid_module
and the IMAS modules ids_schemas
and ids_routines
.
...
Read data about a triangular grid from a given space of GGD grid, put it into a type(triangular_grid)
-structure and call the function arrange_neighbors
(from triangular_grid_module
) to build the missing parts of the structure.
Argument | Type | Intent | Description |
---|---|---|---|
eirene_grid | type(triangular_grid) | result | The retrieved grid |
grid_ggd | type(ids_generic_grid_aos3_root), pointer | pointer | Pointer to the grid_ggd AOS element containing the grid |
space_index | integer | in | Index of the triangular grid in space AOS |
subroutine put_eirene_grids_to_ids (eirene_grid, coord_type, grid_ggd, nSpaces, eirene_space_index, grid_name, grid_description, eirene_space_name, eirene_space_description)
Allocate the space AOS in a given grid_ggd
element with a given number of grid spaces, put a triangular grid given as a type(triangular_grid)
-structure into a desired element of the space
AOS, and organize necessary grid subsets.
Argument | Type | Intent | Description |
---|---|---|---|
eirene_grid | type(triangular_grid) | in | The grid to be saved |
grid_ggd | type(ids_generic_grid_aos3_root), pointer | pointer | Pointer to the grid_ggd AOS element to hold the grid |
coord_type | integer | in | To be done |
nSpaces | integer | in | The dimension of |
eirene_space_index | integer | in | Index of the triangular grid space in |
grid_name | character(len=*) | in | Name assigned to the |
grid_description | character(len=*) | in | Verbose description of the |
eirene_space_name | character(len=*) | in | Name assigned to the triangular grid space |
eirene_space_description | character(len=*) | in | Verbose description of the triangular grid space |
subroutine arrange_triangular_grid_space (space, grid, space_name, space_description)
Put a triangular grid into a given element of the space
AOS. The grid information is taken from a type(triangular_grid)
-structure.
Argument | Type | Intent | Description |
---|---|---|---|
space | type(ids_generic_grid_dynamic_space), pointer | pointer | Pointer to the space AOS element to hold the space |
grid | type(triangular_grid) | in | The grid to be saved |
space_name | character(len=*) | in | Name assigned to the triangular grid space |
space_description | character(len=*) | in | Verbose description of the triangular grid space |
subroutine arrange_standard_2d_subset(subset, space, space_index, dimensionality, subset_id)
Arrange a "standard" subset in the poloidal space – a subset of all nodes, edges, or triangular cells (depending on the dimensionality, 1, 2, or 3, respectively). The subset gets the name 'poln', where n is the dimensionality.
Argument | Type | Intent | Description |
---|---|---|---|
subset | type(ids_generic_grid_dynamic_grid_subset), pointer | pointer | Pointer to the |
space | type(ids_generic_grid_dynamic_space), pointer | pointer | Pointer to the |
space_index | integer | in | Index of the triangular grid space in the |
dimensionality | integer | in | Dimensionality of subset objects (1 for nodes, 2 for edges etc.) |
subset_id | integer | in | Integer identifier of the subset |
subroutine arrange_mat_property_subset (subset, space, space_index, grid, mat_property, subset_id)
Arrange a subset for edges with a certain value of MP. The subset gets the name 'MPnnnn', where nnnn is the MP value.
Argument | Type | Intent | Description |
---|---|---|---|
subset | type(ids_generic_grid_dynamic_grid_subset), pointer | pointer | Pointer to the |
space | type(ids_generic_grid_dynamic_space), pointer | pointer | Pointer to the |
space_index | integer | in | Index of the triangular grid space in the |
grid | type(triangular_grid) | in | The grid being saved |
mat_property | integer | in | MP value |
subset_id | integer | in | Integer identifier of the subset |
...
Template
...
files save_grid.f90
...
and recover_grid.f90
The program contained in the file save_grid.f90
performs the following actions:
...
- Opens the IMAS database by calling the subroutine
imas_open_env
. - Reads the IMAS IDS
edge_profiles
, using the subroutineids_get
. - Extracts the information about the grid from the IDS and puts it into a
type(triangular_grid)
-structure, using the subroutineget_triangular_grid_from_ids
(moduletriangular_grid_ids_io
). - Writes the grid to EIRENE-format files (subroutine
write_eirene_grid
, moduletriangular_grid_module
). - Closes the IMAS database.
...
Things to be done
- Add some simple methods for reading and writing physical data.
- Organize a 1D toroidal space and a couple of subsets in the 3D space.
- Add standard integer identifiers where appropriate.
- Try to adjust the processing of exceptions to GSL practices.
- Understand how the triangular grid can be united with the rectangular grid.
...