Skip to content

Commit 00e5f12

Browse files
committed
Started function to convert units of vessel capability specs - not working yet
1 parent 5d49360 commit 00e5f12

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

famodel/irma/irma.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,46 @@ def loadYAMLtoDict(info, already_dict=False):
8787
#def applyState():
8888

8989

90-
90+
def unifyUnits(d):
91+
'''Converts any capability specification/metric in supported non-SI units
92+
to be in SI units. Converts the key names as well.'''
93+
94+
# >>> not working yet <<<
95+
96+
97+
# load conversion data from YAML (eventually may want to store this in a class)
98+
with open('spec_conversions.yaml') as file:
99+
data = yaml.load(file, Loader=yaml.FullLoader)
100+
101+
keys1 = []
102+
facts = [] # conversion factors
103+
keys2 = []
104+
105+
for line in data:
106+
keys1.append(line[0])
107+
facts.append(line[1])
108+
keys2.append(line[2])
109+
110+
# >>> dcopy = deepcopy(d)
111+
112+
for asset in d.values(): # loop through each asset's dict
113+
for capability in asset['capabilities'].values():
114+
for key, val in capability.items(): # look at each capability metric
115+
try:
116+
i = keys1.index(key) # find if key is on the list to convert
117+
118+
119+
if keys2[i] in capability.keys():
120+
raise Exception(f"Specification '{keys2[i]}' already exists")
121+
122+
capability[keys2[i]] = val * facts[i] # create a new SI entry
123+
124+
breakpoint()
125+
126+
del capability[keys1[i]] # remove the original?
127+
128+
except:
129+
print('not found')
91130

92131

93132
class Scenario():
@@ -105,6 +144,7 @@ def __init__(self):
105144
vessels = loadYAMLtoDict('vessels.yaml', already_dict=True)
106145
objects = loadYAMLtoDict('objects.yaml', already_dict=True)
107146

147+
#unifyUnits(vessels) # (function doesn't work yet!) <<<
108148

109149
# ----- Validate internal cross references -----
110150

famodel/irma/spec_conversions.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file specifies optional capability specification keys that can be used
2+
# to support inputs in common industry units rather than SI units.
3+
4+
# format: key name with common unit, conversation factor from common->SI, fundamental key name (SI unit),
5+
- [ area_sqf , 0.092903 , area ]
6+
- [ max_load_t , 9806.7 , max_load ]
7+
- [ volume_cf , 0.028317 , volume ]
8+
- [ max_line_pull_t , 9806.7 , max_line_pull ] # continuous line pull [t]
9+
- [ brake_load_t , 9806.7 , brake_load ] # static brake holding load [t]
10+
- [ speed_mpm , 0.01667 , speed ] # payout/haul speed [m/min] -> m/s
11+
- [ max_force_t , 9806.7 , max_force ] # bollard pull [t]
12+
- [ capacity_t , 9806.7 , capacity ] # SWL at specified radius [t]
13+
- [ hook_height_ft , 0.3048 , hook_height ] # max hook height [m]
14+
- [ towing_pin_rating_t , 9806.7 , towing_pin_rating ] # rating of towing pins [t] (optional)
15+
- [ power_kW , 1000.0 , power ] # W
16+
- [ pressure_bar , 1e5 , pressure ] # Pa
17+
- [ weight_t , 9806.7 , weight ] # N or should this be mass in kg?
18+
- [ centrifugal_force_kN, 1000.0 , centrifugal_force ]
19+
- [ torque_kNm , 1000.0 , torque ]

0 commit comments

Comments
 (0)