#
# This code has been auto-generated by the MDE Workbench
# Version: 3.1.2.
#
# File: Test
# Date: 2022-12-06 00:16
# Time: 00:16
#


# The following import is required for sys.exit
import sys

from pypws.calculations import FlashCalculation

from pypws.entities import Material, MaterialComponent, State

from pypws.enums import ResultCode, PropertyTemplate, FluidSpec
from pypws.enums import MixtureModelling

from pypws.utilities import getAnalyticsApiTarget

print('\n******************************************************************************************')
print(' Running against: %s' % (getAnalyticsApiTarget()))
print('******************************************************************************************\n')

# No items with data mappings to the flashCalculation instance.
# All input data will have to be specified for the calculation itself.

# Declare the flashCalculation calclulation instance.
flashCalculation = FlashCalculation()


# Set unmapped properties for flashCalculation (Material property).
flashCalculation.material.componentCount = 1
materialComponent = MaterialComponent()
materialComponent.name = "AMMONIA"
materialComponent.moleFraction = 1.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)
materialComponent = MaterialComponent()
materialComponent.name = ""
materialComponent.moleFraction = 0.0
flashCalculation.material.components.append(materialComponent)

flashCalculation.material.propertyTemplate = PropertyTemplate.PHAST_MC

# Set unmapped properties for flashCalculation (MaterialState property).
flashCalculation.materialState.pressure = 446064.0
flashCalculation.materialState.temperature = 240.15
flashCalculation.materialState.liquidFraction = 0.0
flashCalculation.materialState.flashFlag = FluidSpec.TP
flashCalculation.materialState.mixtureModelling = MixtureModelling.PC

# Run the flashCalculation instance.
print('.... Running flash calculation')

resultCode = flashCalculation.run()

print('>>>> Result code of flashCalculation (FlashCalculation) run: ', resultCode)

if resultCode == ResultCode.SUCCESS:

  # Flash calculation ran successfully

  print('>>>> flashCalculation (FlashCalculation) ran successfully')
  # Print out any messages
  flashCalculation.print_messages()

else:

  # Errors encountered running flashCalculation
  # Print the messages as these may help in diagnosing the issue(s)
  flashCalculation.print_messages()

  print('!!!! Errors encountered running flashCalculation')

  sys.exit(flashCalculation.resultCode)
