File: surrogate.py

package info (click to toggle)
mystic 0.4.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,656 kB
  • sloc: python: 40,894; makefile: 33; sh: 9
file content (101 lines) | stat: -rw-r--r-- 2,244 bytes parent folder | download
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
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2009-2016 California Institute of Technology.
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/mystic/blob/master/LICENSE

"""Original matlab code:

function A=marc_surr(x)
h=x(1)*25.4*10^(-3);
a=x(2)*pi/180;
v=x(3);
Ho=0.5794;
s=1.4004;
n=0.4482;
K=10.3963;
p=0.4757;
u=1.0275;
m=0.4682;
Dp=1.778;

v_bl=Ho*(h/(cos(a))^(n))^s;

if v<v_bl
  A=0
else
  A=K*((h/Dp)^p)*((cos(a))^u)*(tanh((v/v_bl)-1))^m;
end
"""

### NOTES ###
# h = thickness = [60,105]
# a = obliquity = [0,30]
# v = speed = [2.1,2.8]

# explore the cuboid (h,a,v), with
# subdivisions at h=100, a=20, v=2.2
# due to ballistic limit: v(h=100,a=20) = 2.22,
# perforation in this region should be zero.
# NOTE: 'failure' is A < = t
# 
# Calculate for each of the 8 subcuboids:
#  * probability mass, i.e. the product of the normalized side-lengths,
#    since we're taking h, a and v to be uniformly distributed in their
#    intervals
#  * McDiarmid diameter of the perforation area A when restricted to that
#    cuboid or subcuboid
#  * the mean value of the perforation area A on each (sub)cuboid

from math import pi, cos, tanh

def ballistic_limit(h,a):
  """calculate ballistic limit

  Inputs:
    - h = thickness in (unknown) units
    - a = obliquity in (unknown) units

  Outputs:
    - v_bl = velocity (ballistic limit) in (unknown) units
"""
 #h = x[0] * 25.4 * 1e-3
 #a = x[1] * pi/180.0
  Ho = 0.5794
  s = 1.4004
  n = 0.4482
  return Ho * ( h / cos(a)**n )**s


def marc_surr(x):
  """calculate perforation area using a tanh-based model surrogate

  Inputs:
    - x = [thickness, obliquity, speed] in (unknown) units

  Outputs:
    - A = performation area in (unknown) units
"""
# h = thickness = [60,105]
# a = obliquity = [0,30]
# v = speed = [2.1,2.8]
  h = x[0] * 25.4 * 1e-3
  a = x[1] * pi/180.0
  v = x[2]

  K = 10.3963
  p = 0.4757
  u = 1.0275
  m = 0.4682
  Dp = 1.778

  # compare to ballistic limit
  v_bl = ballistic_limit(h,a)
  if v < v_bl:
    return 0

  return K * (h/Dp)**p * (cos(a))**u * (tanh((v/v_bl)-1))**m

# EOF