Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
reilleya committed Jan 5, 2025
1 parent 7713aaa commit c99e71d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
40 changes: 39 additions & 1 deletion motorlib/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def runSimulation(self, callback=None):
simRes.channels['exitPressure'].addData(0)
simRes.channels['dThroat'].addData(0)

# Check port/throat ratio and add a warning if it is large enough
# Check port/throat ratio and add a warning if it is not large enough
aftPort = self.grains[-1].getPortArea(0)
if aftPort is not None:
minAllowed = self.config.getProperty('minPortThroat')
Expand Down Expand Up @@ -281,3 +281,41 @@ def runSimulation(self, callback=None):
break

return simRes

def getQuickResults(self):
results = {
'volumeLoading': 0,
'initialKn': 0,
'propellantMass': 0,
'portRatio': 0,
'length': 0
}

simRes = SimulationResult(self)

density = self.propellant.getProperty('density') if self.propellant is not None else None
throatArea = self.nozzle.getThroatArea()
motorVolume = self.calcTotalVolume()

if motorVolume == 0:
return results

# Generate coremaps for perforated grains
for grain in self.grains:
for alert in grain.getGeometryErrors():
if alert.level == SimAlertLevel.ERROR:
return results

grain.simulationSetup(self.config)

perGrainReg = [0 for grain in self.grains]

results['volumeLoading'] = 100 * (1 - (self.calcFreeVolume(perGrainReg) / motorVolume))
if throatArea != 0:
results['initialKn'] = self.calcKN(perGrainReg, 0)
results['portRatio'] = simRes.getPortRatio()
if density is not None:
results['propellantMass'] = sum([grain.getVolumeAtRegression(0) * density for grain in self.grains])
results['length'] = simRes.getPropellantLength()

return results
17 changes: 17 additions & 0 deletions uilib/widgets/mainWindow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from threading import Thread

from PyQt6.QtWidgets import QWidget, QMainWindow, QTableWidgetItem, QHeaderView, QTableWidget
from PyQt6.QtCore import Qt
Expand Down Expand Up @@ -32,6 +33,7 @@ def __init__(self, app):

self.app.fileManager.fileNameChanged.connect(self.updateWindowTitle)
self.app.fileManager.newMotor.connect(self.resetOutput)
self.app.fileManager.newMotor.connect(self.getQuickResults)

self.app.importExportManager.motorImported.connect(self.motorImported)

Expand Down Expand Up @@ -318,6 +320,19 @@ def updateMotorStats(self, simResult):
self.ui.labelPeakMassFlux.setText('-')
self.ui.labelDeliveredThrustCoefficient.setText(self.formatMotorStat(simResult.getAdjustedThrustCoefficient(), ''))

def getQuickResults(self, motor):
thread = lambda: self.showQuickResults(motor.getQuickResults())

dataThread = Thread(target=thread)
dataThread.start()

def showQuickResults(self, results):
self.ui.labelVolumeLoading.setText('{:.2f}%'.format(results['volumeLoading']))
self.ui.labelInitialKN.setText(self.formatMotorStat(results['initialKn'], ''))
self.ui.labelPropellantLength.setText(self.formatMotorStat(results['length'], 'm'))
self.ui.labelPropellantMass.setText(self.formatMotorStat(results['propellantMass'], 'kg'))
self.ui.labelPortThroatRatio.setText(self.formatMotorStat(results['portRatio'], ''))

def runSimulation(self):
self.resetOutput()
cm = self.app.fileManager.getCurrentMotor()
Expand Down Expand Up @@ -356,6 +371,8 @@ def loadMotor(self, path=None):
self.disablePropSelector()
if self.app.fileManager.load(path):
self.postLoadUpdate()
# Needed because postLoadUpdate clears results
self.getQuickResults(self.app.fileManager.getCurrentMotor())
self.enablePropSelector()
self.ui.motorEditor.close()

Expand Down

0 comments on commit c99e71d

Please sign in to comment.