Coverage for backend/PinchAnalysis/models/OutputModels.py: 90%
100 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
1from django.db import models
2from django.contrib.postgres.fields import ArrayField
3from core.auxiliary.enums import pinchEnums
4from core.managers import AccessControlManager
6class PinchOutputs(models.Model):
7 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="Outputs")
8 project_owner = models.OneToOneField("PinchAnalysis.StreamDataProject", on_delete=models.CASCADE, related_name="Outputs", null=True)
9 name = models.CharField(max_length=32, blank=True, null=True)
11 created_at = models.DateTimeField(auto_now_add=True)
12 objects = AccessControlManager()
16class PinchTemp(models.Model):
17 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="PinchTemps")
18 cold_temp = models.FloatField(blank=True, null=True)
19 hot_temp = models.FloatField(blank=True, null=True)
21 created_at = models.DateTimeField(auto_now_add=True)
22 objects = AccessControlManager()
26class TargetSummary(models.Model):
27 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="TargetSummaries")
28 output_owner = models.ForeignKey(PinchOutputs, on_delete=models.CASCADE, related_name="targets", null=True)
29 name = models.CharField(max_length=128)
30 row_type = models.CharField(choices=pinchEnums.SummaryRowType.choices , default=pinchEnums.SummaryRowType.CONTENT)
31 temp_pinch = models.ForeignKey(PinchTemp, on_delete=models.CASCADE, related_name="summary_owner", null=True, blank=True)
32 Qh = models.FloatField(default=0.0, blank=True, null=True)
33 Qc = models.FloatField(default=0.0, blank=True, null=True)
34 Qr = models.FloatField(default=0.0, blank=True, null=True)
35 degree_of_integration = models.FloatField(default=100.0, blank=True, null=True)
36 utility_cost = models.FloatField(default=0.0, blank=True, null=True)
37 work_target = models.FloatField(default=0.0, blank=True, null=True)
38 turbine_efficiency_target = models.FloatField(default=0.0, blank=True, null=True)
39 area = models.FloatField(default=0.0, blank=True, null=True)
40 num_units = models.FloatField(default=0.0, blank=True, null=True)
41 capital_cost = models.FloatField(default=0.0, blank=True, null=True)
42 total_cost = models.FloatField(default=0.0, blank=True, null=True)
43 exergy_sources = models.FloatField(default=0.0, blank=True, null=True)
44 exergy_sinks = models.FloatField(default=0.0, blank=True, null=True)
45 ETE = models.FloatField(default=0.0, blank=True, null=True)
46 exergy_req_min = models.FloatField(default=0.0, blank=True, null=True)
47 exergy_des_min = models.FloatField(default=0.0, blank=True, null=True)
49 created_at = models.DateTimeField(auto_now_add=True)
50 objects = AccessControlManager()
53 class Meta:
54 ordering = ['created_at']
56 @classmethod
57 def create(cls, **kwargs):
58 defaults = {
59 'output_owner': kwargs.get('output_owner', None),
60 'name': kwargs.get('name', None),
61 'Qh': kwargs.get('Qh', 0.0),
62 'Qc': kwargs.get('Qc', 0.0),
63 'Qr': kwargs.get('Qr', 0.0),
64 'degree_of_integration': kwargs.get('degree_of_integration', 100.0),
65 'utility_cost': kwargs.get('utility_cost', 0.0),
66 'work_target': kwargs.get('work_target', 0.0),
67 'turbine_efficiency_target': kwargs.get('turbine_efficiency_target', 0.0),
68 'area': kwargs.get('area', 0.0),
69 'num_units': kwargs.get('num_units', 0.0),
70 'capital_cost': kwargs.get('capital_cost', 0.0),
71 'total_cost': kwargs.get('total_cost', 0.0),
72 }
74 defaults.update(**kwargs)
75 instance = cls.objects.create(**defaults)
76 instance.save()
77 return instance
79class HeatSupplierUtilitySummary(models.Model):
80 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="HeatSupplierUtilities")
81 name = models.CharField(max_length=128)
82 summary_owner = models.ForeignKey(TargetSummary, on_delete=models.CASCADE, related_name="hot_utilities", null=True, blank=True)
83 heat_flow = models.FloatField(default=None, null=True)
85 created_at = models.DateTimeField(auto_now_add=True)
86 objects = AccessControlManager()
91class HeatReceiverUtilitySummary(models.Model):
92 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="HeatReceiverUtilities")
93 name = models.CharField(max_length=128)
94 summary_owner = models.ForeignKey(TargetSummary, on_delete=models.CASCADE, related_name="cold_utilities", null=True, blank=True)
95 heat_flow = models.FloatField(default=None, null=True)
97 created_at = models.DateTimeField(auto_now_add=True)
98 objects = AccessControlManager()
102class PinchGraphSet(models.Model):
103 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="PinchGraphSets")
104 name = models.CharField(max_length=32)
105 output_owner = models.ForeignKey(PinchOutputs, on_delete=models.CASCADE, related_name="graph_sets", null=True)
107 created_at = models.DateTimeField(auto_now_add=True)
108 objects = AccessControlManager()
111 class Meta:
112 ordering = ['created_at']
114 @classmethod
115 def create(cls, **kwargs):
116 defaults = {
117 'output_owner': kwargs.get('output_owner', None),
118 'name': kwargs.get('name', None),
119 }
121 defaults.update(**kwargs)
122 instance = cls.objects.create(**defaults)
123 instance.save()
124 return instance
126class PinchGraph(models.Model):
127 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="PinchGraphs")
128 name = models.CharField(max_length=32, null=True, blank=True)
129 graph_set = models.ForeignKey(PinchGraphSet, on_delete=models.CASCADE, related_name="graphs", null=True)
130 type = models.CharField(choices=pinchEnums.GraphType.choices , default=pinchEnums.GraphType.CC)
132 created_at = models.DateTimeField(auto_now_add=True)
133 objects = AccessControlManager()
137# Can be considered a "line segment" for CC's
138class PinchCurve(models.Model):
139 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="PinchCurves")
140 graph = models.ForeignKey(PinchGraph, on_delete=models.CASCADE, related_name="segments", null=True)
141 title = models.CharField(max_length=32)
142 colour = models.IntegerField(choices=pinchEnums.LineColour.choices , default=pinchEnums.LineColour.Hot)
143 arrow = models.CharField(choices=pinchEnums.ArrowHead.choices , default=pinchEnums.ArrowHead.NO_ARROW)
145 created_at = models.DateTimeField(auto_now_add=True)
146 objects = AccessControlManager()
150class GraphDataPoint(models.Model):
151 flowsheet = models.ForeignKey("core_auxiliary.Flowsheet", on_delete=models.CASCADE, related_name="GraphDataPoints")
152 curve = models.ForeignKey(PinchCurve, on_delete=models.CASCADE, related_name="data_points")
153 x = models.FloatField(null=True)
154 y = models.FloatField(null=True)
156 created_at = models.DateTimeField(auto_now_add=True)
157 objects = AccessControlManager()