Sunteți pe pagina 1din 12

' ' ' ' ' ' ' ' ' ' ' ' ' ' '

' '

Cooler Calculation Routines Copyright 2008 Daniel Wagner O. de Medeiros This file is part of DWSIM. DWSIM is it under the Free (at your free software: you can redistribute it and/or modify the terms of the GNU General Public License as published by Software Foundation, either version 3 of the License, or option) any later version.

DWSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with DWSIM. If not, see <http://www.gnu.org/licenses/>.

Imports Microsoft.MSDN.Samples.GraphicObjects Imports DWSIM.DWSIM.Flowsheet.FlowSheetSolver Namespace DWSIM.SimulationObjects.UnitOps <System.Serializable()> Public Class Cooler Inherits SimulationObjects_UnitOpBaseClass Protected Protected Protected Protected Protected Protected m_dp As Nullable(Of Double) m_dt As Nullable(Of Double) m_DQ As Nullable(Of Double) m_Tout As Nullable(Of Double) m_VFout As Nullable(Of Double) m_cmode As CalculationMode = CalculationMode.HeatRemoved

Protected m_eta As Nullable(Of Double) = 100 Public Enum CalculationMode HeatRemoved = 0 OutletTemperature = 1 OutletVaporFraction = 2 End Enum Public Property OutletTemperature() As Nullable(Of Double) Get Return m_Tout End Get Set(ByVal value As Nullable(Of Double)) m_Tout = value End Set End Property Public Property OutletVaporFraction() As Nullable(Of Double) Get Return m_VFout End Get Set(ByVal value As Nullable(Of Double)) m_VFout = value End Set End Property Public Property CalcMode() As CalculationMode

Get Return m_cmode End Get Set(ByVal value As CalculationMode) m_cmode = value End Set End Property Public Sub New(ByVal nome As String, ByVal descricao As String) MyBase.CreateNew() Me.m_ComponentName = nome Me.m_ComponentDescription = descricao Me.FillNodeItems() Me.QTFillNodeItems() End Sub Public Property Eficiencia() As Nullable(Of Double) Get Return m_eta End Get Set(ByVal value As Nullable(Of Double)) m_eta = value End Set End Property Public Property DeltaP() As Nullable(Of Double) Get Return m_dp End Get Set(ByVal value As Nullable(Of Double)) m_dp = value End Set End Property Public Property DeltaT() As Nullable(Of Double) Get Return m_dt End Get Set(ByVal value As Nullable(Of Double)) m_dt = value End Set End Property Public Property DeltaQ() As Nullable(Of Double) Get Return m_DQ End Get Set(ByVal value As Nullable(Of Double)) m_DQ = value End Set End Property Public Overrides Function Calculate(Optional ByVal args As Object = Nothing) As Integer Dim form As Global.DWSIM.FormFlowsheet = My.Application.ActiveSimulation Dim objargs As New DWSIM.Outros.StatusChangeEventArgs If Not Me.GraphicObject.EnergyConnector.IsAttached Then 'Call function to calculate flowsheet

