darsia.MG#

class MG(depth=2, smoother_iterations=5, maxiter=100, tol=None, dim=2, mass_coeff=None, diffusion_coeff=None, verbose=False)[source]#

Bases: Solver

Muiltilvel solver for the problem: mass_coeff * x - diffusion_coeff * laplace(x) = rhs. For arrays with odd number of elements the last element is dropped in the refinement stages.

V-cycle.

NOTE: Add possibility to actually have a heterogeneous diffusion coefficient. As of now it is assumed to be constant, or multiplied after Laplacian.

Initialize the solver.

Parameters:
depthint

Depth of the multigrid hierarchy.

smoother_iterationsint

Number of iterations for the smoother.

maxiterint

Maximum number of iterations.

tolOptional[float]

Tolerance.

dimint

Dimension of the problem.

mass_coeffnp.ndarray or float

Mass coefficient.

diffusion_coeffnp.ndarray or float

Diffusion coefficient.

verbosebool

Print information.

Methods

base_V_Cycle(x0, rhs, depth[, h])

Base V-Cycle (recursive function)

operator(x, h)

The solution operator for the problem

prolongate_parameters(pad_tuple)

In case of heterogeneous parameters the parameters are prolongated by averaging.

prolongation(x)

Prolongate x, i.e., refine it by a factor 2.

restrict_parameters()

In case of heterogeneous parameters the parameters are restricted by averaging.

restriction(x)

Restrict x, i.e., coarsen it by a factor 2.

update_params([dim, mass_coeff, diffusion_coeff])

Update parameters of the solver.

Attributes

smoother

Smoother used in the MG cycle.

smoother_iterations

Number of smoother iterations per step.

depth

Depth of V-cycle.

heterogeneous

Flag controlling whether the material paremeters are heterogeneous.

dim

Spatial dimension of the problem.

maxiter

Maximum number of iterations.

tol

Tolerance for convergence.

mass_coeff

Mass coefficient.

diffusion_coeff

Diffusion coefficient.

verbose

Verbosity.

base_V_Cycle(x0, rhs, depth, h=1)[source]#

Base V-Cycle (recursive function)

Parameters:
x0np.ndarray

Initial guess.

rhsnp.ndarray

Right hand side.

depthint

Depth of the V-Cycle.

hfloat

Grid spacing.

Returns:
X (np.ndarray): solution.
operator(x, h)[source]#

The solution operator for the problem

Parameters:
xnp.ndarray

Input.

hfloat

Grid spacing.

Returns:
Output (np.ndarray).
prolongate_parameters(pad_tuple)[source]#

In case of heterogeneous parameters the parameters are prolongated by averaging.

Parameters:
pad_tupletuple

Tuple of tuples, each tuple contains the number of elements to be padded before and after the corresponding axis.

prolongation(x)[source]#

Prolongate x, i.e., refine it by a factor 2. All values are repeated twice. NOTE: if odd number of indices are restricted then prolongated, the boundary information is lost. Should probably be imporved upon in the future.

Parameters:
xnp.ndarray

Input.

Returns:
Output (np.ndarray).
restrict_parameters()[source]#

In case of heterogeneous parameters the parameters are restricted by averaging.

restriction(x)[source]#

Restrict x, i.e., coarsen it by a factor 2. Even and odd indices are averaged. Last index is dropped if odd.

Parameters:
xnp.ndarray

Input.

Returns:
Output (np.ndarray).
update_params(dim=None, mass_coeff=None, diffusion_coeff=None)[source]#

Update parameters of the solver.

Parameters:
dimint, optional

Spatial dimension of the problem.

mass_coefffloat or array, optional

Mass coefficient.

diffusion_coefffloat or array, optional

Diffusion coefficient.

depth#

Depth of V-cycle.

heterogeneous#

Flag controlling whether the material paremeters are heterogeneous.

smoother#

Smoother used in the MG cycle.

smoother_iterations#

Number of smoother iterations per step.