Fwd: Wanted help in defining Gmsh files regions created in Gmsh itself(No defining as x> or x< like this)
Forwarding to ML...
-------- Forwarded Message -------- Subject: Wanted help in defining Gmsh files regions created in Gmsh itself(No defining as x> or x< like this) Date: Fri, 20 Oct 2023 17:00:59 +0530 From: Himalaya singh <aayusingh05@gmail.com> To: sfepy-owner@python.org
I am new to this tool, and I have been exploring it for some time. I got some issues related to the microstructure Regions defining problem directly from Gmsh(.msh file) using Sfepy.
Actually, I am working on lithium ion batteries(Electrode Microstructure) and I am confused how I can make sfepy to read two different regions directly From Gmsh file (where there are grain and grain boundaries having different properties ).
I want some help so my microstructure and created regions will be read by sfepy.
Also, if i will create a simple square domain in Gmsh having three different regions as i already defined as physical group region_1, region_2,region_3 in Gmsh. How can I implement codes for these domains? I just want it to read directly from: mesh = Mesh.from_file('Region.msh').
Any lead or help will be highly appreciated Thank you for your help!
Himalaya Singh Machine Design Department of Mechanical Engineering, IIT Madras
Hi Himalaya Singh,
I also happen to work with Sfepy for the FEM part and Gmsh for the meshing part. A while ago I faced the same problem as the one you describe. My solution is the following:
- Define Physical Groups for your different regions in Gmsh
- Save the mesh as a .vtk file
- "Convert" this file into a new .vtk that is more friendly for Sfepy
For the latter step, I use the following bit of Python code:
def converter4sfepy(fullfilename, ignoreTags=[]):
"""
@author: Hugo Lévy
Converts the .vtk mesh written by Gmsh into a new .vtk which facilitates
topological entity selection with Sfepy. Vertices are given a unique
group
id following the convention:
[0 - 99] --> vertex tag (i.e. entity of dimension 0)
[100 - 199] --> edge tag (i.e. entity of dimension 1)
[200 - 299] --> facet tag (i.e. entity of dimension D-1)
[300 - xxx] --> cell tag (i.e. entity of dimension D)
If one node belong to several topological entities, it will be tagged
with
the lowest dimension group id. For instance, a vertex belonging to a
facet
of tag 200 and a subvolume of tag 300 will be tagged 200. This is
problematic for subvolume selection. This difficulty is overcome by
taking
advantage of the 'mat_ids' field that is readable by Sfepy.
Parameters
----------
fullfilename : str
Absolute pathname of the .vtk mesh.
ignoreTags : list, optional
List of tags to be ignored in the new .vtk mesh. The default is [].
"""
from sfepy.discrete.fem import Mesh # Sfepy I/O utilities
mesh = Mesh.from_file(fullfilename)
cell_dim = mesh.dim
# All the necessary & sufficient info for defining a mesh
data = list(mesh._get_io_data(cell_dim_only=cell_dim))
# Managing vertex groups
ngroups = np.array([None for _ in range(mesh.n_nod)])
reader = meshio.read(fullfilename)
for key in reader.cells_dict.keys():
conn = reader.cells_dict[key]
formerTags = list(reader.cell_data_dict.values())[0][key]
for k, tag in enumerate(formerTags):
if tag not in ignoreTags:
for idx in conn[k]:
if ngroups[idx] is None:
ngroups[idx] = int(tag)
ngroups[np.where(ngroups==None)] = 400 # default marker for untagged
data[1] = ngroups.astype(dtype=np.int32)
# Managing cell groups
conns = list(reader.cells_dict.values())[-1] # entities of highest dim
mat_ids = np.max(ngroups[conns], axis=1)
data[3] = [mat_ids.astype(dtype=np.int32)]
# Overwrite the former mesh
if exterior:
if Rcut == None:
raise Exception("Rcut needs to be specified!")
out = split_mesh_spheres(Rcut, data, mesh)
else:
mesh = Mesh.from_data(mesh.name, *data)
mesh.write(fullfilename, None, binary=False)
out = fullfilename
return out
Hope that helps!
Cheers, Hugo
Le ven. 20 oct. 2023 à 13:50, Robert Cimrman <cimrman3@ntc.zcu.cz> a écrit :
Forwarding to ML...
-------- Forwarded Message -------- Subject: Wanted help in defining Gmsh files regions created in Gmsh itself(No defining as x> or x< like this) Date: Fri, 20 Oct 2023 17:00:59 +0530 From: Himalaya singh <aayusingh05@gmail.com> To: sfepy-owner@python.org
I am new to this tool, and I have been exploring it for some time. I got some issues related to the microstructure Regions defining problem directly from Gmsh(.msh file) using Sfepy.
Actually, I am working on lithium ion batteries(Electrode Microstructure) and I am confused how I can make sfepy to read two different regions directly From Gmsh file (where there are grain and grain boundaries having different properties ).
I want some help so my microstructure and created regions will be read by sfepy.
Also, if i will create a simple square domain in Gmsh having three different regions as i already defined as physical group region_1, region_2,region_3 in Gmsh. How can I implement codes for these domains? I just want it to read directly from: mesh = Mesh.from_file('Region.msh').
Any lead or help will be highly appreciated Thank you for your help!
Himalaya Singh Machine Design Department of Mechanical Engineering, IIT Madras
SfePy mailing list -- sfepy@python.org To unsubscribe send an email to sfepy-leave@python.org https://mail.python.org/mailman3/lists/sfepy.python.org/ Member address: hugo.levy@gmail.com
Please ignore (remove) this bit of code:
if exterior:
if Rcut == None:
raise Exception("Rcut needs to be specified!")
out = split_mesh_spheres(Rcut, data, mesh)
as it is not relevant here.
Hugo
Le ven. 20 oct. 2023 à 15:04, Hugo Lévy <hugo.levy@gmail.com> a écrit :
Hi Himalaya Singh,
I also happen to work with Sfepy for the FEM part and Gmsh for the meshing part. A while ago I faced the same problem as the one you describe. My solution is the following:
- Define Physical Groups for your different regions in Gmsh
- Save the mesh as a .vtk file
- "Convert" this file into a new .vtk that is more friendly for Sfepy
For the latter step, I use the following bit of Python code:
def converter4sfepy(fullfilename, ignoreTags=[]): """ @author: Hugo Lévy Converts the .vtk mesh written by Gmsh into a new .vtk which facilitates topological entity selection with Sfepy. Vertices are given a unique group id following the convention: [0 - 99] --> vertex tag (i.e. entity of dimension 0) [100 - 199] --> edge tag (i.e. entity of dimension 1) [200 - 299] --> facet tag (i.e. entity of dimension D-1) [300 - xxx] --> cell tag (i.e. entity of dimension D) If one node belong to several topological entities, it will be tagged with the lowest dimension group id. For instance, a vertex belonging to a facet of tag 200 and a subvolume of tag 300 will be tagged 200. This is problematic for subvolume selection. This difficulty is overcome by taking advantage of the 'mat_ids' field that is readable by Sfepy. Parameters ---------- fullfilename : str Absolute pathname of the .vtk mesh. ignoreTags : list, optional List of tags to be ignored in the new .vtk mesh. The default is []. """ from sfepy.discrete.fem import Mesh # Sfepy I/O utilities mesh = Mesh.from_file(fullfilename) cell_dim = mesh.dim # All the necessary & sufficient info for defining a mesh data = list(mesh._get_io_data(cell_dim_only=cell_dim)) # Managing vertex groups ngroups = np.array([None for _ in range(mesh.n_nod)]) reader = meshio.read(fullfilename) for key in reader.cells_dict.keys(): conn = reader.cells_dict[key] formerTags = list(reader.cell_data_dict.values())[0][key] for k, tag in enumerate(formerTags): if tag not in ignoreTags: for idx in conn[k]: if ngroups[idx] is None: ngroups[idx] = int(tag) ngroups[np.where(ngroups==None)] = 400 # default marker for untagged data[1] = ngroups.astype(dtype=np.int32) # Managing cell groups conns = list(reader.cells_dict.values())[-1] # entities of highest dim mat_ids = np.max(ngroups[conns], axis=1) data[3] = [mat_ids.astype(dtype=np.int32)] # Overwrite the former mesh if exterior: if Rcut == None: raise Exception("Rcut needs to be specified!") out = split_mesh_spheres(Rcut, data, mesh) else: mesh = Mesh.from_data(mesh.name, *data) mesh.write(fullfilename, None, binary=False) out = fullfilename return out
Hope that helps!
Cheers, Hugo
Le ven. 20 oct. 2023 à 13:50, Robert Cimrman <cimrman3@ntc.zcu.cz> a écrit :
Forwarding to ML...
-------- Forwarded Message -------- Subject: Wanted help in defining Gmsh files regions created in Gmsh itself(No defining as x> or x< like this) Date: Fri, 20 Oct 2023 17:00:59 +0530 From: Himalaya singh <aayusingh05@gmail.com> To: sfepy-owner@python.org
I am new to this tool, and I have been exploring it for some time. I got some issues related to the microstructure Regions defining problem directly from Gmsh(.msh file) using Sfepy.
Actually, I am working on lithium ion batteries(Electrode Microstructure) and I am confused how I can make sfepy to read two different regions directly From Gmsh file (where there are grain and grain boundaries having different properties ).
I want some help so my microstructure and created regions will be read by sfepy.
Also, if i will create a simple square domain in Gmsh having three different regions as i already defined as physical group region_1, region_2,region_3 in Gmsh. How can I implement codes for these domains? I just want it to read directly from: mesh = Mesh.from_file('Region.msh').
Any lead or help will be highly appreciated Thank you for your help!
Himalaya Singh Machine Design Department of Mechanical Engineering, IIT Madras
SfePy mailing list -- sfepy@python.org To unsubscribe send an email to sfepy-leave@python.org https://mail.python.org/mailman3/lists/sfepy.python.org/ Member address: hugo.levy@gmail.com
Hi, Hugo Thanks for the code you shared for the paticular problem. you shared some points to be considered during conversion of file to vtk format for diferent regions problem as: 1. Define Physical Groups for your different regions in Gmsh 2. Save the mesh as a .vtk file 3. "Convert" this file into a new .vtk that is more friendly for Sfepy Here, I want to ask about the (new .vtk)? Is this a file format like .msh or .vtk, i didn't able to get it either new .vtk is anyfile name i will choose or its new version of file format does Sfepy Support. ("Convert" this file into a new .vtk that is more friendly for Sfepy): It seems a bit confusing to me.
Any lead or help will be highly appreciated Thank you for your help!
Himalaya Singh Machine Design Department of Mechanical Engineering, IITMadras
participants (3)
-
Himalaya singh
-
Hugo Lévy
-
Robert Cimrman