pymgrit.core package

Submodules

pymgrit.core.application module

Abstract application class for user-defined application classes. Every user-defined application class must inherit from this class.

Required attributes:
  • vector_template

  • vector_t_start

Required functions:
  • step

class pymgrit.core.application.Application(*args, **kwargs)

Bases: object

Abstract application class for user-defined application classes. Every user-defined application class must inherit from this class.

Required attributes:
  • vector_template

  • vector_t_start

Required functions:
  • step

required_attributes = ['vector_template', 'vector_t_start']
abstract step(u_start: object, t_start: float, t_stop: float) object

Time integration routine for the application

Parameters
  • u_start – approximate solution for the input time t_start

  • t_start – time associated with the input approximate solution u_start

  • t_stop – time to evolve the input approximate solution to

Returns

approximate solution at input time t_stop

property vector_t_start: pymgrit.core.vector.Vector

Getter for attribute vector_t_start

property vector_template: pymgrit.core.vector.Vector

Getter for attribute vector_template

class pymgrit.core.application.MetaApplication(name, bases, namespace, **kwargs)

Bases: abc.ABCMeta

MetaClass for the application class. Checks whether required attributes are set.

required_attributes = []

pymgrit.core.at_mgrit module

AT-MGRIT solver in FAS formulation

class pymgrit.core.at_mgrit.AtMgrit(k, *args, **kwargs)

Bases: pymgrit.core.mgrit.Mgrit

create_coarsest_level() None

Creates vectors u and g for coarsest level

forward_solve(lvl: int) None

Solves local coarse grid problems on the coarsest level

Parameters

lvl – AT-MGRIT level

ouput_run_information() None

Outputs information of AT-MGRIT run.

setup_points_and_comm_info(lvl: int) None

Computes local grid information for level lvl. Computes which process holds the previous and next point for each lvl and process.

Parameters

lvl – MGRIT level

pymgrit.core.grid_transfer module

Abstract grid transfer class for user-defined grid transfer classes. Every user-defined grid transfer class must inherit from this class. Allows for additional spatial coarsening and refinement between time levels.

Required functions:
  • restriction

  • interpolation

class pymgrit.core.grid_transfer.GridTransfer

Bases: abc.ABC

Abstract grid transfer class for user-defined grid transfer classes. Every user-defined grid transfer class must inherit from this class. Allows for additional spatial coarsening and refinement between time levels.

Required functions:
  • restriction

  • interpolation

abstract interpolation(u: pymgrit.core.vector.Vector) pymgrit.core.vector.Vector

Spatial interpolation. Receives the spatial solution at a point in time of one level and interpolates it to the same point in time on the next finer level.

Parameters

u – Approximate solution at a time point of one level

Returns

Interpolated input vector u on next finer time grid

Return type

Vector

abstract restriction(u: pymgrit.core.vector.Vector) pymgrit.core.vector.Vector

Spatial restriction. Receives the spatial solution at a point in time of one level and restricts it to the same point in time on the next coarser level.

Parameters

u – Approximate solution at a time point of one level

Returns

Restricted input vector u on next coarser time grid

Return type

Vector

pymgrit.core.grid_transfer_copy module

Standard grid transfer operator. Copies the spatial solution from one level to another.

class pymgrit.core.grid_transfer_copy.GridTransferCopy

Bases: pymgrit.core.grid_transfer.GridTransfer

Standard grid transfer. Copies the spatial solution from one level to another. This function is called for every time point.

interpolation(u: pymgrit.core.vector.Vector) pymgrit.core.vector.Vector

Copies the spatial solution at one point in time of one level and restricts it to the same point in time on the next finer level.

Parameters

u – Approximate solution at a time point of one level

Returns

Input vector u at the same time point on next finer time grid

Return type

Vector

restriction(u: pymgrit.core.vector.Vector) pymgrit.core.vector.Vector

Copies the spatial solution at one point in time of one level and restricts it to the same point in time on the next coarser level.

Parameters

u – Approximate solution at a time point of one level

Returns

Input vector u at the same time point on next coarser time grid

Return type

Vector

pymgrit.core.mgrit module

MGRIT solver in FAS formulation

class pymgrit.core.mgrit.Mgrit(problem: List[pymgrit.core.application.Application], transfer: Optional[List[pymgrit.core.grid_transfer.GridTransfer]] = None, weight_c: float = 1.0, max_iter: int = 100, tol: float = 1e-07, nested_iteration: bool = True, cf_iter: int = 1, cycle_type: str = 'V', comm_time: mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, comm_space: mpi4py.MPI.Comm = <mpi4py.MPI.Comm object>, logging_lvl: int = 20, output_fcn=None, output_lvl=1, t_norm=2, random_init_guess: bool = False)

Bases: object

MGRIT solver class

Implementation of MGRIT FAS algorithm for solving time-stepping problems of the form

u_i = Phi(u_{i-1}),

where Phi propagates u_{i-1} from t = t_{i-1} to t = t_i.

It is assumed that the problems have a constant dimension and the solved space-time matrix stencil is [-Phi I].

c_exchange(lvl: int) None

Point exchange on level lvl if the first point of a process is an F-point.

Typically called after a C-point update.

Parameters

lvl – MGRIT level

c_relax(lvl: int) None

C-relaxation on level lvl.

C-relaxation updates solution values at C-points by propagating the solution from the preceeding F-points.

Parameters

lvl – MGRIT level

convergence_criterion(iteration: int) None

Stopping criterion based on the 2-norm of the space-time residual.

Computes the space-time residual

r_i = Phi(u_{i-1}) - u_i, i = 1, …. nt, r_0 = 0

