MixedNonlinearVariatinalSolver problem with KSPSolve

Hello,

I am trying to use the mixed-dimensional branch to solve a non-linear problem where, at the surface of a cylinder, I have a different constitutive than at the inside. I am defining my problem as a MixedNonlinearVariationalProblem and using MixedNonlinearVariationalSolver to solve it. The problem seems to be defined fine, but at the first iteration, the solver fails:

*** -------------------------------------------------------------------------
*** Error: Unable to successfully call PETSc function ‘KSPSolve’.
*** Reason: PETSc error code is: 56 (No support for this operation for this object type).
*** Where: This error was encountered inside /tmp/dolfin/dolfin/la/PETScKrylovSolver.cpp.
*** Process: 0


*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: d7350469ca8a7a2d3ba3b5efd3cb34a5bea91853
*** -------------------------------------------------------------------------

I did a minimal example, where I just use the same constitutive for the surface and the volume and where I do not add the Lagrange multiplier to constrained that both fields should be the same at the surface.

import dolfin as d
import numpy as np
import mshr

# parameters
ri = 3.
h = 27
E = 250.
nu = 0.3
mu = E/(2.0*(1.0 + nu))
lmbda = E*nu/((1.0 + nu)*(1.0 - 2.0*nu))

#%% Mesh definition
cylinder = mshr.Cylinder(d.Point(0, 0, 0), d.Point(0, 0, h), ri, ri)
geometry = cylinder
mesh = mshr.generate_mesh(geometry, 40)

marker = d.MeshFunction("size_t", mesh, mesh.topology().dim() - 1, 0)

class Surface(d.SubDomain):
    def inside(self,x,on_boundary):
        return d.near(np.linalg.norm(x[0:2]), ri, eps = 0.1) and on_boundary
    
surf = Surface()
surf.mark(marker, 10)

submesh = d.MeshView.create(marker, 10)

#%% Function Spaces
V = d.VectorFunctionSpace(mesh, 'CG', 1)
SV = d.VectorFunctionSpace(submesh, 'CG', 1)
W = d.MixedFunctionSpace(V, SV)

w = d.Function(W)
u, us = w.sub(0), w.sub(1)
(du, dus) = d.TrialFunctions(W)
(delta_u, delta_us) = d.TestFunctions(W)

dV = d.Measure("dx", domain = W.sub_space(0).mesh())
dS = d.Measure("dx", domain = W.sub_space(1).mesh())

#%% Boundary conditions
class BoundaryUP(d.SubDomain):
    def inside(self,x,on_boundary):
        return d.near(x[2], 27.) and on_boundary
    
class BoundaryDOWN(d.SubDomain):
    def inside(self,x,on_boundary):
        return d.near(x[2], 0.) and on_boundary
    
boundary_markers = d.MeshFunction("size_t", mesh, 
                                  mesh.topology().dim() - 1)
boundary_markers.set_all(0)

bu  = BoundaryUP()
bd  = BoundaryDOWN()
bu.mark(boundary_markers, 1)
bd.mark(boundary_markers, 2) 

# define value for BC
uD = d.Constant((0.0, 0.0, 0.1))
uU = d.Constant((0.0, 0.0, 0.0))

# define BC
bcu = d.DirichletBC(W.sub_space(0), uU, boundary_markers, 1)
bcd = d.DirichletBC(W.sub_space(0), uD, boundary_markers, 2)

bcs = [bcu, bcd]

#%% Form non linear problem
# Volume
dim = len(u)

I = d.Identity(dim)             # Identity tensor
F = I + d.grad(u)             # Deformation gradient
J  = d.det(F)
FiT = d.inv(F.T)

PK1 = mu*F + (lmbda*d.ln(J) - mu)*FiT

gradu = d.grad(delta_u)
G = d.inner(PK1, gradu)*dV

# Surface
dim = len(us)

Is = d.Identity(dim)             # Identity tensor
Fs = I + d.grad(us)             # Deformation gradient
Js  = d.det(Fs)
FiTs = d.inv(Fs.T)

PK1s = mu*Fs + (lmbda*d.ln(Js) - mu)*FiTs

gradus = d.grad(delta_us)
G += d.inner(PK1s, gradus)*dS

#%% Extract blocks and find Jacobian
Gi = d.extract_blocks(G)

