Feed Flash (Short)

posted in: C#, Code Snippets 0

This code-snippet in C# shows how to use flash methods short version.

using CCAPI;
using System;
using System.IO;
/* Feed stream will be defined by the user.
 * Use CHEMCAD TPflash calculation and retrieve the calculated liquid
 * and vapor stream, and the k-values at equilibrium. */

namespace User_Flash
{
    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(),
                "..\\...\\OneFeed.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.ReadLine();
                return;
            }
            // Load the flowsheet
            Flowsheet flowsheet = chemcad.CurrentFlowsheet;

            //Collection of the components
            ComponentCollection components = flowsheet.Components;
            Component firstComponent = components.GetComponentAt(0);
            Component secondComponent = components.GetComponentAt(1);
            Component thirdComponent = components.GetComponentAt(2);

            //Enter flowrates of the components
            float firstComponentflowrate = 20;
            float secondComponentflowrate = 20;
            float thirdComponentflowrate = 20;


            FlowRateCurUnits flowFirst = new FlowRateCurUnits(firstComponent, firstComponentflowrate);
            FlowRateCurUnits flowSecond = new FlowRateCurUnits(secondComponent, secondComponentflowrate);
            FlowRateCurUnits flowThird = new FlowRateCurUnits(thirdComponent, thirdComponentflowrate);

            //Defining array of the flowrate of the components 
            FlowRateCurUnits[] flows = new FlowRateCurUnits[] { flowFirst, flowSecond, flowThird };


            //Calculating the flash method results
            FlashResult flashResults = flowsheet.CalculateTPFlash(100, 2, -15444, 50, 2, flows);

            //Reading the flash results
            StreamResult streamLiquid = flashResults.LiquidStream;
            StreamResult streamVapor = flashResults.VaporStream;
            ComponentValueCollection kValues;
            kValues = flashResults.KValues;
            Console.WriteLine("Vapor fraction after flashing the stream: " + flashResults.MoleVaporFraction);
            Console.WriteLine("Enthalpy of vapor stream is " + streamVapor.Enthalpy + " " + flowsheet.UnitsCurrent.EnthalpyRate + "\n");
            Console.WriteLine("Enthalpy of liquid stream is " + streamLiquid.Enthalpy + " " + flowsheet.UnitsCurrent.EnthalpyRate + "\n");
            int counter = 0;

            //Display results of K-Values
            foreach (ComponentValue comp in kValues)
            {
                Console.WriteLine("The K-Value of " + comp.Component.Name + " is " + comp.Amount + "\n");
                counter++;

            }
            Console.WriteLine("Press Any Key To Exit");
            Console.ReadLine(); ;
        }
    }
}


Output:

Files:
Download OneFeed.cc7