multigrid_m Module

Multigrid for solving the Helmholtz problem


Used by


Interfaces

interface

  • public module subroutine initialize_multigrid(self, equi, phi, nlvls, spacing_f, size_neighbor, size_ghost_layer, mesh_finest, reorder_size, extend_beyond_wall, dbgout)

    Sets up multigrids, i.e. - creates meshes on all levels - creates prolongation and restriction operators

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout) :: self

    Instance of the type

    class(equilibrium_t), intent(inout) :: equi

    Equilibrium (not changed)

    real(kind=FP), intent(in) :: phi

    Toroidal angle

    integer, intent(in) :: nlvls

    Number of multigrid levels

    real(kind=FP), intent(inout) :: spacing_f

    Grid spacing on finest level (only adapted possibly for slab geometry)

    integer, intent(in) :: size_neighbor

    Number of neighbor points determined in each direction (for finest level, on coarser levels always 1)

    integer, intent(in) :: size_ghost_layer

    Depth of ghost point layer (for finest level, on coarser levels always 0)

    type(mesh_cart_t), intent(out), target :: mesh_finest

    Finest mesh (lvl=1) that was created

    integer, intent(in), optional, dimension(nlvls) :: reorder_size

    Grid reordering for each level

    logical, intent(in) :: extend_beyond_wall

    If true, meshes are extend beyond the wall

    integer, intent(in), optional :: dbgout

    Debug output level, default = 0, none

interface

  • public module subroutine initialize_np_and_idx_arrays(self)

    Creates arrays containing information on number of points (total, boundary, and inner) for all mesh levels. The np_lvl arrays can be used for defining explicit-shape arrays; the first_idx_lvl arrays can be used for consecutively-stored mesh data.

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout), target :: self

    Instance of the type

interface

  • public module subroutine multigrid_write_netcdf(self, fgid)

    Writes information of multigrid to netcdf file

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout) :: self

    Instance of the type

    integer, intent(in) :: fgid

    File or group id number of existing Netcdf4 file

interface

  • public module subroutine multigrid_read_netcdf(self, fgid, mesh_finest)

    Reads information of multigrid from netcdf file

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout) :: self

    Instance of the type

    integer, intent(in) :: fgid

    File or group id number of existing Netcdf4 file

    type(mesh_cart_t), intent(out), target :: mesh_finest

    Finest mesh (lvl=1) that was read from file

interface

  • public module subroutine restrict(self, lvl_f, uf, lvl_c, uc)

    Restricts quantity from fine grid to coarse grid

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(in) :: self

    Instance of the type

    integer, intent(in) :: lvl_f

    Level of fine grid

    real(kind=FP), intent(in), dimension(:) :: uf

    Quantity on fine grid

    integer, intent(in) :: lvl_c

    Level of coarse grid

    real(kind=FP), intent(out), dimension(:) :: uc

    Quantity on coarse grid

interface

  • public module subroutine restrict_inner(self, lvl_f, uf, lvl_c, uc)

    Restricts quantity defined only on inner grid points from fine grid to coarse grid

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout) :: self

    Instance of the type

    integer, intent(in) :: lvl_f

    Level of fine grid

    real(kind=FP), intent(in), dimension(:) :: uf

    Quantity on fine grid

    integer, intent(in) :: lvl_c

    Level of coarse grid

    real(kind=FP), intent(out), dimension(:) :: uc

    Quantity on coarse grid

interface

  • public module subroutine prolong(self, lvl_c, uc, lvl_f, uf)

    Prolongs quantity from coarse grid to fine grid

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout) :: self

    Instance of the type

    integer, intent(in) :: lvl_c

    Level of coarse grid

    real(kind=FP), intent(in), dimension(:) :: uc

    Quantity on coarse grid

    integer, intent(in) :: lvl_f

    Level of fine grid

    real(kind=FP), intent(out), dimension(:) :: uf

    Quantity on fine grid

interface

  • public module subroutine extrapolate_boundary_points(self, lvl, u)

    Extrapolates boundary points according to homegeneous Neumann boundary condition

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout) :: self

    Instance of the type

    integer, intent(in) :: lvl

    Level of mesh

    real(kind=FP), intent(inout), dimension(:) :: u

    Quantity

