static void Main(string[] args) { DWSIM.Automation.Automation interf = new DWSIM.Automation.Automation(); var samples = Directory.EnumerateFiles("samples", "*.dwxm*", SearchOption.TopDirectoryOnly).OrderBy(x => x).ToList(); var fossee = Directory.EnumerateFiles("tests", "*.dwxm*", SearchOption.TopDirectoryOnly).OrderBy(x => x).ToList(); var basic = Directory.EnumerateFiles(Path.Combine("tests", "basic"), "*.dwxm*", SearchOption.TopDirectoryOnly).OrderBy(x => x).ToList(); Console.WriteLine(); Console.WriteLine("[SET 1/3] Testing Basic Blocks..."); Console.WriteLine(); RunTests(basic, interf); Console.WriteLine(); Console.WriteLine("[SET 2/3] Testing Sample Flowsheets..."); Console.WriteLine(); samples = samples.Where(x => !x.Contains("Dynamic") && !x.Contains("Cantera") && !x.Contains("Pervaporation")).ToList(); RunTests(samples, interf); Console.WriteLine(); Console.WriteLine("[SET 3/3] Testing FOSSEE Flowsheets..."); Console.WriteLine(); RunTests(fossee, interf); }
static void Main() { // replace with DWSIM's installation directory on your computer System.IO.Directory.SetCurrentDirectory("C:/Program Files/DWSIM5"); //create automation manager DWSIM.Automation.Automation interf = new DWSIM.Automation.Automation(); DWSIM.Interfaces.IFlowsheet sim; //load *.dwxmz empty simulation file string fileName = "simulation_template.dwxmz"; sim = interf.LoadFlowsheet(fileName); var c1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.Cooler, 100, 100, "COOLER-001"); var e1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.EnergyStream, 130, 150, "HEAT_OUT"); var m1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.MaterialStream, 50, 100, "INLET"); var m2 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.MaterialStream, 150, 100, "OUTLET"); // create the graphic object connectors manually as they are not being drawn on screen. ((dynamic)c1.GraphicObject).PositionConnectors(); ((dynamic)m1.GraphicObject).PositionConnectors(); ((dynamic)m2.GraphicObject).PositionConnectors(); ((dynamic)e1.GraphicObject).PositionConnectors(); // connect the graphic objects. sim.ConnectObjects(m1.GraphicObject, c1.GraphicObject, 0, 0); sim.ConnectObjects(c1.GraphicObject, m2.GraphicObject, 0, 0); sim.ConnectObjects(c1.GraphicObject, e1.GraphicObject, 0, 0); // create and add an instance of PR Property Package var pr = new DWSIM.Thermodynamics.PropertyPackages.PengRobinsonPropertyPackage(); pr.ComponentName = "Peng-Robinson (PR)"; pr.ComponentDescription = "Any Description"; // <-- important to set any text as description. sim.AddPropertyPackage(pr); m1.PropertyPackage = sim.PropertyPackages.Values.First(); m2.PropertyPackage = sim.PropertyPackages.Values.First(); c1.PropertyPackage = sim.PropertyPackages.Values.First(); // request a calculation sim.RequestCalculation(); // save file as dwxmz (compressed XML) string fileNameToSave = "created_file.dwxmz"; interf.SaveFlowsheet(sim, fileNameToSave, true); }
static void RunTests(List <string> filelist, DWSIM.Automation.Automation interf) { TimeSpan totaltime; var partials = new List <TimeSpan>(); DateTime dt0, dp0, dpf; dt0 = DateTime.Now; System.IO.Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); DWSIM.Interfaces.IFlowsheet sim; List <Exception> errors; int totaltests, passedtests = 0, i = 1; totaltests = filelist.Count; var failed = new List <string>(); foreach (var s in filelist) { dp0 = DateTime.Now; Console.WriteLine(); Console.WriteLine("[" + i + "/" + totaltests + "] " + "Loading '" + Path.GetFileNameWithoutExtension(s) + "'..."); Console.WriteLine(); string status = "PASSED"; try { sim = interf.LoadFlowsheet(s); Console.WriteLine(); Console.WriteLine("[" + i + "/" + totaltests + "] " + "Running '" + Path.GetFileNameWithoutExtension(s) + "'..."); Console.WriteLine(); errors = interf.CalculateFlowsheet2(sim); if (errors.Count > 0) { status = "FAILED"; failed.Add(Path.GetFileNameWithoutExtension(s)); } else { passedtests += 1; } } catch { status = "FAILED"; failed.Add(Path.GetFileNameWithoutExtension(s)); } finally { dpf = DateTime.Now; } partials.Add(dpf - dp0); Console.WriteLine(); Console.WriteLine("[" + i + "/" + totaltests + "] " + "Test Result for '" + Path.GetFileNameWithoutExtension(s) + "': " + status + ", time taken: " + (dpf - dp0).TotalSeconds.ToString("N2") + " s"); Console.WriteLine(); i += 1; } totaltime = DateTime.Now - dt0; double srate = (double)passedtests / (double)totaltests * 100; Console.WriteLine("Success Rate: " + srate.ToString("N2") + "% (" + passedtests + "/" + totaltests + ")"); Console.WriteLine("Total Elapsed Time: " + totaltime.ToString()); if (failed.Count > 0) { Console.WriteLine(); Console.WriteLine("Failed Tests:"); foreach (var s in failed) { Console.WriteLine(s); } Console.WriteLine(); } //Console.WriteLine("Press Any Key to Continue..."); //Console.ReadKey(); }
static void Main() { System.IO.Directory.SetCurrentDirectory("C:/Program Files/DWSIM5"); // replace with DWSIM's installation directory on your computer //create automation manager DWSIM.Automation.Automation interf = new DWSIM.Automation.Automation(); DWSIM.Interfaces.IFlowsheet sim; // workaround DWSIM.GlobalSettings.Settings.OldUI = false; // base path var basepath = "//Mac/Home/Downloads/"; //load *.dwxml empty simulation file string fileName = basepath + "Simulation_template.dwxml"; sim = interf.LoadFlowsheet(fileName); var c1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.Cooler, 100, 100, "COOLER-001"); var e1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.EnergyStream, 130, 150, "HEAT_OUT"); var m1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.MaterialStream, 50, 100, "INLET"); var m2 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.MaterialStream, 150, 100, "OUTLET"); // create the graphic object connectors manually as they are not being drawn on screen. ((dynamic)c1.GraphicObject).PositionConnectors(); ((dynamic)m1.GraphicObject).PositionConnectors(); ((dynamic)m2.GraphicObject).PositionConnectors(); ((dynamic)e1.GraphicObject).PositionConnectors(); // connect the graphic objects. sim.ConnectObjects(m1.GraphicObject, c1.GraphicObject, 0, 0); sim.ConnectObjects(c1.GraphicObject, m2.GraphicObject, 0, 0); sim.ConnectObjects(c1.GraphicObject, e1.GraphicObject, 0, 0); // create and add an instance of NRTL Property Package var nrtl = new DWSIM.Thermodynamics.PropertyPackages.NRTLPropertyPackage(); nrtl.ComponentName = "NRTL"; nrtl.ComponentDescription = "Any Description"; // <-- important to set any text as description. sim.AddPropertyPackage(nrtl); m1.PropertyPackage = sim.PropertyPackages.Values.First(); m2.PropertyPackage = sim.PropertyPackages.Values.First(); c1.PropertyPackage = sim.PropertyPackages.Values.First(); // set inlet stream temperature // default properties: T = 298.15 K, P = 101325 Pa, Mass Flow = 1 kg/s var ms1 = (DWSIM.Thermodynamics.Streams.MaterialStream)m1; ms1.SetTemperature(400); // K // set cooler outlet temperature var cooler = (DWSIM.UnitOperations.UnitOperations.Cooler)c1; cooler.CalcMode = DWSIM.UnitOperations.UnitOperations.Cooler.CalculationMode.OutletTemperature; cooler.OutletTemperature = 320; // K // request a calculation sim.RequestCalculation(); Console.WriteLine(String.Format("Cooler Heat Load: {0} kW", cooler.DeltaQ.GetValueOrDefault())); // compounds var selected = sim.SelectedCompounds; var available = sim.AvailableCompounds; var ethanol = available["Ethanol"]; selected.Add("Ethanol", ethanol); // add ethanol compound to existing material streams // this is not exposed directly to the user, but can be done in a future update using a simplified function. foreach (var obj in sim.SimulationObjects.Values.Where(x => x is DWSIM.Thermodynamics.Streams.MaterialStream)) { var ms = (DWSIM.Thermodynamics.Streams.MaterialStream)obj; foreach (DWSIM.Thermodynamics.BaseClasses.Phase p in ms.Phases.Values) { var comp = new DWSIM.Thermodynamics.BaseClasses.Compound("Ethanol", ""); comp.ConstantProperties = ethanol; p.Compounds.Add("Ethanol", comp); } } // change overall molar composition of m1 ms1.SetOverallComposition(new [] { 0.3, 0.3, 0.4 }); // methanol, water, ethanol // request a calculation sim.RequestCalculation(); Console.WriteLine(String.Format("Cooler Heat Load: {0} kW", cooler.DeltaQ.GetValueOrDefault())); // change cooler calculation mode cooler.CalcMode = DWSIM.UnitOperations.UnitOperations.Cooler.CalculationMode.OutletVaporFraction; cooler.OutletVaporFraction = 0.3; // K // request a calculation sim.RequestCalculation(); // get outlet ms vapor fraction var ms2 = (DWSIM.Thermodynamics.Streams.MaterialStream)m2; var msvf = ms2.GetPhase("Vapor").Properties.molarfraction.GetValueOrDefault(); Console.WriteLine(String.Format("Cooler Heat Load: {0} kW", cooler.DeltaQ.GetValueOrDefault())); Console.WriteLine(String.Format("Outlet Vapor Fraction: {0}", msvf)); // save file string fileNameToSave = basepath + "Created_file_HeatExchanger.dwxml"; interf.SaveFlowsheet(sim, fileNameToSave, false); //use true for dwxmz Console.WriteLine("Done! press any key to close."); Console.ReadKey(); }