def calculateEquilibria(self, gmStat, setverb, T, P, x0):

        # setting verbosity (True or False - default), if set to yes, in particular, when getters are called the returned values are displayed in a comprehensive way
        oc.setVerbosity(setverb)

        # set pressure
        oc.setPressure(P)

        # set temperature
        oc.setTemperature(T)

        # set initial molar amounts
        oc.setElementMolarAmounts(x0)

        #Equilibrium
        if gmStat == 'Off':
            oc.calculateEquilibrium(gmstat.Off)
        elif gmStat == 'On':
            oc.calculateEquilibrium(gmstat.On)
        else:
            raise ValueError(
                'No suitable parameter for gmstat found: Choose from On/Off')

        self.gibbs = oc.getGibbsEnergy()
        self.mu = oc.getChemicalPotentials()
        self.cd = oc.getConstituentsDescription()
        self.mass = oc.getScalarResult('B')

        phasesAtEquilibrium = oc.getPhasesAtEquilibrium()
        self.pec = phasesAtEquilibrium.getPhaseElementComposition()
        self.pcc = phasesAtEquilibrium.getPhaseConstituentComposition()
        self.ps = phasesAtEquilibrium.getPhaseSites()
        self.ma = phasesAtEquilibrium.getPhaseMolarAmounts()
def Gm_bulkphase(temperature, elementMolarAmounts):
    # set temperature
    oc.setTemperature(temperature)
    oc.setElementMolarAmounts(elementMolarAmounts)
    Gm_bulkphase = {}
    Gm_bulkphase = oc.calculateEquilibrium(gmStat.On)
    G = oc.getScalarResult('G')
    phase_description = oc.getPhasesAtEquilibrium(
    ).getPhaseConstituentComposition()
    chemicalpotential = oc.getComponentAssociatedResult('MU')
 def __eqfunc(self, x, phasesSuspended=True):
     if (phasesSuspended):
         # suspend all other phases
         oc.setPhasesStatus(('* ',), phStat.Suspended)
         oc.setPhasesStatus(tuple(self.__phasenames), phStat.Entered, 1.0)
     else:
         oc.setPhasesStatus(('* ',), phStat.Entered, 1.0)
     # set temperature and pressure
     oc.setTemperature(self.__T)
     oc.setPressure(self.__P)
     # set initial molar amounts
     oc.setElementMolarAmounts(self.__calculateMolarAmounts(x))
     # calculate equilibrium
     oc.calculateEquilibrium(self.__gridMinimizerStatus)
