Coverage for backend/django/core/auxiliary/models/CustomPropertyPackage.py: 100%

67 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-07-22 05:22 +0000

1from django.contrib.postgres.fields import ArrayField 

2from django.db import models 

3 

4from core.managers import AccessControlManager, AllFlowsheetStatesManager 

5from typing import TYPE_CHECKING 

6if TYPE_CHECKING: 

7 from .Flowsheet import Flowsheet 

8 

9class CustomCompound(models.Model): 

10 """Represents a custom compound that is added to a flowsheet. 

11 """ 

12 flowsheet_state = models.ForeignKey["FlowsheetState"]("FlowsheetState", on_delete=models.CASCADE, related_name="customCompounds") 

13 name = models.CharField(max_length=255) 

14 

15 objects = AccessControlManager() 

16 all_states = AllFlowsheetStatesManager() 

17 

18 # Foreign keys referenced elsewhere, added for typing: 

19 properties: models.QuerySet["CompoundProperty"] 

20 

21 

22class CompoundPropertyEnum(models.TextChoices): 

23 # the left names are stylised to be readable, 

24 # the right names are to match the keys used in IDAES. 

25 CP_MOL_IG_COMP_COEFF_A = "cp_mol_ig_comp_coeff_A" 

26 CP_MOL_IG_COMP_COEFF_B = "cp_mol_ig_comp_coeff_B" 

27 CP_MOL_IG_COMP_COEFF_C = "cp_mol_ig_comp_coeff_C" 

28 CP_MOL_IG_COMP_COEFF_D = "cp_mol_ig_comp_coeff_D" 

29 ACCENTRIC_FACTOR = "omega" 

30 MOLAR_WEIGHT = "mw" 

31 CRITICAL_PRESSURE = "pressure_crit" 

32 CRITICAL_TEMPERATURE = "temperature_crit" 

33 ENTHALPY_OF_FORMATION = "enth_mol_form_vap_comp_ref" 

34 ENTROPY_OF_FORMATION = "entr_mol_form_vap_comp_ref" # integration constant 

35 PRESSURE_SAT_COMP_COEFF_A = "pressure_sat_comp_coeff_A" 

36 PRESSURE_SAT_COMP_COEFF_B = "pressure_sat_comp_coeff_B" 

37 PRESSURE_SAT_COMP_COEFF_C = "pressure_sat_comp_coeff_C" 

38 PRESSURE_SAT_COMP_COEFF_D = "pressure_sat_comp_coeff_D" 

39 

40class CompoundProperty(models.Model): 

41 """Represents a property of a custom compound that is added to a flowsheet. 

42 For example, this could be cp_mol_ig_comp_coeff_A 

43 see: https://github.com/IDAES/idaes-pse/blob/da90c69ce114d68be3294e271088ca196d3210c2/idaes/models/properties/modular_properties/examples/BT_PR.py#L4 

44 """ 

45 flowsheet_state = models.ForeignKey["FlowsheetState"]("FlowsheetState", on_delete=models.CASCADE, related_name="customCompoundProperties") 

46 compound = models.ForeignKey(CustomCompound, on_delete=models.CASCADE, related_name="properties") 

47 compound_property_key = models.CharField(max_length=255, choices=CompoundPropertyEnum.choices) 

48 value = models.FloatField(null=True) 

49 

50 objects = AccessControlManager() 

51 all_states = AllFlowsheetStatesManager() 

52 

53 

54class CustomPropertyPackage(models.Model): 

55 """Represents a custom property package that is added to a flowsheet. This is a collection of compounds and their properties. 

56 There also are some properties directly on the property package. 

57 """ 

58 flowsheet_state = models.ForeignKey["FlowsheetState"]("FlowsheetState", on_delete=models.CASCADE, related_name="customPropertyPackages") 

59 compounds = models.ManyToManyField(CustomCompound, related_name="propertyPackages") 

60 name = models.CharField(max_length=255) 

61 

62 objects = AccessControlManager() 

63 all_states = AllFlowsheetStatesManager() 

64 

65 # Foreign keys referenced elsewhere, added for typing: 

66 kappas: models.QuerySet["Kappa"] 

67 properties: models.QuerySet["CustomPropertyPackageProperty"] 

68 

69class CustomPropertyPackagePropertyEnum(models.TextChoices): 

70 # the left names are stylised to be readable, 

71 # the right names are to match the keys used in IDAES. 

72 FLOW_MOL_MIN = "flow_mol_min" 

73 FLOW_MOL_NOMINAL = "flow_mol_nominal" 

74 FLOW_MOL_MAX = "flow_mol_max" 

75 TEMPERATURE_MIN = "temperature_min" 

76 TEMPERATURE_NOMINAL = "temperature_nominal" 

77 TEMPERATURE_MAX = "temperature_max" 

78 PRESSURE_MIN = "pressure_min" 

79 PRESSURE_NOMINAL = "pressure_nominal" 

80 PRESSURE_MAX = "pressure_max" 

81 PRESSURE_REF = "pressure_ref" 

82 TEMPERATURE_REF = "temperature_ref" 

83 

84 

85class CustomPropertyPackageProperty(models.Model): 

86 flowsheet_state = models.ForeignKey["FlowsheetState"]("FlowsheetState", on_delete=models.CASCADE, related_name="customPropertyPackageProperties") 

87 package = models.ForeignKey(CustomPropertyPackage, on_delete=models.CASCADE, related_name="properties") 

88 package_property_key = models.CharField(max_length=255, choices=CustomPropertyPackagePropertyEnum.choices) 

89 value = models.FloatField(null=True) 

90 

91 objects = AccessControlManager() 

92 all_states = AllFlowsheetStatesManager() 

93 

94 

95class Kappa(models.Model): 

96 """Represents a kappa value for a custom property package. This is used to capture the kappa values for a custom property package. 

97 Peng-Robinson Kappa values are specified as the interaction between two compounds, 

98 so the two compounds are used to identify this instead of a string key. 

99 """ 

100 flowsheet_state = models.ForeignKey["FlowsheetState"]("FlowsheetState", on_delete=models.CASCADE, related_name="customPropertyPackageKappas") 

101 package = models.ForeignKey(CustomPropertyPackage, on_delete=models.CASCADE, related_name="kappas") 

102 compound1 = models.ForeignKey(CustomCompound, on_delete=models.CASCADE, related_name="kappaCompound1") 

103 compound2 = models.ForeignKey(CustomCompound, on_delete=models.CASCADE, related_name="kappaCompound2") 

104 value = models.FloatField(null=True) 

105 

106 objects = AccessControlManager() 

107 all_states = AllFlowsheetStatesManager() 

108 

109