Circle is not defined

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 ?

Thanks

It says that Circle is not defined. Some people recommend not using import *, because it is not clear what is being imported.

Are you expecting this Circle to be imported? See that it is dolfin.cpp.mesh.Circle.

Yes, I am expecting that circle to be imported. I tried without the import *, but it does not work

>>> 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'
>>> big_circle = delfino.Circle(Point(0.0), 2.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'dolfin' has no attribute 'Circle'

Hi,

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.

Hello, I cannot even get help(dolfin) to work

# 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

Try:

import dolfin

help(dolfin)

on the interpreter prompt.
(upgrade to v3.12)

It seems to be dolfin.cpp.mesh.Circle, not dolfin.cpp.Circle.

When I type help(dolfin) I get something now, see the screenshot attached.
But then I don’t know what to do: if I type ‘circle’ nothing happens.

It doesn’t work either

# 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'

What result do you get from dir(dolfin)?

>>> from dolfin import *
>>> dir(dolfin)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'dolfin' is not defined

Once you have typed:

import dolfin

help(dolfin)

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.).

Also, please don’t use

from dolfin import *

as @franklinvp suggested. Just type:

import dolfin

or 

import dolfin as df  # use an alias so that it is not so verbose

This goes for other modules as well.

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?