I just recently reinstalled fenics in wsl using conda
conda create -n fenics -c conda-forge fenics
And I am trying to run a sample code in fenics
from __future__ import print_function
# from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
%matplotlib inline
from fenics import *
# from dolfin import *
# from mshr import *
from ufl import nabla_div
# Scaled Variables
L = 1
W = 0.2
mu = 1
rho = 1
delta = W/L
gamma = 0.4*delta**2
beta = 1.25
lambda_ = beta
g = gamma
# Create Mesh and define function space
mesh = BoxMesh(Point(0,0,0), Point(L,W,W), 10, 3, 3)
V = VectorFunctionSpace(mesh, 'P', 1)
# Define Boundary Conditions
tol = 1e-14
def clamped_boundary(x, on_boundary):
return on_boundary and x[0] < tol
bc = DirichletBC(V, Constant((0,0,0)), clamped_boundary)
# Define Strain and Stress
def epsilon(u):
return 0.5 * (nabla_grad(u) + nabla_grad(u).T)
def sigma(u):
return lambda_*nabla_div(u)*Identity(d) + 2*mu*epsilon(u)
# Define variational problem
u = TrialFunction(V)
d = u.geometric_dimension() # space dimension
v = TestFunction(V)
f = Constant((0,0,-rho*g))
T = Constant((0,0,0))
a = inner(sigma(u), epsilon(v))*dx
L = dot(f, v)*dx + dot(T, v)*ds
# Compute Solution
u = Function(V)
solve(a == L, u, bc)
# Plot Solution
plot(u)
I encountered this error,
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-8-570178011df2> in <module>
60
61 # Plot Solution
---> 62 plot(u)
~/anaconda3/envs/fenics/lib/python3.8/site-packages/dolfin/common/plotting.py in plot(object, *args, **kwargs)
436 # Plot
437 if backend == "matplotlib":
--> 438 return _plot_matplotlib(object, mesh, kwargs)
439 elif backend == "x3dom":
440 return _plot_x3dom(object, kwargs)
~/anaconda3/envs/fenics/lib/python3.8/site-packages/dolfin/common/plotting.py in _plot_matplotlib(obj, mesh, kwargs)
280 else:
281 ax = plt.gca()
--> 282 ax.set_aspect('equal')
283
284 title = kwargs.pop("title", None)
~/anaconda3/envs/fenics/lib/python3.8/site-packages/mpl_toolkits/mplot3d/axes3d.py in set_aspect(self, aspect, adjustable, anchor, share)
321 """
322 if aspect != 'auto':
--> 323 raise NotImplementedError(
324 "Axes3D currently only supports the aspect argument "
325 f"'auto'. You passed in {aspect!r}."
NotImplementedError: Axes3D currently only supports the aspect argument 'auto'. You passed in 'equal'.
I think in the plotting.py file the ax.set_aspect("equal")
instead of “auto”.
Can you tell me how to bypass this error?