interface

  • public module subroutine expose_data(self, intermediate_object, data_object)

    Exposes multigrid data through multigrid_data object boundary condition

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(in), target :: self

    Instance of the type

    type(multigrid_intermediate_data_t), intent(out), target :: intermediate_object

    Intermediate object, holds arrays of mesh_cart and csrmat "data"

    type(multigrid_data_t), intent(out) :: data_object

    Destination multigrid_data object

interface

  • public module subroutine create_mrcsr(self, order, dbgout)

    Creates the restriction matrix mappings mrcsr between all consecutive mesh levels - Projection method based on wighted 9 point average is used - Only inner grid points are taken into account

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout), target :: self

    Instance of the type

    integer, intent(in) :: order

    Order of restriction 0: trivial restriction 1: weighted restriction (9-point stencil)

    integer, intent(in) :: dbgout

    Debug output level

interface

  • public module subroutine create_mrcsr_inner(self, dbgout)

    Creates restriction matrix mrcsr_inner purely based on inner grid points - Based on conventional restriction matrix previously created by create_mrcsr

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout), target :: self

    Instance of the type

    integer, intent(in) :: dbgout

    Debug output level

interface

  • public module subroutine create_mpcsr(self, dbgout)

    Creates the prolongation matrix mappings mpcsr between all consecutive mesh levels - Based on bilinear interpolation - Only inner grid points can be set via resulting matrix

    Arguments

    Type IntentOptional Attributes Name
    class(multigrid_t), intent(inout), target :: self

    Instance of the type

    integer, intent(in) :: dbgout

    Debug output level


Derived Types

type, public, bind(C) ::  multigrid_data_t

Data type used to expose multigrid_t data to C/C++ Please see multigrid_t for descriptions of individual properties/members. nlvls value is copied directly. Arrays are exposed with pointers.

Components

Type Visibility Attributes Name Initial
integer(kind=c_int32_t), public :: nlvls
type(c_ptr), public :: mesh_finest_ptr
type(c_ptr), public :: mesh_coarse_array
type(c_ptr), public :: mrcsr
type(c_ptr), public :: mrcsr_inner
type(c_ptr), public :: mpcsr
type(c_ptr), public :: np_lvl
type(c_ptr), public :: np_boundary_lvl
type(c_ptr), public :: np_inner_lvl
type(c_ptr), public :: first_idx_lvl
type(c_ptr), public :: first_idx_boundary_lvl
type(c_ptr), public :: first_idx_inner_lvl

type, public ::  multigrid_intermediate_data_t

Data type needed to expose multigrid_t data to C/C++. Objects of this type shall hold arrays of types mesh_cart_data_t and csrmat_data_t. These are strictly required for the exposure (we cannot use the arrays of type mesh_cart_t and csrmat_t that exist within multigrid_t). In princple this data type could be merged into multigrid_t, but keeping it separate should simplify maintenance.

Components

Type Visibility Attributes Name Initial
type(mesh_cart_data_t), public :: mesh_finest_ptr_data
type(mesh_cart_data_t), public, allocatable, dimension(:) :: mesh_coarse_array_data
type(csrmat_data_t), public, allocatable, dimension(:) :: mrcsr_data
type(csrmat_data_t), public, allocatable, dimension(:) :: mrcsr_inner_data
type(csrmat_data_t), public, allocatable, dimension(:) :: mpcsr_data

Finalizations Procedures

final :: destructor_multigrid_intermediate_data

type, public ::  multigrid_t

Object which contains the multigrid meshes for solving Helmholtz problems. This includes nlvl number of meshes of increasing coarseness, restriction and prolongation matrices.

Finalizations Procedures

final :: destructor_multigrid

Type-Bound Procedures

procedure, public :: init => initialize_multigrid
procedure, public :: write_netcdf => multigrid_write_netcdf
procedure, public :: read_netcdf => multigrid_read_netcdf
procedure, public :: set_phi_coarse
procedure, public :: copy
procedure, public :: get_nlvls
procedure, public :: get_np
procedure, public :: get_np_boundary
procedure, public :: get_np_inner
procedure, public :: get_mesh_pointer
procedure, public :: get_first_idx_lvl_pointer
procedure, public :: get_first_idx
procedure, public :: get_first_idx_boundary_lvl_pointer
procedure, public :: get_first_idx_boundary
procedure, public :: get_first_idx_inner_lvl_pointer
procedure, public :: get_first_idx_inner
procedure, public :: get_np_total
procedure, public :: get_np_inner_total
procedure, public :: restrict
procedure, public :: restrict_inner
procedure, public :: prolong
procedure, public :: extrapolate_boundary_points
procedure, public :: expose_data
procedure, public :: get_mrcsr_pointer
procedure, public :: get_mpcsr_pointer

