Is there a way to create multiple pseudo components at once by providing all the component properties. I have an excel table of components and their properties (MW, Density and Boiling Point). Want to create those components all at once rather than one by one through the UI.
Any approach will be appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
importclrimportSystemclr.AddReference("DWSIM")clr.AddReference("System.Core")clr.AddReference("System.Windows.Forms")clr.ImportExtensions(System.Linq)clr.AddReference("DWSIM.Interfaces")clr.AddReference("DWSIM.SharedClasses")clr.AddReference("Newtonsoft.Json")fromSystemimport*fromDWSIMimport*fromDWSIMimportFormPCBulkfromDWSIM.Interfacesimport*fromDWSIM.Interfaces.Enumsimport*fromDWSIM.Interfaces.Enums.GraphicObjectsimport*fromDWSIM.Thermodynamicsimport*fromDWSIM.Thermodynamics.BaseClassesimport*fromDWSIM.Thermodynamics.PropertyPackages.Auxiliaryimport*fromDWSIM.Thermodynamics.Utilities.PetroleumCharacterizationimportGenerateCompoundsfromDWSIM.Thermodynamics.Utilities.PetroleumCharacterization.Methodsimport*fromNewtonsoft.JsonimportJsonConvert,Formatting# assay data from spreadsheetnames=["NBP46","NBP65","NBP85","NBP105","NBP115"]relative_densities=[677.3/1000.0,694.2/1000.0,712.1/1000.0,729.2/1000.0,739.7/1000.0]# relativenbps=[46+273.15,65+273.15,85+273.15,105+273.15,115+273.15]# Kn=5# bulk c7+ pseudocompound creator settingsTccorr="Riazi-Daubert (1985)"Pccorr="Riazi-Daubert (1985)"AFcorr="Lee-Kesler (1976)"MWcorr="Winn (1956)"adjustZR=TrueadjustAf=True# initial values for MW, SG and NBPmw0=65sg0=0.65nbp0=310# pseudocompound generatorcomps=GenerateCompounds()foriinrange(0,n):# will generate only 1 pseudocompound for each item on the list of assay data. Normally we generate from 7 to 10 pseudocompounds for each set of assay data (MW, SG and NBP)comp_results=comps.GenerateCompounds(names[i],1,Tccorr,Pccorr,AFcorr,MWcorr,adjustAf,adjustZR,None,relative_densities[i],nbps[i],None,None,None,None,mw0,sg0,nbp0)comp_values=list(comp_results.Values)comp_values[0].Name=names[i]comp_values[0].ConstantProperties.Name=names[i]comp_values[0].ComponentName=names[i]# save the compound to a JSON file, which can be loaded back on any simulationSystem.IO.File.WriteAllText("C:\\Users\\[YOURUSERNAME]\\Desktop\\"+str(names[i])+".json",JsonConvert.SerializeObject(comp_values[0].ConstantProperties,Formatting.Indented))# the following is for calculation quality check only, not required but desiredmyassay=SharedClasses.Utilities.PetroleumCharacterization.Assay.Assay(0,relative_densities[i],nbps[i],0,0,0,0)ms_check=Streams.MaterialStream("","")ms_check.SetFlowsheet(Flowsheet)ms_check.PropertyPackage=Flowsheet.PropertyPackages.Values.ToList()[0]c1=Compound(names[i],names[i])c1.ConstantProperties=comp_values[0].ConstantPropertiesms_check.Phases[0].Compounds.Add(names[i],c1)c2=Compound(names[i],names[i])c2.ConstantProperties=comp_values[0].ConstantPropertiesms_check.Phases[1].Compounds.Add(names[i],c2)c3=Compound(names[i],names[i])c3.ConstantProperties=comp_values[0].ConstantPropertiesms_check.Phases[2].Compounds.Add(names[i],c3)c4=Compound(names[i],names[i])c4.ConstantProperties=comp_values[0].ConstantPropertiesms_check.Phases[3].Compounds.Add(names[i],c4)c5=Compound(names[i],names[i])c5.ConstantProperties=comp_values[0].ConstantPropertiesms_check.Phases[4].Compounds.Add(names[i],c5)c6=Compound(names[i],names[i])c6.ConstantProperties=comp_values[0].ConstantPropertiesms_check.Phases[5].Compounds.Add(names[i],c6)c7=Compound(names[i],names[i])c7.ConstantProperties=comp_values[0].ConstantPropertiesms_check.Phases[6].Compounds.Add(names[i],c7)c8=Compound(names[i],names[i])c8.ConstantProperties=comp_values[0].ConstantPropertiesms_check.Phases[7].Compounds.Add(names[i],c8)ms_check.EqualizeOverallComposition()qc=QualityCheck(myassay,ms_check)System.Windows.Forms.MessageBox.Show(str(names[i])+" quality report:\n\n"+qc.GetQualityCheckReport())
Last edit: Daniel Medeiros 2019-09-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
Is there a way to create multiple pseudo components at once by providing all the component properties. I have an excel table of components and their properties (MW, Density and Boiling Point). Want to create those components all at once rather than one by one through the UI.
Any approach will be appreciated.
You can do it with a Python script. Can you share a snippet of your table?
The component density and boiling point are present in this attached table. All the rest is to be estimated from the correlations present.
The following works:
Last edit: Daniel Medeiros 2019-09-04