FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
731 stars 177 forks source link

AttributeError: module 'dolfinx.io' has no attribute 'extract_gmsh_geometry' #2264

Closed tbanduc closed 2 years ago

tbanduc commented 2 years ago

I'm working on Google Colab and trying to extract a gmsh geometry using dolfinx.io. I get and error saying AttributeError: module 'dolfinx.io' has no attribute 'extract_gmsh_geometry'. The following lines of code worked yesterday, and I don't know what's happening:

Here are the blocks of code I'm trying to run:

try:
    import google.colab  # noqa: F401
except ImportError:
    from dolfinx import *
else:
  try:
      from dolfinx import *
  except ImportError:
      !wget "https://fem-on-colab.github.io/releases/fenicsx-install-real.sh" -O "/tmp/fenicsx-install.sh" && bash "/tmp/fenicsx-install.sh"
      from dolfinx import *
import ufl
import gmsh
import pyvista
import numpy as np
from mpi4py import MPI
from dolfinx import io
from dolfinx import cpp
from dolfinx import fem
from dolfinx import mesh
from dolfinx import plot
from petsc4py import PETSc
import matplotlib.pyplot as plt
from petsc4py.PETSc import ScalarType
gmsh.initialize()
gdim = 3

domain = gmsh.model.occ.addCylinder(0, 0, -1, 0, 0, 2, 0.8) 

gmsh.model.occ.synchronize()

gmsh.model.occ.synchronize()

volumes = gmsh.model.getEntities(dim=gdim)
status = gmsh.model.addPhysicalGroup(volumes[0][0], [volumes[0][1]])

gmsh.option.setNumber("Mesh.CharacteristicLengthMin",0.05)
gmsh.option.setNumber("Mesh.CharacteristicLengthMax",0.05)
gmsh.model.mesh.generate(gdim)
if MPI.COMM_WORLD.rank == 0:
    # Get mesh geometry
    geometry_data = io.extract_gmsh_geometry(gmsh.model)
    # Get mesh topology for each element
    topology_data = io.extract_gmsh_topology_and_markers(gmsh.model)

# Extract the cell type and number of nodes per cell and broadcast
# it to the other processors 
if MPI.COMM_WORLD.rank == 0:
    # Extract the cell type and number of nodes per cell and broadcast
    # it to the other processors 
    gmsh_cell_type = list(topology_data.keys())[0]    
    properties = gmsh.model.mesh.getElementProperties(gmsh_cell_type)
    name, dim, order, num_nodes, local_coords, _ = properties
    cells = topology_data[gmsh_cell_type]["topology"]
    cell_id, num_nodes = MPI.COMM_WORLD.bcast([gmsh_cell_type, num_nodes], root=0)
else:        
    cell_id, num_nodes = MPI.COMM_WORLD.bcast([None, None], root=0)
    cells, geometry_data = np.empty([0, num_nodes]), np.empty([0, gdim])

# Permute topology data from MSH-ordering to dolfinx-ordering
ufl_domain = io.ufl_mesh_from_gmsh(cell_id, gdim)
gmsh_cell_perm = io.cell_perm_gmsh(cpp.mesh.to_type(str(ufl_domain.ufl_cell())), num_nodes)
cells = cells[:, gmsh_cell_perm]

# Generate domain
domain = mesh.create_mesh(MPI.COMM_WORLD, cells, geometry_data[:, :gdim], ufl_domain)
gmsh.finalize()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-47-3e23f9976d95>](https://localhost:8080/#) in <module>()
      3 if MPI.COMM_WORLD.rank == 0:
      4     # Get mesh geometry
----> 5     geometry_data = io.extract_gmsh_geometry(gmsh.model)
      6     # Get mesh topology for each element
      7     topology_data = io.extract_gmsh_topology_and_markers(gmsh.model)

AttributeError: module 'dolfinx.io' has no attribute 'extract_gmsh_geometry'
jorgensd commented 2 years ago

The API interfacing with Gmsh has been updated, see: https://github.com/FEniCS/dolfinx/pull/2131/files for details

tbanduc commented 2 years ago

Thanks!