Dear. Researchers
I aim at solving two coupled time-dependent problems via the following code. upon execution of the code I have received the following error:
rror: Unable to successfully call PETSc function ‘MatSetValuesLocal’.
*** Reason: PETSc error code is: 63 (Argument out of range).
*** Where: This error was encountered inside /home/conda/feedstock_root/build_artifacts/fenics-pkgs_1739259282872/work/dolfin/la/PETScMatrix.cpp.
*** Process: 0
I am not sure if this error stems from implementation or it possesses an external cause with PETSC. I would be thankful to assess the issue and give me your feedback.
import random
from dolfin import *
import ufl
from ufl.algorithms.formtransformations import compute_form_arities
from ufl.algorithms import expand_derivatives
import numpy as np
import matplotlib.pyplot as plt
dt = 1e-1 # time step
theta = 0.5 # time stepping family, e.g. theta=1 -> backward Euler, theta=0.5 -> Crank-Nicolson
mesh = RectangleMesh(Point(0,0), Point(200,200), 100,100)
P1 = FiniteElement("Lagrange", triangle, 1)
ME = FunctionSpace(mesh,MixedElement(P1, P1, P1))
mesh_file = File("Mesh1D.xml")
mesh_file << mesh
plt.figure()
plot(mesh, title = "domain")
# Define functions
u = Function(ME) # current solution
u0 = Function(ME) # solution from previous converged step
du = TrialFunction(ME)
v1 ,v2, v3 = TestFunctions(ME)
u1, u2, u3 = split(u)
r1, s1, t1 = split(u0)
du1, du2, du3 = split(du)
class K(UserExpression):
def eval(self, values, x):
c0 = 0.5
eps = 0.01
eps_eta = 0.1
Psi = 1.5
values[0] = cos(x[0])*cos(x[1])
values[1] = 0.0
values[2] = cos(x[0]) * cos(x[0])
def value_shape(self):
return(3, )
order_value = K(mesh)
u = interpolate(order_value, ME)
u0.assign(u)
#define parameters
c_alpha = Constant(0.3)
c_beta = Constant(0.7)
ro_s = sqrt(2)
M = Constant(5)
L = Constant(5)
kappa_c = Constant(3)
kappa_eta = Constant(3)
w = Constant(1)
alpha = Constant(5)
u1 = variable(u1)
f_a = (ro_s**2)*(u1 - c_alpha)**2
f_b = (ro_s**2)*(c_beta - u1)**2
fder_a = diff(f_a , u1)
fder_b = diff(f_b, u1)
# define swtiching function
u3 = variable(u3)
hfunction = (u3**3*(6*u3**2 - 15*u3 + 10))
g = ((u3**2)*(1-u3)**2)
fchem = (f_a * (1 - hfunction) + f_b * hfunction + w*g)
fchem_c = diff(fchem,u1)
fchem_eta1 = diff(fchem,u3)
Form_cons= u1*v1*dx - r1*v1*dx + dt*M*inner(grad(u2), grad(v1))*dx
Form_mu = u2*v2*dx - fchem_c*v2*dx - kappa_c*inner(grad(u1), grad(v2))*dx
Form_eta1 = (u3*v3*dx - t1*v3*dx + dt*L*fchem_eta1*v3*dx +
L*kappa_eta*dt*inner(grad(u3), grad(v3))*dx)
Form = Form_cons + Form_mu + Form_eta1
Gain = derivative(Form, u, du)
t = 0.0
T = 1000*dt
while (t < T):
t += dt
solve(Form == 0, u , J = Gain)
u0.assign(u)