With objargs .Calculado = False .Nome = Me.Nome .Tipo = TipoObjeto.Cooler End With CalculateFlowsheet(FlowSheet, objargs, Nothing) Throw New Exception(DWSIM.App.GetLocalString("Nohcorrentedeenergia2")) ElseIf Not Me.GraphicObject.OutputConnectors(0).IsAttached Then 'Call function to calculate flowsheet With objargs .Calculado = False .Nome = Me.Nome .Tipo = TipoObjeto.Cooler End With CalculateFlowsheet(FlowSheet, objargs, Nothing) Throw New Exception(DWSIM.App.GetLocalString("Verifiqueasconexesdo")) ElseIf Not Me.GraphicObject.InputConnectors(0).IsAttached Then 'Call function to calculate flowsheet With objargs .Calculado = False .Nome = Me.Nome .Tipo = TipoObjeto.Cooler End With CalculateFlowsheet(FlowSheet, objargs, Nothing) Throw New Exception(DWSIM.App.GetLocalString("Verifiqueasconexesdo")) End If Dim Ti, Pi, Hi, Wi, ei, ein, T2, P2, H2 As Double Me.PropertyPackage.CurrentMaterialStream = form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.InputConnec tors(0).AttachedConnector.AttachedFrom.Name) Ti = form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.InputConnec tors(0).AttachedConnector.AttachedFrom.Name).Fases(0).SPMProperties.tempera ture.GetValueOrDefault.ToString Pi = form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.InputConnec tors(0).AttachedConnector.AttachedFrom.Name).Fases(0).SPMProperties.pressur e.GetValueOrDefault.ToString Hi = form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.InputConnec tors(0).AttachedConnector.AttachedFrom.Name).Fases(0).SPMProperties.enthalp y.GetValueOrDefault.ToString Wi = form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.InputConnec tors(0).AttachedConnector.AttachedFrom.Name).Fases(0).SPMProperties.massflo w.GetValueOrDefault.ToString ei = Hi * Wi ein = ei Dim es As DWSIM.SimulationObjects.Streams.EnergyStream = form.Collections.CLCS_EnergyStreamCollection(Me.GraphicObject.EnergyConnect or.AttachedConnector.AttachedTo.Name) P2 = Pi - Me.DeltaP.GetValueOrDefault Select Case Me.CalcMode

Case CalculationMode.HeatRemoved H2 = -Me.DeltaQ.GetValueOrDefault * (Me.Eficiencia.GetValueOrDefault / 100) / Wi + Hi Dim tmp = Me.PropertyPackage.DW_CalcEquilibrio_ISOL(PropertyPackages.FlashSpec.P, PropertyPackages.FlashSpec.H, P2, H2, 0) T2 = tmp(2) Me.DeltaT = T2 - Ti 'Corrente de energia - atualizar valor da potncia (kJ/s) With es .Energia = Me.DeltaQ.GetValueOrDefault .GraphicObject.Calculated = True End With Case CalculationMode.OutletTemperature T2 = Me.OutletTemperature.GetValueOrDefault Dim tmp = Me.PropertyPackage.DW_CalcEquilibrio_ISOL(PropertyPackages.FlashSpec.T, PropertyPackages.FlashSpec.P, T2, P2, 0) H2 = tmp(4) Me.DeltaT = T2 - Ti Me.DeltaQ = -(H2 - Hi) / (Me.Eficiencia.GetValueOrDefault / 100) * Wi 'Corrente de energia - atualizar valor da potncia (kJ/s) With es .Energia = Me.DeltaQ.GetValueOrDefault .GraphicObject.Calculated = True End With Case CalculationMode.OutletVaporFraction Dim tmp = Me.PropertyPackage.DW_CalcEquilibrio_ISOL(PropertyPackages.FlashSpec.P, PropertyPackages.FlashSpec.VAP, P2, m_VFout.GetValueOrDefault, Ti) H2 = tmp(4) T2 = tmp(2) Me.DeltaT = T2 - Ti Me.DeltaQ = -(H2 - Hi) / (Me.Eficiencia.GetValueOrDefault / 100) * Wi 'Corrente de energia - atualizar valor da potncia (kJ/s) With es .Energia = Me.DeltaQ.GetValueOrDefault .GraphicObject.Calculated = True End With End Select 'Atribuir valores corrente de matria conectada jusante With form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.OutputConne ctors(0).AttachedConnector.AttachedTo.Name) .Fases(0).SPMProperties.temperature = T2

