--- Begin Message ---
Merge authors:
Anders Logg (logg)
------------------------------------------------------------
revno: 6237 [merge]
committer: Anders Logg <logg@xxxxxxxxx>
branch nick: dolfin
timestamp: Tue 2011-09-20 15:41:03 +0200
message:
merge: Anders Logg 2011-09-20 Check for valid keyword arguments in solve(), fix...
modified:
site-packages/dolfin/fem/solving.py
--
lp:dolfin
https://code.launchpad.net/~dolfin-core/dolfin/main
Your team DOLFIN Core Team is subscribed to branch lp:dolfin.
To unsubscribe from this branch go to https://code.launchpad.net/~dolfin-core/dolfin/main/+edit-subscription
=== modified file 'site-packages/dolfin/fem/solving.py'
--- site-packages/dolfin/fem/solving.py 2011-09-19 12:24:45 +0000
+++ site-packages/dolfin/fem/solving.py 2011-09-20 13:36:11 +0000
@@ -198,10 +198,10 @@
.. code-block:: python
solve(a == L, u)
- solve(a == L, u, bc)
- solve(a == L, u, [bc1, bc2])
+ solve(a == L, u, bcs=bc)
+ solve(a == L, u, bcs=[bc1, bc2])
- solve(a == L, u, bcs,
+ solve(a == L, u, bcs=bcs,
solver_parameters={"linear_solver": "lu"},
form_compiler_parameters={"optimize": True})
@@ -225,8 +225,8 @@
.. code-block:: python
solve(F == 0, u)
- solve(F == 0, u, bc)
- solve(F == 0, u, [bc1, bc2])
+ solve(F == 0, u, bcs=bc)
+ solve(F == 0, u, bcs=[bc1, bc2])
solve(F == 0, u, bcs, J=J,
solver_parameters={"linear_solver": "lu"},
@@ -264,9 +264,8 @@
"Solve variational problem a == L or F == 0"
# Extract arguments
- eq, u, bcs, J, tol, M = _extract_args(*args, **kwargs)
- form_compiler_parameters = kwargs.get("form_compiler_parameters", {})
- solver_parameters = kwargs.get("solver_parameters", {})
+ eq, u, bcs, J, tol, M, form_compiler_parameters, solver_parameters \
+ = _extract_args(*args, **kwargs)
# Solve linear variational problem
if isinstance(eq.lhs, ufl.Form) and isinstance(eq.rhs, ufl.Form):
@@ -303,9 +302,8 @@
"Solve variational problem a == L or F == 0 adaptively"
# Extract arguments
- eq, u, bcs, J, tol, M = _extract_args(*args, **kwargs)
- form_compiler_parameters = kwargs.get("form_compiler_parameters", {})
- solver_parameters = kwargs.get("solver_parameters", {})
+ eq, u, bcs, J, tol, M, form_compiler_parameters, solver_parameters \
+ = _extract_args(*args, **kwargs)
# Solve linear variational problem
if isinstance(eq.lhs, ufl.Form) and isinstance(eq.rhs, ufl.Form):
@@ -341,17 +339,28 @@
def _extract_args(*args, **kwargs):
"Common extraction of arguments for _solve_varproblem[_adaptive]"
+ # Check for use of valid kwargs
+ valid_kwargs = ["bcs", "J", "tol", "M",
+ "form_compiler_parameters", "solver_parameters"]
+ for kwarg in kwargs.iterkeys():
+ if not kwarg in valid_kwargs:
+ cpp.dolfin_error("solving.py",
+ "solve variational problem",
+ "Illegal keyword argument \"%s\"; valid keywords are %s" % \
+ (kwarg,
+ ", ".join("\"%s\"" % kwarg for kwarg in valid_kwargs)))
+
# Extract equation
if not len(args) >= 2:
cpp.dolfin_error("solving.py",
"solve variational problem",
"Missing arguments, expecting solve(lhs == rhs, "\
- "u, [bc]), where bc is optional")
+ "u, bcs=bcs), where bcs is optional")
if len(args) > 3:
cpp.dolfin_error("solving.py",
"solve variational problem",
"Too many arguments, expecting solve(lhs == rhs, "\
- "u, [bc]), where bc is optional")
+ "u, bcs=bcs), where bcs is optional")
# Extract equation
eq = _extract_eq(args[0])
@@ -386,7 +395,11 @@
"solve variational problem",
"Expecting goal functional M to be a UFL Form")
- return eq, u, bcs, J, tol, M
+ # Extract parameters
+ form_compiler_parameters = kwargs.get("form_compiler_parameters", {})
+ solver_parameters = kwargs.get("solver_parameters", {})
+
+ return eq, u, bcs, J, tol, M, form_compiler_parameters, solver_parameters
def _extract_eq(eq):
"Extract and check argument eq"
--- End Message ---