# -*- coding: utf-8"""Module of class NodeBase.This file is part of project TESPy (github.com/oemof/tespy). It's copyrightedby the contributors recorded in the version control history of the file,available from its original location tespy/components/nodes/base.pySPDX-License-Identifier: MIT"""fromtespy.components.componentimportComponentfromtespy.components.componentimportcomponent_registry
[docs]@component_registryclassNodeBase(Component):"""Class NodeBase is parent class for all components of submodule nodes."""
[docs]defmass_flow_func(self):r""" Calculate the residual value for mass flow balance equation. Returns ------- res : float Residual value of equation. .. math:: 0 = \sum \dot{m}_{in,i} - \sum \dot{m}_{out,j} \; \forall i \in inlets, \forall j \in outlets """res=0foriinself.inl:res+=i.m.val_SIforoinself.outl:res-=o.m.val_SIreturnres
[docs]defpressure_equality_func(self):r""" Calculate the residual values of pressure equality equations. Returns ------- residual : list Vector with residual value for pressure equality equations. .. math:: 0 = p_{in,1} - p_{in,i}\forall i \in \text{inlets > 1}\\ 0 = p_{in,1} - p_{out,j}\forall j \in \text{outlets} """residual=[]inl=[]ifself.num_i>1:inl=self.inl[1:]forcininl+self.outl:residual+=[self.inl[0].p.val_SI-c.p.val_SI]returnresidual
[docs]defpressure_structure_matrix(self,k):r""" Calculate partial derivatives for all pressure equations. """ifself.num_i>1:conns=self.inl[1:]+self.outlelse:conns=self.outlforeq,conninenumerate(conns):self._structure_matrix[k+eq,self.inl[0].p.sm_col]=1self._structure_matrix[k+eq,conn.p.sm_col]=-1
[docs]@staticmethoddefinitialise_source(c,key):r""" Return a starting value for pressure and enthalpy at outlet. Parameters ---------- c : tespy.connections.connection.Connection Connection to perform initialisation on. key : str Fluid property to retrieve. Returns ------- val : float Starting value for pressure/enthalpy in SI units. .. math:: val = \begin{cases} 10^5 & \text{key = 'p'}\\ 5 \cdot 10^5 & \text{key = 'h'} \end{cases} """ifkey=='p':return1e5elifkey=='h':return5e5
[docs]@staticmethoddefinitialise_target(c,key):r""" Return a starting value for pressure and enthalpy at inlet. Parameters ---------- c : tespy.connections.connection.Connection Connection to perform initialisation on. key : str Fluid property to retrieve. Returns ------- val : float Starting value for pressure/enthalpy in SI units. .. math:: val = \begin{cases} 10^5 & \text{key = 'p'}\\ 5 \cdot 10^5 & \text{key = 'h'} \end{cases} """ifkey=='p':return1e5elifkey=='h':return5e5