99from .cal_layout import multi_aperture_pos
1010import sys
1111
12+ def yamltransform (pos ,rot ):
13+ return "transform: { translation: [%e,%e,%e], rotation: [%e,%e,%e] }" % (* pos ,* rot )
14+
1215class Sun :
1316 """Sun parameters for solstice-input
1417
@@ -22,8 +25,8 @@ def __init__(self,dni=1000,sunshape=None,csr=0.01,half_angle_deg=0.2664,std_dev=
2225
2326 `dni`: Direct normal irradance (W/m2)
2427 `sunshape`: Sunshape: can be None, ``'pillbox'``,``'gaussian'`` or ``'buie'``
25- `half_angle_deg`: sun angular size (in DEGREES, half-angle) (ONLY in case of ``'pillbox'``)
2628 `csr`: circumsolar ratio (ONLY in case of ``'buie'``)
29+ `half_angle_deg`: sun angular size (in DEGREES, half-angle) (ONLY in case of ``'pillbox'``)
2730 `std_dev`: standard deviation of the angular dsn ratio (ONLY in case of ``'gaussian'``)
2831 """
2932 self .dni = dni
@@ -117,9 +120,9 @@ def gen_yaml(sun, hst_pos, hst_foc, hst_aims,hst_w, hst_h
117120 # CREATE the spectrum for the sun
118121 iyaml += '- spectrum: &solar_spectrum \n '
119122 for i in range (0 ,len (I_sun )- 1 ):
120- iyaml += ' - {wavelength: %s , data: %s }\n ' % (I_sun [i ][0 ],I_sun [i ][1 ])
123+ iyaml += ' - {wavelength: %e , data: %e }\n ' % (I_sun [i ][0 ],I_sun [i ][1 ])
121124 i = len (I_sun )- 1
122- iyaml += ' - {wavelength: %s , data: %s }\n ' % (I_sun [i ][0 ],I_sun [i ][1 ])
125+ iyaml += ' - {wavelength: %e , data: %e }\n ' % (I_sun [i ][0 ],I_sun [i ][1 ])
123126 iyaml += '\n '
124127
125128 # CREATE the spectrum for the reflectivity (mirror)
@@ -154,7 +157,7 @@ def gen_yaml(sun, hst_pos, hst_foc, hst_aims,hst_w, hst_h
154157 iyaml += "- sun: %s\n " % (sun .yaml (spectrum ),)
155158
156159 if medium > 1e-99 :
157- iyaml += '- atmosphere: {extinction: %s }\n ' % medium
160+ iyaml += '- atmosphere: {extinction: %e }\n ' % medium
158161 iyaml += '\n '
159162
160163
@@ -166,41 +169,36 @@ def gen_yaml(sun, hst_pos, hst_foc, hst_aims,hst_w, hst_h
166169 #------------------------------
167170 #
168171 # CREATE an occultant material
169- r_f = 0. # front
170- r_b = 0. # and back reflectivity
171- iyaml += '- material: &%s\n ' % 'material_black'
172+ iyaml += '- material: &material_black\n '
172173 iyaml += ' front:\n '
173- iyaml += ' matte: {reflectivity: %6.4f }\n ' % r_f
174+ iyaml += ' matte: {reflectivity: 0. }\n ' # front
174175 iyaml += ' back:\n '
175- iyaml += ' matte: {reflectivity: %6.4f }\n ' % r_b
176+ iyaml += ' matte: {reflectivity: 0. }\n ' # and back reflectivity
176177 iyaml += '\n '
177178 #
178179 # CREATE a specular material
179- r_f = rho_refl # front
180- r_b = 0. # and back reflectivity
181- iyaml += '- material: &%s\n ' % 'material_mirror'
180+ iyaml += '- material: &material_mirror\n '
182181 iyaml += ' front:\n '
183182 if spectral :
184- iyaml += ' mirror: {reflectivity: *%s , slope_error: %15.8e }\n ' % ('ref_mirror' , slope_error )
183+ iyaml += ' mirror: {reflectivity: *ref_mirror , slope_error: %15.8e }\n ' % (slope_error )
185184 else :
186- iyaml += ' mirror: {reflectivity: %6.4f, slope_error: %15.8e }\n ' % (r_f , slope_error )
187-
185+ iyaml += ' mirror: {reflectivity: %6.4f, slope_error: %15.8e }\n ' % (rho_refl , slope_error )
188186 iyaml += ' back:\n '
189- iyaml += ' matte: {reflectivity: %6.4f }\n ' % r_b
187+ iyaml += ' matte: {reflectivity: 0. }\n '
190188 iyaml += '\n '
191189 #
192190 # CREATE a material for the target
193191 r_f = 1. - rec_abs # front
194192 r_b = 1. - rec_abs # and back reflectivity
195- iyaml += '- material: &%s \n ' % 'material_target '
193+ iyaml += '- material: &material_target \n '
196194 iyaml += ' front:\n '
197195 iyaml += ' matte: {reflectivity: %6.4f }\n ' % r_f
198196 iyaml += ' back:\n '
199197 iyaml += ' matte: {reflectivity: %6.4f }\n ' % r_b
200198 iyaml += '\n '
201199 #
202200 # CREATE a virtual material for the calculation of spillage
203- iyaml += '- material: &%s \n ' % 'material_virtual '
201+ iyaml += '- material: &material_virtual \n '
204202 iyaml += ' virtual:\n '
205203 iyaml += '\n '
206204
@@ -216,8 +214,8 @@ def gen_yaml(sun, hst_pos, hst_foc, hst_aims,hst_w, hst_h
216214 # (cylindrical shape)
217215 #
218216 slices = 10 # slices for the envelop circle
219- iyaml += '- geometry: &%s \n ' % 'tower_g '
220- iyaml += ' - material: *%s \n ' % 'material_black '
217+ iyaml += '- geometry: &tower_g \n '
218+ iyaml += ' - material: *material_black \n '
221219 #iyaml+=' transform: { translation: %s, rotation: %s }\n' % ([0, 0, h_tow*0.5], [0, 90, 0])
222220 iyaml += ' cylinder: {height: %7.3f, radius: %7.3f, slices: %d }\n ' % (tower_h , tower_r , slices )
223221 iyaml += '\n '
@@ -259,27 +257,27 @@ def gen_yaml(sun, hst_pos, hst_foc, hst_aims,hst_w, hst_h
259257 aim_z = hst_aims [:,2 ]
260258 num_hst = len (hst_x )
261259 slices = 4 # slices for the envelop circle
262- pts_hst = [ [ - hst_w * 0.5 , - hst_h * 0.5 ], [ - hst_w * 0.5 , hst_h * 0.5 ], [ hst_w * 0.5 , hst_h * 0.5 ], [ hst_w * 0.5 , - hst_h * 0.5 ] ]
260+
263261 # CREATE a reflective facet (mirror)
264262 for i in range (0 ,num_hst ):
265263 name_hst_g = 'hst_g_' + str (i )
266264 iyaml += '- geometry: &%s\n ' % name_hst_g
267- iyaml += ' - material: *%s \n ' % 'material_mirror '
265+ iyaml += ' - material: *material_mirror \n '
268266 #iyaml+=' transform: { translation: %s, rotation: %s }\n' % ([hst_x[i], hst_y[i], hst_z[i]], [0, 0, 0]) )
269267 iyaml += ' parabol: \n '
270268 iyaml += ' focal: %s\n ' % hst_foc [i ]
271269 iyaml += ' clip: \n '
272270 iyaml += ' - operation: AND \n '
273- iyaml += ' vertices: %s \n ' % pts_hst
271+ iyaml += ' vertices: [ [%e, %e], [%e, %e], [%e, %e], [%e, %e] ] \n ' % ( - hst_w * 0.5 , - hst_h * 0.5 , - hst_w * 0.5 , hst_h * 0.5 , hst_w * 0.5 , hst_h * 0.5 , hst_w * 0.5 , - hst_h * 0.5 )
274272 iyaml += ' slices: %d\n ' % slices
275273
276274 # CREATE the pylon "pylon_g" geometry cylindrical shape
277275 h_pyl = 0.001 # pylon height
278276 r_pyl = 0.2 # pylon radius
279277 slices = 4 # slices for the envelop circle
280- iyaml += '- geometry: &%s \n ' % 'pylon_g'
281- iyaml += ' - material: *%s \n ' % 'material_black '
282- iyaml += ' transform: { translation: %s, rotation: %s } \n ' % ( [0 , 0 , - h_pyl * 3 ], [0 , 90 , 0 ])
278+ iyaml += '- geometry: &pylon_g \n '
279+ iyaml += ' - material: *material_black \n '
280+ iyaml += ' ' + yamltransform ( pos = [0 ,0 , - h_pyl * 3 ],rot = [0 ,90 ,0 ]) + ' \n '
283281 iyaml += ' cylinder: {height: %7.3f, radius: %7.3f, slices: %d }\n ' % (h_pyl ,r_pyl ,slices )
284282 #
285283
@@ -298,7 +296,7 @@ def gen_yaml(sun, hst_pos, hst_foc, hst_aims,hst_w, hst_h
298296 iyaml += ' geometry: *pylon_g\n '
299297 iyaml += ' children: \n '
300298 iyaml += ' - name: pivot\n '
301- iyaml += ' zx_pivot: {target: {position: %s}} \n ' % ([ float ( aim_x [i ]), float ( aim_y [i ]), float ( aim_z [i ])])
299+ iyaml += ' zx_pivot: {target: {position: [%.6f, %.6f, %.6f]}} \n ' % (aim_x [i ], aim_y [i ], aim_z [i ])
302300 iyaml += ' children: \n '
303301 iyaml += ' - name: reflect_surface\n '
304302 iyaml += ' primary: 1\n '
@@ -319,7 +317,7 @@ def gen_yaml(sun, hst_pos, hst_foc, hst_aims,hst_w, hst_h
319317 iyaml += '\n - entity:\n '
320318 iyaml += ' name: tower_e\n '
321319 iyaml += ' primary: 0\n '
322- iyaml += ' transform: { translation: %s, rotation: %s } \n ' % ( [0 , - tower_r , tower_h * 0.5 ], [0 , 0 , 0 ])
320+ iyaml += ' ' + yamltransform ( pos = [0 ,- tower_r , tower_h * 0.5 ],rot = [0 ,0 , 0 ]) + ' \n '
323321 iyaml += ' geometry: *%s\n ' % 'tower_g'
324322 #
325323 # heliostat entities from the template
@@ -328,7 +326,7 @@ def gen_yaml(sun, hst_pos, hst_foc, hst_aims,hst_w, hst_h
328326 name_hst_t = 'hst_t_' + str (i )
329327 iyaml += '\n - entity:\n '
330328 iyaml += ' name: %s\n ' % name_e
331- iyaml += ' transform: { translation: %s, rotation: %s } \n ' % ([ float ( hst_x [i ]), float ( hst_y [i ]), float ( hst_z [i ])], [0 , 0 , 0 ])
329+ iyaml += ' ' + yamltransform ( pos = [ hst_x [i ], hst_y [i ], hst_z [i ]], rot = [0 ,0 , 0 ]) + ' \n '
332330 iyaml += ' children: [ *%s ]\n ' % name_hst_t
333331
334332 with open (outfile_yaml ,'w' ) as f :
@@ -361,14 +359,13 @@ def flat_receiver(rec_param, hemisphere='North'):
361359 # rotation anagle, positive is anti-clockwise
362360
363361 geom = ''
364- pts = [ [- rec_w * 0.5 , - rec_h * 0.5 ], [- rec_w * 0.5 , rec_h * 0.5 ], [rec_w * 0.5 , rec_h * 0.5 ], [rec_w * 0.5 ,- rec_h * 0.5 ] ]
365362
366- geom += '- geometry: &%s \n ' % 'target_g '
367- geom += ' - material: *%s \n ' % 'material_target '
363+ geom += '- geometry: &target_g \n '
364+ geom += ' - material: *material_target \n '
368365 geom += ' plane: \n '
369366 geom += ' clip: \n '
370367 geom += ' - operation: AND \n '
371- geom += ' vertices: %s \n ' % pts
368+ geom += ' vertices: [ [%e, %e], [%e, %e], [%e, %e], [%e, %e] ] \n ' % ( - rec_w * 0.5 , - rec_h * 0.5 , - rec_w * 0.5 , rec_h * 0.5 , rec_w * 0.5 , rec_h * 0.5 , rec_w * 0.5 , - rec_h * 0.5 )
372369 geom += ' slices: %d\n ' % slices
373370 geom += '\n '
374371
@@ -378,27 +375,27 @@ def flat_receiver(rec_param, hemisphere='North'):
378375 entt += ' name: target_e\n '
379376 entt += ' primary: 0\n '
380377 if hemisphere == 'North' :
381- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [x , y , z ], [- 90. - tilt , 0 , 0 ])
378+ entt += ' ' + yamltransform ( pos = [x , y , z ],rot = [- 90. - tilt , 0 , 0 ]) + ' \n '
382379 else :
383- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [x , y , z ], [90. + tilt , 0 , 0 ])
380+ entt += ' ' + yamltransform ( pos = [x , y , z ],rot = [90. + tilt , 0 , 0 ]) + ' \n '
384381 entt += ' geometry: *%s\n ' % 'target_g'
385382
386383 # CREATE a virtual target entity from "target_g" geometry (primary = 0)
387- pts = [ [ - rec_w * 10. , - rec_h * 10. ], [ - rec_w * 10. , rec_h * 10. ], [ rec_w * 10. , rec_h * 10. ], [ rec_w * 10. , - rec_h * 10. ] ]
384+
388385 slices = 4
389386 entt += '\n - entity:\n '
390387 entt += ' name: virtual_target_e\n '
391388 entt += ' primary: 0\n '
392389 if hemisphere == 'North' :
393- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [x , y - 5. , z ], [- 90. - tilt , 0 , 0 ])
390+ entt += ' ' + yamltransform ( pos = [x , y - 5 , z ],rot = [- 90. - tilt , 0 , 0 ]) + ' \n '
394391 else :
395- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [x , y + 5. , z ], [90. + tilt , 0 , 0 ])
392+ entt += ' ' + yamltransform ( pos = [x , y + 5 , z ],rot = [90. + tilt , 0 , 0 ]) + ' \n '
396393 entt += ' geometry: \n '
397394 entt += ' - material: *%s\n ' % 'material_virtual'
398395 entt += ' plane: \n '
399396 entt += ' clip: \n '
400397 entt += ' - operation: AND \n '
401- entt += ' vertices: %s \n ' % pts
398+ entt += ' vertices: [ [%e, %e], [%e, %e], [%e, %e], [%e, %e] ] \n ' % ( - rec_w * 10. , - rec_h * 10. , - rec_w * 10. , rec_h * 10. , rec_w * 10. , rec_h * 10. , rec_w * 10. , - rec_h * 10. )
402399 entt += ' slices: %d\n ' % slices
403400
404401 rcv = ''
@@ -446,27 +443,23 @@ def cylindrical_receiver(rec_param, hemisphere='North'):
446443 entt += '\n - entity:\n '
447444 entt += ' name: target_e\n '
448445 entt += ' primary: 0\n '
449-
450- entt += ' transform: { translation: %s, rotation: %s }\n ' % ([x , y , z ], [0. , 0. , 0. ])
451-
446+ entt += ' ' + yamltransform (pos = [x , y , z ],rot = [0 , 0 , 0 ]) + '\n '
452447 entt += ' geometry: *%s\n ' % 'target_g'
453448
454449 # CREATE a virtual target entity from "target_g" geometry (primary = 0)
455450 Vsize = 100.
456- pts = [ [ - rec_h * Vsize , - rec_h * Vsize ], [ - rec_h * Vsize , rec_h * Vsize ], [ rec_h * Vsize , rec_h * Vsize ], [ rec_h * Vsize , - rec_h * Vsize ] ]
451+
457452 slices = 4
458453 entt += '\n - entity:\n '
459454 entt += ' name: virtual_target_e\n '
460455 entt += ' primary: 0\n '
461-
462- entt += ' transform: { translation: %s, rotation: %s }\n ' % ([x , y , z + rec_h / 2. + 1 ], [- 180. , 0 , 0 ])
463-
456+ entt += ' ' + yamltransform (pos = [x , y , z + rec_h / 2. + 1 ],rot = [- 180. , 0 , 0 ]) + '\n '
464457 entt += ' geometry: \n '
465458 entt += ' - material: *%s\n ' % 'material_virtual'
466459 entt += ' plane: \n '
467460 entt += ' clip: \n '
468461 entt += ' - operation: AND \n '
469- entt += ' vertices: %s \n ' % pts
462+ entt += ' vertices: [ [%e, %e], [%e, %e], [%e, %e], [%e, %e] ] \n ' % ( - rec_h * Vsize , - rec_h * Vsize , - rec_h * Vsize , rec_h * Vsize , rec_h * Vsize , rec_h * Vsize , rec_h * Vsize , - rec_h * Vsize )
470463 entt += ' slices: %d\n ' % slices
471464
472465 rcv = ''
@@ -506,33 +499,32 @@ def STL_receiver(rec_param, hemisphere='North'):
506499 entt += ' name: STL_receiver_e\n '
507500 entt += ' primary: 0\n '
508501 if hemisphere == 'North' :
509-
510- entt += ' transform: { translation: %s, rotation: %s }\n ' % ([x , y , z ], [- 90. - tilt , 0 , 0 ])
502+ entt += ' ' + yamltransform (pos = [x , y , z ],rot = [- 90. - tilt , 0 , 0 ]) + '\n '
511503 else :
512504 # if it is the mesh model of the bladed receiver at CSIRO
513- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [x , y , z ], [180. + tilt , 0 , 0 ])
505+ entt += ' ' + yamltransform ( pos = [x , y , z ],rot = [180. + tilt , 0 , 0 ]) + ' \n '
514506 entt += ' geometry:\n '
515507 entt += ' - material: *material_target\n '
516- entt += ' transform: {translation: [0, 0, 0], rotation: [0, 0, 0]} \n '
508+ entt += ' ' + yamltransform ( pos = [0 ,0 , 0 ],rot = [0 , 0 , 0 ]) + ' \n '
517509 entt += " stl : {path: %s } \n " % (stlfile )
518510
519511
520512 # CREATE a virtual target entity from "target_g" geometry (primary = 0)
521- pts = [ [ - rec_w * 10. , - rec_h * 10. ], [ - rec_w * 10. , rec_h * 10. ], [ rec_w * 10. , rec_h * 10. ], [ rec_w * 10. , - rec_h * 10. ] ]
513+
522514 slices = 4
523515 entt += '\n - entity:\n '
524516 entt += ' name: virtual_target_e\n '
525517 entt += ' primary: 0\n '
526518 if hemisphere == 'North' :
527- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [x , y - 5. , z ], [- 90. - tilt , 0 , 0 ])
519+ entt += ' ' + yamltransform ( pos = [x , y - 5. , z ],rot = [- 90. - tilt , 0 , 0 ]) + ' \n '
528520 else :
529- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [x , y + 5. , z ], [90. + tilt , 0 , 0 ])
521+ entt += ' ' + yamltransform ( pos = [x , y + 5. , z ],rot = [90. + tilt , 0 , 0 ]) + ' \n '
530522 entt += ' geometry: \n '
531523 entt += ' - material: *%s\n ' % 'material_virtual'
532524 entt += ' plane: \n '
533525 entt += ' clip: \n '
534526 entt += ' - operation: AND \n '
535- entt += ' vertices: %s \n ' % pts
527+ entt += ' vertices: [ [%e, %e], [%e, %e], [%e, %e], [%e, %e] ] \n ' % ( - rec_w * 10. , - rec_h * 10. , - rec_w * 10. , rec_h * 10. , rec_w * 10. , rec_h * 10. , rec_w * 10. , - rec_h * 10. )
536528 entt += ' slices: %d\n ' % slices
537529
538530 rcv = ''
@@ -583,14 +575,12 @@ def multi_aperture_receiver(rec_param, hemisphere='North', plot=False):
583575 vir_z = 0.
584576 for i in range (num_aperture ):
585577
586- pts = [ [- rec_w [i ]* 0.5 , - rec_h [i ]* 0.5 ], [- rec_w [i ]* 0.5 , rec_h [i ]* 0.5 ], [rec_w [i ]* 0.5 , rec_h [i ]* 0.5 ], [rec_w [i ]* 0.5 ,- rec_h [i ]* 0.5 ] ]
587-
588578 geom += '- geometry: &%s\n ' % 'target_g_%.0f\n ' % (i )
589579 geom += ' - material: *%s\n ' % 'material_target'
590580 geom += ' plane: \n '
591581 geom += ' clip: \n '
592582 geom += ' - operation: AND \n '
593- geom += ' vertices: %s \n ' % pts
583+ geom += ' vertices: [ [%e, %e], [%e, %e], [%e, %e], [%e, %e] ] \n ' % ( - rec_w [ i ] * 0.5 , - rec_h [ i ] * 0.5 , - rec_w [ i ] * 0.5 , rec_h [ i ] * 0.5 , rec_w [ i ] * 0.5 , rec_h [ i ] * 0.5 , rec_w [ i ] * 0.5 , - rec_h [ i ] * 0.5 )
594584 geom += ' slices: %d\n ' % rec_grid_w
595585 geom += '\n '
596586
@@ -605,9 +595,9 @@ def multi_aperture_receiver(rec_param, hemisphere='North', plot=False):
605595 entt += ' name: target_e_%.0f\n ' % (i )
606596 entt += ' primary: 0\n '
607597 if hemisphere == 'North' :
608- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [xc , yc , zc ], [- 90. - rec_tilt , 90. - ang_pos ,0 ])
598+ entt += ' ' + yamltransform ( pos = [xc , yc , zc ],rot = [- 90. - rec_tilt , 90. - ang_pos ,0 ]) + ' \n '
609599 else :
610- entt += ' transform: { translation: %s, rotation: %s } \n ' % ( [- xc , - yc , zc ], [90. + rec_tilt , 90. - ang_pos ,0 ])
600+ entt += ' ' + yamltransform ( pos = [- xc , - yc , zc ],rot = [90. + rec_tilt , 90. - ang_pos ,0 ]) + ' \n '
611601 entt += ' geometry: *%s\n ' % 'target_g_%.0f\n ' % (i )
612602
613603 vir_z /= float (num_aperture )
@@ -637,6 +627,3 @@ def multi_aperture_receiver(rec_param, hemisphere='North', plot=False):
637627 return geom , entt , rcv
638628
639629
640-
641- #------------------------------
642-
0 commit comments