Skip to content

Commit 2fc1b8c

Browse files
committed
Copy FADesign/fadesign/installation to FAModel/famodel
1 parent 3b00198 commit 2fc1b8c

33 files changed

+397458
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
This example unloads a project class from a conceptDesign class.
3+
"""
4+
import matplotlib.pyplot as plt
5+
import os
6+
from fadesign.conceptual.conceptDesign import ConceptDesign
7+
from fadesign.conceptual import metrics as metr
8+
import numpy as np
9+
from famodel.project import Project
10+
import pandas as pd
11+
12+
plt.rcParams['font.family'] = 'serif'
13+
plt.rcParams['font.serif'] = ['Times New Roman']
14+
15+
# CONCEPT CATEGORY & NAME
16+
# LIST OF CONCEPTS for installation (keep it updated)
17+
18+
# category | conceptName
19+
# ILIA | 3_ILIA_1P2C_grd_mini (caseI for installation)
20+
21+
category = "ILIA"
22+
conceptName = "3_ILIA_1P2C_grd_mini"
23+
24+
# FILE LOCATIONS
25+
filePath = os.path.dirname(os.path.abspath(__file__))
26+
inputFile = os.path.join(filePath, category, f"{conceptName}.yaml")
27+
28+
concept = ConceptDesign(baseDir=filePath, filename=inputFile, plot=False)
29+
concept.design(plot=False)
30+
31+
# unload to yaml
32+
outputFilename = f"proj_{conceptName}.yaml"
33+
outputFile = os.path.join(filePath, category, outputFilename)
34+
print(f"Unloading project to {outputFilename}")
35+
concept.project.unload(file=outputFile)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
This example loads a project class and conducts some analysis and performance metrics.
3+
4+
NOTE: If the project yaml file does not exist, please run 01_unload_driver.py before this
5+
so you have a project that you can load here in this example. The project yaml file generated
6+
by the unload driver is named proj_{<concept name>}. Insert that in the inputFile in this script.
7+
"""
8+
9+
import matplotlib.pyplot as plt
10+
import os
11+
from fadesign.conceptual.conceptDesign import ConceptDesign
12+
import numpy as np
13+
from famodel.project import Project
14+
from fadesign.conceptual import metrics as mtr
15+
16+
# CONCEPT CATEGORY & NAME
17+
category = "ILIA" # ILIA | ILSA | SLIA | SLSA | hybrid
18+
conceptName = "3_ILIA_1P2C_grd_mini"
19+
20+
# FILE LOCATIONS
21+
filePath = os.path.dirname(os.path.abspath(__file__))
22+
inputFile = os.path.join(filePath, category, f"proj_{conceptName}.yaml")
23+
mtricFile = os.path.join(filePath, category, f"{conceptName}_mtr.xlsx")
24+
windFile = os.path.join(filePath, "sites/wind_data/humboldt_rose_1.csv")
25+
currentFile = os.path.join(filePath, "sites/surface_currents/HumboldtBay_currentRose.csv")
26+
27+
# Load project
28+
proj = Project(file=inputFile)
29+
model = proj.array
30+
model.mooring_currentMod = 0
31+
model.ms.moorMod = 0
32+
proj.trimGrids()
33+
34+
proj.plot3d(draw_boundary=True, boundary_on_bath=True, draw_bathymetry=True)
35+
plt.show()
36+
# Compute metrics
37+
proj = mtr.metrics(proj, mtricFile, windFile=windFile, currentFile=currentFile)
38+
39+
# Plots
40+
proj.plot3d(fowt=True, draw_boundary=False, boundary_on_bath=False, draw_bathymetry=False)
41+
proj.plot2d(plot_boundary=False, plot_bathymetry=True)
42+
plt.show()
43+
44+
# unload to yaml
45+
proj.unload(file=inputFile)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
'''Loads an ontology file and performs material itemization.'''
2+
import matplotlib.pyplot as plt
3+
import os
4+
from fadesign.conceptual.conceptDesign import ConceptDesign
5+
import numpy as np
6+
from famodel.project import Project
7+
from famodel.mooring.mooring import Mooring
8+
from fadesign.conceptual import metrics as mtr
9+
import pickle
10+
import networkx as nx
11+
12+
13+
def create_mtrlPkg(moor):
14+
'''Clusters components that needs to be mobilized/installed simultaneously. '''
15+
16+
pkg = {}
17+
if moor.shared:
18+
# installation itemization for shared line
19+
for i, sec in enumerate(moor.dd['sections']):
20+
pkg[f"sec_{i}"] = {
21+
"obj": sec,
22+
"mass": sec['type']['m']*sec['L']/1e3, # mass [t]
23+
"length": sec['L'], # length [m]
24+
"dependencies": [],
25+
}
26+
if i>1:
27+
pkg[f"sec_{i}"]['dependencies'].append(f"sec_{0}")
28+
29+
for i, conn in enumerate(moor.dd['connectors']):
30+
if conn['m'] > 0:
31+
pkg[f"conn_{i}"] = {
32+
"obj": conn,
33+
"mass": conn['m']/1e3, # mass [t]
34+
# "load": ?, # pressure [t/m^2] # NOTE: I am not checking load because clump weights could be easily sized in a way to reduce load if needed.
35+
"dependencies": [f"sec_{0}"],
36+
}
37+
else:
38+
for att in moor.attached_to:
39+
if type(att).__name__ == "Anchor":
40+
M = att.mass / 1e3 # mass [t]
41+
D = att.dd['design']['D'] # diameter [m]
42+
L = att.dd['design']['L'] # length [m]
43+
area_xy = D * L
44+
pkg = {
45+
f"anchor_{att.id}": {
46+
"obj": att,
47+
"mass": M,
48+
"load": M/area_xy,
49+
"space": area_xy,
50+
"dependencies": []
51+
},
52+
}
53+
break
54+
55+
for i, sec in enumerate(moor.dd['sections']):
56+
pkg[f"sec_{i}"] = {
57+
"obj": sec,
58+
"mass": sec['type']['m']*sec['L']/1e3,
59+
"length": sec['L'],
60+
"dependencies": [f"anchor_{att.id}"],
61+
}
62+
for i, conn in enumerate(moor.dd['connectors']):
63+
if conn['m'] > 0:
64+
pkg[f"conn_{i}"] = {
65+
"obj": conn,
66+
"mass": conn['m']/1e3,
67+
"load": conn['m']/conn['v'],
68+
"dependencies": [f"anchor_{att.id}"],
69+
}
70+
return pkg
71+
72+
73+
# CONCEPT CATEGORY & NAME
74+
category = "ILIA" # ILIA | ILSA | SLIA | SLSA | hybrid
75+
conceptName = "3_ILIA_1P2C_grd_mini"
76+
# FILE LOCATIONS
77+
filePath = os.path.dirname(os.path.abspath(__file__))
78+
inputFile = os.path.join(filePath, category, f"proj_{conceptName}.yaml")
79+
80+
# Load project
81+
proj = Project(file=inputFile)
82+
83+
# Step1: create Material Items
84+
mtrlPkgs = []
85+
for moor in proj.mooringList.values():
86+
mtrlPkgs.append(create_mtrlPkg(moor))
87+
88+
output = os.path.join(filePath, "mtrlPkgs.pkl")
89+
with open(output, 'wb') as f:
90+
pickle.dump(mtrlPkgs, f)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'''loads material package saved in step1, loads vessel description, and creates action items for transport, mobilization, and installation.'''
2+
import matplotlib.pyplot as plt
3+
import os
4+
from fadesign.conceptual.conceptDesign import ConceptDesign
5+
import numpy as np
6+
from famodel.project import Project
7+
from famodel.mooring.mooring import Mooring
8+
from fadesign.conceptual import metrics as mtr
9+
import yaml
10+
import networkx as nx
11+
import pickle
12+
import install_helpers as inst
13+
14+
15+
# FILE LOCATIONS
16+
filePath = os.path.dirname(os.path.abspath(__file__))
17+
itemFile = os.path.join(filePath, "mtrlPkgs.pkl")
18+
19+
with open(itemFile, 'rb') as f:
20+
pkgs = pickle.load(f)
21+
22+
vesselFile = os.path.join(filePath, "vesselDesc.yaml")
23+
vesselNames = ['AHTS']
24+
25+
with open(vesselFile) as file:
26+
vesselDisc = yaml.load(file, Loader=yaml.FullLoader)
27+
28+
29+
for vesselName in vesselNames:
30+
vessel = vesselDisc[vesselName]
31+
vessel['state'] = {
32+
'remaining_cargo': vessel['storage_specs']['max_cargo'],
33+
'remaining_deck_space': vessel['storage_specs']['max_deck_space'],
34+
'remaining_spool_capacity': vessel['storage_specs']['spool_capacity'],
35+
'assigned_materials': []
36+
}
37+
38+
# Action list:
39+
# Transport
40+
distance2port = 250 # km [not sure where this information would be handled]
41+
transport_V1 = inst.tranportTo_actionItem(vessel, distance2port)
42+
# Mobilization
43+
pkg = pkgs[0] # example
44+
mobilize_V1, vessel = inst.mobilizeM_actionItem(vessel, pkg)
45+
print(vessel['state'])
46+
# Installation
47+
pkg = pkgs[0] # example
48+
install_V1, vessel = inst.install_actionItem(vessel, pkg)
49+
print(vessel['state'])
50+
51+
inst.visualizeAction(transport_V1)
52+
plt.show()
53+
54+
inst.visualizeAction(mobilize_V1)
55+
plt.show()
56+
57+
inst.visualizeAction(install_V1)
58+
plt.show()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'''an example of how install manager is used to register a vessel and port, and schedule an event and run (not finished yet).'''
2+
# from fadesign.conceptual.installation.vessel import Vessel
3+
# from fadesign.conceptual.installation.port import Port
4+
from fadesign.installation.install_manager import InstallManager as IM
5+
from pyproj import Proj, Transformer
6+
import pandas as pd
7+
import os
8+
9+
# FILE LOCATIONS
10+
filePath = os.path.dirname(os.path.abspath(__file__))
11+
vessel1_file = os.path.join(filePath, "ahts.yaml")
12+
port1_file = os.path.join(filePath, "port_of_humboldt.yaml")
13+
14+
# Initialize
15+
im = IM()
16+
17+
# Register Port
18+
im.registerPort()
19+
# Register Vessels
20+
im.registerVessel(vessel1_file)
21+
22+
# Register vessel mob activity
23+
im.scheduleEvent(im.now, im.vessels['ahts1'], action='mob', params={"portLocation": [0, 0]})
24+
# Register
25+
im.run()
764 KB
Binary file not shown.

0 commit comments

Comments
 (0)