Functions

public function get_mesh_pointer(self, lvl) result(ptr)

Returns mesh on desired level

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(inout), target :: self

Instance of the type

integer, intent(in) :: lvl

Multigrid level of desired mesh

Return Value type(mesh_cart_t), pointer

Pointer to desired mesh

public pure function get_nlvls(self)

Returns nlvls

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

Return Value integer

public pure function get_np(self, lvl)

Returns the number of total mesh points at the given level

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

integer, intent(in) :: lvl

Desired multigrid level

Return Value integer

public pure function get_np_boundary(self, lvl)

Returns the number of boundary mesh points at the given level

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

integer, intent(in) :: lvl

Desired multigrid level

Return Value integer

public pure function get_np_inner(self, lvl)

Returns the number of inner mesh points at the given level

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

integer, intent(in) :: lvl

Desired multigrid level

Return Value integer

public function get_first_idx_lvl_pointer(self) result(ptr)

Returns a pointer to the first_idx_lvl array

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in), target :: self

Instance of the type

Return Value integer, pointer, dimension(:)

public pure function get_first_idx(self, lvl) result(res)

Returns first_idx at lvl

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

integer, intent(in) :: lvl

Level (up to nlvl+1)

Return Value integer

public function get_first_idx_boundary_lvl_pointer(self) result(ptr)

Returns a pointer to the first_idx_boundary_lvl array

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in), target :: self

Instance of the type

Return Value integer, pointer, dimension(:)

public pure function get_first_idx_boundary(self, lvl) result(res)

Returns first_idx_boundary at lvl

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

integer, intent(in) :: lvl

Level (up to nlvl+1)

Return Value integer

public function get_first_idx_inner_lvl_pointer(self) result(ptr)

Returns a pointer to the first_idx_inner_lvl array

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in), target :: self

Instance of the type

Return Value integer, pointer, dimension(:)

public pure function get_first_idx_inner(self, lvl) result(res)

Returns first_idx_inner at lvl

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

integer, intent(in) :: lvl

Level (up to nlvl+1)

Return Value integer

public pure function get_np_total(self) result(res)

Returns number of mesh points sumed over all levels

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

Return Value integer

public pure function get_np_inner_total(self) result(res)

Returns number of inner mesh points sumed over all levels

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

Return Value integer

public function get_mrcsr_pointer(self, lvl_f) result(res)

Returns pointer to restriction matrix

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in), target :: self

Instance of the type

integer, intent(in) :: lvl_f

Level of restriction matrix (from lvl_f to lvl_f+1)

Return Value type(csrmat_t), pointer

Helmholtz matrix for level lvl

public function get_mpcsr_pointer(self, lvl_f) result(res)

Returns pointer to prolongation matrix

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in), target :: self

Instance of the type

integer, intent(in) :: lvl_f

Level of prolongation matrix (from lvl_f+1 to lvl_f)

Return Value type(csrmat_t), pointer

Helmholtz matrix for level lvl


Subroutines

public subroutine set_phi_coarse(self, new_phi)

Sets phi value on coarse meshes to a new value On finest mesh that is pointed to, needs to be set separately

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(inout), target :: self

Instance of the type

real(kind=FP), intent(in) :: new_phi

New phi value

public subroutine copy(self, multigrid_copy, mesh_finest)

Copies the type to multigrid_copy, setting the internal pointer to mesh_finest

Arguments

Type IntentOptional Attributes Name
class(multigrid_t), intent(in) :: self

Instance of the type

type(multigrid_t), intent(out) :: multigrid_copy

Copied multigrid

type(mesh_cart_t), intent(in), target :: mesh_finest

Finest (lvl=1) mesh to point to

public subroutine destructor_multigrid(self)

Frees memory associated with multigrid

Arguments

Type IntentOptional Attributes Name
type(multigrid_t), intent(inout) :: self

Instance of the type

public subroutine destructor_multigrid_intermediate_data(self)

Frees memory associated with multigrid_intermediate_data

Arguments

Type IntentOptional Attributes Name
type(multigrid_intermediate_data_t), intent(inout) :: self

Instance of the type