polars_m.f90 Source File


Contents

Source Code


Source Code

module polars_m
    !! Polar grid and map operators
    use netcdf
    use precision_grillix_m, only : GP
    use error_handling_grillix_m, only: handle_error_netcdf, handle_error, error_info_t
    use status_codes_grillix_m, only : GRILLIX_ERR_NAMELIST, &
                                       GRILLIX_ERR_OTHER
    use parallelisation_setup_m, only : is_rank_info_writer
    ! From PARALLAX
    use screen_io_m, only :  get_stdout
    use equilibrium_m, only : equilibrium_t 
    use mesh_cart_m, only : mesh_cart_t
    use csrmat_m, only : csrmat_t
    use coords_polar_m, only : polar_to_cart
    use polar_grid_m, only : polar_grid_t
    use polar_map_factory_m, only : create_polar_map_matrix 
    use zonal_averages_factory_m, only : create_flux_surface_average_csr, create_surface_average_csr
    implicit none

    type, public :: polars_t
        !! Polar type contains polar grid, map matrix, surface and flux surface matrices
        type(polar_grid_t), public :: grid
        !! Polar grid
        real(GP), public, allocatable, dimension(:,:) :: xpol
        !! x-coordiantes of polar grid
        real(GP), public, allocatable, dimension(:,:) :: ypol
        !! y-coordiantes of polar grid
        type(csrmat_t), public, allocatable :: cart_to_polar_csr 
        !! Matrix mapping from Carteisan mesh to polar grid
        type(csrmat_t), public, allocatable :: surface_average_csr
        !! Matrix evaluating surface average
        type(csrmat_t), public, allocatable :: flux_surface_average_csr
        !! Matrix evaluating flux-surface average
        real(GP), dimension(:), public, allocatable :: fluxsurf_area
        !! Area of each discrete flux surface
        real(GP), dimension(:), public, allocatable :: fluxsurf_vol
        !! Volume of each discrete flux surface 
        integer, private :: intorder
        !! Interpolation order for cart_to_polar map matrix
        integer, private :: iwrk1, iwrk2
        !! Work variables needed for temporary storage of nrho and ntheta
        
    contains
        procedure, public :: set_parameters => set_parameters_polars
        procedure, public :: build => build_polars
        procedure, public :: write_netcdf => write_netcdf_polars
        procedure, public :: read_netcdf => read_netcdf_polars
        procedure, public :: display => display_polars
        final :: destructor
        
    end type 

    interface

        module subroutine set_parameters_polars(self, filename, nrho_in, ntheta_in, intorder_in)
            !! Sets parameters for polars, either via namelist from file, or setting explicitly
            implicit none
            class(polars_t), intent(inout) :: self
            !! Instance of the type
            character(*), intent(in), optional :: filename
            !! Filename where parameter are read from
            integer, intent(in), optional :: nrho_in
            !! Number of radial polar grid points
            integer, intent(in), optional :: ntheta_in
            !! Number of poloidal polar grid points
            integer, intent(in), optional :: intorder_in
            !! Interpolation order
        end subroutine 

        module subroutine build_polars(self, equi, mesh, dbgout)
            !! Builds polar grid and map operators
            class(polars_t), intent(inout) :: self
            !! Instance of the type
            class(equilibrium_t) :: equi
            !! Equilibrium (not changed)
            type(mesh_cart_t), intent(in) :: mesh
            !! Mesh   
            integer, intent(in), optional :: dbgout
            !! Debug output level
        end subroutine

        module subroutine display_polars(self)
            !! Displays information on polars
            class(polars_t), intent(in) :: self
            !! Instance of the type
        end subroutine

        module subroutine write_netcdf_polars(self, equi, fgid)
            !! Writes information to netcdf file
            class(polars_t), intent(in) :: self
            !! Instance of the type
            class(equilibrium_t), intent(inout) :: equi
            !! Equilibrium
            integer, intent(in) :: fgid
            !! Netcdf file or group id
        end subroutine

        module subroutine read_netcdf_polars(self, fgid)
            !! Reads penalisation from netcdf file
            class(polars_t), intent(inout) :: self
            !! Instance of the type
            integer, intent(in) :: fgid
            !! Netcdf file or group id
        end subroutine

        module subroutine destructor(self)
            !! Frees memory associated with parallel_map
            type(polars_t), intent(inout) :: self
            !! Instance of the type
        end subroutine

    end interface

end module