but it seems to me that this post and the link that you shared mostly covers geometry that are generated from scratch with gmsh, whereas I deal with a CAD in a .step format. Is anyone has already dealt with such a thing ?
Traceback (most recent call last):
File "/mnt/c/Users/quent/Documents/Codes/Python/Mesh_GMSH2MeshIO/XDMF_OUTPUT_BOUNDARIES_TAGS/Conversion_GMSH2MeshIO.py", line 151, in <module>
tetrahedron_mesh = create_mesh(MAILLAGE, "tetrahedron", prune_z=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/c/Users/quent/Documents/Codes/Python/Mesh_GMSH2MeshIO/XDMF_OUTPUT_BOUNDARIES_TAGS/Conversion_GMSH2MeshIO.py", line 141, in create_mesh
cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/quentin_digimind/anaconda3/envs/MESHING/lib/python3.12/site-packages/meshio/_mesh.py", line 227, in get_cell_data
return np.concatenate(
^^^^^^^^^^^^^^^
ValueError: need at least one array to concatenate
even though I added physical groups for volumes as
volumes = gmsh.model.getEntities(dim=3)
for volume in volumes:
gmsh.model.addPhysicalGroup(3, [volume[1]] ,tag=volume[1] )
gmsh.model.setPhysicalName(3, volume[1], str(volume[1]))
I finally fixe this issue ( was related to an issue with volume physical groups), so I am able to write the mesh as described in the post, but when I try to import the mesh into FeniCS I get the error
mesh = Mesh()
with XDMFFile("SLICE.xdmf") as infile:
infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("facet_SLICE.xdmf") as infile:
infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
I get the error
Traceback (most recent call last):
File "/mnt/c/Users/quent/Documents/Codes/FENICS/CaseSetup/HeatTransfer/SliceCalculation_FirstGo/OneSliceCalculus.py", line 25, in <module>
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
^^^^^^^^
AttributeError: module 'mshr.cpp' has no attribute 'mesh'
inspired from other scripts, I tried to declare something like
mf = MeshFunction("size_t",mesh, 2)
but I cannot find a way to get the mvc values into mf âŚ
import numpy as np
from fenics import *
from dolfin import *
from mshr import *
tol=1E-8
# read a mesh properly written
mesh = Mesh()
with XDMFFile("SLICE.xdmf") as infile:
infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 1)
with XDMFFile("facet_SLICE.xdmf") as infile:
infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
```
I tried this but unfortunately it didnât work for my case. My python script and the error message can be found below. What mistakes did I make?
from future import print_function
from fenics import *
from dolfin import *
from ufl import nabla_div
from mpi4py import MPI
import numpy as np
import meshio
Scaled variables
E = 2.5e11
nv = 0.27
lambda_ = E * nv / ((1 + nv) * (1 - 2 * nv))
mu = 0.5 * E / (1 + nv)
I updated my codes and now I got another issue saying "KeyError:âgmsh:physicalâ ". My msh file is generated from gmsh based on a stl file. My python scrip for gmsh is pasted below.
The good news is that there is cell data in your grid, marked with âgmsh:physicalâ, so the error you had in:
does not make sense, and as you can see from your new code, you get way further, as you get to the write stage. Please remove the âtetra_mesh.xdmfâ and âtetra_mesh.h5â file and try to run the script again.