Dear Firedrake team, i'm trying to get u*v*dx as a array which each component is amount of the integral on each element. I want to do that in order to compute error indicator. In dolfin implementation it be done like: assemble(u*v*dx).array() Is there a way to do this in Firedrake? Runing the above code in Firedrake gives: AttributeError: 'numpy.float64' object has no attribute 'array' Thank you in advance. Best, Amireh
Dear Amireh, What are the types of u and v? I suspect you have Function for both when you need TestFunction and TrialFunction? All the best Cjc On Wednesday, 1 August 2018, Amireh Mousavi <amireh.mousavi@math.iut.ac.ir> wrote:
Dear Firedrake team, i'm trying to get u*v*dx as a array which each component is amount of the integral on each element. I want to do that in order to compute error indicator. In dolfin implementation it be done like: assemble(u*v*dx).array() Is there a way to do this in Firedrake? Runing the above code in Firedrake gives: *AttributeError: 'numpy.float64' object has no attribute 'array'* Thank you in advance.
Best, Amireh
-- Colin Cotter Department of Mathematics Imperial College London I don’t expect a reply to this email from you outside of your normal working hours. http://www.imperial.ac.uk/people/colin.cotter www.cambridge.org/9781107663916
In the following, I put more clear code with more detail, mesh = UnitSquareMesh(16, 16) BDM = FunctionSpace(mesh, "BDM", 1) DG = FunctionSpace(mesh, "DG", 0) W = BDM * DG sigma, u = TrialFunctions(W) tau, v = TestFunctions(W) x, y = SpatialCoordinate(mesh) f = Function(DG).interpolate( 10*exp(-(pow(x - 0.5, 2) + pow(y - 0.5, 2)) / 0.02)) a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx L = - f*v*dx bc0 = DirichletBC(W.sub(0), as_vector([0.0, -sin(5*x)]), 1) bc1 = DirichletBC(W.sub(0), as_vector([0.0, sin(5*y)]), 2) w = Function(W) solve(a == L, w, bcs=[bc0, bc1]) sigma, u = w.split() Re = assemble((div(sigma)+f)*(div(sigma)+f)*dx).array() and I got the error: AttributeError: 'numpy.float64' object has no attribute 'array' How can I compute "Re" on each element? ----- Original Message ----- From: Colin Cotter (colin.cotter@imperial.ac.uk) Date: 10/05/97 16:03 To: firedrake@imperial.ac.uk Subject: Re: [firedrake] .array() Dear Amireh, What are the types of u and v? I suspect you have Function for both when you need TestFunction and TrialFunction? All the best Cjc On Wednesday, 1 August 2018, Amireh Mousavi <amireh.mousavi@math.iut.ac.ir> wrote: Dear Firedrake team, i'm trying to get u*v*dx as a array which each component is amount of the integral on each element. I want to do that in order to compute error indicator. In dolfin implementation it be done like: assemble(u*v*dx).array() Is there a way to do this in Firedrake? Runing the above code in Firedrake gives: AttributeError: 'numpy.float64' object has no attribute 'array' Thank you in advance. Best, Amireh -- Colin Cotter Department of Mathematics Imperial College London I don't expect a reply to this email from you outside of your normal working hours. http://www.imperial.ac.uk/people/colin.cotter www.cambridge.org/9781107663916 _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Dear Amireh, For "assembled" matrices, please use .M instead of .array() .M.values gives you a dense (!) numpy array, while .M.handle gives you a petsc4py object handle. Miklos ________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Amireh Mousavi <amireh.mousavi@math.iut.ac.ir> Sent: 01 August 2018 18:41:52 To: firedrake Subject: Re: [firedrake] .array() In the following, I put more clear code with more detail, mesh = UnitSquareMesh(16, 16) BDM = FunctionSpace(mesh, "BDM", 1) DG = FunctionSpace(mesh, "DG", 0) W = BDM * DG sigma, u = TrialFunctions(W) tau, v = TestFunctions(W) x, y = SpatialCoordinate(mesh) f = Function(DG).interpolate( 10*exp(-(pow(x - 0.5, 2) + pow(y - 0.5, 2)) / 0.02)) a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx L = - f*v*dx bc0 = DirichletBC(W.sub(0), as_vector([0.0, -sin(5*x)]), 1) bc1 = DirichletBC(W.sub(0), as_vector([0.0, sin(5*y)]), 2) w = Function(W) solve(a == L, w, bcs=[bc0, bc1]) sigma, u = w.split() Re = assemble((div(sigma)+f)*(div(sigma)+f)*dx).array() and I got the error: AttributeError: 'numpy.float64' object has no attribute 'array' How can I compute "Re" on each element? ----- Original Message ----- ________________________________ From: Colin Cotter (colin.cotter@imperial.ac.uk<mailto:colin.cotter@imperial.ac.uk>) Date: 10/05/97 16:03 To: firedrake@imperial.ac.uk<mailto:firedrake@imperial.ac.uk> Subject: Re: [firedrake] .array() Dear Amireh, What are the types of u and v? I suspect you have Function for both when you need TestFunction and TrialFunction? All the best Cjc On Wednesday, 1 August 2018, Amireh Mousavi <amireh.mousavi@math.iut.ac.ir<mailto:amireh.mousavi@math.iut.ac.ir>> wrote: Dear Firedrake team, i'm trying to get u*v*dx as a array which each component is amount of the integral on each element. I want to do that in order to compute error indicator. In dolfin implementation it be done like: assemble(u*v*dx).array() Is there a way to do this in Firedrake? Runing the above code in Firedrake gives: AttributeError: 'numpy.float64' object has no attribute 'array' Thank you in advance. Best, Amireh -- Colin Cotter Department of Mathematics Imperial College London I don't expect a reply to this email from you outside of your normal working hours. http://www.imperial.ac.uk/people/colin.cotter www.cambridge.org/9781107663916<http://www.cambridge.org/9781107663916> ________________________________ _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk<mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
I changed .array() to .M : aa = assemble((div(sigma)+f)*(div(sigma)+f)*dx).M But again, I got the following error : AttributeError: 'numpy.float64' object has no attribute 'M' Any help would be appreciated. ----- Original Message ----- From: Homolya, Miklós (m.homolya14@imperial.ac.uk) Date: 10/05/97 21:46 To: firedrake (firedrake@imperial.ac.uk) Subject: Re: [firedrake] .array() Dear Amireh, For "assembled" matrices, please use .M instead of .array() .M.values gives you a dense (!) numpy array, while .M.handle gives you a petsc4py object handle. Miklos From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Amireh Mousavi <amireh.mousavi@math.iut.ac.ir> Sent: 01 August 2018 18:41:52 To: firedrake Subject: Re: [firedrake] .array() In the following, I put more clear code with more detail, mesh = UnitSquareMesh(16, 16) BDM = FunctionSpace(mesh, "BDM", 1) DG = FunctionSpace(mesh, "DG", 0) W = BDM * DG sigma, u = TrialFunctions(W) tau, v = TestFunctions(W) x, y = SpatialCoordinate(mesh) f = Function(DG).interpolate( 10*exp(-(pow(x - 0.5, 2) + pow(y - 0.5, 2)) / 0.02)) a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx L = - f*v*dx bc0 = DirichletBC(W.sub(0), as_vector([0.0, -sin(5*x)]), 1) bc1 = DirichletBC(W.sub(0), as_vector([0.0, sin(5*y)]), 2) w = Function(W) solve(a == L, w, bcs=[bc0, bc1]) sigma, u = w.split() Re = assemble((div(sigma)+f)*(div(sigma)+f)*dx).array() and I got the error: AttributeError: 'numpy.float64' object has no attribute 'array' How can I compute "Re" on each element? ----- Original Message ----- From: Colin Cotter (colin.cotter@imperial.ac.uk) Date: 10/05/97 16:03 To: firedrake@imperial.ac.uk Subject: Re: [firedrake] .array() Dear Amireh, What are the types of u and v? I suspect you have Function for both when you need TestFunction and TrialFunction? All the best Cjc On Wednesday, 1 August 2018, Amireh Mousavi <amireh.mousavi@math.iut.ac.ir> wrote: Dear Firedrake team, i'm trying to get u*v*dx as a array which each component is amount of the integral on each element. I want to do that in order to compute error indicator. In dolfin implementation it be done like: assemble(u*v*dx).array() Is there a way to do this in Firedrake? Runing the above code in Firedrake gives: AttributeError: 'numpy.float64' object has no attribute 'array' Thank you in advance. Best, Amireh -- Colin Cotter Department of Mathematics Imperial College London I don't expect a reply to this email from you outside of your normal working hours. http://www.imperial.ac.uk/people/colin.cotter www.cambridge.org/9781107663916 _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
On 1 Aug 2018, at 18:41, Amireh Mousavi <amireh.mousavi@math.iut.ac.ir> wrote:
sigma, u = w.split() Re = assemble((div(sigma)+f)*(div(sigma)+f)*dx).array()
Here you assemble a functional. So it is just a number. If you want the cellwise value of this expression write: P0 = FunctionSpace(mesh, "DG", 0) Re = project(expr, P0) Where expr is the integrals of your expression above. Thanks, Lawrence
Yes you are right. Now how can I get the constant value on each cell? Because I need to have an array in order to sort and mark some of them to refine. I'm quite new to python and firedrake. So sorry if my questions are too simple. Many thanks for answering. ----- Original Message ----- From: Lawrence Mitchell ( [lawrence.mitchell@imperial.ac.uk] (mailto:lawrence.mitchell@imperial.ac.uk) ) Date: 11/05/97 07:20 To: [firedrake@imperial.ac.uk] (mailto:firedrake@imperial.ac.uk) Subject: Re: [firedrake] .array() > On 1 Aug 2018, at 18:41, Amireh Mousavi < [amireh.mousavi@math.iut.ac.ir] (mailto:amireh.mousavi@math.iut.ac.ir) > wrote: > > sigma, u = w.split() > Re = assemble((div(sigma)+f)*(div(sigma)+f)*dx).array() Here you assemble a functional. So it is just a number. If you want the cellwise value of this expression write: P0 = FunctionSpace(mesh, "DG", 0) Re = project(expr, P0) Where expr is the integrals of your expression above. Thanks, Lawrence _______________________________________________ firedrake mailing list [firedrake@imperial.ac.uk] (mailto:firedrake@imperial.ac.uk) [https://mailman.ic.ac.uk/mailman/listinfo/firedrake] (https://mailman.ic.ac.uk/mailman/listinfo/firedrake)
Project returns a Function, which is to say a function in the relevant finite element space (in this case P0). The simplest way to get at the coefficients of the function is to access the underlying dat: Re = project(expr, P0) coeffs = Re.dat.data_ro Note that accessing the data_ro property is an assertion that you are not going to change the coefficients in the numpy array. If you intended to change the values, you would instead use: Re.dat.data Regards, David On 02/08/2018, 09:09, "firedrake-bounces@imperial.ac.uk on behalf of Amireh Mousavi" <firedrake-bounces@imperial.ac.uk on behalf of amireh.mousavi@math.iut.ac.ir> wrote: Yes you are right. Now how can I get the constant value on each cell? Because I need to have an array in order to sort and mark some of them to refine. I'm quite new to python and firedrake. So sorry if my questions are too simple. Many thanks for answering. ----- Original Message ----- From: Lawrence Mitchell ( [lawrence.mitchell@imperial.ac.uk] (mailto:lawrence.mitchell@imperial.ac.uk) ) Date: 11/05/97 07:20 To: [firedrake@imperial.ac.uk] (mailto:firedrake@imperial.ac.uk) Subject: Re: [firedrake] .array() > On 1 Aug 2018, at 18:41, Amireh Mousavi < [amireh.mousavi@math.iut.ac.ir] (mailto:amireh.mousavi@math.iut.ac.ir) > wrote: > > sigma, u = w.split() > Re = assemble((div(sigma)+f)*(div(sigma)+f)*dx).array() Here you assemble a functional. So it is just a number. If you want the cellwise value of this expression write: P0 = FunctionSpace(mesh, "DG", 0) Re = project(expr, P0) Where expr is the integrals of your expression above. Thanks, Lawrence _______________________________________________ firedrake mailing list [firedrake@imperial.ac.uk] (mailto:firedrake@imperial.ac.uk) [https://mailman.ic.ac.uk/mailman/listinfo/firedrake] (https://mailman.ic.ac.uk/mailman/listinfo/firedrake) _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (5)
- 
                
                Amireh Mousavi
- 
                
                Colin Cotter
- 
                
                Ham, David A
- 
                
                Homolya, Miklós
- 
                
                Lawrence Mitchell