salomeToElmer - export Salome mesh to Elmer

Discussion about coding and new developments
vencels
Posts: 30
Joined: 20 Sep 2016, 17:05
Antispam: Yes
Location: Latvia
Contact:

salomeToElmer - export Salome mesh to Elmer

Post by vencels »

Hi,

I have written a script to export Salome mesh to Elmer.

https://github.com/jvencels/salomeToElmer

Typically users export Salome mesh in .unv format and then import it into Elmer. The problem is that .unv format does not support pyramids (5 nodal elements). These elements typically arise in mixed tetra and hexa 3D meshes.

I was looking for existing solutions but did not find any. Therefore decided to write salomeToElmer script to export mesh directly to Elmer's native mesh.* format.

It is barely tested so let me know if any suggestions and/or problems.

Cheers,
Juris
RaJa
Posts: 75
Joined: 22 Oct 2014, 09:48
Antispam: Yes

Re: salomeToElmer - export Salome mesh to Elmer

Post by RaJa »

Does your script maintain the naming of the mesh and mesh groups? If so, I could incorporate your script into my Salome plugin the emulates the Elmer GUI.

Thanks,
Rainer
vencels
Posts: 30
Joined: 20 Sep 2016, 17:05
Antispam: Yes
Location: Latvia
Contact:

Re: salomeToElmer - export Salome mesh to Elmer

Post by vencels »

Yes, it keeps names of domains and boundaries.
It would be nice to put it in your Salome plugin.
c_prabal
Posts: 3
Joined: 25 Oct 2010, 03:35

Re: salomeToElmer - export Salome mesh to Elmer

Post by c_prabal »

I tried to export and load it in Elmer 8.2 GUI. It failed. I am attaching salome file. It is not accepting hdf files.

Prabal
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: salomeToElmer - export Salome mesh to Elmer

Post by mzenker »

Hi,

.hdf is the format for Salomé studies. An exported mesh has the format .unv, or, if in Elmer format, it has several files called mesh.boundary, mesh.elements, mesh.header, mesh.nodes. The mesh export is in the mesh module if you select the mesh in the tree view and do a rightclick, or activate the script.

HTH,

Matthias
panosvar
Posts: 74
Joined: 29 Oct 2019, 16:02
Antispam: Yes

Re: salomeToElmer - export Salome mesh to Elmer

Post by panosvar »

Hi,

I tried the script as well, and Elmer is crashing when I import mesh files. I used Salome-Meca 9.3.0 and elmerfem-mpi-8.4_Windows-AMD64.exe .

P.S.: By using ElmerGrid 8 2 example_mesh.unv -autoclean, everything works fine.

Panos
panosvar
Posts: 74
Joined: 29 Oct 2019, 16:02
Antispam: Yes

Re: salomeToElmer - export Salome mesh to Elmer

Post by panosvar »

I found out you can modify the script that comes from "Dump Study" option in Salome to convert the .unv file into *.mesh (Elmer format), by calling cmd inside that script like this:

Code: Select all

def export_elmer(filename):
  """
  Input

    filename: name of the .unv file exported by Salome

  Output

    .unv to *.mesh (Elmer format)
  
  """
  start = time.time()
  os.system('cmd /c "ElmerGrid 8 2 {}.unv -autoclean"'.format(filename))
  end = time.time()
  print("Salome to Elmer convertion time: {:.2f} sec".format(end - start))

# Export .unv file
try:
  Structure_1.ExportUNV( r'Structure.unv' )
  pass
except:
  print('ExportUNV() failed. Invalid file name?')

# Export mesh to Elmer
export_elmer('Structure')
Which creates a folder with all the necessairy files in a folder with the same name as the filename you provided, in the same directory you are working on. I also found out it's good to change directory at the beginning of this .py file, in case you want both .unv files and Elmer files to be saved in another directory, like this:

Code: Select all

os.chdir(path)
Otherwise you have to open cmd with admin rights inside the .py, which I don't know how to do (Salome is really weird in handling external libraries).

Edit: However, the names are not transferred as they were in Salome, which is bad.
kevinarden
Posts: 1169
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: salomeToElmer - export Salome mesh to Elmer

Post by kevinarden »

I just changed the python script itself to write the files where I want them

if not os.path.exists(dirname):
os.makedirs(dirname)
try:
fileHeader = open("/home/titan/fea/salomeToElmer/mesh.header",'w')
fileNodes = open("/home/titan/fea/salomeToElmer/mesh.nodes",'w')
fileNames = open("/home/titan/fea/salomeToElmer/mesh.names",'w')
fileElements = open("/home/titan/fea/salomeToElmer/mesh.elements",'w')
fileBoundary = open("/home/titan/fea/salomeToElmer/mesh.boundary",'w')
except Exception:
print ("ERROR: Cannot open files for writting")
return

Kevin
panosvar
Posts: 74
Joined: 29 Oct 2019, 16:02
Antispam: Yes

Re: salomeToElmer - export Salome mesh to Elmer

Post by panosvar »

Yeah makes sense. Did you find a way to preserve same face names from Salome to Elmer?
kevinarden
Posts: 1169
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: salomeToElmer - export Salome mesh to Elmer

Post by kevinarden »

If I create groups in Salome for volumes, faces, and edges. The groups become bodies, and boundaries. The names come out in the mesh.name file

! ----- names for bodies -----
$ body1 = 1
! ----- names for boundaries -----
$ fixed_end = 2
$ load_end = 3
$ empty = 4
Post Reply