Assign solution from previous problem to new problem

334 views
Skip to first unread message

mircea...@gmail.com

unread,
Jul 16, 2018, 10:38:17 AM7/16/18
to fenics-support
Hi everyone!

I want to use the solution of one pde that I solved in fenics as initial conditions for the Newton solver on another problem.  

So, for the first problem I defined a mixed function space :
mesh = UnitSquareMesh(32, 32)

# Define function spaces
P1 = VectorElement("CG", mesh.ufl_cell(), 2)
P2 = FiniteElement("CG", mesh.ufl_cell(), 1)
element = MixedElement([P1,P2])
W = FunctionSpace(mesh, element)


After setting the boundary conditions and formulating the problem I solved it and saved the result in a h5 file format
w = Function(W)
solve(a == L, w, bcs) #bcs are the boundary conditions
(u, p) = w.split()

#Save result
stokes_file = HDF5File(MPI.comm_world,"data/stokes.h5", "w")
stokes_file.write(u, "velocity")
stokes_file.write(p, "pressure")
stokes_file.close()

Now, I would like to use this saved file for my new problem, which is defined in the following space
mesh = UnitSquareMesh(32, 32)

P1 = FiniteElement("CG", mesh.ufl_cell(), 1)
P2 = VectorElement("CG", mesh.ufl_cell(), 2)
P3 = TensorElement("CG", mesh.ufl_cell(), 2, symmetry = True)
element = MixedElement([P1, P2, P3])
W = FunctionSpace(mesh, element)

So I read the file with the solution of the variables
V = VectorFunctionSpace(mesh, "CG", 2)
Q = FunctionSpace(mesh, "CG", 1)

stokes = HDF5File(MPI.comm_world,"data/stokes.h5", "r")

w = Function(W)

(q, v, psi) = TestFunctions(W)

u = Function(V)
p = Function(Q)

#load result from Stokes here
stokes.read(u, "velocity")
stokes.read(p, "pressure")

#Create Tensor
sigma = grad(u)
sigma = project(sigma, W.sub(2).collapse())

But when I run the Solver for nonlinear variational problems I get this error:
Error:   Unable to successfully call PETSc function 'MatSetValuesLocal'.
*** Reason:  PETSc error code is: 63 (Argument out of range).

I also tried to assign those values to my function, like this:
assign(w, [p,u,sigma])

But I get the same error. Can someone point me towards a solution to this problem?

Thank you!







Jan Blechta

unread,
Jul 17, 2018, 12:26:58 PM7/17/18
to mircea...@gmail.com, fenics-support
I would be skeptical relying on the symmetry=True option. There are some
bug reports on the FFC and/or DOLFIN issue tracker.

Jan

mircea...@gmail.com

unread,
Jul 18, 2018, 5:49:19 AM7/18/18
to fenics-support
Yes, I know, I read the bug reports. But I get the same error with or without the symmetry argument. I think I am not properly assigning my functions onto the new function space. Is there some documentation on how to use functions from a h5 file format as initial values for the variational problem?
Reply all
Reply to author
Forward
0 new messages