dGi = []
for J in Gi:
    for wi in w.split():
        dg = d.derivative(J, wi)
        dGi.append(dg)
        
u_sol = w.split()
problem = d.MixedNonlinearVariationalProblem(Gi, u_sol, bcs, dGi)
solver = d.MixedNonlinearVariationalSolver(problem)
solver.solve()

I am using docker to run the program. Does anyone has any idea why this fails?
Thank you in advance!

Hello,

I have push minor fixes in the mixed-dimensional branch that might fix your issue (the Docker container has been updated accordingly, tag latest ).

Also, mshr should now be available in the Docker container.

Thank you! That fix my issue.

Dear javjiv4 and cadaversin,

I am using docker containr with the image ceciledc/fenics_mixed_dimensional:latest as suggested by user cdaversin for solving a mixed dimensional problem.

I am working with this example to learn mixed dimensional. I am trying to output the results to a pvd file, but it seems to be giving the following error when I run the above code with the following lines added for file output. The import line is added at the top.

import fenics as fn
............................
filename = fn.File('displacement.pvd')
filename << u_sol

Error:
fenics@eb5691dd1a41:~/shared$ python3 exampleMixed.py
Generating mesh with CGAL 3D mesh generator
[problem] create list of residual forms OK
[problem] create list of jacobian forms OK, J_list size = 4
[MixedNonlinearVariationalProblem]::check_forms - To be implemented
Solving mixed nonlinear variational problem.
Newton iteration 0: r (abs) = 8.185e-01 (tol = 1.000e-10) r (rel) = 1.000e+00 (tol = 1.000e-09)
Newton iteration 1: r (abs) = 1.834e-02 (tol = 1.000e-10) r (rel) = 2.240e-02 (tol = 1.000e-09)
Newton iteration 2: r (abs) = 4.726e-08 (tol = 1.000e-10) r (rel) = 5.774e-08 (tol = 1.000e-09)
Newton iteration 3: r (abs) = 9.287e-13 (tol = 1.000e-10) r (rel) = 1.135e-12 (tol = 1.000e-09)
Newton solver finished in 3 iterations and 3 linear solver iterations.
Traceback (most recent call last):
File “exampleMixed.py”, line 114, in
filename << u_sol
File “/usr/local/lib/python3.6/dist-packages/fenics_dolfin-2019.2.0.dev0-py3.6-linux-x86_64.egg/dolfin/io/init.py”, line 17, in lshift
self.write(u[0]._cpp_object, u[1])
TypeError: write(): incompatible function arguments. The following argument types are supported:
1. (self: dolfin.cpp.io.File, arg0: dolfin::Parameters) -> None
2. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.Mesh) -> None
3. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.Mesh, arg1: float) -> None
4. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.function.Function) -> None
5. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.function.Function, arg1: float) -> None
6. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshFunctionInt) -> None
7. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshFunctionInt, arg1: float) -> None
8. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshFunctionSizet) -> None
9. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshFunctionSizet, arg1: float) -> None
10. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshFunctionDouble) -> None
11. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshFunctionDouble, arg1: float) -> None
12. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshFunctionBool) -> None
13. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshFunctionBool, arg1: float) -> None
14. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshValueCollection_int) -> None
15. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshValueCollection_sizet) -> None
16. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshValueCollection_double) -> None
17. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.mesh.MeshValueCollection_bool) -> None
18. (self: dolfin.cpp.io.File, arg0: dolfin::GenericVector) -> None
19. (self: dolfin.cpp.io.File, arg0: dolfin.cpp.log.Table) -> None
20. (self: dolfin.cpp.io.File, arg0: object) -> None
21. (self: dolfin.cpp.io.File, arg0: object, arg1: float) -> None

Invoked with: <dolfin.cpp.io.File object at 0x7fefc86b4848>, <dolfin.cpp.function.Function object at 0x7fefc8693d50>, Coefficient(FunctionSpace(Mesh(VectorElement(FiniteElement(‘Lagrange’, Cell(‘triangle’, 3), 1), dim=3), 10), VectorElement(FiniteElement(‘Lagrange’, Cell(‘triangle’, 3), 1), dim=3)), 20)

Interestingly, when I run it on ubuntu using the superuser privileges like sudo python3 example.py, it crashes at the mshr stage itself with the following error:

fenics@eb5691dd1a41:~/shared$ sudo python3 exampleMixed.py
Traceback (most recent call last):
File “exampleMixed.py”, line 3, in
import mshr
File “/usr/local/lib/python3.6/dist-packages/mshr-2019.2.0.dev0-py3.6-linux-x86_64.egg/mshr/init.py”, line 24, in
from .cpp import Circle
ImportError: libmshr.so.2019.2: cannot open shared object file: No such file or directory
fenics@eb5691dd1a41:~/shared$

Any leads on why this behavior is happening will be highly appreciated. And how to output the values

Dear @Ankit_Verma,

What you did didn’t work because u_sol is actually a list containing the displacement function in the volume of the cylinder and in the surface of it (i.e. u_sol = [u, us]). To output the displacements to a pvd file you need to save each function separately:

# Save displacements at the volume: u
filename = d.File('disp_volume.pvd')
filename << u_sol[0]

# Save displacements at the surface: us
filename = d.File('disp_surface.pvd')
filename << u_sol[1]

This should let you output the values. I’m not sure about the mshr error or how does sudo works inside a docker container.

1 Like

Dear @javijv4

Thanks much for the prompt response. This makes a lot of sense. I made the above changes in the code. The outputting issues are still there but I think that is now a result of some thing related to the docker container I am using. When I want to output something, I have to remove the mshr command, and use sudo in the docker. Weird!

@cdaversin Any insights will be very helpful:

Current error:
fenics@eb5691dd1a41:~/shared$ python3 exampleMixed.py
Generating mesh with CGAL 3D mesh generator
[problem] create list of residual forms OK
[problem] create list of jacobian forms OK, J_list size = 4
[MixedNonlinearVariationalProblem]::check_forms - To be implemented
Solving mixed nonlinear variational problem.
Newton iteration 0: r (abs) = 8.185e-01 (tol = 1.000e-10) r (rel) = 1.000e+00 (tol = 1.000e-09)
Newton iteration 1: r (abs) = 1.834e-02 (tol = 1.000e-10) r (rel) = 2.240e-02 (tol = 1.000e-09)
Newton iteration 2: r (abs) = 4.726e-08 (tol = 1.000e-10) r (rel) = 5.774e-08 (tol = 1.000e-09)
Newton iteration 3: r (abs) = 9.287e-13 (tol = 1.000e-10) r (rel) = 1.135e-12 (tol = 1.000e-09)
Newton solver finished in 3 iterations and 3 linear solver iterations.
Traceback (most recent call last):
File “exampleMixed.py”, line 118, in
filename << u_sol[0]
File “/usr/local/lib/python3.6/dist-packages/fenics_dolfin-2019.2.0.dev0-py3.6-linux-x86_64.egg/dolfin/io/init.py”, line 14, in lshift
self.write(u._cpp_object)
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** fenics-support@googlegroups.com


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to write to file.
*** Reason: Unable to open file “disp_volume.pvd” for writing.
*** Where: This error was encountered inside GenericFile.cpp.
*** Process: 0


*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: f0a90b8fffc958ed612484cd3465e59994b695f9
*** -------------------------------------------------------------------------

Hello,

I tried running the MWE in the initial post and I am getting the same error. I tried using the latest Docker container found here, (ceciledc/fenics_mixed_dimensional), but the error persists.

Does the MWE work for anyone else?

This looks like a permission issue. In what folder in the docker container are you running the script?
What is the output of the command ls -l in that folder (and in its parent directory).

This is how I run Docker:
docker run -ti -v $(pwd):/home/fenics/shared ceciledc/fenics_mixed_dimensional:latest

where $pwd = ~/Documents/Code/-Workspace/FEniCS

image

I can confirm that the Docker container tagged 27-01-20 works (although mshr is not included in this container so the script will not run as is). Hopefully that helps narrow down the issue.

I can reproduce the error and I will fix that ASAP. In the meantime you can use the previous version of the container (just before latest) : ceciledc/fenics_mixed_dimensional:27-03-20
As far as I remember this one includes mshr so the script should work as is.

1 Like

This should also work with ceciledc/fenics_mixed_dimensional:latest now

Thank you for updating the Docker container! The script above is now working fine. However, this same KSPSolve error comes up in my own code, which I had recently made a separate post about here: [diffusion coupled with boundary equation (mixed-dimensional)].