-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathatmosphere_comp.py
More file actions
54 lines (31 loc) · 1.18 KB
/
atmosphere_comp.py
File metadata and controls
54 lines (31 loc) · 1.18 KB
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
import numpy as np
import matplotlib.pyplot as plt
from openmdao.api import ExplicitComponent, Problem
class Atmosphere(ExplicitComponent):
def initialize(self):
self.options.declare("num_nodes", types=int)
def setup(self):
nn = self.options["num_nodes"]
self.add_input("h", val=np.ones(nn), desc="altitude", units="ft")
self.add_output("rho", val=np.ones(nn), desc="local density", units="slug/ft**3")
partial_range = np.arange(nn, dtype=int)
self.declare_partials("rho", "h", rows=partial_range, cols=partial_range)
def compute(self, inputs, outputs):
h = inputs["h"]
h_r = 23800
rho_0 = .002378
outputs["rho"] = rho_0*np.exp(-h/h_r)
def compute_partials(self, inputs, J):
h = inputs["h"]
h_r = 23800
rho_0 = .002378
J["rho", "h"] = -1/(h_r)*rho_0*np.exp(-h/h_r)
def test_atmosphere():
prob = Problem()
prob.model = Atmosphere(num_nodes=5)
prob.setup(check=False, force_alloc_complex=True)
prob.run_model()
return(prob)
if __name__ == "__main__":
prob = test_atmosphere()
prob.check_partials(compact_print=True, method="cs")