-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswtofenics.py
executable file
·73 lines (57 loc) · 2.1 KB
/
swtofenics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
"""
Created on Tuesday Sep 17 2019
Usage: ./swtofenics.py filename.INP
Note: A new file called 'filename.xml' will be created if all goes well.
Make sure you don't have a file with the same name you want to keep
before running this.
Note: You will need to have meshio installed on your system.
Note: This only works with Python 2.x. It does not work with Python 3.
You can use the resulting mesh in fenics with Python 3 though. I am
not sure why it fails - it is within the call to meshio.
EXPORTING FROM SOLIDWORKS SIMULATION
------------------------------------
1. Create your desired geometry in Solidworks (v2018 & v2019 tested)
2. Choose Simulation->New Study->Thermal
3. Right-click Mesh->Create Mesh...
4. Choose your resolution (Mesh Parameters)
5. Under Advanced, choose Draft Quality Mesh (IMPORTANT)
6. From the menu at the top Simulation->Export
7. Save as type: MUST be ABAQUS FILES(*.inp)
8. Save to a file WITHOUT a space in the name
@author: Martin Buist (Github: DocMartinB)
"""
import meshio
import os
import re
import sys
if (len(sys.argv) != 2):
print('Usage: ./swtofenics.py filename.INP')
exit()
mesh_filename = sys.argv[1]
# Meshio seems to require the file extension to be lower case
temp_filename = '_tmpTmpTmPTMP_.inp'
try:
mesh_file = open(mesh_filename, "r")
except:
print('Error: Unable to open input file')
try:
temp_file = open(temp_filename, "w+")
except:
print('Error: Unable to open temporary file')
# By default Abaqus file has an unusual element type which is incompatible
# with meshio. This fixes the problem, by changing to a common compatible
# element type.
for line in mesh_file:
line = re.sub(r'DC1D2', r'C3D4', line)
temp_file.write(line)
mesh_file.close()
temp_file.close()
try:
geometry = meshio.read(temp_filename)
mesh_basename = os.path.splitext(mesh_filename)[0]
meshio.write(mesh_basename + '.xml', geometry)
except:
print('Error: Mesh conversion failed')
if os.path.exists(temp_filename):
os.remove(temp_filename)