Conversation
| elif form_type == 'Jp': | ||
| return tuple(bc if isinstance(bc, DirichletBC) else bc._Jp for bc in bcs) | ||
| else: | ||
| raise TypeError("Unknown form_type: 'form_type' must be 'F', 'J', or 'Jp'.") |
There was a problem hiding this comment.
Given you're using strings, just do:
if form_type not in {"F", "J", "Jp"}:
raise ValueError(...)
else:
return tuple(bc if isinstance(bc, DirichletBC) else getattr(bc, f"_{form_type}") for bc in bcs)
|
|
||
| assemble(a, bcs=extract_equation_bc_forms(bc, 'J')) | ||
| assemble(a, bcs=extract_equation_bc_forms([bc], 'Jp')) | ||
| with pytest.raises(RuntimeError) as excinfo: |
There was a problem hiding this comment.
Change the raise to ValueError (it's not a TypeError) and then assert that you get a ValueError here.
There was a problem hiding this comment.
Fixed TypeError -> ValueError in bc.py.
Here assemble(..., bcs=bc) should actually complain that a raw (unpreprocessed) EquationBC object is given instead of a EquationBCSplit object.
Tried to remove ambiguity in the error message and added more comments.
| bc = EquationBC(F1 == 0, u, 1) | ||
|
|
||
| assemble(F, bcs=extract_equation_bc_forms(bc, 'F')) | ||
| assemble(F, bcs=bc) |
There was a problem hiding this comment.
Can we check for something more than "the code runs"?
There was a problem hiding this comment.
Now checks assembled values.
| bc = EquationBC(a1 == L1, u, 1) | ||
|
|
||
| assemble(a, bcs=extract_equation_bc_forms(bc, 'J')) | ||
| assemble(a, bcs=extract_equation_bc_forms([bc], 'Jp')) |
There was a problem hiding this comment.
Likewise here, can we check that we got the right values?
| Preprocess `bcs` either with: \ | ||
| `bcs = extract_equation_bc_forms(bcs, 'J')`, \ | ||
| or with \ | ||
| `bcs = extract_equation_bc_forms(bcs, 'Jp')`.") |
There was a problem hiding this comment.
Prefer to paste strings like this:
raise RuntimeError("Part of a long string: "
"Another part ")Also, this message will be very long.
| raise TypeError("homogenize only takes a DirichletBC or a list/tuple of DirichletBCs") | ||
|
|
||
|
|
||
| def extract_equation_bc_forms(bcs, form_type): |
There was a problem hiding this comment.
Make this a method on EquationBC? then just call it extract forms?
|
I have rebased on top of master (fixing the merge conflicts) please have a check. |
|
Thanks!! |
|
thanks. |
This PR fixes some equation_bc related bugs: see #1725.