porepy.utils.error module
- error_L2(g, val, val_ex, relative=True)[source]
Compute the L2 error of a scalar or vector field with respect to a reference field. It is possible to compute the relative error (default) or the absolute error.
Parameters
- ggrid
Grid, or a subclass, with geometry fields computed.
- valnp.ndarray (dim of val, g.num_cells)
Scalar or vector field.
- val_exnp.ndarray (dim of val, g.num_cells)
Reference scalar or vector field, i.e. the exact solution
- relative: bool (True default)
Compute the relative error (if True) or the absolute error (if False).
Return
- out: double
The L2 error of the input fields.
Examples
p = …
def fun_p(pt): return np.sin(2*np.pi*pt[0])*np.sin(2*np.pi*pt[1]) p_ex = interpolate(g, fun_p) err_p = err_L2(g, p, p_ex)
- grid_error(mdg, mdg_ref, variable, variable_dof)[source]
Compute grid errors a grid bucket and refined reference grid bucket
Assumes that the coarse grid bucket has a property ‘coarse_fine_cell_mapping’ assigned on each subdomain, which maps from coarse to fine cells according to the method ‘coarse_fine_cell_mapping(…)’.
Parameters
- mdg, mdg_refpp.MixedDimensionalGrid
Coarse and fine grid buckets, respectively
- variableList[str]
which variables to compute error over
- variable_dofList[int]
Degrees of freedom for each variable in the list ‘variable’.
Returns
- errorsdict
Dictionary with top level keys as node_number, within which for each variable, the error is reported.
- Parameters
mdg (MixedDimensionalGrid) –
mdg_ref (MixedDimensionalGrid) –
- Return type
- interpolate(g, fun)[source]
Interpolate a scalar or vector function on the cell centers of the grid.
Parameters
- ggrid
Grid, or a subclass, with geometry fields computed.
- funfunction
Scalar or vector function.
Return
- out: np.ndarray (dim of fun, g.num_cells)
Function interpolated in the cell centers.
Examples
def fun_p(pt): return np.sin(2*np.pi*pt[0])*np.sin(2*np.pi*pt[1])
- def fun_u(pt): return [ -2*np.pi*np.cos(2*np.pi*pt[0])*np.sin(2*np.pi*pt[1]),
-2*np.pi*np.sin(2*np.pi*pt[0])*np.cos(2*np.pi*pt[1])]
p_ex = interpolate(g, fun_p) u_ex = interpolate(g, fun_u)
- Parameters
g (Union[Grid, MortarGrid]) –
fun (Callable) –
- norm_L2(g, val)[source]
Compute the L2 norm of a scalar or vector field.
Parameters
- g:
Grid, or a subclass, with geometry fields computed.
- val:
Scalar or vector field (dim of val = g.num_cells).
Return
- out: double
The L2 norm of the input field.
Examples
def fun_p(pt): return np.sin(2*np.pi*pt[0])*np.sin(2*np.pi*pt[1]) p_ex = interpolate(g, fun_p) norm_ex = norm_L2(g, p_ex)
- Parameters
g (Union[Grid, MortarGrid]) –
val (ndarray) –