Parameters

iteration – MGRIT iteration number

create_coarsest_level()

Creates vectors u and g for coarsest level

create_u(lvl: int) None

Creates solution vectors for all local time points on a given MGRIT level.

Parameters

lvl – MGRIT level

create_v_g(lvl: int) None

Creates vectors v and g for all local time points on a given MGRIT level.

Parameters

lvl – MGRIT level

error_correction(lvl: int) None

Computes the error approximation on level lvl and updates the approximation on the next finer level.

Parameters

lvl – MGRIT level

f_exchange(lvl: int) None

Point exchange on level lvl if the first point of a process is a C-point.

Typically called after an F-point update.

Parameters

lvl – MGRIT level

f_relax(lvl: int) None

F-relaxation on level lvl.

F-relaxation updates solution values at F-points by propagating the solution from one C-point to all F-points up to the next C-point.

Parameters

lvl – MGRIT level

fas_residual(lvl: int) None

Injects the fine-grid approximation and its residual from level lvl to the next coarser grid.

Parameters

lvl – MGRIT level

forward_solve(lvl: int) None

Solves the problem directly on level lvl with time stepping.

Parameters

lvl – MGRIT level

get_c_point(lvl: int) pymgrit.core.application.Application

Exchanges the first/last C-point between two processes

Parameters

lvl – MGRIT level

iteration(lvl: int, cycle_type: str, iteration: int, first_f: bool) None

MGRIT iteration on level lvl

Parameters
  • lvl – MGRIT level

  • cycle_type – Cycle type

  • iteration – Number of current iteration

  • first_f – F-relaxation at the beginning

log_info(message: str) None

Writes a message to the logger. Only one process

Parameters

message – Message

nested_iteration() None

Generates an initial approximation on the finest grid by solving the problem on the coarsest grid and interpolating the approximation to the finest level.

ouput_run_information() None

Outputs information of pyMGRIT run.

setup_points_and_comm_info(lvl: int) None

Computes local grid information for level lvl. Computes which process holds the previous and next point for each lvl and process.

Parameters

lvl – MGRIT level

solve() dict

Driver function for solving the problem using MGRIT.

Performs MGRIT iterations until a stopping criterion is fulfilled or the maximum number of iterations is reached.

Returns

dictionary with residual history, setup time, and solve time

split_into(number_points: int, number_processes: int) numpy.ndarray

Split points

Parameters
  • number_points – Number of points

  • number_processes – Number of processes

Returns

split_points(length: int, size: int, rank: int) Tuple[int, int]

Splits length points evenly in size parts and computes the index of the first point and block size of the local time interval.

Parameters
  • length – Number of points

  • size – Number of processes

  • rank – Process rank

Returns

Block size and index of first point

pymgrit.core.mgrit_with_plots module

class pymgrit.core.mgrit_with_plots.MgritWithPlots(*args, **kwargs)

Bases: pymgrit.core.mgrit.Mgrit

plot(plot_function)
plot_convergence(save_name=None, fig_size_x=6.4, fig_size_y=4.8, dpi=100, text_size=15)
plot_cycle(iterations=1, save_name=None, fig_size_x=6.4, fig_size_y=4.8, dpi=100, text_size=15)
plot_parallel_distribution(time_procs=None, save_name=None, fig_size_x=6.4, fig_size_y=4.8, dpi=100, text_size=15)

pymgrit.core.simple_setup_problem module

Simple setup of a time-multigrid hierarchy for a problem.

Creates a time-multigrid hierarchy using the finest problem, the number of levels, and the coarsening factor.

pymgrit.core.simple_setup_problem.simple_setup_problem(problem: pymgrit.core.application.Application, level: int, coarsening: int) List[pymgrit.core.application.Application]

Simple setup of a time-multigrid hierarchy for a problem.

Creates a time-multigrid hierarchy using the finest problem, the number of levels, and the coarsening factor.

Parameters
  • problem – Application problem on the finest grid

  • level – Number of time-grid levels

  • coarsening – Coarsening factor to be used for all levels

Returns

List of application problems; one application problem per time-grid level

pymgrit.core.split module

Creates new communicators for space & time parallelism

pymgrit.core.split.split_communicator(comm: mpi4py.MPI.Comm, splitting: int) Tuple[mpi4py.MPI.Comm, mpi4py.MPI.Comm]

Creates new communicators for space & time parallelism by “splitting” the input communicator into two sub-communicators.

Parameters
  • comm – Communicator to be used as the basis for new communicators

  • splitting – Splitting factor (number of processes for spatial parallelism)

Returns

Space and time communicator

pymgrit.core.vector module

Abstract vector class for user-defined vector classes that hold information of a single time point. Every user-defined vector class must inherit from this class.

Required functions:
  • __add__

  • __sub__

  • norm

  • clone_zero

  • clone_rand

  • set_values

  • get_values

class pymgrit.core.vector.Vector

Bases: abc.ABC

Abstract vector class for user-defined vector classes that hold information of a single time point. Every user-defined vector class must inherit from this class.

Required functions:
  • __add__

  • __sub__

  • norm

  • clone_zero

  • clone_rand

  • set_values

  • get_values

abstract clone()

Initialize vector object with same values

abstract clone_rand()

Initialize vector object with random values

abstract clone_zero()

Initialize vector object with zeros

abstract get_values(*args, **kwargs)

Get vector data

abstract norm()

Norm of a vector object

abstract pack(*args, **kwargs)

Specifying communication data

abstract set_values(*args, **kwargs)

Set vector data

abstract unpack(*args, **kwargs)

Unpacking communication data

Module contents