Skip to content

Commit dbb1c31

Browse files
authored
Merge pull request #709 from bobmyhill/n_moles
Add number_of_moles property and extensive thermodynamic properties to Material
2 parents a2a82bc + 5fb9ba4 commit dbb1c31

15 files changed

+449
-159
lines changed

burnman/classes/anisotropicsolution.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ def set_composition(self, molar_fractions):
178178
)
179179
# Calculate all other required properties
180180
Solution.set_composition(self, molar_fractions)
181-
if self._scalar_solution.pressure is not None:
181+
try: # if pressure and temperature are already set, compute base properties
182182
self.compute_base_properties()
183+
except AttributeError:
184+
pass
183185

184186
@cached_property
185187
def ones(self):
@@ -349,9 +351,12 @@ def set_state(self, pressure, temperature, relaxed=True):
349351
"""
350352
self.unrelaxed.set_state(pressure, temperature)
351353

352-
if hasattr(self.unrelaxed, "molar_fractions") and relaxed:
353-
self._relax_at_PTX()
354-
AnisotropicSolution.set_state(self, pressure, temperature)
354+
if relaxed:
355+
try: # relax the structure if composition has been set
356+
self._relax_at_PTX()
357+
AnisotropicSolution.set_state(self, pressure, temperature)
358+
except AttributeError:
359+
pass
355360

356361
def set_composition(self, molar_fractions, q_initial=None, relaxed=True):
357362
"""
@@ -383,11 +388,14 @@ def set_composition(self, molar_fractions, q_initial=None, relaxed=True):
383388

384389
self.unrelaxed.set_composition(n)
385390

386-
if self.unrelaxed.pressure is not None and relaxed:
387-
AnisotropicSolution.set_composition(self, n)
388-
self._relax_at_PTX()
389-
self.unrelaxed._scalar_solution.set_composition(self.molar_fractions)
390-
self.unrelaxed.set_composition(self.molar_fractions)
391+
if relaxed:
392+
try: # relax the structure if state has been set
393+
AnisotropicSolution.set_composition(self, n)
394+
self._relax_at_PTX()
395+
self.unrelaxed._scalar_solution.set_composition(self.molar_fractions)
396+
self.unrelaxed.set_composition(self.molar_fractions)
397+
except AttributeError:
398+
pass
391399

392400
def _relax_at_PTX(self):
393401
"""

burnman/classes/composite.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def phase_volumes(self):
214214
"""
215215
volumes = np.array(
216216
[
217-
phase.molar_volume * molar_fraction
217+
phase.volume * molar_fraction * self.number_of_moles
218218
for (phase, molar_fraction) in zip(self.phases, self.molar_fractions)
219219
]
220220
)
@@ -227,7 +227,7 @@ def phase_masses(self):
227227
"""
228228
masses = np.array(
229229
[
230-
phase.molar_mass * molar_fraction
230+
phase.mass * molar_fraction * self.number_of_moles
231231
for (phase, molar_fraction) in zip(self.phases, self.molar_fractions)
232232
]
233233
)
@@ -236,9 +236,10 @@ def phase_masses(self):
236236
@material_property
237237
def formula(self):
238238
"""
239-
Returns molar chemical formula of the composite
239+
Returns extensive chemical formula of the composite
240240
"""
241-
return sum_formulae([ph.formula for ph in self.phases], self.molar_fractions)
241+
molar_amounts = self.molar_fractions * self.number_of_moles
242+
return sum_formulae([ph.formula for ph in self.phases], molar_amounts)
242243

243244
@material_property
244245
def molar_internal_energy(self):
@@ -282,14 +283,14 @@ def molar_volume(self):
282283
Returns molar volume of the composite [m^3/mol]
283284
Aliased with self.V
284285
"""
285-
return np.sum(self.phase_volumes)
286+
return np.sum(self.phase_volumes) / self.number_of_moles
286287

287288
@material_property
288289
def molar_mass(self):
289290
"""
290291
Returns molar mass of the composite [kg/mol]
291292
"""
292-
return sum(self.phase_masses)
293+
return sum(self.phase_masses) / self.number_of_moles
293294

294295
@material_property
295296
def density(self):
@@ -438,7 +439,7 @@ def effective_isentropic_bulk_modulus(self):
438439
Returns the effective isotropic, isentropic bulk modulus of the composite [Pa]
439440
Aliased with self.K_eff
440441
"""
441-
V_frac = self.phase_volumes
442+
V_frac = self.phase_volumes / sum(self.phase_volumes)
442443
K_ph = np.array([phase.isentropic_bulk_modulus_reuss for phase in self.phases])
443444
G_ph = np.array([phase.shear_modulus for phase in self.phases])
444445

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

burnman/classes/elasticsolution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ def set_composition(self, molar_fractions):
111111
self.reset()
112112
self.molar_fractions = np.array(molar_fractions)
113113

114-
if self.temperature is not None:
114+
try: # set the volume if pressure and temperature are already set
115115
_ = self.molar_volume
116+
except AttributeError:
117+
pass
116118

117119
def set_method(self, method):
118120
for i in range(self.n_endmembers):

0 commit comments

Comments
 (0)