firedrakeproject / firedrake

Firedrake is an automated system for the portable solution of partial differential equations using the finite element method (FEM)
https://firedrakeproject.org
Other
508 stars 159 forks source link

4-th order ODE #3456

Open HumbertHumbert7 opened 7 months ago

HumbertHumbert7 commented 7 months ago

I’m trying to solve a simoleODE: u’’’’=1 With BCs u(0)=u(1)=0 and u’’(0)=u’’(1)=0 My code:

import firedrake as fd import numpy as np import matplotlib.pyplot as plt

N=20 mesh=fd.UnitIntervalMesh(N)

V=fd.FunctionSpace(mesh,'CG',2)

u=fd.TrialFunction(V) v=fd.TestFunction(V)

Def. BC

u_d=fd.Constant(0.) #Dir. BC bc=fd.DirichletBC(V,u_d,'on_boundary')

x=fd.SpatialCoordinate(mesh)[0] #x is a vect., we take the first component. x is used for the Firedrake funct. f=fd.Constant(-1.0)

Weak form.

a=fd.dot(fd.div(fd.grad(u)),fd.div(fd.grad(v)))fd.dx L=fv*fd.dx

u_h=fd.Function(V) fd.solve(a==L,u_h,bc)

fig,ax=plt.subplots() fd.plot(u_h,axes=ax,color='g')

I have an error in the solver. Why?

HumbertHumbert7 commented 7 months ago

u’’’’=-1 actually

colinjcotter commented 7 months ago

Your discretisation space is not contained in H^2 as is required for fourth order operators. You would need to use an H^2 conforming space. In 1D, cubic Hermite works.

From: HumbertHumbert7 @.> Date: Friday, 15 March 2024 at 16:35 To: firedrakeproject/firedrake @.> Cc: Subscribed @.***> Subject: [firedrakeproject/firedrake] 4-th order ODE (Issue #3456)

I’m trying to solve a simoleODE: u’’’’=1 With BCs u(0)=u(1)=0 and u’’(0)=u’’(1)=0 My code:

import firedrake as fd import numpy as np import matplotlib.pyplot as plt

N=20 mesh=fd.UnitIntervalMesh(N)

V=fd.FunctionSpace(mesh,'CG',2)

u=fd.TrialFunction(V) v=fd.TestFunction(V)

Def. BC

u_d=fd.Constant(0.) #Dir. BC bc=fd.DirichletBC(V,u_d,'on_boundary')

x=fd.SpatialCoordinate(mesh)[0] #x is a vect., we take the first component. x is used for the Firedrake funct. f=fd.Constant(-1.0)

Weak form.

a=fd.dot(fd.div(fd.grad(u)),fd.div(fd.grad(v)))fd.dx L=fv*fd.dx

u_h=fd.Function(V) fd.solve(a==L,u_h,bc)

fig,ax=plt.subplots() fd.plot(u_h,axes=ax,color='g')

I have an error in the solver. Why?

— Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/3456, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOSV4UOTC3UPYCYCM45DCTYYMPM3AVCNFSM6AAAAABEYJ4RG6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE4DSMBVGM2TOMA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

HumbertHumbert7 commented 7 months ago

Thank you very much, so what do I have to change?

colinjcotter commented 7 months ago

The finite element space.

From: HumbertHumbert7 @.> Date: Friday, 15 March 2024 at 16:55 To: firedrakeproject/firedrake @.> Cc: Cotter, Colin J @.>, Comment @.> Subject: Re: [firedrakeproject/firedrake] 4-th order ODE (Issue #3456)

Thank you very much, so what do I have to change?

— Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/3456#issuecomment-2000068000, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOSV4WCI4BV2SDUIPCOCB3YYMRYJAVCNFSM6AAAAABEYJ4RG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBQGA3DQMBQGA. You are receiving this because you commented.Message ID: @.***>

HumbertHumbert7 commented 7 months ago

And how can I set the cubic hermite?

colinjcotter commented 7 months ago

https://www.firedrakeproject.org/variational-problems.html#supported-finite-elements

From: HumbertHumbert7 @.> Date: Friday, 15 March 2024 at 16:57 To: firedrakeproject/firedrake @.> Cc: Cotter, Colin J @.>, Comment @.> Subject: Re: [firedrakeproject/firedrake] 4-th order ODE (Issue #3456)

And how can I set the cubic hermite?

— Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/3456#issuecomment-2000070816, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOSV4RZERUTTZHC6G4XWBDYYMR55AVCNFSM6AAAAABEYJ4RG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBQGA3TAOBRGY. You are receiving this because you commented.Message ID: @.***>

HumbertHumbert7 commented 7 months ago

Thank you, I’ll try

colinjcotter commented 7 months ago

Also note that Dirichlet BCs are not supported for these spaces so you will need to use a Nitche method.

From: HumbertHumbert7 @.> Date: Friday, 15 March 2024 at 16:59 To: firedrakeproject/firedrake @.> Cc: Cotter, Colin J @.>, Comment @.> Subject: Re: [firedrakeproject/firedrake] 4-th order ODE (Issue #3456)

Thank you, I’ll try

— Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/3456#issuecomment-2000075697, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOSV4UIBHBKU3UEMXROAJ3YYMSHXAVCNFSM6AAAAABEYJ4RG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBQGA3TKNRZG4. You are receiving this because you commented.Message ID: @.***>

HumbertHumbert7 commented 7 months ago

Do you have the documentation, I’m not familiar with the Nitche method

colinjcotter commented 7 months ago

It isn’t documented, because Firedrake documentation is about how to express your chosen FE discretisation, not which discretisation to use for which problem. For that you will need to do a literature search.

From: HumbertHumbert7 @.> Date: Friday, 15 March 2024 at 17:03 To: firedrakeproject/firedrake @.> Cc: Cotter, Colin J @.>, Comment @.> Subject: Re: [firedrakeproject/firedrake] 4-th order ODE (Issue #3456)

Do you have the documentation, I’m not familiar with the Nitche method

— Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/3456#issuecomment-2000082412, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOSV4QEDMVZ4OGAXDHF3BLYYMSW5AVCNFSM6AAAAABEYJ4RG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBQGA4DENBRGI. You are receiving this because you commented.Message ID: @.***>

HumbertHumbert7 commented 7 months ago

Ok, thank you but there is not an example inthe firedrake documentation with it?

colinjcotter commented 7 months ago

There is a formula in this paper

Kirby, Robert C., and Lawrence Mitchell. "Code generation for generally mapped finite elements." ACM Transactions on Mathematical Software (TOMS) 45, no. 4 (2019): 1-23.

On 15 Mar 2024, at 17:10, HumbertHumbert7 @.***> wrote:



If I have understood correctly, I just add a term that in this case is ufd.grad(v)[0]fd.ds?

— Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/3456#issuecomment-2000093881, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOSV4QVSKHQLDGGYWHOT3DYYMTR5AVCNFSM6AAAAABEYJ4RG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBQGA4TGOBYGE. You are receiving this because you commented.Message ID: @.***>

HumbertHumbert7 commented 7 months ago

I check it now, thank you very much

Ig-dolci commented 12 hours ago

@HumbertHumbert7 can we close this issue?