-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeovar.py
217 lines (173 loc) · 8.61 KB
/
geovar.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
'''
*
* Automatic configuration and meshing of Onshape parts using Python
*
* VERSION: 1.1.2
* - ADDED : Script is now COMPLETELY independent of hardcoded
* values. Script can now determine number of
* features and dynamically adjust as needed.
* - ADDED : Optimized script for speed. If current feature parameter
* is the same as the previous value (no change to it), then
* it is not sent to Onshape to reduce time needed.
* - MODIFIED: Adaptive width line printing.
*
*
* VERSION: 1.2.8
* - ADDED : Ability to check whether part failed to mutate or not!
* - FIXED : Now fully compatible with Windows machines
* - FIXED : Fixed check_default() method's logic. Now we only export
* parts that do NOT revert back to default value after mutation.
* - ADDED : More beautiful formatting FTW!
* - ADDED : Give user ability to define array bounds!
* - ADDED : Enforce correct math, you can call me the math police.
* (i.e. make sure lower bound can't be greater than upper bound)
* - MODIFIED: Simplify code to reduce clutter.
* - FIXED : Doesn't break when user inputs invalid values (i.e str instead of float)
*
*
* VERSION: 1.2.9
* - ADDED : Automated localization of the tetgen directory/path
*
*
* KNOWN ISSUES:
* - Nada atm.
*
*
* AUTHOR : Mohammad Odeh, Fluvio L. Lobo Fenoglietto
* DATE : Dec. 10th, 2018 Year of Our Lord
* LAST CONTRIBUTION DATE : Jan. 09th, 2019 Year of Our Lord
*
'''
# onshape modules and libraries
from onshapepy.play import * # Onshape API
# adapted onshape modules and libraries
import _setup
import _onshape
import _morph
import _vis
import _mesh
import _febio
import _performance
# additional python modules and libraries
from time import sleep, time # Timers/delays
from platform import system # Running platform info
from datetime import datetime # Get date and time
from argparse import ArgumentParser # Add input arguments to script
from itertools import product # Apply product rule on combinations
import numpy as np # Fast array creation
import os, re # Dir/path manipulation, extract numerics from strings
# ************************************************************************
# =====================> CONSTRUCT ARGUMENT PARSER <=====================*
# ************************************************************************
ap = ArgumentParser()
# Operation Modalities ------------------------------------------------- #
# Operation Mode
string = """(1) Generate Geometric Variations of Input Geometry
(2) Mesh Geometric Variations using TetGen
(3) Simulate Geometric Variations using FEBio
"""
ap.add_argument( "-m" , "--mode" , type = int ,
dest = "mode" , default = 2 ,
help = "{}".format(string) )
# Input File
string = "Input file name (no extensions)"
ap.add_argument( "-i" , "--input_file" , type = str ,
dest = "input_file" , default = "permute.xml",
help = "{}".format(string) )
args = ap.parse_args()
# ************************************************************************
# ===========================> PROGRAM SETUP <==========================*
# ************************************************************************
class geovar( object ):
def __init__( self ):
# VARIABLES
self.prog_start_time = time() # start time (for performance analysis)
self.mode = args.mode # operation mode (user input)
self.input_file = args.input_file
self.r = {} # Initialize the 'r' dict for everything
self.configs = {} # Initialized the 'configs' dict
self.variant_iter = 0
self.setup() # Setup & define directories
# ----------------------------------------------------------------------------- #
def setup( self ):
'''
SETUP
- Locating and defining directories
- Gathering document information (did, wid, eid)
- Gathering document variables
- Generating the morphing array
- Gather template FEBio (or simulation file)
- Connect to onshape document
'''
print( "PROGRAM SETUP" )
print( "===========================================================" )
_setup.setup_directories( self ) # retrieve directory information
print( self.input_file )
_setup.generate_filenames( self, self.input_file )
_setup.read_doc( self, self.input_file ) # retrieve document information
_setup.read_vars( self, self.input_file ) # retrieve variable information
_setup.generate_variant_array( self )
_onshape.connect_to_sketch( self, args ) # connect to the onshape document
_onshape.get_list_of_parts( self )
# ----------------------------------------------------------------------------- #
def generate_variant( self ):
'''
GENERATE GEOMETRY VARIANT:
- Connects to onshape document
- Retrieves default configurations
- Updates configurations based on morphing array
- Exports geometric variant (.STL)
'''
_onshape.get_configurations( self )
_onshape.get_values( self )
_morph.simple_morph( self )
_onshape.export_stl( self )
#_vis.import_stl( self )
#_vis.read_stl( self )
#_vis.vis_stl( self, 0, 1, 1 )
# --------------------------------------------------------------------- # update variant_iter
self.variant_iter = self.variant_iter + 1
# ----------------------------------------------------------------------------- #
def mesh_variant( self ):
'''
MESH VARIANT
- Generates a mesh of the geometric variant
'''
_mesh.tetgen( self, 1 )
# ----------------------------------------------------------------------------- #
def sim_variant( self ):
'''
SIMULATE VARIANT
- Triggers the simulation of the geometric variant
'''
# ***************************************************************************
# =========================> MAKE IT ALL HAPPEN <============================
# ***************************************************************************
try:
prog = geovar()
print()
print()
print('[{:0.6f}] WARNING: This program will generate {} geometric variants (.STL)...'.format(_performance.current_time( prog ), prog.Nprods))
_setup.query_variants( '[{:0.6f}] Do you wish to continue?'.format(_performance.current_time( prog )), default="yes")
print()
print()
print( "PROGRAM STARTING " )
print( " ========================================================= " )
Nprods = prog.Nprods
for i in range( 0, Nprods ):
print('[{:0.6f}] GENERATING VARIANT {}/{}'.format(_performance.current_time( prog ), (i+1), Nprods ) )
# MODE 1: Geometric Variations ======================================== #
if prog.mode == 1:
prog.generate_variant()
# MODE 2: Meshing ==================================================== #
elif prog.mode == 2:
prog.generate_variant()
prog.mesh_variant()
# MODE 3: Simulation ================================================== #
elif prog.mode == 3:
print( "> MODE {} HAS NOT BEEN INTEGRATED...".format( prog.mode ) )
print( ">> Goodbye..." )
exit()
print( " --------------------------------------------------------- " )
except KeyboardInterrupt:
print('[{:0.6f}] PROGRAM TERMINATED...'.format(_performance.current_time( prog )))