-
Hello, Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Hi @fzanst At the moment that feature (support physical groups) is not available. Having said that, I would probably create a CDB file for each group, and then import them one by one and assign them component selections at the same time you import them. |
Beta Was this translation helpful? Give feedback.
-
Here's a minimum working example: Create a Mesh Using gmshimport pyvista as pv
from ansys.mapdl.reader import save_as_archive
from ansys.mapdl.core import launch_mapdl
import gmsh
import math
import sys
gmsh.initialize()
gmsh.clear()
# Copied from t1.py...
lc = 1e-2
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(0.1, 0, 0, lc, 2)
gmsh.model.geo.addPoint(0.1, 0.3, 0, lc, 3)
gmsh.model.geo.addPoint(0, 0.3, 0, lc, 4)
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(3, 2, 2)
gmsh.model.geo.addLine(3, 4, 3)
gmsh.model.geo.addLine(4, 1, 4)
gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
ps = gmsh.model.addPhysicalGroup(2, [1]) # this is just the first area
# create second area
gmsh.model.geo.addPoint(0.3, 0, 0, lc, 5)
gmsh.model.geo.addPoint(0.4, 0, 0, lc, 6)
gmsh.model.geo.addPoint(0.4, 0.3, 0, lc, 7)
gmsh.model.geo.addPoint(0.3, 0.3, 0, lc, 8)
gmsh.model.geo.addLine(5, 6, 5)
gmsh.model.geo.addLine(7, 6, 6)
gmsh.model.geo.addLine(7, 8, 7)
gmsh.model.geo.addLine(8, 5, 8)
gmsh.model.geo.addCurveLoop([8, 5, -6, 7], 2)
gmsh.model.geo.addPlaneSurface([2], 2)
ps = gmsh.model.addPhysicalGroup(2, [2]) # this is just the first area
# must sync geo before meshing
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate(3)
# write the gmsh to disk
filename = "t1.msh"
gmsh.write(filename)
# read in the mesh using pyvista. plot it for fun just to show the physical maps
mesh = pv.read(filename)
mesh.plot(scalars="gmsh:physical", categories=True, show_edges=True, cmap="blues") Convert physical groups to Ansys ComponentsNow, here's the trick. Node components need to be bool arrays to for them to be saved to the archive: # the archive reader writer must have node components stored as bool arrays
for group in range(1, 3):
mesh.cell_data[f'GROUP_{group}'] = mesh.cell_data['gmsh:physical'] == group Write to an archive using pymapdl_readerarchive_filename = "archive.cdb"
save_as_archive("archive.cdb", mesh) # load in mesh in MAPDL and plot the elements
mapdl = launch_mapdl()
mapdl.clear()
mapdl.cdread("db", archive_filename)
mapdl.eplot() Show components are indeed loaded into MAPDL>>> mapdl.mesh.n_elem
1448
>>> mapdl.cmsel('S', 'GROUP_1', 'ELEM')
722
>>> mapdl.cmsel('S', 'GROUP_2', 'ELEM')
722
>>> mapdl.allsel()
>>> mapdl.mesh.n_elem
1448 If you need ansys-mapdl-reader to support physical groups, ping me and I'll add them. I'm starting to realize how awesome gmsh is and how we should support it better. 18 days late, sorry about that. |
Beta Was this translation helpful? Give feedback.
-
Hi @fzanst @germa89 @akaszynski fzanst sorry the MAPDL help is not clear on this. Usually the cdb file will contain the necessary NUMOFF commands to offset the numbering of the existing FEM so as to fit the FEM contained in the cdb into the model with numbering starting at 1. Looks like gmsh does not write that command to the cdb file. So you would need to add it manually. The NOOFFSET command can bypass NUMOFF. The Clear option does not result in an offset being created. The cdb files have element types, nodes and elements. Whether to offset nodes and elements is usually straight-forward. But element types, materials, real constants, etc may not be. Anyway this will import the two cdb files properly: from ansys.mapdl.core import launch_mapdl
import os
import sys
path = os.getcwd()
mapdl = launch_mapdl(run_location = path, additional_switches = '-smp')
mapdl.clear()
mapdl.prep7()
mapdl.clocal("11", 0, "", "0.15")
mapdl.csys(0)
mapdl.cdread("db", "square1.cdb")
mapdl.transfer("11","","all")
mapdl.cm("square1", "elem")
n_max = mapdl.get_value('node',0,'num','max')
e_max = mapdl.get_value('elem',0,'num','max')
mapdl.cmsel('u','square1')
mapdl.numoff('node',n_max)
mapdl.numoff('elem',e_max)
mapdl.cdread("db", "square2.cdb")
mapdl.cm('square2','elem')
mapdl.allsel()
mapdl.cmsel('s','square1')
mapdl.cmsel('a','square2')
mapdl.show('png','rev')
mapdl.cmplot('all','elem')
mapdl.show()
mapdl.exit() Mike |
Beta Was this translation helpful? Give feedback.
Hi @fzanst @germa89 @akaszynski
fzanst sorry the MAPDL help is not clear on this. Usually the cdb file will contain the necessary NUMOFF commands to offset the numbering of the existing FEM so as to fit the FEM contained in the cdb into the model with numbering starting at 1. Looks like gmsh does not write that command to the cdb file. So you would need to add it manually. The NOOFFSET command can bypass NUMOFF. The Clear option does not result in an offset being created. The cdb files have element types, nodes and elements. Whether to offset nodes and elements is usually straight-forward. But element types, materials, real constants, etc may not be. Anyway this will import the two cdb fi…