Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot dot CellVariables #1069

Closed
dsseara opened this issue Aug 15, 2024 · 1 comment · Fixed by #1074
Closed

Cannot dot CellVariables #1069

dsseara opened this issue Aug 15, 2024 · 1 comment · Fixed by #1074

Comments

@dsseara
Copy link

dsseara commented Aug 15, 2024

Hello,

I was trying to measure the magnitude of the gradient of a scalar field $a(x)$, i.e. $|\nabla a|^2$, but ran into an issue when using the .dot() function. I was able to reproduce the error with the following example:

>>> import fipy as fp
>>> mesh = fp.Grid1D(nx=10)
>>> a = fp.CellVariable(mesh=mesh)
>>> a.dot(a)
Uncaught exception:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/danny/miniconda3/envs/fipy/lib/python3.10/site-packages/fipy/variables/operatorVariable.py", line 307, in __repr__
    return self._getRepresentation()
  File "/Users/danny/miniconda3/envs/fipy/lib/python3.10/site-packages/fipy/variables/binaryOperatorVariable.py", line 66, in _getRepresentation
    return "(" + operatorClass._getRepresentation(self, style=style, argDict=argDict, id=id, freshen=freshen) + ")"
  File "/Users/danny/miniconda3/envs/fipy/lib/python3.10/site-packages/fipy/variables/operatorVariable.py", line 87, in _getRepresentation
    representation = self._py3kInstructions(op=self.op, style=style, argDict=argDict, id=id, freshen=freshen)
  File "/Users/danny/miniconda3/envs/fipy/lib/python3.10/site-packages/fipy/variables/operatorVariable.py", line 234, in _py3kInstructions
    stack.append(stack.pop() + "(" + ", ".join(args) + ")")
TypeError: sequence item 2: expected str instance, tuple found

This may be related to #961 or #962.

I am using fipy version 3.4.4.

Thank you for the wonderful package!

@guyer
Copy link
Member

guyer commented Oct 1, 2024

Thank you for the report and my apologies for the delayed response. I was on leave and had some health issues; sorry this got missed.

This is, I think, caused by the fix to #961. I have pushed a fix.

  • FWIW, a.dot(a) doesn't really make sense, since a is scalar, but a.grad.dot(a.grad) and a.faceGrad.dot(a.faceGrad) raise the same error.
  • a.dot(a).value works. It's an issue with the representation of the operation.
  • FYI, we have an a.mag property, but its representation exhibits the same bug.

Thank you for the wonderful package!

You're welcome!

guyer added a commit that referenced this issue Oct 4, 2024
* Add test of #1069

* Ensure function arguments are all in repr form

* Reverse order of pop'd arguments

Successive pops reverses, so reverse back

* Install miniconda on macos

Grrr.  Laggards on Azure/GHA team
[dropped miniconda on macos images](actions/runner-images#9262)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants