Skip to content
Merged
26 changes: 17 additions & 9 deletions burnman/classes/anisotropicsolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ def set_composition(self, molar_fractions):
)
# Calculate all other required properties
Solution.set_composition(self, molar_fractions)
if self._scalar_solution.pressure is not None:
try: # if pressure and temperature are already set, compute base properties
self.compute_base_properties()
except AttributeError:
pass

@cached_property
def ones(self):
Expand Down Expand Up @@ -349,9 +351,12 @@ def set_state(self, pressure, temperature, relaxed=True):
"""
self.unrelaxed.set_state(pressure, temperature)

if hasattr(self.unrelaxed, "molar_fractions") and relaxed:
self._relax_at_PTX()
AnisotropicSolution.set_state(self, pressure, temperature)
if relaxed:
try: # relax the structure if composition has been set
self._relax_at_PTX()
AnisotropicSolution.set_state(self, pressure, temperature)
except AttributeError:
pass

def set_composition(self, molar_fractions, q_initial=None, relaxed=True):
"""
Expand Down Expand Up @@ -383,11 +388,14 @@ def set_composition(self, molar_fractions, q_initial=None, relaxed=True):

self.unrelaxed.set_composition(n)

if self.unrelaxed.pressure is not None and relaxed:
AnisotropicSolution.set_composition(self, n)
self._relax_at_PTX()
self.unrelaxed._scalar_solution.set_composition(self.molar_fractions)
self.unrelaxed.set_composition(self.molar_fractions)
if relaxed:
try: # relax the structure if state has been set
AnisotropicSolution.set_composition(self, n)
self._relax_at_PTX()
self.unrelaxed._scalar_solution.set_composition(self.molar_fractions)
self.unrelaxed.set_composition(self.molar_fractions)
except AttributeError:
pass

def _relax_at_PTX(self):
"""
Expand Down
17 changes: 9 additions & 8 deletions burnman/classes/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def phase_volumes(self):
"""
volumes = np.array(
[
phase.molar_volume * molar_fraction
phase.volume * molar_fraction * self.number_of_moles
for (phase, molar_fraction) in zip(self.phases, self.molar_fractions)
]
)
Expand All @@ -227,7 +227,7 @@ def phase_masses(self):
"""
masses = np.array(
[
phase.molar_mass * molar_fraction
phase.mass * molar_fraction * self.number_of_moles
for (phase, molar_fraction) in zip(self.phases, self.molar_fractions)
]
)
Expand All @@ -236,9 +236,10 @@ def phase_masses(self):
@material_property
def formula(self):
"""
Returns molar chemical formula of the composite
Returns extensive chemical formula of the composite
"""
return sum_formulae([ph.formula for ph in self.phases], self.molar_fractions)
molar_amounts = self.molar_fractions * self.number_of_moles
return sum_formulae([ph.formula for ph in self.phases], molar_amounts)

@material_property
def molar_internal_energy(self):
Expand Down Expand Up @@ -282,14 +283,14 @@ def molar_volume(self):
Returns molar volume of the composite [m^3/mol]
Aliased with self.V
"""
return np.sum(self.phase_volumes)
return np.sum(self.phase_volumes) / self.number_of_moles

@material_property
def molar_mass(self):
"""
Returns molar mass of the composite [kg/mol]
"""
return sum(self.phase_masses)
return sum(self.phase_masses) / self.number_of_moles

@material_property
def density(self):
Expand Down Expand Up @@ -438,7 +439,7 @@ def effective_isentropic_bulk_modulus(self):
Returns the effective isotropic, isentropic bulk modulus of the composite [Pa]
Aliased with self.K_eff
"""
V_frac = self.phase_volumes
V_frac = self.phase_volumes / sum(self.phase_volumes)
K_ph = np.array([phase.isentropic_bulk_modulus_reuss for phase in self.phases])
G_ph = np.array([phase.shear_modulus for phase in self.phases])

Expand All @@ -450,7 +451,7 @@ def effective_shear_modulus(self):
Returns the effective isotropic shear modulus of the mineral [Pa]
Aliased with self.G_eff
"""
V_frac = self.phase_volumes
V_frac = self.phase_volumes / sum(self.phase_volumes)
K_ph = np.array([phase.isentropic_bulk_modulus_reuss for phase in self.phases])
G_ph = np.array([phase.shear_modulus for phase in self.phases])

Expand Down
4 changes: 3 additions & 1 deletion burnman/classes/elasticsolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ def set_composition(self, molar_fractions):
self.reset()
self.molar_fractions = np.array(molar_fractions)

if self.temperature is not None:
try: # set the volume if pressure and temperature are already set
_ = self.molar_volume
except AttributeError:
pass

def set_method(self, method):
for i in range(self.n_endmembers):
Expand Down
Loading