# -*- 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_registryfromtespy.tools.document_modelsimportgenerate_latex_eq
[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]defmass_flow_func_doc(self,label):r""" Calculate the residual value for mass flow balance equation. Parameters ---------- label : str Label for equation. Returns ------- latex : str LaTeX code of equations applied. """latex=(r'0 =\sum\dot{m}_{\mathrm{in},i}-\sum\dot{m}_{\mathrm{out},j}'r'\;\forall i \in \text{inlets}, \forall j \in \text{outlets}')returngenerate_latex_eq(self,latex,label)
[docs]defmass_flow_deriv(self,k):r""" Calculate partial derivatives for mass flow equation. Returns ------- deriv : list Matrix with partial derivatives for the fluid equations. """foriinself.inl:ifi.m.is_var:self.jacobian[k,i.m.J_col]=1foroinself.outl:ifo.m.is_var:self.jacobian[k,o.m.J_col]=-1
[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_equality_deriv(self,k):r""" Calculate partial derivatives for all pressure equations. Returns ------- deriv : ndarray Matrix with partial derivatives for the fluid equations. """ifself.num_i>1:conns=self.inl[1:]+self.outlelse:conns=self.outlforeq,oinenumerate(conns):ifself.inl[0].p.is_var:self.jacobian[k+eq,self.inl[0].p.J_col]=1ifo.p.is_var:self.jacobian[k+eq,o.p.J_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