Heat Curve Points

posted in: C#, Code Snippets 0

This code-snippet in C# shows how to calculate the points of heat curves.

using CCAPI;
using System;
using System.IO;
using CCAPI.UnitOperations;

//Get the Heat Curve points of a heat exchnager by using Equal cut enthalpy method. 
//This method returns the temperature points using enthalpy and pressure. 
namespace Kvalues
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initiate a new instance of CHEMCAD
            Console.WriteLine("Initializing CC-API...");
            Server chemcad;
            //Put your .NET Interface key here
            var license_key="...";
            try
            {
                chemcad = new Server(license_key);
            }

            // If the server doesn't respond or
            // if reply results in end of program:
            catch (Exception ex)
            {
                // Display server message and close after key is pushed
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                return;
            }

            // Open a CHEMCAD file relative from the current directory
            string path = Path.Combine(Directory.GetCurrentDirectory(),
                "..\\..\\Bulk.cc7");
            Console.WriteLine("Opening: " + path + "...\n");
            try
            {
                chemcad.LoadFlowsheet(path);
            }
            // If flowsheet cannot be opened:
            catch (Exception ex)
            {
                // Display error message and close after key is pushed
                Console.WriteLine(ex.Message);
                Console.WriteLine("Press Any Key To Exit");
                Console.ReadLine();
                return;
            }
            // Load the flowsheet

            Flowsheet flowsheet = chemcad.CurrentFlowsheet;

            //Read the current flowsheet engineering units

            var units = flowsheet.UnitsCurrent;

            //Select the heat exchanger from the flowsheet

            HeatExchanger hetx = (HeatExchanger)flowsheet.GetUnitOperationById(8);

            //Perform the heat curve method to get the corresponding results

            var results = flowsheet.HeatCurveEqualCutH(hetx,11);
            var hotStream = results.HotStream;
            var coldStream = results.ColdStream;

            //Write the results to the command window

            Console.WriteLine(String.Format("{0,-5} {1,-14} {2,-14} {3,-10} {4,-10} {5,-10} {6,-10}", "NP", "Temperature", "Pressure"
               , "Del H", "Vapor", "Liquid", "Vapor mole frac." +
               ""));
            Console.WriteLine(String.Format("{0,-5} {1,-14} {2,-14} {3,-10} {4,-10} {5,-10} {6,-10}", "", units.Temperature, units.Pressure
                , units.EnthalpyRate, units.MolarFlowRate, units.MolarFlowRate, ""));
            for (int i = 0; i < 11; i++)
            {

                Console.WriteLine(String.Format("{0,-5} {1,-14} {2,-14} {3,-10} {4,-10} {5,-10} {6,5}", i.ToString(), coldStream.Temperature[i], coldStream.Pressure[i]
                , coldStream.DeltaH[i], coldStream.VaporMolarFlowrate[i], coldStream.LiquidMolarFlowrate[i], coldStream.VaporFraction[i]));

            }
            Console.WriteLine("");
            Console.WriteLine(String.Format("{0,-5} {1,-14} {2,-14} {3,-10} {4,-10} {5,-10} {6,-10}", "NP", "Temperature", "Pressure"
               , "Del H", "Vapor", "Liquid", "Vapor mole frac." +
               ""));
            Console.WriteLine(String.Format("{0,-5} {1,-14} {2,-14} {3,-10} {4,-10} {5,-10} {6,-10}", "", units.Temperature, units.Pressure
                , units.EnthalpyRate, units.MolarFlowRate, units.MolarFlowRate, ""));
            for (int i = 0; i <span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>< 11; i++)
            {
                Console.WriteLine(String.Format("{0,-5} {1,-14} {2,-14} {3,-10} {4,-10} {5,-10} {6,5}", i.ToString(), hotStream.Temperature[i], hotStream.Pressure[i]
               , hotStream.DeltaH[i], hotStream.VaporMolarFlowrate[i], hotStream.LiquidMolarFlowrate[i], hotStream.VaporFraction[i]));
            }

            Console.ReadLine();

        }
    }
}



Output:

 

Files:
Download Bulk.cc7