Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Creating a model for cross flow Heat Exchanger

Creating a model for cross flow Heat Exchanger

Hello OM users,
I am writing, because maybe somebody is familiar with this topic and will help.
I tried to develop a model of cross flow heat exchanger, but the checker always tells me that the system is under-constrained (28 variables and 26 equations) I have no idea where is the problem, so I am attaching my code below:

within HeatPump;

model Condenser

  // For 100% Vapour- 1 phase of Refr.
  //outer Modelica.Fluid.System system "System properties";

  import SI = Modelica.SIunits;
  import IF = Modelica.Fluid.Interfaces;

  //parameter SI.MassFlowRate m_flow_min =0.001 " Smallest Mass flow rate in model";
  replaceable package Medium_1 = Modelica.Media.Air.SimpleAir constrainedby
    Modelica.Media.Interfaces.PartialMedium "Fluid 1"
                             annotation(choicesAllMatching);
  replaceable package Medium_2 = Modelica.Media.R134a.R134a_ph constrainedby
    Modelica.Media.Interfaces.PartialMedium "Fluid 2"
                             annotation(choicesAllMatching);
   
// Declaration of the state of the both Fluid


Medium_1.ThermodynamicState State_1;
Medium_2.ThermodynamicState State_2;

 
 
  parameter SI.Area Aref = 1 "Tube with refrigerant contact area";
  parameter SI.CoefficientOfHeatTransfer href = 1;
  parameter SI.CoefficientOfHeatTransfer hair=1;
  parameter SI.Area Aair = 1 "Air with condenser contact area";
  parameter SI.Area Ao = 1;
  parameter SI.Efficiency etao = 1;


  Modelica.Fluid.Interfaces.FluidPort_a port_a(redeclare package Medium = Medium_2) "Inlet refrigerant" annotation(
    Placement(visible = true, transformation(extent = {{-110, -10}, {-90, 10}}, rotation = 0), iconTransformation(extent = {{-10, 88}, {12, 110}}, rotation = 0)));
   
  Modelica.Fluid.Interfaces.FluidPort_b port_b(redeclare package Medium = Medium_2) "Outlet refrigerant" annotation(
    Placement(visible = true,transformation(extent = {{90, -10}, {110, 10}}, rotation = 0), iconTransformation(extent = {{92, -10}, {114, 12}}, rotation = 0)));
   
  Modelica.Fluid.Interfaces.FluidPort_a port_a1(redeclare package Medium = Medium_1) "Inlet air" annotation(
    Placement(visible = true,transformation(extent = {{-10, 90}, {10, 110}}, rotation = 0), iconTransformation(origin = {-99, 1}, extent = {{-11, -11}, {11, 11}}, rotation = 0)));
   
  Modelica.Fluid.Interfaces.FluidPort_b port_b1(redeclare package Medium = Medium_1) "Outlet air" annotation(
    Placement(visible = true,transformation(origin = {1.33227e-15, -100}, extent = {{-10, 10}, {10, -10}}, rotation = 0), iconTransformation(origin = {1, -99}, extent = {{-11, -11}, {11, 11}}, rotation = 0)));


   Real Cair = port_a1.m_flow * Medium_1.specificHeatCapacityCp(State_1);
   Real Cref = port_a.m_flow * Medium_2.specificHeatCapacityCp(State_2);
   Real Cmin = min(Cair, Cref);
   Real Cmax = max(Cair, Cref);
   Real Cx = Cmin / Cmax;
   Real UA = 1/(1 / href * Aref + 1 / etao * hair * Ao);
   Real NTU = UA / Cmin;
   Real eps1 = 1 - exp(1 / Cx * NTU ^ 0.22 * (exp(-Cx * NTU ^ 0.78) - 1));
   Real Q = eps1 * Cmin * (Medium_2.temperature(State_2)-Medium_1.temperature(State_1));

 
equation
 
State_1=Medium_1.setState_phX(
port_a1.p,
port_a1.h_outflow,
port_a1.Xi_outflow);

State_2=Medium_2.setState_phX(
port_a.p,
port_a.h_outflow,
port_a.Xi_outflow);


  port_b.h_outflow = port_a.h_outflow + (Q/port_a.m_flow);
  port_b1.h_outflow = port_a1.h_outflow+ (Q/port_a1.m_flow);
 
  0=port_a.m_flow+port_b.m_flow;
  0=port_a1.m_flow+port_b1.m_flow;
 
  port_a.p=port_b.p;
  port_a1.p=port_b1.p;
   
  port_a1.Xi_outflow=port_b1.Xi_outflow;
  port_a.Xi_outflow=port_b.Xi_outflow;
 
  port_a1.C_outflow=port_b1.C_outflow;
  port_a.C_outflow=port_b.C_outflow;
 
  annotation(
    Icon(graphics = {Rectangle(fillPattern = FillPattern.Solid, extent = {{-100, 80}, {100, -80}}), Rectangle(origin = {1, 64}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-101, 6}, {99, -14}}), Rectangle(origin = {1, 24}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-101, 6}, {99, -14}}), Rectangle(origin = {1, -18}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-101, 6}, {99, -14}}), Rectangle(origin = {1, -56}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-101, 6}, {99, -14}}), Rectangle(origin = {87, 0}, rotation = 90, fillPattern = FillPattern.Solid, extent = {{-81, 2}, {81, -14}}), Rectangle(origin = {-99, 0}, rotation = 90, fillPattern = FillPattern.Solid, extent = {{-81, 2}, {81, -14}})}));
end Condenser;

all the parameters are just for an example.

Maybe someone have made such a model and have some advice? Thanks in advance.


I also made a test bench for that:

within HeatPump;

model Condenser_Test

