I am trying to load a set of data using numpy and converting it to fenics mesh before solving the poisson equation. However, the following error is encountered
Traceback (most recent call last):
File “sample_poisson.py”, line 92, in
coeff0.vector().set_local(coeff0_val[d2v])
RuntimeError:*** Error: Unable to successfully call PETSc function ‘VecSetValuesLocal’.
*** Reason: PETSc error code is: 63 (Argument out of range).
*** Where: This error was encountered inside /home/yl398/aur/fenics/dolfin/src/dolfin-2019.1.0.post0/dolfin/la/PETScVector.cpp.
*** Process: 0
*** DOLFIN version: 2019.1.0
*** Git changeset: acf365fd0a6e5ea80243a27621f7d9678f01d99f
I have attached a code here. The m_h data contains 13^3=2197 entries, which matches the dimension of the mesh generated for the cube. There should be no problems with the boundary conditions. Any help is greatly appreciated.
from fenics import *
import numpy as np
from math import *
deg = 1
a = 12
## Create mesh and define function space
mesh = BoxMesh(Point(0.0, 0.0, 0.0), Point(a, a, a), a, a, a)
m_h_input = np.genfromtxt('m_h.dat')
class PeriodicBoundary(SubDomain):
# Left boundary is "target domain" G
def inside(self, x, on_boundary):
# return True if on left or bottom boundary AND NOT on one of the two slave edges
return bool ((near(x[0], 0) or near(x[1], 0) or near(x[2], 0)) and
(not ((near(x[0], a) and near(x[2], a)) or
(near(x[0], a) and near(x[1], a)) or
(near(x[1], a) and near(x[2], a)))) and on_boundary)
# Map right boundary (H) to left boundary (G)
def map(self, x, y):
#### define mapping for a single point in the box, such that 3 mappings are required
if near(x[0], a) and near(x[1], a) and near(x[2],a):
y[0] = x[0] - a
y[1] = x[1] - a
y[2] = x[2] - a
##### define mapping for edges in the box, such that mapping in 2 Cartesian coordinates are required
if near(x[0], a) and near(x[2], a):
y[0] = x[0] - a
y[1] = x[1]
y[2] = x[2] - a
elif near(x[1], a) and near(x[2], a):
y[0] = x[0]
y[1] = x[1] - a
y[2] = x[2] - a
elif near(x[0], a) and near(x[1], a):
y[0] = x[0] - a
y[1] = x[1] - a
y[2] = x[2]
#### right maps to left: left/right is defined as the x-direction
elif near(x[0], a):
y[0] = x[0] - a
y[1] = x[1]
y[2] = x[2]
### back maps to front: front/back is defined as the y-direction
elif near(x[1], a):
y[0] = x[0]
y[1] = x[1] - a
y[2] = x[2]
#### top maps to bottom: top/bottom is defined as the z-direction
elif near(x[2], a):
y[0] = x[0]
y[1] = x[1]
y[2] = x[2] - a
## Define boundary condition
pbc = PeriodicBoundary()
V = FunctionSpace(mesh, 'Lagrange', deg, constrained_domain=pbc)
u = TrialFunction(V)
v = TestFunction(V)
d2v = dof_to_vertex_map(V)
coeff0_val = m_h_input
coeff0 = Function(V)
coeff0.vector().set_local(coeff0_val[d2v])
a = coeff0*inner(grad(u), grad(v))*dx
f = Constant(-6.0)
L = f*v*dx
## Compute solution
u = Function (V)
solve(a == L, u, [])