public void addValue(Bed[] bed, Condenser cond, Evaporator eva, int timeStep) { array_bed1_pressure[timeStep] = bed[0].averagePressure; array_bed2_pressure[timeStep] = bed[1].averagePressure; array_cond_pressure[timeStep] = cond.averagePressure; array_eva_pressure[timeStep] = eva.averagePressure; array_bed1_phase[timeStep] = bed[0].phase; array_bed2_phase[timeStep] = bed[1].phase; }
public void condensationOnCondenserTubeSurface(Condenser cond, out double rateOfCondensation) { int r = cond.numOfRNodes_fluid + cond.numOfRNodes_tubeWall - 1; //saturated temperature for adsorbate double A = 8.07131, B = 1730.63, C = 233.426; double T_sat = (B / (A - Math.Log10(cond.averagePressure * 0.00750062))) - C + 273; //averaged wall temperature double sum = 0; int count = 0; for (int z = 0; z < numOfZNodes; z++) { sum += T[r, z].TP; count++; } double T_wall = sum / count; //calculate modified latent heat of vaporisation double JakobNumber = cond.adsorbate.heatCapacity_condensed * (T_sat - T_wall) / cond.adsorbate.latentHeat; double modifiedLatentHeat = cond.adsorbate.latentHeat * (1 + 0.68 * JakobNumber); //calculate heat transfer coefficient for film condensation double g = 9.81; //kgm/s2 double c = 0.729; //for tube double numerator = g * cond.adsorbate.density_condensed * (cond.adsorbate.density_condensed - cond.adsorbate.density) * Math.Pow(cond.adsorbate.thermalConductivity_condensed, 3) * modifiedLatentHeat; double denominator = cond.adsorbate.dynamicViscosity_condensed * (T_sat - T_wall) * 2 * (cond.numOfRNodes_fluid + cond.numOfRNodes_tubeWall) * deltaR; double heatTransferCoefficient_condensation = c * Math.Pow(Math.Abs(numerator / denominator), 0.25) * deltaZ * cond.numOfZNodes; double heatOfCondensation = 0; rateOfCondensation = 0; if ((T_sat - T_wall) > 0) { //apply heat flux for (int z = 0; z < numOfZNodes; z++) { T[r, z].aN = 0; T[r, z].Sc = 2 * Math.PI * T[r, z].rn * deltaZ * heatTransferCoefficient_condensation * (T_sat - T_wall); T[r, z].aP = T[r, z].aW + T[r, z].aE + T[r, z].aS + T[r, z].aN + T[r, z].aP0 - T[r, z].Sp + T[r, z].deltaF; } heatOfCondensation = heatTransferCoefficient_condensation * cond.tubeOuterSurfaceArea * (T_sat - T_wall); rateOfCondensation = heatOfCondensation / modifiedLatentHeat; } }
public void assignBoundary_for_cond(Condenser cond) { int rtop = cond.numOfRNodes_fluid + cond.numOfRNodes_tubeWall; for (int r = 0; r < rtop; r++) { for (int z = 0; z < numOfZNodes; z++) { T[r, z].boundary = Boundary.Center; if (z == 0) { T[r, z].boundary = Boundary.Left; } else if (z == (numOfZNodes - 1)) { T[r, z].boundary = Boundary.Right; } if (r == 0) { T[r, z].boundary = Boundary.Bottom; if (z == 0) { T[r, z].boundary = Boundary.BottomLeft; } else if (z == (numOfZNodes - 1)) { T[r, z].boundary = Boundary.BottomRight; } } else if (r == (rtop - 1)) { T[r, z].boundary = Boundary.Top; if (z == 0) { T[r, z].boundary = Boundary.TopLeft; } else if (z == (numOfZNodes - 1)) { T[r, z].boundary = Boundary.TopRight; } } } } }
public void updateCoefficients2(double inletTemperature, Condenser cond) { foreach (TNodes node in T) { //inlet temperature if (node.boundary == Boundary.Left || node.boundary == Boundary.BottomLeft) { if (node.materialType == MaterialType.HeatExchangeFluid) { node.Sc = (2 * node.Dw + node.Fw) * inletTemperature; node.Sp = -(2 * node.Dw + node.Fw); node.aP = node.aW + node.aE + node.aS + node.aN + node.aP0 - node.Sp + node.deltaF; } } } //condensation on tube surface condensationOnCondenserTubeSurface(cond, out cond.rateOfCondensation); }
public CondTemperaturePDE(Condenser cond) { deltaR = cond.deltaR; deltaZ = cond.deltaZ; numOfRNodes = cond.numOfRNodes; numOfZNodes = cond.numOfZNodes; T = cond.T; assignBoundary_for_cond(cond); //initial conditions foreach (TNodes node in T) { node.TP0 = Parameters.T0; node.TP = node.TP0; } assignCoefficients2_for_cond(cond); }
static void Main(string[] args) { //define chambers Bed[] bed = new Bed[Parameters.numOfBed]; for (int i = 0; i < Parameters.numOfBed; i++) { bed[i] = new Bed(); } Condenser cond = new Condenser(); Evaporator eva = new Evaporator(); //define connecting pipes ConnectingPipes[] connectingPipe = new ConnectingPipes[Parameters.numOfBed + 1 + 1]; connectingPipe[0] = new ConnectingPipes(bed[0], cond); connectingPipe[1] = new ConnectingPipes(bed[1], cond); connectingPipe[2] = new ConnectingPipes(eva, bed[0]); connectingPipe[3] = new ConnectingPipes(eva, bed[1]); //define time plots TemperaurePlot temperaturePlot = new TemperaurePlot(); PressurePlot pressurePlot = new PressurePlot(); //define performance indicators PerformanceIndicator.initialise(); Report.initialise(bed); //starting operation int cycle = 1; for (int timeStep = 1; timeStep <= Parameters.numOfTimeStep; timeStep++) { if (timeStep > 1) { updateNodeAtNewTimeStep(bed[0]); updateq(bed[0]); updateNodeAtNewTimeStep(bed[1]); updateq(bed[1]); updateNodeAtNewTimeStep(cond); updateNodeAtNewTimeStep(eva); } if (timeStep > ((cycle - 1) * 2 * Parameters.switchingTime * Parameters.timeStepPerSecond) && timeStep <= (Parameters.switchingTime * Parameters.timeStepPerSecond + (cycle - 1) * 2 * (Parameters.switchingTime + Parameters.sorptionTime) * Parameters.timeStepPerSecond)) { //Phase bed[0].phase = Phase.Preheating; bed[1].phase = Phase.Precooling; cond.phase = Phase.NA; eva.phase = Phase.NA; updateMassFlowrate(connectingPipe); //switching time List <Task> TaskList = new List <Task>(); Task task1 = new Task(bed[0].preheating); task1.Start(); TaskList.Add(task1); Task task2 = new Task(bed[1].precooling); task2.Start(); TaskList.Add(task2); Task task3 = new Task(cond.disconnected); task3.Start(); TaskList.Add(task3); Task task4 = new Task(eva.disconnected); task4.Start(); TaskList.Add(task4); Task.WaitAll(TaskList.ToArray()); } else if (timeStep > ((Parameters.switchingTime + (cycle - 1) * 2 * (Parameters.switchingTime + Parameters.sorptionTime)) * Parameters.timeStepPerSecond) && timeStep <= ((Parameters.switchingTime + Parameters.sorptionTime + (cycle - 1) * 2 * (Parameters.switchingTime + Parameters.sorptionTime)) * Parameters.timeStepPerSecond)) { //Phase bed[0].phase = Phase.Desorption; bed[1].phase = Phase.Adsorption; cond.phase = Phase.Desorption; eva.phase = Phase.Adsorption; updateMassFlowrate(connectingPipe); //sorption time List <Task> TaskList = new List <Task>(); Task task1 = new Task(bed[0].desorption); task1.Start(); TaskList.Add(task1); Task task2 = new Task(bed[1].adsorption); task2.Start(); TaskList.Add(task2); Task.WaitAll(TaskList.ToArray()); cond.condensation(); eva.evaporation(); } else if (timeStep > ((Parameters.switchingTime + Parameters.sorptionTime + (cycle - 1) * 2 * (Parameters.switchingTime + Parameters.sorptionTime)) * Parameters.timeStepPerSecond) && timeStep <= ((2 * Parameters.switchingTime + Parameters.sorptionTime + (cycle - 1) * 2 * (Parameters.switchingTime + Parameters.sorptionTime)) * Parameters.timeStepPerSecond)) { //Phase bed[0].phase = Phase.Precooling; bed[1].phase = Phase.Preheating; cond.phase = Phase.NA; eva.phase = Phase.NA; updateMassFlowrate(connectingPipe); //switching time List <Task> TaskList = new List <Task>(); Task task1 = new Task(bed[0].precooling); task1.Start(); TaskList.Add(task1); Task task2 = new Task(bed[1].preheating); task2.Start(); TaskList.Add(task2); Task task3 = new Task(cond.disconnected); task3.Start(); TaskList.Add(task3); Task task4 = new Task(eva.disconnected); task4.Start(); TaskList.Add(task4); Task.WaitAll(TaskList.ToArray()); } else if (timeStep > ((2 * Parameters.switchingTime + Parameters.sorptionTime + (cycle - 1) * 2 * (Parameters.switchingTime + Parameters.sorptionTime)) * Parameters.timeStepPerSecond) && timeStep <= ((2 * Parameters.switchingTime + 2 * Parameters.sorptionTime + (cycle - 1) * 2 * (Parameters.switchingTime + Parameters.sorptionTime)) * Parameters.timeStepPerSecond)) { //Phase bed[0].phase = Phase.Adsorption; bed[1].phase = Phase.Desorption; cond.phase = Phase.Desorption; eva.phase = Phase.Adsorption; updateMassFlowrate(connectingPipe); //sorption time List <Task> TaskList = new List <Task>(); Task task1 = new Task(bed[0].adsorption); task1.Start(); TaskList.Add(task1); Task task2 = new Task(bed[1].desorption); task2.Start(); TaskList.Add(task2); Task.WaitAll(TaskList.ToArray()); cond.condensation(); eva.evaporation(); } if (timeStep == cycle * 2 * (Parameters.switchingTime + Parameters.sorptionTime) * Parameters.timeStepPerSecond) { cycle++; } //reset mass flow rate to 0 resetMassFlowRate(connectingPipe); //update aveage pressure bed[0].calculateAveragePressure(); bed[1].calculateAveragePressure(); cond.calculateAveragePressure(); eva.calculateAveragePressure(); bed[0].calculateAverageMass(); cond.calculateAverageMass(); //update time plots temperaturePlot.addValue(bed, cond, eva, timeStep); pressurePlot.addValue(bed, cond, eva, timeStep); //update performance indicators for (int i = 0; i < Parameters.numOfBed; i++) { if (bed[i].phase == Phase.Preheating || bed[i].phase == Phase.Desorption) { //heat input switch (i) { case 0: PerformanceIndicator.addBedValue(temperaturePlot.array_bed1_inlet[timeStep], temperaturePlot.array_bed1_outlet[timeStep], timeStep); break; case 1: PerformanceIndicator.addBedValue(temperaturePlot.array_bed2_inlet[timeStep], temperaturePlot.array_bed2_outlet[timeStep], timeStep); break; default: Console.WriteLine("more bed than declared"); Console.Read(); break; } } } //heat output PerformanceIndicator.addEvaValue(temperaturePlot.array_eva_inlet[timeStep], temperaturePlot.array_eva_outlet[timeStep], timeStep); //condensatation PerformanceIndicator.addCondensateValue(cond.rateOfCondensation, timeStep); //output the current time step Console.WriteLine("{0} of {1} time steps completed...", timeStep, Parameters.numOfTimeStep); Console.WriteLine("{0}" + " " + "{1}", bed[0].averagePressure, cond.averagePressure); Console.WriteLine("{0}" + " " + "{1}", bed[1].averagePressure, eva.averagePressure); } string cycleTime = (Parameters.switchingTime / 60).ToString() + "m " + (Parameters.sorptionTime / 60).ToString() + "m"; export_T(bed[0], cycleTime + " bed 1 temperature contour"); export_T(bed[1], cycleTime + " bed 2 temperature contour"); export_T(cond, cycleTime + " cond temperature contour"); export_T(eva, cycleTime + " eva temperature contour"); export_P(bed[0], cycleTime + " bed 1 pressure contour"); export_P(bed[1], cycleTime + " bed 2 pressure contour"); export_P(cond, cycleTime + " cond pressure contour"); export_P(eva, cycleTime + " eva pressure contour"); temperaturePlot.exportPlot(cycleTime + " temperature plot"); pressurePlot.exportPlot(cycleTime + " pressure plot"); PerformanceIndicator.calculatePerformance(bed, eva); Console.WriteLine("COP is {0}", PerformanceIndicator.COP); Report.publish(cycleTime + " report"); Console.WriteLine("Simulation is completed, press any key to close this window"); Console.Read(); }
public void TDMA2_for_cond(Condenser cond)//solve: west to east, sweep: south to north { int rtop = cond.numOfRNodes_fluid + cond.numOfRNodes_tubeWall; do { foreach (TNodes node in T) { node.TP_prime = node.TP; } for (int r = 0; r < rtop; r++) { //get from neighbour lines for (int z = 0; z < numOfZNodes; z++) { if (r == 0) { T[r, z].TS = 0; T[r, z].TN = T[r + 1, z].TP; } else if (r == (rtop - 1)) { T[r, z].TS = T[r - 1, z].TP; T[r, z].TN = 0; } else { T[r, z].TS = T[r - 1, z].TP; T[r, z].TN = T[r + 1, z].TP; } } } for (int r = 0; r < rtop; r++) { //set from west to east for (int z = 0; z < numOfZNodes; z++) { T[r, z].betaj = T[r, z].aW; T[r, z].alphaj = T[r, z].aE; T[r, z].Dj = T[r, z].aP; T[r, z].Cj = T[r, z].aS * T[r, z].TS + T[r, z].aN * T[r, z].TN + T[r, z].aP0 * T[r, z].TP0 + T[r, z].Sc; if (z == 0) { T[r, z].Aj = T[r, z].alphaj / (T[r, z].Dj); T[r, z].Cj_prime = (T[r, z].Cj) / (T[r, z].Dj); } else { T[r, z].Aj = T[r, z].alphaj / (T[r, z].Dj - T[r, z].betaj * T[r, z - 1].Aj); T[r, z].Cj_prime = (T[r, z].betaj * T[r, z - 1].Cj_prime + T[r, z].Cj) / (T[r, z].Dj - T[r, z].betaj * T[r, z - 1].Aj); } } } for (int r = 0; r < rtop; r++) { //solve from east to west for (int z = (numOfZNodes - 1); z >= 0; z--) { if (z == (numOfZNodes - 1)) { T[r, z].TP = T[r, z].Cj_prime; } else { T[r, z].TP = T[r, z].Aj * T[r, z + 1].TP + T[r, z].Cj_prime; } T[r, z].TP = Parameters.relaxationFactor_temperature * T[r, z].TP + (1 - Parameters.relaxationFactor_temperature) * T[r, z].TP_prime; if (double.IsNaN(T[r, z].TP)) { int test = 1; } } } endOfIteration = true; foreach (TNodes node in T) { node.error = Helper.calculate_error(node.TP, node.TP_prime); if (Math.Abs(node.error) < Parameters.tolerance_temperature) { node.isConverged = true; } else { node.isConverged = false; endOfIteration = false; break; } } iterationCounter++; } while (endOfIteration == false); }
public void assignCoefficients2_for_cond(Condenser cond) { int rtop = cond.numOfRNodes_fluid + cond.numOfRNodes_tubeWall; for (int r = 0; r < rtop; r++) { for (int z = 0; z < numOfZNodes; z++) { if (r == 0) { T[r, z].Dw = 2 * Math.PI * T[r, z].rp * deltaR * T[r, z].thermalConductivity / deltaZ; T[r, z].De = 2 * Math.PI * T[r, z].rp * deltaR * T[r, z].thermalConductivity / deltaZ; T[r, z].Ds = 2 * Math.PI * T[r, z].rs * deltaZ * 0.5 * (T[r, z].thermalConductivity + T[r, z].thermalConductivity) / deltaR; T[r, z].Dn = 2 * Math.PI * T[r, z].rn * deltaZ * 0.5 * (T[r, z].thermalConductivity + T[r + 1, z].thermalConductivity) / deltaR; } else if (r == (rtop - 1)) { T[r, z].Dw = 2 * Math.PI * T[r, z].rp * deltaR * T[r, z].thermalConductivity / deltaZ; T[r, z].De = 2 * Math.PI * T[r, z].rp * deltaR * T[r, z].thermalConductivity / deltaZ; T[r, z].Ds = 2 * Math.PI * T[r, z].rs * deltaZ * 0.5 * (T[r, z].thermalConductivity + T[r - 1, z].thermalConductivity) / deltaR; T[r, z].Dn = 2 * Math.PI * T[r, z].rn * deltaZ * 0.5 * (T[r, z].thermalConductivity + T[r, z].thermalConductivity) / deltaR; } else { T[r, z].Dw = 2 * Math.PI * T[r, z].rp * deltaR * T[r, z].thermalConductivity / deltaZ; T[r, z].De = 2 * Math.PI * T[r, z].rp * deltaR * T[r, z].thermalConductivity / deltaZ; T[r, z].Ds = 2 * Math.PI * T[r, z].rs * deltaZ * 0.5 * (T[r, z].thermalConductivity + T[r - 1, z].thermalConductivity) / deltaR; T[r, z].Dn = 2 * Math.PI * T[r, z].rn * deltaZ * 0.5 * (T[r, z].thermalConductivity + T[r + 1, z].thermalConductivity) / deltaR; } } } foreach (TNodes node in T) { node.aP0 = 2 * Math.PI * node.density * node.heatCapacity * node.rp * deltaR * deltaZ / Parameters.deltat; node.Fw = 2 * Math.PI * node.rp * deltaR * node.velocity * node.density * node.heatCapacity; node.Fe = 2 * Math.PI * node.rp * deltaR * node.velocity * node.density * node.heatCapacity; node.Fs = 2 * Math.PI * deltaZ * node.density * node.heatCapacity * 0 * node.rs; node.Fn = 2 * Math.PI * deltaZ * node.density * node.heatCapacity * 0 * node.rn; node.aW = Helper.max3(node.Fw, (node.Dw + 0.5 * node.Fw), 0); node.aE = Helper.max3(-node.Fe, (node.De - 0.5 * node.Fe), 0); node.aS = Helper.max3(node.Fs, (node.Ds + 0.5 * node.Fs), 0); node.aN = Helper.max3(-node.Fn, (node.Dn - 0.5 * node.Fn), 0); node.Sc = 0; node.Sp = 0; switch (node.boundary) { case Boundary.Left: node.aW = 0; break; case Boundary.Right: node.aE = 0; break; case Boundary.Bottom: node.aS = 0; break; case Boundary.Top: node.aN = 0; break; case Boundary.BottomLeft: node.aW = 0; node.aS = 0; break; case Boundary.BottomRight: node.aE = 0; node.aS = 0; break; case Boundary.TopLeft: node.aW = 0; node.aN = 0; break; case Boundary.TopRight: node.aE = 0; node.aN = 0; break; default: break; } node.deltaF = node.Fe - node.Fw + node.Fn - node.Fs; node.aP = node.aW + node.aE + node.aS + node.aN + node.aP0 - node.Sp + node.deltaF; } }
public void addValue(Bed[] bed, Condenser cond, Evaporator eva, int timeStep) { double sum_in, sum_out; double value_in, value_out; //for beds for (int i = 0; i < Parameters.numOfBed; i++) { sum_in = 0; sum_out = 0; value_in = 0; value_out = 0; //inlet temperature for (int r = 0; r < bed[i].numOfRNodes_fluid; r++) { sum_in += bed[i].T[r, 0].TP; } value_in = sum_in / bed[i].numOfRNodes_fluid; //outlet temperature for (int r = 0; r < bed[i].numOfRNodes_fluid; r++) { sum_out += bed[i].T[r, (bed[i].numOfZNodes - 1)].TP; } value_out = sum_out / bed[i].numOfRNodes_fluid; switch (i) { case 0: array_bed1_inlet[timeStep] = value_in; array_bed1_outlet[timeStep] = value_out; break; case 1: array_bed2_inlet[timeStep] = value_in; array_bed2_outlet[timeStep] = value_out; break; default: Console.WriteLine("more beds are sued than declared"); Console.Read(); break; } } //for condenser sum_in = 0; sum_out = 0; value_in = 0; value_out = 0; //inlet temperature for (int r = 0; r < cond.numOfRNodes_fluid; r++) { sum_in += cond.T[r, 0].TP; } value_in = sum_in / cond.numOfRNodes_fluid; //outlet temperature for (int r = 0; r < cond.numOfRNodes_fluid; r++) { sum_out += cond.T[r, (cond.numOfZNodes - 1)].TP; } value_out = sum_out / cond.numOfRNodes_fluid; array_cond_inlet[timeStep] = value_in; array_cond_outlet[timeStep] = value_out; //for evaporator sum_in = 0; sum_out = 0; value_in = 0; value_out = 0; //inlet temperature for (int r = 0; r < eva.numOfRNodes_fluid; r++) { sum_in += eva.T[r, 0].TP; } value_in = sum_in / eva.numOfRNodes_fluid; //outlet temperature for (int r = 0; r < eva.numOfRNodes_fluid; r++) { sum_out += eva.T[r, (eva.numOfZNodes - 1)].TP; } value_out = sum_out / eva.numOfRNodes_fluid; array_eva_inlet[timeStep] = value_in; array_eva_outlet[timeStep] = value_out; }