.Fases(0).SPMProperties.pressure = P2 .Fases(0).SPMProperties.enthalpy = H2 Dim comp As DWSIM.ClassesBasicasTermodinamica.Substancia For Each comp In .Fases(0).Componentes.Values comp.FracaoMolar = form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.InputConnec tors(0).AttachedConnector.AttachedFrom.Name).Fases(0).Componentes(comp.Nome ).FracaoMolar comp.FracaoMassica = form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.InputConnec tors(0).AttachedConnector.AttachedFrom.Name).Fases(0).Componentes(comp.Nome ).FracaoMassica Next .Fases(0).SPMProperties.massflow = form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.InputConnec tors(0).AttachedConnector.AttachedFrom.Name).Fases(0).SPMProperties.massflo w.GetValueOrDefault End With 'Call function to calculate flowsheet With objargs .Calculado = True .Nome = Me.Nome .Tipo = TipoObjeto.Cooler End With form.CalculationQueue.Enqueue(objargs) End Function Public Overrides Function DeCalculate() As Integer Dim form As Global.DWSIM.FormFlowsheet = My.Application.ActiveSimulation If Me.GraphicObject.OutputConnectors(0).IsAttached Then 'Zerar valores da corrente de matria conectada a jusante With form.Collections.CLCS_MaterialStreamCollection(Me.GraphicObject.OutputConne ctors(0).AttachedConnector.AttachedTo.Name) .Fases(0).SPMProperties.temperature = Nothing .Fases(0).SPMProperties.pressure = Nothing .Fases(0).SPMProperties.enthalpy = Nothing .Fases(0).SPMProperties.molarfraction = 1 .Fases(0).SPMProperties.massfraction = 1 Dim comp As DWSIM.ClassesBasicasTermodinamica.Substancia Dim i As Integer = 0 For Each comp In .Fases(0).Componentes.Values comp.FracaoMolar = 0 comp.FracaoMassica = 0 i += 1 Next .Fases(0).SPMProperties.massflow = Nothing .Fases(0).SPMProperties.molarflow = Nothing .GraphicObject.Calculated = False End With End If 'Corrente de energia - atualizar valor da potncia (kJ/s) If Me.GraphicObject.EnergyConnector.IsAttached Then

With form.Collections.CLCS_EnergyStreamCollection(Me.GraphicObject.EnergyConnect or.AttachedConnector.AttachedTo.Name) .Energia = Nothing .GraphicObject.Calculated = False End With End If 'Call function to calculate flowsheet Dim objargs As New DWSIM.Outros.StatusChangeEventArgs With objargs .Calculado = False .Nome = Me.Nome .Tag = Me.GraphicObject.Tag .Tipo = TipoObjeto.Cooler End With form.CalculationQueue.Enqueue(objargs) End Function Public Overloads Overrides Sub UpdatePropertyNodes(ByVal su As SistemasDeUnidades.Unidades, ByVal nf As String) Dim Conversor As New DWSIM.SistemasDeUnidades.Conversor If Me.NodeTableItems Is Nothing Then Me.NodeTableItems = New System.Collections.Generic.Dictionary(Of Integer, DWSIM.Outros.NodeItem) Me.FillNodeItems() End If For Each nti As Outros.NodeItem In Me.NodeTableItems.Values nti.Value = GetPropertyValue(nti.Text, FlowSheet.Options.SelectedUnitSystem) nti.Unit = GetPropertyUnit(nti.Text, FlowSheet.Options.SelectedUnitSystem) Next If Me.QTNodeTableItems Is Nothing Then Me.QTNodeTableItems = New System.Collections.Generic.Dictionary(Of Integer, DWSIM.Outros.NodeItem) Me.QTFillNodeItems() End If With Me.QTNodeTableItems Dim valor As String If Me.DeltaP.HasValue Then valor = Format(Conversor.ConverterDoSI(su.spmp_deltaP, Me.DeltaP), nf) Else valor = DWSIM.App.GetLocalString("NC") End If .Item(0).Value = valor .Item(0).Unit = su.spmp_deltaP If Me.DeltaT.HasValue Then valor = Format(Conversor.ConverterDoSI(su.spmp_deltaT, Me.DeltaT), nf) Else

