Hello everyone,
I am using Fenics 2019.1.0 and trying to solve the following Poisson problem.
import matplotlib.pyplot as plt
from dolfin import *
from mshr import *
import logging
import time
refRuns = 1
# Importing mesh
# !dolfin-convert annulus.msh annulus.xml
mesh = Mesh("../meshes/annulus_refined_8000.xml")
# Defining function space for fluid dynamics
V = VectorElement("Lagrange", mesh.ufl_cell(), 2)
Q = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
W = FunctionSpace(mesh,Q*Q)
WTilde = FunctionSpace(mesh,Q*Q)
################################
####### Case parameters ########
################################
def determineCase(cs,csV):
if cs == "m":
debye = Constant(csV)
beta = Constant(1/(csV**2))
else:
debye = Constant(csV**2)
beta = Constant(1/(csV))
return debye, beta
Re = Constant(0.001) # Reynolds number
t = 0.0
m = 0
kappa = 1.0 #D/aU
case = "m"
caseValue = Constant(10.0)
choiceOfSolver = "LU"
saveVTK = False
stopSimulation = False
withVarTime = True
debye, beta = determineCase(case,caseValue)
#################################
##### Simulation parameters #####
#################################
t = 0
dt = 100
old_dt = dt
res = 1
old_res = 100
eps = 1e-10
i = 0
max_iter = 5000
# Boundaries
tol = 0.04*(0.5)**refRuns
tolout = 720*(0.5)**refRuns
domain_end = 8000.0
def walls(x,on_boundary):
return on_boundary and near(x[0]**2 + x[1]**2,1.0,tol)
def farfield(x,on_boundary):
return on_boundary and near(sqrt(x[0]**2 + x[1]**2),domain_end,tolout)
##############################
#### Boundary conditions ####
#############################
bc_phi_walls = DirichletBC(W.sub(1),Constant(0.0),walls)
bc_phi_farfield = DirichletBC(W.sub(1),Expression("-beta*x[0]",beta=beta,degree=2),farfield)
# bc_q_farfield = DirichletBC(W.sub(0),Constant(0.0),farfield)
bcs = [bc_phi_walls,bc_phi_farfield]
parameters["form_compiler"]["cpp_optimize"] = True
parameters["form_compiler"]["quadrature_degree"] = 3
var,dvar = TrialFunction(W),TestFunction(W)
q,phi = split(var)
dq,dphi = split(dvar)
Res = inner(grad(phi),grad(dphi))*dx - (q/(2*debye**2))*dphi*dx
aa = lhs(Res)
ll = rhs(Res)
varTilde = Function(WTilde)
solve(aa==ll,varTilde,bcs,solver_parameters={'linear_solver':'mumps'})
However when I solve it I get the following error.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-36-710a040acf80> in <module>
211 varTilde = Function(WTilde)
212 # varTilde.assign(old_var)
--> 213 solve(aa==ll,varTilde,bcs,solver_parameters={'linear_solver':'mumps'})
214
215
/usr/local/lib/python3.6/dist-packages/dolfin/fem/solving.py in solve(*args, **kwargs)
218 # tolerance)
219 elif isinstance(args[0], ufl.classes.Equation):
--> 220 _solve_varproblem(*args, **kwargs)
221
222 # Default case, just call the wrapped C++ solve function
/usr/local/lib/python3.6/dist-packages/dolfin/fem/solving.py in _solve_varproblem(*args, **kwargs)
240 # Create problem
241 problem = LinearVariationalProblem(eq.lhs, eq.rhs, u, bcs,
--> 242 form_compiler_parameters=form_compiler_parameters)
243
244 # Create solver and call solve
/usr/local/lib/python3.6/dist-packages/dolfin/fem/problem.py in __init__(self, a, L, u, bcs, form_compiler_parameters)
57
58 # Initialize C++ base class
---> 59 cpp.fem.LinearVariationalProblem.__init__(self, a, L, u._cpp_object, bcs)
60
61
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 define linear variational problem a(u, v) = L(v) for all v.
*** Reason: Expecting the solution variable u to be a member of the trial space.
*** Where: This error was encountered inside LinearVariationalProblem.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.1.0
*** Git changeset: 74d7efe1e84d65e9433fd96c50f1d278fa3e3f3f
*** -------------------------------------------------------------------------
I have already referred the following links (1) , (2) , (3) , but the hints provided there could not solve the error I am receiving.
If I am missing out on something please do let me know. Any insights would highly be appreciated.