| 1 | #!/usr/bin/env python |
|---|
| 2 | # |
|---|
| 3 | # Author: Mike McKerns (mmckerns @caltech and @uqfoundation) |
|---|
| 4 | # Copyright (c) 2012-2016 California Institute of Technology. |
|---|
| 5 | # License: 3-clause BSD. The full license text is available at: |
|---|
| 6 | # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE |
|---|
| 7 | |
|---|
| 8 | from math import pi, cos, tanh |
|---|
| 9 | |
|---|
| 10 | def ballistic_limit(h,a): |
|---|
| 11 | """calculate ballistic limit |
|---|
| 12 | |
|---|
| 13 | Inputs: |
|---|
| 14 | - h = thickness in (unknown) units |
|---|
| 15 | - a = obliquity in (unknown) units |
|---|
| 16 | |
|---|
| 17 | Outputs: |
|---|
| 18 | - v_bl = velocity (ballistic limit) in (unknown) units |
|---|
| 19 | """ |
|---|
| 20 | #h = x[0] * 25.4 * 1e-3 |
|---|
| 21 | #a = x[1] * pi/180.0 |
|---|
| 22 | Ho = 0.5794 |
|---|
| 23 | s = 1.4004 |
|---|
| 24 | n = 0.4482 |
|---|
| 25 | return Ho * ( h / cos(a)**n )**s |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | from klepto.safe import inf_cache as memoized |
|---|
| 29 | #from klepto import inf_cache as memoized |
|---|
| 30 | from klepto.archives import cache, file_archive |
|---|
| 31 | from klepto.keymaps import picklemap, stringmap, hashmap |
|---|
| 32 | dumps = picklemap(flat=False) |
|---|
| 33 | encode = stringmap(flat=False) |
|---|
| 34 | hashed = hashmap(flat=False) |
|---|
| 35 | cache = cache(archive=file_archive('surrogate.pkl')) |
|---|
| 36 | #@memoized(keymap=dumps, tol=0, deep=True) # slower, but more robust |
|---|
| 37 | #@memoized(keymap=encode, tol=0, deep=True) |
|---|
| 38 | #@memoized(cache=cache, keymap=dumps) # slower, but more robust |
|---|
| 39 | #@memoized(cache=cache, keymap=hashed) # fails to cache (unhashable) |
|---|
| 40 | @memoized(cache=cache, keymap=encode) |
|---|
| 41 | def marc_surr(x): |
|---|
| 42 | """calculate perforation area using a tanh-based model surrogate |
|---|
| 43 | |
|---|
| 44 | Inputs: |
|---|
| 45 | - x = [thickness, obliquity, speed] in (unknown) units |
|---|
| 46 | |
|---|
| 47 | Outputs: |
|---|
| 48 | - A = performation area in (unknown) units |
|---|
| 49 | """ |
|---|
| 50 | # h = thickness = [60,105] |
|---|
| 51 | # a = obliquity = [0,30] |
|---|
| 52 | # v = speed = [2.1,2.8] |
|---|
| 53 | h = x[0] * 25.4 * 1e-3 |
|---|
| 54 | a = x[1] * pi/180.0 |
|---|
| 55 | v = x[2] |
|---|
| 56 | |
|---|
| 57 | K = 10.3963 |
|---|
| 58 | p = 0.4757 |
|---|
| 59 | u = 1.0275 |
|---|
| 60 | m = 0.4682 |
|---|
| 61 | Dp = 1.778 |
|---|
| 62 | |
|---|
| 63 | # compare to ballistic limit |
|---|
| 64 | v_bl = ballistic_limit(h,a) |
|---|
| 65 | if v < v_bl: |
|---|
| 66 | return 0 |
|---|
| 67 | |
|---|
| 68 | return K * (h/Dp)**p * (cos(a))**u * (tanh((v/v_bl)-1))**m |
|---|
| 69 | |
|---|
| 70 | # EOF |
|---|