valor = DWSIM.App.GetLocalString("NC") End If .Item(1).Value = valor .Item(1).Unit = su.spmp_deltaT If Me.DeltaQ.HasValue Then valor = Format(Conversor.ConverterDoSI(su.spmp_heatflow, Me.DeltaQ), nf) Else valor = DWSIM.App.GetLocalString("NC") End If .Item(2).Value = valor .Item(2).Unit = su.spmp_heatflow End With End Sub Public Overrides Sub QTFillNodeItems() With Me.QTNodeTableItems .Clear() .Add(0, New DWSIM.Outros.NodeItem("DP", "", "", 0, 0, "")) .Add(1, New DWSIM.Outros.NodeItem("DT", "", "", 1, 0, "")) .Add(2, New DWSIM.Outros.NodeItem("Pot", "", "", 2, 0, "")) End With End Sub Public Overrides Sub PopulatePropertyGrid(ByRef pgrid As PropertyGridEx.PropertyGridEx, ByVal su As SistemasDeUnidades.Unidades) Dim Conversor As New DWSIM.SistemasDeUnidades.Conversor With pgrid .PropertySort = PropertySort.Categorized .ShowCustomProperties = True .Item.Clear() MyBase.PopulatePropertyGrid(pgrid, su) Dim ent, saida, energ As String If Me.GraphicObject.InputConnectors(0).IsAttached = True Then ent = Me.GraphicObject.InputConnectors(0).AttachedConnector.AttachedFrom.Tag Else ent = "" End If If Me.GraphicObject.OutputConnectors(0).IsAttached = True Then saida = Me.GraphicObject.OutputConnectors(0).AttachedConnector.AttachedTo.Tag Else saida = "" End If If Me.GraphicObject.EnergyConnector.IsAttached = True Then

energ = Me.GraphicObject.EnergyConnector.AttachedConnector.AttachedTo.Tag Else energ = "" End If .Item.Add(DWSIM.App.GetLocalString("Correntedeentrada"), ent, False, DWSIM.App.GetLocalString("Conexes1"), "", True) With .Item(.Item.Count - 1) .DefaultValue = Nothing .CustomEditor = New DWSIM.Editors.Streams.UIInputMSSelector End With .Item.Add(DWSIM.App.GetLocalString("Correntedesada"), saida, False, DWSIM.App.GetLocalString("Conexes1"), "", True) With .Item(.Item.Count - 1) .DefaultValue = Nothing .CustomEditor = New DWSIM.Editors.Streams.UIOutputMSSelector End With .Item.Add(DWSIM.App.GetLocalString("Correntedeenergia"), energ, False, DWSIM.App.GetLocalString("Conexes1"), "", True) With .Item(.Item.Count - 1) .DefaultValue = Nothing .CustomEditor = New DWSIM.Editors.Streams.UIOutputESSelector End With Dim valor = Format(Conversor.ConverterDoSI(su.spmp_deltaP, Me.DeltaP.GetValueOrDefault), FlowSheet.Options.NumberFormat) .Item.Add(FT(DWSIM.App.GetLocalString("Quedadepresso"), su.spmp_deltaP), valor, False, DWSIM.App.GetLocalString("Parmetrosdeclculo2"), DWSIM.App.GetLocalString("Quedadepressoaplicad4"), True) With .Item(.Item.Count - 1) .Tag = New Object() {FlowSheet.Options.NumberFormat, su.spmp_deltaP, "DP"} .CustomEditor = New DWSIM.Editors.Generic.UIUnitConverter End With .Item.Add(DWSIM.App.GetLocalString("HeaterCoolerCalcMode"), Me, "CalcMode", False, DWSIM.App.GetLocalString("Parmetrosdeclculo2"), "", True) Select Case Me.CalcMode Case CalculationMode.HeatRemoved valor = Format(Conversor.ConverterDoSI(su.spmp_heatflow, Me.DeltaQ.GetValueOrDefault), FlowSheet.Options.NumberFormat) .Item.Add(FT(DWSIM.App.GetLocalString("CalorRemovido"), su.spmp_heatflow), valor, False, DWSIM.App.GetLocalString("Parmetrosdeclculo2"), DWSIM.App.GetLocalString("Quantidadedecalorced"), True) With .Item(.Item.Count - 1) .Tag = New Object() {FlowSheet.Options.NumberFormat, su.spmp_heatflow, "E"}