replaceable package Medium_1= Modelica.Media.Air.MoistAir;
replaceable package Medium_2=Modelica.Media.R134a.R134a_ph;

  Condenser condenser1 annotation(
    Placement(visible = true, transformation(origin = {-2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
   
  Modelica.Fluid.Sources.MassFlowSource_h boundary(
 
  redeclare package Medium=Medium_2,h = 280,
  m_flow = 0.005,
  nPorts = 1,
  use_h_in = false, use_m_flow_in = false)  annotation(
    Placement(visible = true, transformation(origin = {-70, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
 
 
  Modelica.Fluid.Sources.MassFlowSource_h boundary2(
  redeclare package Medium = Medium_1,
  h = 76.9,
  m_flow = 0.05,
  nPorts = 1,
  use_m_flow_in = false)  annotation(
    Placement(visible = true, transformation(origin = {-2, 44}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
 
 
  Modelica.Fluid.Sources.Boundary_pT boundary4( 
  redeclare package Medium=Medium_2, T = 280, nPorts = 1, p = 1e5,
  use_T_in = false,
  use_X_in = false, use_p_in = false)  annotation(
    Placement(visible = true, transformation(origin = {48, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
 
 
  Modelica.Fluid.Sources.Boundary_pT boundary5( 
  redeclare package Medium=Medium_1, T = 278, p = 1e5,
  use_T_in = false,
  use_X_in = false, use_p_in = false)  annotation(
    Placement(visible = true, transformation(origin = {-2, -52}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
 
 
  inner Modelica.Fluid.System system(allowFlowReversal = false, energyDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial, m_flow_start = 0.005, massDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial, momentumDynamics = Modelica.Fluid.Types.Dynamics.DynamicFreeInitial)  annotation(
    Placement(visible = true, transformation(origin = {70, 72}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(condenser1.port_b1, boundary5.ports[1]) annotation(
    Line(points = {{-2, -10}, {-2, -10}, {-2, -42}, {-2, -42}}, color = {0, 127, 255}));
  connect(condenser1.port_b, boundary4.ports[1]) annotation(
    Line(points = {{8, 0}, {36, 0}, {36, 0}, {38, 0}}, color = {0, 127, 255}));
  connect(boundary.ports[1], condenser1.port_a) annotation(
    Line(points = {{-60, 0}, {-12, 0}, {-12, 0}, {-12, 0}}, color = {0, 127, 255}));
  connect(boundary2.ports[1], condenser1.port_a1) annotation(
    Line(points = {{-2, 34}, {-2, 34}, {-2, 10}, {-2, 10}}, color = {0, 127, 255}));
end Condenser_Test;

but while solving error occurs:

[1] 18:50:11 Translation Error
[HeatPump.Condenser_Test: 46:3-47:88]: Incompatible components in connect statement: connect(condenser1.port_b1, boundary5.ports[1])
- condenser1.port_b1 has components {C_outflow, Xi_outflow, h_outflow, m_flow, p}
- boundary5.ports[1] has components {C_outflow, Xi_outflow, h_outflow, m_flow, p}



Re: Creating a model for cross flow Heat Exchanger

Hi:

I have made a fast look to your code. I made a small change to your Condenser_Test model:

Condenser condenser1(redeclare package Medium_1=Medium_1, redeclare package Medium_2=Medium_2) annotation(
    Placement(visible = true, transformation(origin = {-2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));

I think that perhaps the problem was in the incompatibility of the Mediums. Your are passing the Medium definition from the condenser to its ports, but you are not granting the same Medium for the boundaries and the condenser ports. In fact you are declaring SimpleAir inside the condenser and MoistAir at the boundary.
In the code is missing also  nPorts=1 for boundary5.
After making these changes I get that the model has 143 equations and 146 variables.
I will look further to your  code. I am developing some open source libraries for media definition,  fluid flow, and heat exchange and, although I do not like Modelica.Fluid too much (the stream approach complicates things in excess), I want to better check some applications with Modelica.Fluid.

Carlos

Re: Creating a model for cross flow Heat Exchanger

Hi:

ModelicaTests3.mo

I finished the review and I found the following issues:
There is a miss-understanding about how stream variables work. When you use port_a.h_outflow you are taking the value of h at the port when the flow is going out of the port. But you are using the port as an inlet, so you need to retrieve the value of h for the inlet flow using the function inStream. So the enthalpy variation must be written as:
port_b.h_outflow = inStream(port_a.h_outflow) + (Q/port_a.m_flow);
It is the same for the others stream variables, and for any reference at the value of the variables when the flow is coming in.
The second point is referenced to the lack of equations. For each stream variable there are two associated values: the value when the flow is going in and the value when is going out. When you are connecting the ports ‘a’ to its boundaries, the out value of the boundary is going to the in value of your port, but the out value of your port remains unsolved. As you are using the port ‘a’ as an inlet, this value means nothing, but it is necessary. So, I added:
  port_a.h_outflow=inStream(port_a.h_outflow);
  port_a1.h_outflow=inStream(port_a1.h_outflow);
  port_a.Xi_outflow=inStream(port_a.Xi_outflow);

After doing this the model compiled but didn’t converge. Here there is a recurrent problem with the  medium usage. When you are coming from enthalpy and you need temperature, some mediums use a nonlinear solver type regula-falsi, but if the initial value of enthalpy is outside the expected bracket the solution is not found. It is quite difficult to know which enthalpy value must be assigned to the boundary because the enthalpy value depends also on the selected standard state reference. Normally refrigerants media use the ASHRAE reference (saturated liquid at -40ºC). You can test in a separate model the enthalpy that corresponds to your T and p. I have changed the boundary 2 enthalpy to 3.1e5.
You will find the find the working models as Condenser2 and Condenser_Test2 in the attached file.

Attachments:
There are 0 guests and 0 other users also viewing this topic
You are here: