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 suspendPhases(self, suspended_phase, phasenames):

        oc.setPhasesStatus((suspended_phase, ), phStat.Suspended)

        entered_phase = phasenames[phasenames == suspended_phase]

        oc.setPhasesStatus((entered_phase, ), phStat.Entered)
 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 __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)
 def multiPhaseAnalysis(self, phasenames):
     oc.setPhasesStatus((phasenames[0], phasenames[1]), phStat.Entered)
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),
    '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),
    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),
    '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':
#x0['O'] -= 2.0*0.1

# 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 = pathname + 'feouzr.tdb'
print(tdbFile)
exit

# reading tdb
elems = ('O', 'U', 'ZR')
oc.readtdb(tdbFile, elems)

# play with phase status
oc.setPhasesStatus(('*', ), phStat.Suspended)
phaseNames = ('LIQUID', )
oc.setPhasesStatus(phaseNames, phStat.Entered)

# set pressure
oc.setPressure(1E5)

# set temperature
oc.setTemperature(2773)
'''------------------------------------------------------------
COHERENT GIBBS ENERGY CALCUATIONS
------------------------------------------------------------'''

oc.setElementMolarAmounts(x0)

# calculate equilibrium without the grid-minimizer (equilibrium record = eq2)