Exemplo n.º 4
0
    def eqfunc(self, x, calc_value):

        # setting verbosity (True or False - default), if set to yes, in particular, when getters are called the returned values are displayed in a comprehensive way
        oc.setVerbosity(self.setverb)

        # set pressure
        oc.setPressure(self.P)

        # set temperature
        oc.setTemperature(self.T)

        # set initial molar amounts
        oc.setElementMolarAmounts(x)

        #Equilibrium
        oc.calculateEquilibrium(gmstat.Off)

        if calc_value == 'gibbs':
            self.eq_val = oc.getGibbsEnergy()

        elif calc_value == 'mu':
            self.eq_val = oc.getChemicalPotentials()

        elif calc_value == 'cd':
            self.eq_val = oc.getConstituentsDescription()

        elif calc_value == 'mass':
            self.eq_val = oc.getScalarResult('B')

        elif calc_value == 'pec':
            self.eq_val = oc.getPhasesAtEquilibrium(
            ).getPhaseElementComposition()

        elif calc_value == 'pcc':
            self.eq_val = oc.getPhasesAtEquilibrium(
            ).getPhaseConstituentComposition()

        elif calc_value == 'ps':
            self.eq_val = oc.getPhasesAtEquilibrium().getPhaseSites()

        elif calc_value == 'ma':
            self.eq_val = oc.getPhasesAtEquilibrium().getPhaseMolarAmounts()

        return self.eq_val
 def calculatePartialMolarVolume(self,elementMolarAmounts,endmemberMassDensityLaws, epsilon, constituentToEndmembersConverter=None):
     #print(elementMolarAmounts, epsilon)
     # suspend all other phases
     oc.setPhasesStatus(('* ',), phStat.Suspended)
     oc.setPhasesStatus(tuple(self.__phasenames), phStat.Entered, 1.0)
     # set pressure
     oc.setPressure(self.__P)
     # set temperature
     oc.setTemperature(self.__T)
     # evaluate volume
     oc.setElementMolarAmounts(elementMolarAmounts)
     oc.calculateEquilibrium(gmStat.Off)
     exactVolume = self.__calculateVolume(oc.getPhasesAtEquilibrium().getPhaseConstituentComposition(),oc.getConstituentsDescription(),endmemberMassDensityLaws, constituentToEndmembersConverter)
     # evaluate (elementwise) partial molar volume (approximation of first order volume derivative by a second-order finite difference formula)
     partialMolarVolumes={}
     for element in elementMolarAmounts:
         # evaluate volume for n[element]+epsilone
         modifiedElementMolarAmounts=elementMolarAmounts.copy()
         modifiedElementMolarAmounts[element] += epsilon
         #print(element, modifiedElementMolarAmounts)
         oc.setElementMolarAmounts(modifiedElementMolarAmounts)
         oc.calculateEquilibrium(gmStat.Off)
         volumePlus = self.__calculateVolume(oc.getPhasesAtEquilibrium().getPhaseConstituentComposition(),oc.getConstituentsDescription(),endmemberMassDensityLaws, constituentToEndmembersConverter)
         # evaluate volume for n[element]-epsilone
         modifiedElementMolarAmounts[element] -= 2.0*epsilon
         #print(element, modifiedElementMolarAmounts)
         oc.setElementMolarAmounts(modifiedElementMolarAmounts)
         oc.calculateEquilibrium(gmStat.Off)
         volumeMinus = self.__calculateVolume(oc.getPhasesAtEquilibrium().getPhaseConstituentComposition(),oc.getConstituentsDescription(),endmemberMassDensityLaws, constituentToEndmembersConverter)
         partialMolarVolumes[element]=(volumePlus-volumeMinus)/(2.0*epsilon)
     # calculate approximate volume from partial volumes
     approxVolume = 0.0
     for element, molarAmount in oc.getPhasesAtEquilibrium().getPhaseElementComposition()[list(oc.getPhasesAtEquilibrium().getPhaseElementComposition())[0]].items():
         approxVolume+=molarAmount*partialMolarVolumes[element]
     return partialMolarVolumes,exactVolume,approxVolume
 def eqfunc(self, x):
     """Calculate Phase Equilibrium"""
     # setting verbosity (True or False - default), if set to yes, in particular, when getters are called the returned values are displayed in a comprehensive way
     oc.setVerbosity(self.setverb)
     
      # tdb filepath
     tdbFile=self.pathname+self.db
     #print(tdbFile)
      # reading tdb
     oc.readtdb(tdbFile,self.comps)
     oc.setPhasesStatus((self.phasename[0],self.phasename[1]),phStat.Entered)
    
     #Equilibrium 
     variable = oc.setElementMolarAmounts(self.x)+ [oc.setTemperature(self.T), oc.setPressure(self.P)]
     xs = [v.X(each) for each in self.comps if each != "VA"]
     xxs = [xs[i] for i in range(1, len(xs))]
     xxxs = xxs + [v.T, v.P]
     var = {xxxs[i]: variable[i] for i in range(len(variable))}
     eq_result = oc.calculateEquilibrium(self.db, self.comps, self.phasename, var)
     return eq_result
## tdb filepath
tdbFile = os.environ.get('OCDATA') + '/feouzr.tdb'
## reading tdb
elems = ('O', 'U', 'ZR')
oc.readtdb(tdbFile, elems)

# set pressure
oc.setPressure(1E5)

# set temperature
oc.setTemperature(2800)
## suspend all phases except the liquid one
oc.setPhasesStatus(('* ', ), phStat.Suspended)
oc.setPhasesStatus(('LIQUID', ), phStat.Entered)

oc.setElementMolarAmounts(x0)

# calculate equilibrium
oc.changeEquilibriumRecord('eq2')
oc.calculateEquilibrium(gmStat.Off)

# retrieving mu data
phasesAtEquilibrium = oc.getPhasesAtEquilibrium()
phaseConstituentComposition = phasesAtEquilibrium.getPhaseConstituentComposition(
)
mueq_inf = oc.getChemicalPotentials()

# calculate equilibrium with the grid-minimizer (equilibrium record = default equilibrium)
oc.changeEquilibriumRecord()
oc.calculateEquilibrium()