Hello,
I am trying to execute a Python script for Fenics on Linux
from fenics import *
from dolfin import *
from mshr import *
import matplotlib.pyplot as plt
import meshio
# Create mesh and define function space
circle = Circle(Point(0.0), 2.0)
but I get the error message
# python script.py
Traceback (most recent call last):
File "/mnt/beegfs/home/mcastel1/ft01_poisson.py", line 22, in <module>
big_circle = Circle(Point(0.0), 2.0)
NameError: name 'Circle' is not defined
I installed mshr and matplot lib, but it does not work. Any ideas ?
from the error generated, it appears that you are expecting the dolfin module to provide the Circle attribute (class/function). On the interpreter prompt, type:
help(dolfin)
Once the module information is displayed, do a word search to see if Circle is included as you assumed it did.
# python
Python 3.9.18 (main, Sep 7 2023, 00:00:00)
[GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dolfin import *
>>> help(dolfin)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'dolfin' is not defined
# python3
Python 3.9.18 (main, Sep 7 2023, 00:00:00)
[GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dolfin as delfino
>>> circle = delfino.cpp.Circle(Point(0.0), 2.0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'dolfin' has no attribute 'cpp'
>>> circle = delfino.cpp.mesh.Circle(Point(0.0), 2.0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'dolfin' has no attribute 'cpp'
>>> circle = delfino.mesh.Circle(Point(0.0), 2.0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'dolfin' has no attribute 'mesh'
>>> from dolfin import *
>>> dir(dolfin)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'dolfin' is not defined
You might have to wait a while if it is a long module. You might even have to click twice for the information to appear (as is with the numpy module, for example).
Press the following keys on your keyboard simultaneously:
CTRL + F
The search box should appear. Type: circle to perform a word search.
This should find the function or class that you are looking for in the help documentation. Read the information that it provides. It should give some information related to how it is used along with a little background (parameters used, examples, description, etc.).
Okay, there’s something I don’t understand here. How come when someone asks you to try something to help us understand the problem, you start by doing from dolfin import *; but when you try to figure things out yourself, you start with import dolfin as delfino?