Skip to content

Negation of ResidualTerm throws error #885

@Maxwellfire

Description

@Maxwellfire

Background: I am trying to implement newton iterations, as described in here. In this document, they use a fipy.ResidualTerm to avoid having to recalculate the entire simple equation as an explicit source term

The issue:
Residual terms don't seem to implement coefficients, and so are not able to be negated. A simple piece of code demonstrates the problem:

import fipy
-fipy.ResidualTerm(equation=None)

which throws the error:

Traceback (most recent call last):

  File "/tmp/ipykernel_36715/862288887.py", line 1, in <cell line: 1>
    -fipy.ResidualTerm(equation=None)

  File "/home/max/Tools/anaconda3/envs/fipy/lib/python3.9/site-packages/fipy/terms/nonDiffusionTerm.py", line 23, in __neg__
    return self.__class__(coeff=-self.coeff, var=self.var)

TypeError: __init__() got an unexpected keyword argument 'coeff'

Looking at the code, this seems to happen because the signature of the Residual term is different from every other term. Every other term is fully defined by a coefficient and a variable, but ResidualTerm is defined by an equation.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions