Menu

DWSIM Python.NET error ims1 not defiend

nihal
2021-03-15
2021-03-15
  • nihal

    nihal - 2021-03-15

    import numpy as np
    from scipy.integrate import odeint
    import math
    import System
    from System import IO
    MF=ims1.Phases[0].Properties.molarflow
    WF=ims1.Phases[0].Properties.massflow
    T=ims1.Phases[0].Properties.temperature #temperature
    P=ims1.Phases[0].Properties.pressure #Pressure

    defining the function

    def dehyd(y,z):
    ......... inputing the variables
    MF1=(ims1.Phases[0].Compounds['perhydrodibenzyltoulene'].MolarFlow)/1000 #molar flow rate of 18H-DBT (kmol/s)
    MF2=(ims1.Phases[0].Compounds['Dibenzyltoulene'].MolarFlow)/1000 #molar flow rate of DBT (kmol/s)
    MF3=(ims1.Phases[0].Compounds['Hydrogen'].MolarFlow)/1000 #molar flow rate of H2 (kmol/s)
    WF1=ims1.Phases[0].Compounds['perhydrodibenzyltoulene'].MassFlow #mass flow rate of 18H-DBT
    WF2=ims1.Phases[0].Compounds['Dibenzyltoulene'].MassFlow #mass flow rate of DBT
    WF3=ims1.Phases[0].Compounds['Hydrogen'].MassFlow #mass flow rate of H2
    inPDBT=(MF1/MF) #mole fraction
    inDBT=(MF2/MF) #mole fraction
    inH2=(MF3/MF) #mole fraction
    QDBT1=ims1.Phases[0].Compounds['perhydrodibenzyltoulene'].VolumetricFlow #m3/s
    QDBT2=ims1.Phases[0].Compounds['Dibenzyltoulene'].VolumetricFlow #m3/s
    QDBT3=ims1.Phases[0].Compounds['Hydrogen'].VolumetricFlow #m3/s
    usDBT1 =(QDBT1/(A)) #superficial velocity of 18H-DBT (m/s)
    ......... inputing the variables
    C1=y[0]
    C2=y[1]
    C3=y[2]
    dC1dz=equation
    dC2dz= equation
    dC3dz= equation
    return [dC1dz,dC2dz,dC3dz]
    #These are all in the same indent as def
    #Solving the ode
    MF1=(ims1.Phases[0].Compounds['perhydrodibenzyltoulene'].MolarFlow)/1000 #molar flow rate of 18H-DBT (kmol/s)
    MF2=(ims1.Phases[0].Compounds['Dibenzyltoulene'].MolarFlow)/1000 #molar flow rate of DBT (kmol/s)
    MF3=(ims1.Phases[0].Compounds['Hydrogen'].MolarFlow)/1000 #molar flow rate of H2 (kmol/s)
    QDBT1=ims1.Phases[0].Compounds['perhydrodibenzyltoulene'].VolumetricFlow #m3/s
    QDBT2=ims1.Phases[0].Compounds['Dibenzyltoulene'].VolumetricFlow #m3/s
    QDBT3=ims1.Phases[0].Compounds['Hydrogen'].VolumetricFlow #m3/s
    initial condition
    C1=(MF1/QDBT1)
    y0 = [C1,0,0]
    time points
    z = np.linspace(0,1,1000)
    solve ODE
    y = odeint(dehyd,y0,z)
    taking the output value of the diffrential equation
    Cend1=np.array(y[:,0])
    Cendlength1=len(Cend1)
    Cendvalue1=Cend1[Cendlength1-1]
    Cend2=np.array(y[:,1])
    Cendlength2=len(Cend2)
    Cendvalue2=Cend2[Cendlength2-1]
    Cend3=np.array(y[:,2])
    Cendlength3=len(Cend3)
    Cendvalue2=Cend1[Cendlength3-1]

    output mole fraction

    totC=Cendvalue1+Cendvalue2+Cendvalue3
    outy1=(Cendvalue1/totC)
    outy2=(Cendvalue2/totC)
    outy3=(Cendvalue3/totC)

    return output connected to port 1

    oms1.Clear()
    oms1.Phases[0].Properties.temperature = System.NullableSystem.Double
    oms1.Phases[0].Properties.pressure = System.NullableSystem.Double
    oms1.Phases[0].Compounds['perhydrodibenzyltoulene'].MoleFraction = System.NullableSystem.Double
    oms1.Phases[0].Compounds['Dibenzyltoulene'].MoleFraction = System.NullableSystem.Double
    oms1.Phases[0].Compounds['Hydrogen'].MoleFraction = System.NullableSystem.Double

    Error

    ims1 is not defined ?? How is that possible

     

    Last edit: nihal 2021-03-15
  • Daniel Medeiros

    Daniel Medeiros - 2021-03-15

    Is this script inside a Python Script Unit Operation? If yes, is there a material stream connected to inlet port 1?

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.