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()
Ejemplo n.º 2
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
 def __init__(self, T, P, phasenames, verbosity=False, enforceGridMinimizerForLocalEq=False):
     if (self.__db==None):
         raise RuntimeError('database has not been set, class method initOC should be called first')
     self.__T = T
     self.__P = P
     if (type(phasenames) is list):
         self.__phasenames = phasenames
     else:
         self.__phasenames = [phasenames]
     # see in which case we are: global or local equilibrium
     if (len(self.__phasenames)==2):
         self.__gridMinimizerStatus = gmStat.On
     elif(len(self.__phasenames)==1):
         if (enforceGridMinimizerForLocalEq):
             self.__gridMinimizerStatus = gmStat.On
         else:
             self.__gridMinimizerStatus = gmStat.Off
     else:
         raise ValueError('invalid number of phases provided (should be one or two)')
     # set verbosity
     oc.setVerbosity(verbosity)
     self.__eq_val = None
Ejemplo n.º 5
0
import os
import pyOC
import numpy as np
import matplotlib.pyplot as plt
from pyOC import opencalphad as oc
from pyOC import PhaseStatus as phStat
from pyOC import GridMinimizerStatus as gmStat
import math

######
# 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),
    Returns:   
    -----------
    Components:list of str - Given components.
    Temperature: float - Given temperature.
    Initial_Alloy_Composition: list - Given initial alloy composition.
    Interfacial_Composition: list - Interfacial composition of the grid minimization.
    Partial_Interfacial_Energies: list - Partial interfacial energies of components.
    Interfacial_Energy: float - Requested interfacial energies.
    Return type: xarray Dataset
    """


# 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(True)
## 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(('C1_FCC',),phStat.Suspended)
oc.setPhasesStatus(('LIQUID', 'C1_FCC'), phStat.Entered)
## set pressure
oc.setPressure(1E5)

# mass density laws (from Barrachin2004)
coriumMassDensityLaws = {
    'U1':
    lambda T: 17270.0 - 1.358 * (T - 1408),