Solving nonlinear problem directly
I'm trying to solve u'^2-u=0. u(0)=1, u(2)=4 with the built in solver but it does not converge. I have tried to use u_.vector()[:] = 1.0 as was suggested in another question but I'm not sure I put it in the right place. What to do?
from dolfin import*
mesh =Interval(50,0,2)
V = FunctionSpace(mesh, 'Lagrange', 1)
#boundary condition init.
u0=Constant(1)
def u0_boundary(x):
return x[0]<DOLFIN_EPS
bc0 = DirichletBC(V, u0, u0_boundary)
u2=Constant(4)
def u2_boundary(x):
return abs(x[0]
bc2 = DirichletBC(V, u2, u2_boundary)
bcs=[bc0, bc2]
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
u_ = Function(V) # the most recently computed solution
F = inner(grad(
F = action(F, u_)
J = derivative(F, u_, u)
u_.vector()[:] = 1.0
problem = NonlinearVariat
solver = NonlinearVariat
solver.solve()
plot(u_,title="u")
interactive()
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Gustav Kettil for more information if necessary.