{"action":"created","issue":{"url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/973","repository_url":"https://api.github.com/repos/firedrakeproject/firedrake","labels_url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/973/labels{/name}","comments_url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/973/comments","events_url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/973/events","html_url":"https://github.com/firedrakeproject/firedrake/issues/973","id":196238895,"number":973,"title":"Counterintuitive behaviour of assemble","user":{"login":"pefarrell","id":3494657,"avatar_url":"https://avatars.githubusercontent.com/u/3494657?v=3","gravatar_id":"","url":"https://api.github.com/users/pefarrell","html_url":"https://github.com/pefarrell","followers_url":"https://api.github.com/users/pefarrell/followers","following_url":"https://api.github.com/users/pefarrell/following{/other_user}","gists_url":"https://api.github.com/users/pefarrell/gists{/gist_id}","starred_url":"https://api.github.com/users/pefarrell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pefarrell/subscriptions","organizations_url":"https://api.github.com/users/pefarrell/orgs","repos_url":"https://api.github.com/users/pefarrell/repos","events_url":"https://api.github.com/users/pefarrell/events{/privacy}","received_events_url":"https://api.github.com/users/pefarrell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-12-17T19:39:43Z","updated_at":"2016-12-19T09:13:54Z","closed_at":null,"body":"I expect assemble to give me a nonzero matrix, but it gives me a zero matrix instead.\r\n\r\nConsider the following firedrake code:\r\n```\r\nfrom firedrake import *\r\n\r\nmesh = UnitSquareMesh(3, 3)\r\nV = FunctionSpace(mesh, \"CG\", 1)\r\nu = TrialFunction(V)\r\nv = TestFunction(V)\r\na = u*v*dx\r\n\r\nA = assemble(a, mat_type=\"aij\")\r\nprint \"A.norm: \", A.petscmat.norm()\r\n```\r\n\r\nI expect `assemble` to actually assemble the matrix, and for its norm to be nonzero. But this code prints\r\n\r\n```\r\n[pfarrell@saoirse:~]$ python norm-firedrake.py \r\nA.norm:  0.0\r\n```\r\n\r\nThe analogous dolfin code\r\n\r\n```\r\nfrom dolfin import *\r\nfrom petsc4py import PETSc\r\n\r\ncomm = mpi_comm_world()\r\n\r\nmesh = UnitSquareMesh(3, 3)\r\nV = FunctionSpace(mesh, \"CG\", 1)\r\nu = TrialFunction(V)\r\nv = TestFunction(V)\r\na = u*v*dx\r\n\r\nA = PETScMatrix(comm)\r\nassemble(a, tensor=A)\r\n\r\nprint \"A.norm: \", A.mat().norm()\r\n\r\n```\r\n\r\ncorrectly prints\r\n\r\n```\r\n [pfarrell@saoirse:~]$ python norm-dolfin.py \r\nA.norm:  0.153268012567\r\n```\r\n\r\nWhat am I doing wrong? Why doesn't `assemble` assemble something nonzero?\r\n"},"comment":{"url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/comments/267916204","html_url":"https://github.com/firedrakeproject/firedrake/issues/973#issuecomment-267916204","issue_url":"https://api.github.com/repos/firedrakeproject/firedrake/issues/973","id":267916204,"user":{"login":"wence-","id":1126981,"avatar_url":"https://avatars.githubusercontent.com/u/1126981?v=3","gravatar_id":"","url":"https://api.github.com/users/wence-","html_url":"https://github.com/wence-","followers_url":"https://api.github.com/users/wence-/followers","following_url":"https://api.github.com/users/wence-/following{/other_user}","gists_url":"https://api.github.com/users/wence-/gists{/gist_id}","starred_url":"https://api.github.com/users/wence-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wence-/subscriptions","organizations_url":"https://api.github.com/users/wence-/orgs","repos_url":"https://api.github.com/users/wence-/repos","events_url":"https://api.github.com/users/wence-/events{/privacy}","received_events_url":"https://api.github.com/users/wence-/received_events","type":"User","site_admin":false},"created_at":"2016-12-19T09:13:54Z","updated_at":"2016-12-19T09:13:54Z","body":"Hmm, this is confusing, because the code does:\r\n\r\n```python\r\n    def __init__(self, a, bcs, *args, **kwargs):\r\n        # sets self._a and self._bcs\r\n        super(Matrix, self).__init__(a, bcs)\r\n        self._M = op2.Mat(*args, **kwargs)\r\n        self.petscmat = self._M.handle\r\n\r\n    @property\r\n    def M(self):\r\n        \"\"\"The :class:`pyop2.Mat` representing the assembled form\r\n\r\n        .. note ::\r\n\r\n            This property forces an actual assembly of the form, if you\r\n            just need a handle on the :class:`pyop2.Mat` object it's\r\n            wrapping, use :attr:`_M` instead.\"\"\"\r\n        self.assemble()\r\n        # User wants to see it, so force the evaluation.\r\n        self._M._force_evaluation()\r\n        return self._M\r\n\r\n    def force_evaluation(self):\r\n        \"Ensures that the matrix is fully assembled.\"\r\n        self.assemble()\r\n        self._M._force_evaluation()\r\n```\r\n\r\nSo `A.force_evaluation()` and `A.M` should really be executing the same code."}}
{"actor":{"display_login":"wence-"}}