-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseInput.py
92 lines (75 loc) · 3.49 KB
/
parseInput.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
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
import xmltodict
from Tanks import MassObject, GasLiquidTank, GasTank
from param_types import CEAFuelType, CEAOxidizerType, CoolPropFluid
from Engine import Engine
class Parser(object):
def __init__(self, filePath):
self.filePath = filePath
self.data = None
self.parse()
self.generalData = self.data["rocket"]["general"]
self.inputData = self.data["rocket"]["inputData"]
self.componentData = self.data["rocket"]["components"]
self.engineData = self.componentData["engine"]
def parse(self):
with open(self.filePath, "r") as xml_obj:
self.data = xmltodict.parse(xml_obj.read())
xml_obj.close()
def generateEngine(self, fuelTankName, oxidizerTankName):
return Engine(
self.getEngineName(),
CEAFuelType(self.generalData["fuelType"]),
eval(self.componentData[fuelTankName]["liquidTemperature"]),
CEAOxidizerType[self.generalData["oxidizerType"]],
eval(self.componentData[oxidizerTankName]["liquidTemperature"]),
float(self.generalData["oxidizerFuelRatio"]),
eval(self.engineData["chamberPressure"]),
eval(self.generalData["referenceAmbientPressure"]),
float(self.engineData["referenceThrust"]),
float(self.generalData["engineEfficiency"]),
float(self.generalData["waterFraction"])
)
def generateLiquidTank(self, name):
return GasLiquidTank(
eval(self.componentData[name]["tankVolume"]),
float(self.componentData[name]["tankLength"]),
float(self.componentData[name]["tankMass"]),
CoolPropFluid[self.generalData[self.componentData[name]["tankType"] + "Type"]],
eval(self.componentData[name]["liquidTemperature"]),
CoolPropFluid(self.componentData[self.componentData[name]["pressurantTank"]]["gasType"]),
eval(self.componentData[name]["gasTemperature"]),
float(self.componentData[name]["fillLevel"]),
eval(self.componentData[name]["tankPressure"])
)
def generatePressurantTank(self, name):
return GasTank(
eval(self.componentData[name]["tankVolume"]),
float(self.componentData[name]["tankLength"]),
float(self.componentData[name]["tankMass"]),
CoolPropFluid(str(self.componentData[name]["gasType"])),
eval(self.componentData[name]["gasTemperature"]),
eval(self.componentData[name]["tankPressure"])
)
def generateMassObject(self, name):
return MassObject(
float(self.componentData[name]["mass"]),
float(self.componentData[name]["length"])
)
def getComponents(self):
return list(self.componentData.keys())
def getInputName(self):
return self.inputData["orDataFileName"]
def getReductionFactor(self):
return self.inputData["orDataReductionFactor"]
def getMaxBurnDuration(self):
return self.generalData["maxBurnDuration"]
def getEngineManufacturer(self):
return self.generalData["engineManufacturer"]
def getEngineName(self):
return str(self.generalData["engineName"])
def getDisplayedSystemDiameter(self):
return self.generalData["displayedSystemDiameter"]
def getAutomaticMassCalculation(self):
return self.generalData["automaticMassCalculation"]
def getEngineFilePath(self):
return str("outputFiles/" + self.getEngineName() + ".rse")