.CustomEditor = New DWSIM.Editors.Generic.UIUnitConverter End With Case CalculationMode.OutletTemperature valor = Format(Conversor.ConverterDoSI(su.spmp_temperature, Me.OutletTemperature.GetValueOrDefault), FlowSheet.Options.NumberFormat) .Item.Add(FT(DWSIM.App.GetLocalString("HeaterCoolerOutletTemperature"), su.spmp_temperature), valor, False, DWSIM.App.GetLocalString("Parmetrosdeclculo2"), "", True) With .Item(.Item.Count - 1) .Tag = New Object() {FlowSheet.Options.NumberFormat, su.spmp_temperature, "T"} .CustomEditor = New DWSIM.Editors.Generic.UIUnitConverter End With Case CalculationMode.OutletVaporFraction valor = Format(Me.OutletVaporFraction.GetValueOrDefault, FlowSheet.Options.NumberFormat) .Item.Add(DWSIM.App.GetLocalString("FraomolardafaseFaseV"), valor, False, DWSIM.App.GetLocalString("Parmetrosdeclculo2"), "", True) End Select .Item.Add(DWSIM.App.GetLocalString("Eficincia0100"), Me, "Eficiencia", False, DWSIM.App.GetLocalString("Parmetrosdeclculo2"), DWSIM.App.GetLocalString("Eficinciadoaquecedor2"), True) With .Item(.Item.Count - 1) .DefaultValue = Nothing .DefaultType = GetType(Nullable(Of Double)) End With If Me.GraphicObject.Calculated And Not Me.CalcMode = CalculationMode.HeatRemoved Then valor = Format(Conversor.ConverterDoSI(su.spmp_heatflow, Me.DeltaQ.GetValueOrDefault), FlowSheet.Options.NumberFormat) .Item.Add(FT(DWSIM.App.GetLocalString("CalorRemovido"), su.spmp_heatflow), valor, True, DWSIM.App.GetLocalString("Resultados3"), DWSIM.App.GetLocalString("Quantidadedecalorced"), True) End If .Item.Add(FT(DWSIM.App.GetLocalString("DeltaT2"), su.spmp_deltaT), Format(Conversor.ConverterDoSI(su.spmp_deltaT, Me.DeltaT.GetValueOrDefault), FlowSheet.Options.NumberFormat), True, DWSIM.App.GetLocalString("Resultados3"), DWSIM.App.GetLocalString("Diferenadetemperatur"), True) With .Item(.Item.Count - 1) .DefaultValue = Nothing .DefaultType = GetType(Nullable(Of Double)) End With If Me.GraphicObject.Calculated = False Then

