Dear all,
I’m very new to fenicsx and mpi. I try to run my code in parallel as I’m going to use big meshes.
I broke down the code to a small example in order to compare the results for c for running it on one core and on multiple cores.
Somehow, I get every time I run the code in parallel (randomly) a different result (3 different possible solutions).
Maybe I’m missing out some essential part… I also tried to update the ghosts and tried set_bc…same result.
I’d appreciate some help and advice! Thank you!
import numpy as np
from mpi4py import MPI
from dolfinx import mesh, fem, default_scalar_type, nls, plot
from dolfinx.mesh import create_mesh, create_unit_cube
from dolfinx.fem import functionspace
from dolfinx import *
import dolfinx.nls.petsc
import ufl
from ufl import SpatialCoordinate
from mmapy import gcmmasub, mmasub, subsolv, asymp, concheck, raaupdate
import dolfinx
from petsc4py import PETSc
#create mesh / create_unit_cube: cubic mesh with corners [0,0,0] and [1,1,1]
domain = mesh.create_unit_cube(MPI.COMM_WORLD, 20, 20, 20, mesh.CellType.hexahedron, ghost_mode=dolfinx.cpp.mesh.GhostMode.shared_facet)
#
#, ghost_mode=dolfinx.cpp.mesh.GhostMode.none
tdim = domain.topology.dim
fdim = tdim - 1
#domain.topology.create_entities(fdim)
domain.topology.create_connectivity(fdim, tdim)
#define function space
V = functionspace(domain, ("Lagrange", 1))
#concentration c, porosity eps
eps = fem.Function(V) #design variable
phi = ufl.TestFunction(V)
eps.x.array[:] = 0.5 #uD = fem.Function(V)
##Dirichlet
def on_boundary(x):
return np.isclose(x[0], 0)
dofs_L = fem.locate_dofs_geometrical(V , on_boundary)
bc_L = fem.dirichletbc(default_scalar_type(1), dofs_L, V) ##Dirichlet = 1
#Parameter
D0 = 1;
k0 = -1.0;
eta2 = 2.0;
gamma = 2.0;
Rfl = 0.0072
for loop in range(0,11):
c = fem.Function(V)
f = fem.Constant(domain, default_scalar_type(0))
R = ufl.inner(D0*eps**eta2*ufl.grad(c), ufl.grad(phi))*ufl.dx - ufl.inner(k0*(1-eps)**gamma*c,phi)*ufl.dx - ufl.inner(f,phi) *ufl.ds
R_form = dolfinx.fem.form(R)
problem_u = fem.petsc.NonlinearProblem(R, c, bcs=[bc_L])
solver = nls.petsc.NewtonSolver(domain.comm,problem_u)
uh = solver.solve(c)
c.x.scatter_forward()
np.save('c',c.x.array)