forked from polyspectra/workingcurve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
230 lines (164 loc) · 8.13 KB
/
app.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
218
219
220
221
222
223
224
225
226
227
228
229
230
import dash
import numpy as np
import pandas as pd
import dash_core_components as dcc
from dash.dependencies import Input, Output
import dash_html_components as html
import plotly.graph_objs as go
import os
app = dash.Dash(__name__)
server = app.server
server.secret_key = os.environ.get('SECRET_KEY', 'my-secret-key')
app.layout = html.Div([
dcc.Markdown('''
# Stereolithography Print Settings Utility:
#### Built with love by [polySpectra](http://polyspectra.com). Fork on [GitHub](https://github.com/polyspectra/workingcurve).
'''),
dcc.Markdown('''
## Photopolymer Working Curve:
'''),
html.Div('Penetration Depth (microns):'),
dcc.Input(id='dp', value='120', type="number"),
html.Div('Critical Exposure (mJ / cm^2):'),
dcc.Input(id='ec', value='25', type="number"),
html.Div(id='my-div'),
dcc.Graph(
style={'height': 300},
id='my-graph'
),
dcc.Markdown('''
## Solve the Exposure for a Specific Cure Depth:
'''),
html.Div('Cure Depth (microns):'),
dcc.Input(id='cd', value='1', type="number"),
html.Div(id='expSolve', children='''Set exposure to: n/a'''),
dcc.Markdown('''
## Helpful Metrics for Specific Print Settings:
'''),
html.Div('Exposure (mJ / cm^2):'),
dcc.Input(id='exp', value='0', type="number"),
html.Div('Slice Thickness (microns):'),
dcc.Input(id='dz', value='100', type="number"),
html.Div('"Maximum" Volumetric / Multilayer Exposure:'),
html.Div(id='vol', children=''',
n/a
'''),
html.Div('"Maximum" Print Through Exposure & Additional Cure Depth:'),
html.Div(id='thru_exp', children='''
n/a
'''),
dcc.Markdown('''
## Explanation:
This is a utility to facilitate stereolithographic 3D printing (SLA / DLP).
**Penetration Depth:** The 'effective' absorption length (Naperian (natural) log)
**Critical Exposure:** The minimum exposure to cure an infinitesimally small film
**Cure Depth:** The thickness of the cured layer at a given exposure
**Exposure:** The energy density of the light at the window / resin surface (power density * time)
**Slice Thickness:** The z step size of the printer, aka layer thickness
**"Maximum" Volumetric / Multilayer Exposure:** This is the total exposure a 'bottom' layer would receive after subsequently printing _many_ layers on top of it. This is an attempt to quantify the maximum amount of light received by the layer when there is bleed through.
**"Maximum" Print Through Exposure & Additional Cure Depth:** This is the 'extra' exposure an empty layer would receive after subsequently printing _many_ layers on top of it. This is an attempt to quantify the worse case scenario for "print through", the effect that printed layers are often thicker than the desired layer thickness / cure depth, because light from subsequent layers bleeds through. Both the extra "print-through" exposure and corresponding "print-through" cure depth are calculated. The bigger this number, the larger the error on the dimensional accuracy of 'overhung' features.
## Assumptions:
This utility only accounts for Beer's Law absorption, which means that there is no scattering accounted for in the optics. It also assumes that the critical exposure and penetration depth of the photopolymer do not change throughout the print process. The "maximum" print through assumes that 1000 layers 'on top' is enough to account for the excess light from subsequently printed layers. It also assumes that there is still liquid resin around to be polymerized (ie - the resin bath level is very high).
## References:
* P.F. Jacobs - [Rapid Prototyping & Manufacturing: Fundamentals of Stereolithography](https://www.amazon.com/Rapid-Prototyping-Manufacturing-Fundamentals-StereoLithography/dp/0872634256/ref=as_li_ss_tl?ie=UTF8&qid=1504746907&sr=8-1&keywords=fundamentals+of+stereolithography&linkCode=ll1&tag=rawwerks09-20&linkId=06bf9e70b23b749cc52c5dda61d326b1)
'''),
])
#this callback updates the working curve graph
@app.callback(Output(component_id='my-graph', component_property='figure'),
[Input(component_id='dp', component_property='value'),
Input(component_id='ec', component_property='value')
])
def update_wc(dp,ec):
traces = working_curve(dp,ec)
return {
'data': traces,
'layout': go.Layout(
title='Working Curve',
xaxis=dict( # all "layout's" "xaxis" attributes: /python/reference/#layout-xaxis
title="mJ / cm^2" # more about "layout's" "xaxis's" "title": /python/reference/#layout-xaxis-title
),
yaxis=dict( # all "layout's" "xaxis" attributes: /python/reference/#layout-xaxis
title="microns" # more about "layout's" "xaxis's" "title": /python/reference/#layout-xaxis-title
),
showlegend=False,
margin=go.Margin(l=50, r=50, t=40, b=40),
annotations=[
# dict( # all "annotation" attributes: /python/reference/#layout-annotations
# text="simple annotation",
# )
]
)
}
def working_curve(dp,ec):
#number of data points
N = 1000
#exposure array from 0.5ec to 10ec
expo = np.linspace(0.5 * float(ec), 10 * float(ec), N)
#calculate the cure depth
cd = float(dp)*np.log(expo / float(ec))
#build the xy matrix for plotting
traces = []
traces.append(go.Scatter(x = expo,y = cd, mode='lines'))
return traces
#this callback updates the exposure
@app.callback(Output(component_id='expSolve', component_property='children'),
[Input(component_id='dp', component_property='value'),
Input(component_id='ec', component_property='value'),
Input(component_id='cd', component_property='value')
])
def exposure(dp,ec,cd):
if(float(cd) > 0 and float(dp)>0):
exp = np.exp(float(cd) / float(dp)) * float(ec)
return '''Set exposure to: ''' + str(exp)
else:
return '''Set exposure to: n/a'''
#this callback updates the cure depth
@app.callback(Output(component_id='cd', component_property='value'),
[Input(component_id='dp', component_property='value'),
Input(component_id='ec', component_property='value'),
Input(component_id='exp', component_property='value')
])
def cd_update(dp,ec,exp):
if(float(exp)>0 and float(ec)>0):
cd = cure_depth(dp,ec,exp)
if(cd > 0):
return str(cd)
else:
return None
else:
return None
def cure_depth(_dp,_ec,_exp):
_cd = float(_dp)*np.log(float(_exp) / float(_ec))
return _cd
#this callback updates the volumetric exposure
@app.callback(Output(component_id='vol', component_property='children'),
[Input(component_id='dp', component_property='value'),
Input(component_id='ec', component_property='value'),
Input(component_id='exp', component_property='value'),
Input(component_id='dz', component_property='value'),
])
def volumetric_exp(dp,ec,exp,dz):
limit = 1000
add = 0
for i in range(0,limit):
add = add + (float(exp) * np.exp(-(float(dz)*i) / float(dp)))
return str(int(add)) + ''' mJ / cm^2 volumetric exposure'''
#this callback updates the print through exposure
@app.callback(Output(component_id='thru_exp', component_property='children'),
[Input(component_id='dp', component_property='value'),
Input(component_id='ec', component_property='value'),
Input(component_id='exp', component_property='value'),
Input(component_id='dz', component_property='value'),
])
def thru_exp(dp,ec,exp,dz):
limit = 1000
add = 0
for i in range(1,limit):
add = add + (float(exp) * np.exp(-(float(dz)*i) / float(dp)))
thru = cure_depth(dp,ec,add)
if(thru < 0.00):
thru = 0
return str(int(add)) + ''' mJ / cm^2 "print through" exposure and
''' + str(int(thru)) + ''' microns "print through" cure depth '''
if __name__ == '__main__':
app.run_server()