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

62 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-03-26 20:57 +0000

1from django.contrib.postgres.fields import ArrayField 

2from django.db import models 

3 

4from core.managers import AccessControlManager 

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 = models.ForeignKey["Flowsheet"]("Flowsheet", on_delete=models.CASCADE, related_name="customCompounds") 

13 name = models.CharField(max_length=255) 

14 

15 objects = AccessControlManager() 

16 

17 # Foreign keys referenced elsewhere, added for typing: 

18 properties: models.QuerySet["CompoundProperty"] 

19 

20 

21class CompoundPropertyEnum(models.TextChoices): 

22 # the left names are stylised to be readable, 

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

24 CP_MOL_IG_COMP_COEFF_A = "cp_mol_ig_comp_coeff_A" 

25 CP_MOL_IG_COMP_COEFF_B = "cp_mol_ig_comp_coeff_B" 

26 CP_MOL_IG_COMP_COEFF_C = "cp_mol_ig_comp_coeff_C" 

27 CP_MOL_IG_COMP_COEFF_D = "cp_mol_ig_comp_coeff_D" 

28 ACCENTRIC_FACTOR = "omega" 

29 MOLAR_WEIGHT = "mw" 

30 CRITICAL_PRESSURE = "pressure_crit" 

31 CRITICAL_TEMPERATURE = "temperature_crit" 

32 ENTHALPY_OF_FORMATION = "enth_mol_form_vap_comp_ref" 

33 ENTROPY_OF_FORMATION = "entr_mol_form_vap_comp_ref" # integration constant 

34 PRESSURE_SAT_COMP_COEFF_A = "pressure_sat_comp_coeff_A" 

35 PRESSURE_SAT_COMP_COEFF_B = "pressure_sat_comp_coeff_B" 

36 PRESSURE_SAT_COMP_COEFF_C = "pressure_sat_comp_coeff_C" 

37 PRESSURE_SAT_COMP_COEFF_D = "pressure_sat_comp_coeff_D" 

38 

39class CompoundProperty(models.Model): 

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

41 For example, this could be cp_mol_ig_comp_coeff_A 

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

43 """ 

44 flowsheet = models.ForeignKey["Flowsheet"]("Flowsheet", on_delete=models.CASCADE, related_name="customCompoundProperties") 

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

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

47 value = models.FloatField(null=True) 

48 

49 objects = AccessControlManager() 

50 

51 

52class CustomPropertyPackage(models.Model): 

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

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

55 """ 

56 flowsheet = models.ForeignKey["Flowsheet"]("Flowsheet", on_delete=models.CASCADE, related_name="customPropertyPackages") 

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

58 name = models.CharField(max_length=255) 

59 

60 objects = AccessControlManager() 

61 

62 # Foreign keys referenced elsewhere, added for typing: 

63 kappas: models.QuerySet["Kappa"] 

64 properties: models.QuerySet["CustomPropertyPackageProperty"] 

65 

66class CustomPropertyPackagePropertyEnum(models.TextChoices): 

67 # the left names are stylised to be readable, 

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

69 FLOW_MOL_MIN = "flow_mol_min" 

70 FLOW_MOL_NOMINAL = "flow_mol_nominal" 

71 FLOW_MOL_MAX = "flow_mol_max" 

72 TEMPERATURE_MIN = "temperature_min" 

73 TEMPERATURE_NOMINAL = "temperature_nominal" 

74 TEMPERATURE_MAX = "temperature_max" 

75 PRESSURE_MIN = "pressure_min" 

76 PRESSURE_NOMINAL = "pressure_nominal" 

77 PRESSURE_MAX = "pressure_max" 

78 PRESSURE_REF = "pressure_ref" 

79 TEMPERATURE_REF = "temperature_ref" 

80 

81 

82class CustomPropertyPackageProperty(models.Model): 

83 flowsheet = models.ForeignKey["Flowsheet"]("Flowsheet", on_delete=models.CASCADE, related_name="customPropertyPackageProperties") 

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

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

86 value = models.FloatField(null=True) 

87 

88 objects = AccessControlManager() 

89 

90 

91class Kappa(models.Model): 

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

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

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

95 """ 

96 flowsheet = models.ForeignKey["Flowsheet"]("Flowsheet", on_delete=models.CASCADE, related_name="customPropertyPackageKappas") 

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

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

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

100 value = models.FloatField(null=True) 

101 

102 objects = AccessControlManager() 

103 

104