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:
SolverMuiltilvel 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:
- depth
int Depth of the multigrid hierarchy.
- smoother_iterations
int Number of iterations for the smoother.
- maxiter
int Maximum number of iterations.
- tol
Optional[float] Tolerance.
- dim
int Dimension of the problem.
- mass_coeff
np.ndarrayorfloat Mass coefficient.
- diffusion_coeff
np.ndarrayorfloat Diffusion coefficient.
- verbosebool
Print information.
- depth
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.
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 used in the MG cycle.
Number of smoother iterations per step.
Depth of V-cycle.
Flag controlling whether the material paremeters are heterogeneous.
dimSpatial dimension of the problem.
maxiterMaximum number of iterations.
tolTolerance for convergence.
mass_coeffMass coefficient.
diffusion_coeffDiffusion coefficient.
verboseVerbosity.
- base_V_Cycle(x0, rhs, depth, h=1)[source]#
Base V-Cycle (recursive function)
- Parameters:
- x0
np.ndarray Initial guess.
- rhs
np.ndarray Right hand side.
- depth
int Depth of the V-Cycle.
- h
float Grid spacing.
- x0
- Returns:
X(np.ndarray): solution.
- operator(x, h)[source]#
The solution operator for the problem
- Parameters:
- x
np.ndarray Input.
- h
float Grid spacing.
- x
- Returns:
Output(np.ndarray).
- prolongate_parameters(pad_tuple)[source]#
In case of heterogeneous parameters the parameters are prolongated by averaging.
- Parameters:
- pad_tuple
tuple Tuple of tuples, each tuple contains the number of elements to be padded before and after the corresponding axis.
- pad_tuple
- 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:
- x
np.ndarray Input.
- x
- 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:
- x
np.ndarray Input.
- x
- Returns:
Output(np.ndarray).
- update_params(dim=None, mass_coeff=None, diffusion_coeff=None)[source]#
Update parameters of the solver.
- 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.