← Back to team overview

dolfin team mailing list archive

Re: [Question #156790]: eikonal equation

 

Question #156790 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/156790

    Status: Open => Answered

Mikael Mortensen proposed the following answer:
Hi Chaffra,

There were a few errors in the posted script. The following works for me

mesh = UnitInterval(51, )

class RefractiveIndex(Expression):
   def eval(self, values,x):
       if x[0]<0.5:
           values[0] = 1.0
       else:
           values[0] = 1.0

def light_exposed_area(x, on_boundary):
   return near(x[0],0.0) and on_boundary
light_boundary = AutoSubDomain(light_exposed_area)

#k_markers = MeshFunction("uint", mesh, mesh.topology().dim() - 1)
#k_markers.set_all(0)
#light_boundary.mark(k_markers,1)

Q = FunctionSpace(mesh,'CG',1)
u = Function(Q)
du = TrialFunction(Q)
v = TestFunction(Q)
eps = Constant(0.01)

n = RefractiveIndex()
F = inner(grad(u), grad(u))*v*dx - n**2*v*dx + eps*inner(grad(u),
grad(v))*dx
J = derivative(F,u,du)

bc = DirichletBC(Q,Constant(0.0),light_boundary)

problem = VariationalProblem(J,-F, bcs=[bc,])
problem.solve(u)
plot(u)


Best regards

Mikael

On 10 May 2011 15:50, Chaffra <question156790@xxxxxxxxxxxxxxxxxxxxx>
wrote:

> Question #156790 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/156790
>
>     Status: Answered => Open
>
> Chaffra is still having a problem:
> Thanks for your answers Mikael. I would be interested in knowing more
> about the chain rule implementation if you have more info/resources  on
> how to do it. Also using you code above I can solve the eikonal equation
> for my case but the solution is zero everywhere. I assume this has to do
> with the boundary conditions but is there a working demo example I could
> work from?
>
> Many thanks,
> Chaffra
>
> --new code--
>
> mesh = UnitInterval(51, )
>
> class RefractiveIndex(Expression):
>    def eval(self, values,x):
>        if x[0]<0.5:
>             values[0] = 1.0
>        else:
>            values[0] = 100.0
>
> def light_exposed_area(x, on_boundary):
>    return near(x[0],0.0) and on_boundary
> light_boundary = AutoSubDomain(light_exposed_area)
>
> #k_markers = MeshFunction("uint", mesh, mesh.topology().dim() - 1)
> #k_markers.set_all(0)
> #light_boundary.mark(k_markers,1)
>
> Q = FunctionSpace(mesh,'CG',1)
> u = Function(Q)
> du = TrialFunction(Q)
> v = TestFunction(Q)
> eps = Constant(0.01)
>
> n = RefractiveIndex()
> F = inner(grad(u), grad(u))*dx - n**2*v*dx + eps*inner(grad(du),grad(v))*dx
> J = derivative(F,u,du)
>
> bc = DirichletBC(Q,Constant(0.0),light_boundary)
>
> problem = VariationalProblem(J,-F, bcs=[bc,])
> problem.solve(u)
> plot(u)
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp
>

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.