Anda di halaman 1dari 11

' ' ' ' ' ' by ' ' ' ' ' ' ' ' '

'

Energy Recycle Calculation Routines Copyright 2009 Daniel Wagner O. de Medeiros This file is part of DWSIM. DWSIM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published the Free Software Foundation, either version 3 of the License, or (at your 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/>. Microsoft.MSDN.Samples.GraphicObjects DWSIM.DWSIM.SimulationObjects.SpecialOps.Helpers.Recycle LukeSw.Windows.Forms System.ComponentModel PropertyGridEx DWSIM.DWSIM.Flowsheet.FlowSheetSolver

Imports Imports Imports Imports Imports Imports

Namespace DWSIM.SimulationObjects.SpecialOps <System.Serializable()> Public Class EnergyRecycle Inherits SimulationObjects_UnitOpBaseClass Protected Protected Protected Protected Protected Protected Protected Protected m_ConvPar As ConvergenceParametersE m_ConvHist As ConvergenceHistoryE m_AccelMethod As AccelMethod = AccelMethod.Wegstein m_WegPars As WegsteinParameters m_MaxIterations As Integer = 10 m_IterationCount As Integer = 0 m_InternalCounterE As Integer = 0 m_IterationsTaken As Integer = 0

Public Property IterationsTaken() As Integer Get Return m_IterationsTaken End Get Set(ByVal value As Integer) m_IterationsTaken = value End Set End Property Public Property IterationCount() As Integer Get Return m_IterationCount End Get Set(ByVal value As Integer) m_IterationCount = value

End Set End Property Public Property WegsteinParameters() As WegsteinParameters Get Return m_WegPars End Get Set(ByVal value As WegsteinParameters) m_WegPars = value End Set End Property Public Property AccelerationMethod() As AccelMethod Get Return m_AccelMethod End Get Set(ByVal value As AccelMethod) m_AccelMethod = value End Set End Property Public Property ConvergenceParameters() As ConvergenceParametersE Get Return m_ConvPar End Get Set(ByVal value As ConvergenceParametersE) m_ConvPar = value End Set End Property Public Property ConvergenceHistory() As ConvergenceHistoryE Get Return m_ConvHist End Get Set(ByVal value As ConvergenceHistoryE) m_ConvHist = value End Set End Property Public Property MaximumIterations() As Integer Get Return Me.m_MaxIterations End Get Set(ByVal value As Integer) Me.m_MaxIterations = value End Set End Property Public Sub New(ByVal nome As String, ByVal descricao As String) MyBase.CreateNew() m_ConvPar = New ConvergenceParametersE m_ConvHist = New ConvergenceHistoryE m_WegPars = New WegsteinParameters

Me.m_ComponentName = nome Me.m_ComponentDescription = descricao Me.FillNodeItems() Me.QTFillNodeItems() End Sub Public Overrides Sub QTFillNodeItems() With Me.QTNodeTableItems .Clear() .Add(0, New DWSIM.Outros.NodeItem(DWSIM.App.GetLocalString("Iteraes"), "", "", 0, 0, "")) .Add(1, New DWSIM.Outros.NodeItem(DWSIM.App.GetLocalString("ErroE"), "", "", 1, 0, "")) End With End Sub Public 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 Try 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 .Item(0).Value = Me.IterationsTaken .Item(0).Unit = ""

valor = Format(Conversor.ConverterDoSI(su.spmp_deltaT, Me.ConvergenceHistory.EnergyE), nf) .Item(1).Value = valor .Item(1).Unit = su.spmp_deltaT End With Catch ex As Exception End Try End Sub 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.OutputConnectors(0).IsAttached Then 'Call function to calculate flowsheet With objargs .Calculado = False .Nome = Me.Nome .Tipo = TipoObjeto.OT_Reciclo End With CalculateFlowsheet(FlowSheet, objargs, Nothing) Throw New Exception(DWSIM.App.GetLocalString("Nohcorrentedeenergia2")) ElseIf Not Me.GraphicObject.InputConnectors(0).IsAttached Then 'Call function to calculate flowsheet With objargs .Calculado = False .Nome = Me.Nome .Tipo = TipoObjeto.OT_Reciclo End With CalculateFlowsheet(FlowSheet, objargs, Nothing) Throw New Exception(DWSIM.App.GetLocalString("Nohcorrentedeenergia2")) End If Dim Enew As Double Dim ees As DWSIM.SimulationObjects.Streams.EnergyStream = form.Collections.CLCS_EnergyStreamCollection(Me.GraphicObject.InputConn ectors(0).AttachedConnector.AttachedFrom.Name) With ees Me.ConvergenceHistory.EnergyE = .Energia.GetValueOrDefault - Me.ConvergenceHistory.Energy Me.ConvergenceHistory.EnergyE0 = Me.ConvergenceHistory.Energy - Me.ConvergenceHistory.Energy0

Me.ConvergenceHistory.Energy0 = Me.ConvergenceHistory.Energy Me.ConvergenceHistory.Energy = .Energia.GetValueOrDefault End With If Me.IterationCount <= 3 Then SS: Else Select Case Me.AccelerationMethod Case AccelMethod.None GoTo SS Case AccelMethod.Wegstein If Me.WegsteinParameters.AccelDelay <= Me.IterationCount + 3 Then Dim sE, qE As Double sE = (Me.ConvergenceHistory.EnergyE Me.ConvergenceHistory.EnergyE0) / (Me.ConvergenceHistory.Energy Me.ConvergenceHistory.Energy0) qE = sE / (sE - 1) If Me.WegsteinParameters.AccelFreq <= Me.m_InternalCounterE And Double.IsNaN(sE) = False And qE > Me.WegsteinParameters.Qmin And qE < Me.WegsteinParameters.Qmax Then Enew = Me.ConvergenceHistory.EnergyE * (1 - qE) + Me.ConvergenceHistory.Energy * qE Me.m_InternalCounterE = 0 Else Enew = Me.ConvergenceHistory.Energy Me.m_InternalCounterE += 1 End If Else GoTo SS End If End Select End If 'Corrente de energia - atualizar valor da potncia (kJ/s) Dim es As DWSIM.SimulationObjects.Streams.EnergyStream = form.Collections.CLCS_EnergyStreamCollection(Me.GraphicObject.OutputCon nectors(0).AttachedConnector.AttachedTo.Name) Enew = Me.ConvergenceHistory.Energy

With es .Energia = Enew .GraphicObject.Calculated = True End With If Me.IterationCount >= Me.MaximumIterations Then Dim msgres As MsgBoxResult = VDialog.Show(DWSIM.App.GetLocalString("Onmeromximodeiteraes"), _ Me.GraphicObject.Tag & " - " & DWSIM.App.GetLocalString("Nmeromximodeiteraesa3"), _ MessageBoxButtons.YesNo, MessageBoxIcon.Question) If msgres = MsgBoxResult.No Then GoTo final Else Me.IterationCount = 0 End If End If Me.IterationCount += 1 If Math.Abs(Me.ConvergenceHistory.EnergyE) > Me.ConvergenceParameters.Energy Then 'Call function to calculate flowsheet With objargs .Calculado = True .Nome = Me.Nome .Tipo = TipoObjeto.OT_EnergyRecycle End With form.CalculationQueue.Enqueue(objargs) Else final: Me.IterationsTaken = Me.IterationCount.ToString Me.IterationCount = 0 End If

Me.UpdatePropertyNodes(form.Options.SelectedUnitSystem, form.Options.NumberFormat) End Function Public Overrides Function DeCalculate() As Integer Dim form As Global.DWSIM.FormFlowsheet = My.Application.ActiveSimulation Me.IterationCount = 0 End Function Function MAX(ByVal Vv As Object) Dim n = UBound(Vv) Dim mx As Double

If n >= 1 Then Dim i As Integer = 1 mx = Vv(i - 1) i = 0 Do If Vv(i) > mx Then mx = Vv(i) End If i += 1 Loop Until i = n + 1 Return mx Else Return Vv(0) End If End Function 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() Dim ent, saida 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 .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.UIInputESSelector 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.UIOutputESSelector End With .Item.Add(DWSIM.App.GetLocalString("Mtododeacelerao"), Me, "AccelerationMethod", False, DWSIM.App.GetLocalString("Configuraes2"), DWSIM.App.GetLocalString("Mtododeaceleraodacon"), True) If Me.AccelerationMethod = DWSIM.SimulationObjects.SpecialOps.Helpers.Recycle.AccelMethod.Wegstein Then Dim cpc As New CustomPropertyCollection cpc.Add(DWSIM.App.GetLocalString("Atrasonaacelerao"), Me.WegsteinParameters, "AccelDelay", False, DWSIM.App.GetLocalString("ParmetrosWegstein"), "", True) cpc.Add(DWSIM.App.GetLocalString("Ferqunciadeacelerao"), Me.WegsteinParameters, "AccelFreq", False, DWSIM.App.GetLocalString("ParmetrosWegstein"), "", True) cpc.Add(DWSIM.App.GetLocalString("Qmnimo"), Me.WegsteinParameters, "Qmin", False, DWSIM.App.GetLocalString("Wegstein"), "", True) cpc.Add(DWSIM.App.GetLocalString("Qmximo"), Me.WegsteinParameters, "Qmax", False, DWSIM.App.GetLocalString("Wegstein"), "", True) .Item.Add(DWSIM.App.GetLocalString("ParmetrosWegstein"), cpc, True, DWSIM.App.GetLocalString("Configuraes2"), DWSIM.App.GetLocalString("ParmetrosdomtododeWe")) With .Item(.Item.Count - 1) .IsBrowsable = True .BrowsableLabelStyle = BrowsableTypeConverter.LabelStyle.lsEllipsis End With End If .Item.Add(DWSIM.App.GetLocalString("NmeroMximodeIteraes"), Me, "MaximumIterations", False, DWSIM.App.GetLocalString("Configuraes2"), DWSIM.App.GetLocalString("Nmeromximodeiteraesd"), True) Dim valor As Double valor = Format(Conversor.ConverterDoSI(su.spmp_heatflow, Me.ConvergenceParameters.Energy), FlowSheet.Options.NumberFormat) .Item.Add(FT(DWSIM.App.GetLocalString("Energia"), su.spmp_heatflow), valor, False, DWSIM.App.GetLocalString("Parmetrosdeconvergn3"), "", True) .Item.Add(DWSIM.App.GetLocalString("Iteraesnecessrias"), Me, "IterationsTaken", True, DWSIM.App.GetLocalString("Resultados4"), DWSIM.App.GetLocalString("Nmerodeiteraesusadas"), True) valor = Format(Conversor.ConverterDoSI(su.spmp_deltaT, Me.ConvergenceHistory.EnergyE), FlowSheet.Options.NumberFormat)

.Item.Add(FT(DWSIM.App.GetLocalString("Erronaenergia"), su.spmp_heatflow), valor, True, DWSIM.App.GetLocalString("Resultados4"), DWSIM.App.GetLocalString("Diferenaentreosvalor"), True) 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 .ExpandAllGridItems() 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_ER_0 Maximum Iterations value = Me.MaximumIterations Case 1 'PROP_ER_1 Power Tolerance value = cv.ConverterDoSI(su.spmp_heatflow, Me.ConvergenceParameters.Energy) Case 2 'PROP_ER_2 Power Error value = cv.ConverterDoSI(su.spmp_heatflow, Me.ConvergenceHistory.EnergyE) 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 = 2 To 2 proplist.Add("PROP_ER_" + CStr(i)) Next Case PropertyType.RW

For i = 0 To 2 proplist.Add("PROP_ER_" + CStr(i)) Next Case PropertyType.WR For i = 0 To 1 proplist.Add("PROP_ER_" + CStr(i)) Next Case PropertyType.ALL For i = 0 To 2 proplist.Add("PROP_ER_" + 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_RY_0 Maximum Iterations Me.MaximumIterations = propval Case 1 'PROP_ER_1 Power Tolerance Me.ConvergenceParameters.Energy = 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_ER_0 Maximum Iterations value = "" Case 1 'PROP_ER_1 Power Tolerance value = su.spmp_heatflow Case 2 'PROP_ER_2 Power Error value = su.spmp_heatflow

End Select Return value End Function End Class End Namespace Namespace DWSIM.SimulationObjects.SpecialOps.Helpers.Recycle <System.Serializable()> Public Class ConvergenceParametersE Public Energy As Double = 0.1 Sub New() End Sub End Class <System.Serializable()> Public Class ConvergenceHistoryE Public Energy As Double = 0 Public Energy0 As Double = 0 Public EnergyE As Double = 0 Public EnergyE0 As Double = 0 Sub New() End Sub End Class End Namespace

Anda mungkin juga menyukai