.Item.Add(DWSIM.App.GetLocalString("Mensagemdeerro"), Me, "ErrorMessage", True, DWSIM.App.GetLocalString("Miscelnea4"), DWSIM.App.GetLocalString("Mensagemretornadaqua"), True) With .Item(.Item.Count - 1) .DefaultType = GetType(System.String) End With End If If Me.IsSpecAttached = True Then .Item.Add(DWSIM.App.GetLocalString("ObjetoUtilizadopor"), FlowSheet.Collections.ObjectCollection(Me.AttachedSpecId).GraphicObject.Tag , True, DWSIM.App.GetLocalString("Miscelnea4"), "", True) .Item.Add(DWSIM.App.GetLocalString("Utilizadocomo"), Me.SpecVarType, True, DWSIM.App.GetLocalString("Miscelnea4"), "", True) End If If Not Me.Annotation Is Nothing Then .Item.Add(DWSIM.App.GetLocalString("Anotaes"), Me, "Annotation", False, DWSIM.App.GetLocalString("Outros"), DWSIM.App.GetLocalString("Cliquenobotocomretic"), True) With .Item(.Item.Count - 1) .IsBrowsable = False .CustomEditor = New DWSIM.Editors.Annotation.UIAnnotationEditor End With End If End With End Sub Public Overrides Function GetPropertyValue(ByVal prop As String, Optional ByVal su As SistemasDeUnidades.Unidades = Nothing) As Object If su Is Nothing Then su = New DWSIM.SistemasDeUnidades.UnidadesSI Dim cv As New DWSIM.SistemasDeUnidades.Conversor Dim value As Double = 0 Dim propidx As Integer = CInt(prop.Split("_")(2)) Select Case propidx Case 0 'PROP_HT_0 Pressure Drop value = cv.ConverterDoSI(su.spmp_deltaP, Me.DeltaP.GetValueOrDefault) Case 1 'PROP_HT_1(Efficiency) value = Me.Eficiencia.GetValueOrDefault Case 2 'PROP_HT_2 Outlet Temperature value = cv.ConverterDoSI(su.spmp_temperature, Me.OutletTemperature.GetValueOrDefault) Case 3 'PROP_CL_3 Heat Removed value = cv.ConverterDoSI(su.spmp_heatflow, Me.DeltaQ.GetValueOrDefault) Case 4 'PROP_HT_4(Delta - T)

value = cv.ConverterDoSI(su.spmp_deltaT, Me.DeltaT.GetValueOrDefault) End Select Return value End Function Public Overloads Overrides Function GetProperties(ByVal proptype As SimulationObjects_BaseClass.PropertyType) As String() Dim i As Integer = 0 Dim proplist As New ArrayList Select Case proptype Case PropertyType.RO For i = 4 To 4 proplist.Add("PROP_CL_" + CStr(i)) Next Case PropertyType.RW For i = 0 To 4 proplist.Add("PROP_CL_" + CStr(i)) Next Case PropertyType.WR For i = 0 To 3 proplist.Add("PROP_CL_" + CStr(i)) Next Case PropertyType.ALL For i = 0 To 4 proplist.Add("PROP_CL_" + CStr(i)) Next End Select Return proplist.ToArray(GetType(System.String)) proplist = Nothing End Function Public Overrides Function SetPropertyValue(ByVal prop As String, ByVal propval As Object, Optional ByVal su As DWSIM.SistemasDeUnidades.Unidades = Nothing) As Object If su Is Nothing Then su = New DWSIM.SistemasDeUnidades.UnidadesSI Dim cv As New DWSIM.SistemasDeUnidades.Conversor Dim propidx As Integer = CInt(prop.Split("_")(2)) Select Case propidx Case 0 'PROP_HT_0 Pressure Drop Me.DeltaP = cv.ConverterParaSI(su.spmp_deltaP, propval) Case 1 'PROP_HT_1(Efficiency) Me.Eficiencia = propval Case 2 'PROP_HT_2 Outlet Temperature Me.OutletTemperature = cv.ConverterParaSI(su.spmp_temperature, propval) Case 3 'PROP_HT_3 Heat Added Me.DeltaQ = cv.ConverterParaSI(su.spmp_heatflow, propval)

End Select Return 1 End Function Public Overrides Function GetPropertyUnit(ByVal prop As String, Optional ByVal su As SistemasDeUnidades.Unidades = Nothing) As Object If su Is Nothing Then su = New DWSIM.SistemasDeUnidades.UnidadesSI Dim cv As New DWSIM.SistemasDeUnidades.Conversor Dim value As String = "" Dim propidx As Integer = CInt(prop.Split("_")(2)) Select Case propidx Case 0 'PROP_HT_0 Pressure Drop value = su.spmp_deltaP Case 1 'PROP_HT_1(Efficiency) value = "" Case 2 'PROP_HT_2 Outlet Temperature value = su.spmp_temperature Case 3 'PROP_HT_3 Heat Added value = su.spmp_heatflow Case 4 'PROP_HT_4(Delta - T) value = su.spmp_deltaT End Select Return value End Function End Class End Namespace

S-ar putea să vă placă și