forked from h1he2li3/ZeroCarbonPlane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FCSysProperties.py
58 lines (45 loc) · 1.86 KB
/
FCSysProperties.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
import math
import openmdao.api as om
import numpy as np
class FCSysPropertiesComp(om.ExplicitComponent):
"""
Fuel cell system mass model that calculates the mass of the fuel cell
system based on the number of fuel cell system modules and the mass of a single
fuel cell system module.
Inputs
------
mass_per_fcsysmodule : float
Mass of a single fuel cell system module (vector, kg).
n_fcsysmodules : float
Number of fuel cell system modules required (vector, dimensionless).
Outputs
-------
mass_fcsys : float
Mass of fuel cell system (vector, kg).
Options
-------
num_nodes : int
Number of analysis points to run (scalar, dimensionless).
"""
def initialize(self):
self.options.declare('num_nodes', types=int)
def setup(self):
nn = self.options['num_nodes']
# Inputs
self.add_input('mass_per_fcsysmodule', val=400000.0*np.ones(nn))#, units='kg'
self.add_input('n_fcsysmodules', val=1.0*np.ones(nn))#, units=None
# Outputs
self.add_output('mass_fcsys', val=1.0*np.ones(nn))#, units='kg'
# Partials
ar = np.arange(nn)
self.declare_partials(of='mass_fcsys', wrt='mass_per_fcsysmodule', rows=ar, cols=ar)
self.declare_partials(of='mass_fcsys', wrt='n_fcsysmodules', rows=ar, cols=ar)
def compute(self, inputs, outputs):
mass_per_fcsysmodule = inputs['mass_per_fcsysmodule']
n_fcsysmodules = inputs['n_fcsysmodules']
outputs['mass_fcsys'] = mass_per_fcsysmodule * n_fcsysmodules
def compute_partials(self, inputs, partials):
mass_per_fcsysmodule = inputs['mass_per_fcsysmodule']
n_fcsysmodules = inputs['n_fcsysmodules']
partials['mass_fcsys', 'mass_per_fcsysmodule'] = n_fcsysmodules
partials['mass_fcsys', 'n_fcsysmodules'] = mass_per_fcsysmodule