component jet_pump
inputs
    Anozzle      = { 1e-4,   'm^2'       };  
end
nodes
  A = foundation.thermal_liquid.thermal_liquid; 
    B = foundation.thermal_liquid.thermal_liquid; 
    C = foundation.thermal_liquid.thermal_liquid; 
end
parameters
    length  = { 1e-1,  'm'         };  
    area    = { 1e-2,   'm^2'       };  
    An_min  = { 1e-10,  'm^2'       };  
    Ath     = { 1e-4,   'm^2'       };  
    Ad      = { 1e-3,   'm^2'       };  
    Kn    = { 0.05,   '1'         };  
    Ken     = { 0.005,  '1'         };  
    Kth     = { 0.1,    '1'         };  
    Kdi     = { 0.1,    '1'         };  
end
variables
  
    mdot_A          = { 0,      'kg/s'  };  
    mdot_B          = { 0,      'kg/s'  };  
    mdot_C          = { 0,      'kg/s'  };  
    Phi_A           = { 0,      'J/s'  };   
    Phi_B           = { 0,      'J/s'   };   
    Phi_C           = { 0,      'J/s'   };   
    p               = { 1.01325,'bar'   };  
end
variables(Conversion=absolute)
    T               = { 293.15,  'K'     };   
end
variables(Access = protected)
    Phi_convection_A= { 0,      'J/s'   };  
    Phi_convection_B= { 0,      'J/s'  };  
    Phi_convection_C= { 0,      'J/s'  };  
      
      
      u    = { 84,  'J/g'   };  
     u_A  = { 84,  'J/g'   };  
     u_B  = { 84,  'J/g'   };  
      u_C  = { 84,  'J/g'   };  
      
     rho     = {998.2,  'kg/m^3'  };  
     rho_A   = {998.2,   'kg/m^3'    };  
       rho_B   = {998.2,   'kg/m^3'    };  
      rho_C   = {998.2,   'kg/m^3'    };  
      
     cp      = { 4.16,         'J/(g*K)'   };  
      alpha   = { -2.0691e-04,  '1/K'      };  
      k       = { 598.5,          'mW/(m*K)'  };  
     
     beta  = { 2.1791,  'GPa'      };  
       nu      = { 1,      'mm^2/s'  };  
  end
branches
    mdot_A : A.mdot -> *;
    mdot_B : B.mdot -> *;
    mdot_C : C.mdot -> *;
    Phi_A  : A.Phi  -> *;
    Phi_B  : B.Phi  -> *;
    Phi_C  : C.Phi  -> *;
end
equations   
    let 
          
          An = if Anozzle < An_min, An_min else Anozzle end;
          
          p_A  = A.p;
          T_A = A.T;
          p_B  = B.p;
          T_B = B.T;
          p_C  = C.p;
          T_C = C.T;
        
          Gth = if k*(area/2)/(length/2) <= A.G_min, A.G_min else k*(area/2)/(length/2) end;     
          
          p_dv_A = A.p * mdot_A * if gt(mdot_A, 0), 1/rho_A - 1/rho else 1/rho - 1/rho end;
          p_dv_B = B.p * mdot_B * if gt(mdot_B, 0), 1/rho_B - 1/rho else 1/rho - 1/rho end;
          p_dv_C = C.p * mdot_C * if gt(mdot_C, 0), 1/rho_C - 1/rho else 1/rho - 1/rho end;
          
          u_out_A = tablelookup(A.T_TLU, A.p_TLU, A.u_TLU, T, p_A, interpolation = linear, extrapolation = nearest);
          u_out_B = tablelookup(B.T_TLU, B.p_TLU, A.u_TLU, T, p_B, interpolation = linear, extrapolation = nearest);
          u_out_C = tablelookup(C.T_TLU, C.p_TLU, A.u_TLU, T, p_C, interpolation = linear, extrapolation = nearest);
          
          b = An / Ath;
          c = (1 - b) / b;
          Z = rho_A * (((mdot_A / rho_A)^2) / (2 * An^2));
          M = mdot_B / mdot_A;
          a = Ath / Ad;
      in
          
          Phi_convection_A == mdot_A * if gt(mdot_A, 0), u_A else u_out_A end;
          Phi_convection_B == mdot_B * if gt(mdot_B, 0), u_B else u_out_B end; 
          Phi_convection_C == mdot_C * if gt(mdot_C, 0), u_C else u_out_C end; 
          
  
          mdot_A == (An/sqrt(1+Kn))*(sqrt((2/rho_A)*(abs(A.p-p))))*rho_A*(A.p-p)/abs(A.p-p); 
  
          mdot_B == (An*c/sqrt(1+Ken))*(sqrt((2/rho_B)*(abs(B.p-p))))*rho_B*(B.p-p)/abs(B.p-p); 
          0 == mdot_A + mdot_B+ mdot_C;
          
          C.p-p == Z*(b^2)*((2/b)+(2/1-b)*M^2-((1+M)^2)*(1+Kth+Kdi+a^2)); 
          
          
          Phi_A == Phi_convection_A + Gth * (A.T - T);
          Phi_B == Phi_convection_B + Gth * (B.T - T);
          Phi_C == Phi_convection_C + Gth * (C.T - T);
  
  
  
           
           0 == Phi_A + Phi_B + p_dv_A + p_dv_B+Phi_C + p_dv_C;  
  
          
          u       == tablelookup(A.T_TLU, A.p_TLU, A.u_TLU, T, p, interpolation = linear, extrapolation = nearest);
          u_A     == tablelookup(A.T_TLU, A.p_TLU, A.u_TLU, T_A, p_A, interpolation = linear, extrapolation = nearest);
          u_B     == tablelookup(A.T_TLU, A.p_TLU, A.u_TLU, T_B, p_B, interpolation = linear, extrapolation = nearest);
          u_C     == tablelookup(A.T_TLU, A.p_TLU, A.u_TLU, T_C, p_C, interpolation = linear, extrapolation = nearest);
          rho     == tablelookup(A.T_TLU, A.p_TLU, A.rho_TLU, T, p, interpolation = linear, extrapolation = nearest);
          rho_A   == tablelookup(A.T_TLU, A.p_TLU, A.rho_TLU, T_A , p_A, interpolation = linear, extrapolation = nearest);
          rho_B   == tablelookup(A.T_TLU, A.p_TLU, A.rho_TLU, T_B , p_B, interpolation = linear, extrapolation = nearest);
          rho_C   == tablelookup(A.T_TLU, A.p_TLU, A.rho_TLU, T_C , p_C, interpolation = linear, extrapolation = nearest);
          nu      == tablelookup(A.T_TLU, A.p_TLU, A.nu_TLU, T, p, interpolation = linear, extrapolation = nearest);
          cp      == tablelookup(A.T_TLU, A.p_TLU, A.cp_TLU, T, p, interpolation = linear, extrapolation = nearest);
          alpha   == tablelookup(A.T_TLU, A.p_TLU, A.alpha_TLU, T, p, interpolation = linear, extrapolation = nearest);
          k       == tablelookup(A.T_TLU, A.p_TLU, A.k_TLU, T, p, interpolation = linear, extrapolation = nearest);
          beta    == tablelookup(A.T_TLU, A.p_TLU, A.beta_TLU, T, p, interpolation = linear, extrapolation = nearest);
      end
  end
end