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 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, 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)
Esempio 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 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
# An example of Interfacil energy calculation
######

# oc setup
## 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(False)
## tdb filepath
tdbFile = os.environ.get('OCDATA') + '/feouzr.tdb'
## reading tdb
elems = ('O', 'U', 'ZR')
oc.readtdb(tdbFile, elems)
## suspend all phases except the liquid one
oc.setPhasesStatus(('*', ), phStat.Suspended)
oc.setPhasesStatus(('LIQUID', ), phStat.Entered)
## set pressure
oc.setPressure(1E5)

# mass density laws (from Barrachin2004)
coriumMassDensityLaws = {
    'U1':
    lambda T: 17270.0 - 1.358 * (T - 1408),
    'ZR1':
    lambda T: 6844.51 - 0.609898 * T + 2.05008E-4 * T**2 - 4.47829E-8 * T**3 +
    3.26469E-12 * T**4,
    'O2U1':
    lambda T: 8860.0 - 9.285E-1 * (T - 3120),
    'O2ZR1':
    lambda T: 5150 - 0.445 * (T - 2983),
    'O1':
    lambda T:
    1.141  # set to meaningless value but ok as, no 'free' oxygen in the considered mixtures