Source code for fe_utils.solvers.mastery

"""Solve a nonlinear problem using the finite element method.
If run as a script, the result is plotted. This file can also be
imported as a module and convergence tests run on the solver.
"""
from argparse import ArgumentParser


[docs]def solve_mastery(resolution, analytic=False, return_error=False): """This function should solve the mastery problem with the given resolution. It should return both the solution :class:`~fe_utils.function_spaces.Function` and the :math:`L^2` error in the solution. If ``analytic`` is ``True`` then it should not solve the equation but instead return the analytic solution. If ``return_error`` is true then the difference between the analytic solution and the numerical solution should be returned in place of the solution. """ raise NotImplementedError
# return (u, p) error if __name__ == "__main__": parser = ArgumentParser( description="""Solve the mastery problem.""") parser.add_argument( "--analytic", action="store_true", help="Plot the analytic solution instead of solving the finite" " element problem.") parser.add_argument("--error", action="store_true", help="Plot the error instead of the solution.") parser.add_argument( "resolution", type=int, nargs=1, help="The number of cells in each direction on the mesh." ) args = parser.parse_args() resolution = args.resolution[0] analytic = args.analytic plot_error = args.error u, error = solve_mastery(resolution, analytic, plot_error) u.plot()