Dear all, I have had an error while trying to solve the Helmholtz eqn on Icosahedral grids. The code used is:
from firedrake import * m = IcosahedralSphereMesh(radius=3, refinement_level=3) mesh = ExtrudedMesh(m, 5, layer_height=0.1, extrusion_type='radial') horiz_elt = FiniteElement("CG", triangle, 1) vert_elt = FiniteElement("CG", interval, 1) elt = OuterProductElement(horiz_elt, vert_elt) V = FunctionSpace(mesh, elt) u = TrialFunction(V) v = TestFunction(V) f = Function(V) f.interpolate(Expression("(2*x[0])+(sin(3*x[1]))+(cos(0.5*x[2]))")) Coefficient(FunctionSpace(Mesh(OuterProductVectorElement(OuterProductElement(FiniteElement('Lagrange', triangle, 1), FiniteElement('Lagrange', interval, 1), OuterProductCell(triangle, interval)), dim=3), 4), OuterProductElement(FiniteElement('Lagrange', triangle, 1), FiniteElement('Lagrange', interval, 1), OuterProductCell(triangle, interval))), 3) a = (dot(grad(v), grad(u)) + v * u) * dx L = f * v * dx solve(a == L, u, solver_parameters={'ksp_type': 'cg'}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/solving.py", line 120, in solve _solve_varproblem(*args, **kwargs) File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/solving.py", line 132, in _solve_varproblem nest = _extract_args(*args, **kwargs) File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/solving.py", line 259, in _extract_args u = _extract_u(args[1]) File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/solving.py", line 299, in _extract_u raise RuntimeError("Expecting second argument to be a Coefficient") RuntimeError: Expecting second argument to be a Coefficient
I will be glad to get help on how to fix this, and any other advice on implementation of icosahedral grids. Receive thanks in advance. David
On 17/12/15 14:34, Angwenyi David wrote:
Dear all,
I have had an error while trying to solve the Helmholtz eqn on Icosahedral grids. The code used is:
from firedrake import * m = IcosahedralSphereMesh(radius=3, refinement_level=3) mesh = ExtrudedMesh(m, 5, layer_height=0.1, extrusion_type='radial') horiz_elt = FiniteElement("CG", triangle, 1) vert_elt = FiniteElement("CG", interval, 1) elt = OuterProductElement(horiz_elt, vert_elt) V = FunctionSpace(mesh, elt) u = TrialFunction(V) v = TestFunction(V) f = Function(V) f.interpolate(Expression("(2*x[0])+(sin(3*x[1]))+(cos(0.5*x[2]))")) Coefficient(FunctionSpace(Mesh(OuterProductVectorElement(OuterProductElement(FiniteElement('Lagrange', triangle, 1), FiniteElement('Lagrange', interval, 1), OuterProductCell(triangle, interval)), dim=3), 4), OuterProductElement(FiniteElement('Lagrange', triangle, 1), FiniteElement('Lagrange', interval, 1), OuterProductCell(triangle, interval))), 3) a = (dot(grad(v), grad(u)) + v * u) * dx L = f * v * dx solve(a == L, u, solver_parameters={'ksp_type': 'cg'}) ...
RuntimeError: Expecting second argument to be a Coefficient
You need to redefine "u" to be a Function (or Coefficient) rather than a TrialFunction: u = Function(V) solve(a == L, u, ...) should work. Cheers, Lawrence
Well, it works awhile but stops at some point with an error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/solving.py", line 120, in solve _solve_varproblem(*args, **kwargs) File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/solving.py", line 145, in _solve_varproblem options_prefix=options_prefix) File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/variational_solver.py", line 232, in __init__ super(LinearVariationalSolver, self).__init__(*args, **kwargs) File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/variational_solver.py", line 118, in __init__ if ctx.is_mixed: File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/solving_utils.py", line 152, in is_mixed return self._jacs[-1]._M.sparsity.shape != (1, 1) File "/Users/master/firedrake/lib/python2.7/site-packages/firedrake/function.py", line 248, in __getattr__ return getattr(self._data, name) AttributeError: 'CoordinatelessFunction' object has no attribute '_M' On 17 December 2015 at 15:38, Lawrence Mitchell < lawrence.mitchell@imperial.ac.uk> wrote:
On 17/12/15 14:34, Angwenyi David wrote:
Dear all,
I have had an error while trying to solve the Helmholtz eqn on Icosahedral grids. The code used is:
from firedrake import * m = IcosahedralSphereMesh(radius=3, refinement_level=3) mesh = ExtrudedMesh(m, 5, layer_height=0.1, extrusion_type='radial') horiz_elt = FiniteElement("CG", triangle, 1) vert_elt = FiniteElement("CG", interval, 1) elt = OuterProductElement(horiz_elt, vert_elt) V = FunctionSpace(mesh, elt) u = TrialFunction(V) v = TestFunction(V) f = Function(V) f.interpolate(Expression("(2*x[0])+(sin(3*x[1]))+(cos(0.5*x[2]))"))
Coefficient(FunctionSpace(Mesh(OuterProductVectorElement(OuterProductElement(FiniteElement('Lagrange',
triangle, 1), FiniteElement('Lagrange', interval, 1), OuterProductCell(triangle, interval)), dim=3), 4), OuterProductElement(FiniteElement('Lagrange', triangle, 1), FiniteElement('Lagrange', interval, 1), OuterProductCell(triangle, interval))), 3)
a = (dot(grad(v), grad(u)) + v * u) * dx L = f * v * dx solve(a == L, u, solver_parameters={'ksp_type': 'cg'}) ...
RuntimeError: Expecting second argument to be a Coefficient
You need to redefine "u" to be a Function (or Coefficient) rather than a TrialFunction:
u = Function(V) solve(a == L, u, ...)
should work.
Cheers,
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Hi David, On 17/12/15 14:51, Angwenyi David wrote: ...
AttributeError: 'CoordinatelessFunction' object has no attribute '_M'
Hmm, the following works for me: from firedrake import * m = IcosahedralSphereMesh(radius=3, refinement_level=3) mesh = ExtrudedMesh(m, 5, layer_height=0.1, extrusion_type='radial') horiz_elt = FiniteElement("CG", triangle, 1) vert_elt = FiniteElement("CG", interval, 1) elt = OuterProductElement(horiz_elt, vert_elt) V = FunctionSpace(mesh, elt) u = TrialFunction(V) v = TestFunction(V) f = Function(V) f.interpolate(Expression("(2*x[0])+(sin(3*x[1]))+(cos(0.5*x[2]))")) a = (dot(grad(v), grad(u)) + v * u) * dx L = f * v * dx u = Function(V) solve(a == L, u, solver_parameters={'ksp_type': 'cg'}) which I copy-pasted from your first email except for the addition of the u = Function(V) line before the solve. If things still don't work for you, can you please report a github issue (at github.com/firedrakeproject/firedrake) with some code that we can run to reproduce it? Thanks, Lawrence
Hi Lawrence, Thank you so much for posting the code you used. I made an error by not initialising the solution function, and instead, I defined the trial function as the function itself. Thanks again. David
On 17 Dec 2015, at 16:13, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> wrote:
Hi David,
On 17/12/15 14:51, Angwenyi David wrote: ...
AttributeError: 'CoordinatelessFunction' object has no attribute '_M'
Hmm, the following works for me:
from firedrake import * m = IcosahedralSphereMesh(radius=3, refinement_level=3) mesh = ExtrudedMesh(m, 5, layer_height=0.1, extrusion_type='radial') horiz_elt = FiniteElement("CG", triangle, 1) vert_elt = FiniteElement("CG", interval, 1) elt = OuterProductElement(horiz_elt, vert_elt) V = FunctionSpace(mesh, elt) u = TrialFunction(V) v = TestFunction(V) f = Function(V) f.interpolate(Expression("(2*x[0])+(sin(3*x[1]))+(cos(0.5*x[2]))"))
a = (dot(grad(v), grad(u)) + v * u) * dx L = f * v * dx
u = Function(V) solve(a == L, u, solver_parameters={'ksp_type': 'cg'})
which I copy-pasted from your first email except for the addition of the u = Function(V) line before the solve.
If things still don't work for you, can you please report a github issue (at github.com/firedrakeproject/firedrake) with some code that we can run to reproduce it?
Thanks,
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (2)
- 
                
                Angwenyi David
- 
                
                Lawrence Mitchell