[cig-commits] [commit] inversion, master, validate_MT_params: move EOS into sub-package, rework imports, cleanup, documentation (4d4cd9f)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Fri Dec 12 18:27:59 PST 2014
Repository : https://github.com/geodynamics/burnman
On branches: inversion,master,validate_MT_params
Link : https://github.com/geodynamics/burnman/compare/80c2a295c42dfdb38f83f6c1334bf7d8f97a8463...409647ff05dfad6a686198cac1481bd46b5e2e62
>---------------------------------------------------------------
commit 4d4cd9fb374acee329be079afa04a2676a271302
Author: Timo Heister <timo.heister at gmail.com>
Date: Fri Dec 12 13:24:23 2014 -0800
move EOS into sub-package, rework imports, cleanup, documentation
>---------------------------------------------------------------
4d4cd9fb374acee329be079afa04a2676a271302
burnman/__init__.py | 14 +++++----
burnman/composite.py | 5 ++--
burnman/{ => eos}/birch_murnaghan.py | 4 ++-
burnman/{ => eos}/cork.py | 4 +--
burnman/{ => eos}/einstein.py | 3 +-
burnman/{ => eos}/equation_of_state.py | 2 +-
burnman/{ => eos}/mie_grueneisen_debye.py | 2 +-
burnman/{ => eos}/modified_tait.py | 7 ++---
burnman/{ => eos}/slb.py | 2 +-
burnman/geotherm.py | 2 +-
burnman/main.py | 1 +
burnman/mineral.py | 47 +++++--------------------------
burnman/mineral_helpers.py | 15 +++++-----
burnman/minerals/__init__.py | 1 -
burnman/solidsolution.py | 41 +++++++++++++++++++--------
burnman/solutionmodel.py | 23 +++++++++++----
tests/test_eos.py | 4 +--
17 files changed, 88 insertions(+), 89 deletions(-)
diff --git a/burnman/__init__.py b/burnman/__init__.py
index 5f34555..c32eba1 100644
--- a/burnman/__init__.py
+++ b/burnman/__init__.py
@@ -51,26 +51,28 @@ Acknowledgement and Support:
from version import version as __version__
-#classes for representing rocks and minerals
+# classes for representing rocks and minerals:
from mineral import Mineral
from material import Material
from composite import Composite
from solidsolution import SolidSolution
from mineral_helpers import *
-#high level functions
+# high level functions
from main import *
from model import Model
-#mineral library
+# mineral library
import minerals
-#central user tools
+# central user tools
import seismic
import averaging_schemes
-import solutionmodel
+import eos
+
+from solutionmodel import SolutionModel
import geotherm
-#miscellaneous
+# miscellaneous
import tools
from partitioning import calculate_partition_coefficient,calculate_phase_percents
diff --git a/burnman/composite.py b/burnman/composite.py
index c7521d8..da933d8 100644
--- a/burnman/composite.py
+++ b/burnman/composite.py
@@ -5,9 +5,8 @@
import numpy as np
import warnings
-from burnman.material import Material
-from burnman.mineral import Mineral
-
+from burnman import Material
+from burnman import Mineral
def check_pairs(fractions, minerals):
if len(fractions) < 1:
diff --git a/burnman/birch_murnaghan.py b/burnman/eos/birch_murnaghan.py
similarity index 99%
rename from burnman/birch_murnaghan.py
rename to burnman/eos/birch_murnaghan.py
index d0fc4f0..40a1dcc 100644
--- a/burnman/birch_murnaghan.py
+++ b/burnman/eos/birch_murnaghan.py
@@ -3,7 +3,8 @@
# Released under GPL v2 or later.
import scipy.optimize as opt
-import burnman.equation_of_state as eos
+import equation_of_state as eos
+
def bulk_modulus(volume, params):
"""
@@ -20,6 +21,7 @@ def bulk_modulus(volume, params):
5*params['K_0'] ) * f + 27./2. * (params['K_0']*params['Kprime_0'] - 4.* params['K_0'])*f*f)
return K
+
def birch_murnaghan(x, params):
"""
equation for the third order birch-murnaghan equation of state, returns
diff --git a/burnman/cork.py b/burnman/eos/cork.py
similarity index 98%
rename from burnman/cork.py
rename to burnman/eos/cork.py
index f98e2ba..ce4e09c 100644
--- a/burnman/cork.py
+++ b/burnman/eos/cork.py
@@ -8,8 +8,8 @@
import numpy as np
import scipy.optimize as opt
-import burnman.equation_of_state as eos
-import constants
+import equation_of_state as eos
+import burnman.constants as constants
T_0=298.15 # Standard temperature = 25 C
P_0=1.e5 # Standard pressure = 1.e5 Pa
diff --git a/burnman/einstein.py b/burnman/eos/einstein.py
similarity index 97%
rename from burnman/einstein.py
rename to burnman/eos/einstein.py
index b4053f8..66fa392 100644
--- a/burnman/einstein.py
+++ b/burnman/eos/einstein.py
@@ -3,7 +3,7 @@
# Released under GPL v2 or later.
import numpy as np
-import constants
+import burnman.constants as constants
"""
Functions for the Einstein model of a solid.
@@ -22,6 +22,7 @@ def thermal_energy(T, einstein_T, n):
E_th = 3.*n*constants.gas_constant*einstein_T*( 0.5 + 1. / (np.exp( x ) - 1.0) ) # include the zero point energy
return E_th
+
def heat_capacity_v(T,einstein_T,n):
"""
Heat capacity at constant volume. In J/K/mol
diff --git a/burnman/equation_of_state.py b/burnman/eos/equation_of_state.py
similarity index 100%
rename from burnman/equation_of_state.py
rename to burnman/eos/equation_of_state.py
index 2fe41ae..47e7fe2 100644
--- a/burnman/equation_of_state.py
+++ b/burnman/eos/equation_of_state.py
@@ -1,8 +1,8 @@
-
# BurnMan - a lower mantle toolkit
# Copyright (C) 2012, 2013, Heister, T., Unterborn, C., Rose, I. and Cottaar, S.
# Released under GPL v2 or later.
+
class EquationOfState(object):
"""
This class defines the interface for an equation of state
diff --git a/burnman/mie_grueneisen_debye.py b/burnman/eos/mie_grueneisen_debye.py
similarity index 99%
rename from burnman/mie_grueneisen_debye.py
rename to burnman/eos/mie_grueneisen_debye.py
index b5b3603..6bc0d26 100644
--- a/burnman/mie_grueneisen_debye.py
+++ b/burnman/eos/mie_grueneisen_debye.py
@@ -8,7 +8,7 @@ import scipy.optimize as opt
import burnman.equation_of_state as eos
import burnman.birch_murnaghan as bm
import burnman.debye as debye
-import constants
+import burnman.constants as constants
class MGDBase(eos.EquationOfState):
"""
diff --git a/burnman/modified_tait.py b/burnman/eos/modified_tait.py
similarity index 99%
rename from burnman/modified_tait.py
rename to burnman/eos/modified_tait.py
index bb42824..5196a5d 100644
--- a/burnman/modified_tait.py
+++ b/burnman/eos/modified_tait.py
@@ -3,12 +3,11 @@
# Released under GPL v2 or later.
import numpy as np
-import scipy.optimize as opt
-import burnman.equation_of_state as eos
-import burnman.einstein as einstein
+import equation_of_state as eos
+import einstein
from burnman.endmemberdisorder import *
-import constants
+import burnman.constants as constants
T_0=298.15 # Standard temperature = 25 C
P_0=1.e5 # Standard pressure = 1.e5 Pa
diff --git a/burnman/slb.py b/burnman/eos/slb.py
similarity index 99%
rename from burnman/slb.py
rename to burnman/eos/slb.py
index 11baec0..c4a50b8 100644
--- a/burnman/slb.py
+++ b/burnman/eos/slb.py
@@ -8,7 +8,7 @@ import warnings
import burnman.birch_murnaghan as bm
import burnman.debye as debye
-import burnman.equation_of_state as eos
+import equation_of_state as eos
class SLBBase(eos.EquationOfState):
"""
diff --git a/burnman/geotherm.py b/burnman/geotherm.py
index 5faf0f7..9e3c418 100644
--- a/burnman/geotherm.py
+++ b/burnman/geotherm.py
@@ -3,11 +3,11 @@
# Released under GPL v2 or later.
import numpy as np
-import matplotlib.pyplot as pyplot
import scipy.integrate as integrate
import tools
import seismic
+
def brown_shankland(pressure):
"""
Geotherm from Brown and Shankland (1981).
diff --git a/burnman/main.py b/burnman/main.py
index eb27e74..5801f21 100644
--- a/burnman/main.py
+++ b/burnman/main.py
@@ -9,6 +9,7 @@ import burnman.geotherm
import burnman.seismic
import burnman.averaging_schemes
+
class ElasticProperties(object):
"""
Class that contains volume, density, and moduli. This is generated for
diff --git a/burnman/mineral.py b/burnman/mineral.py
index 9733652..aa0bb18 100644
--- a/burnman/mineral.py
+++ b/burnman/mineral.py
@@ -7,13 +7,8 @@ import warnings
import numpy as np
from burnman.material import Material
-import burnman.equation_of_state as eos
-import burnman.birch_murnaghan as bm
-import burnman.slb as slb
-import burnman.mie_grueneisen_debye as mgd
-import inspect
-import burnman.modified_tait as mt
-import burnman.cork as cork
+import burnman.eos as eos
+
class Mineral(Material):
"""
@@ -43,12 +38,12 @@ class Mineral(Material):
def __init__(self):
if 'params' not in self.__dict__:
- self.params={}
+ self.params = {}
self.method = None
if 'equation_of_state' in self.params:
self.set_method(self.params['equation_of_state'])
- def set_method(self, method):
+ def set_method(self, equation_of_state):
"""
Set the equation of state to be used for this mineral.
Takes a string corresponding to any of the predefined
@@ -57,41 +52,13 @@ class Mineral(Material):
class which derives from the equation_of_state base class.
"""
- if method is None:
+ if equation_of_state is None:
self.method = None
return
- def to_method_obj(method):
-
- if isinstance(method, basestring):
- if (method == "slb2"):
- return slb.SLB2()
- elif (method == "mgd2"):
- return mgd.MGD2()
- elif (method == "mgd3"):
- return mgd.MGD3()
- elif (method == "slb3"):
- return slb.SLB3()
- elif (method == "bm2"):
- return bm.BM2()
- elif (method == "bm3"):
- return bm.BM3()
- elif (method == "mtait"):
- return mt.MT()
- elif (method == "cork"):
- return cork.CORK()
- else:
- raise Exception("unsupported material method " + method)
- elif isinstance(method, eos.EquationOfState):
- return method
- elif inspect.isclass(method) and issubclass(method, eos.EquationOfState):
- return method()
- else:
- raise Exception("unsupported material method " + method.__class__.__name__ )
-
- new_method = to_method_obj(method)
+ new_method = eos.create(equation_of_state)
if self.method is not None and 'equation_of_state' in self.params:
- self.method = to_method_obj(self.params['equation_of_state'])
+ self.method = eos.create(self.params['equation_of_state'])
if type(new_method).__name__ == 'instance':
raise Exception("Please derive your method from object (see python old style classes)")
diff --git a/burnman/mineral_helpers.py b/burnman/mineral_helpers.py
index ace9683..cd605d7 100644
--- a/burnman/mineral_helpers.py
+++ b/burnman/mineral_helpers.py
@@ -11,13 +11,12 @@ This module provides several helper minerals/materials.
import numpy as np
import warnings
-from burnman.material import Material
+from burnman import Material, Mineral
-from burnman.mineral import Mineral
-import burnman.equation_of_state as eos
-import burnman.birch_murnaghan as bm
-import burnman.slb as slb
-import burnman.mie_grueneisen_debye as mgd
+#import burnman.equation_of_state as eos
+#import burnman.birch_murnaghan as bm
+#import burnman.slb as slb
+#import burnman.mie_grueneisen_debye as mgd
class HelperSolidSolution(Mineral):
@@ -52,9 +51,9 @@ class HelperSolidSolution(Mineral):
self.params = {}
- def set_method(self, method):
+ def set_method(self, equation_of_state):
for m in self.base_materials:
- m.set_method(method)
+ m.set_method(equation_of_state)
def debug_print(self, indent=""):
print "%sHelperSolidSolution(%s):" % (indent, self.to_string())
diff --git a/burnman/minerals/__init__.py b/burnman/minerals/__init__.py
index 1df557c..1bf7171 100644
--- a/burnman/minerals/__init__.py
+++ b/burnman/minerals/__init__.py
@@ -11,7 +11,6 @@ Mineral database
- :mod:`~burnman.minerals.Murakami_etal_2012`
- :mod:`~burnman.minerals.Murakami_2013`
- :mod:`~burnman.minerals.Matas_etal_2007`
- - :mod:`~burnman.minerals.HP_2011_fluids`
- :mod:`~burnman.minerals.HP_2011_ds62`
- :mod:`~burnman.minerals.HHPH_2013`
- :mod:`~burnman.minerals.other`
diff --git a/burnman/solidsolution.py b/burnman/solidsolution.py
index 953a781..48c4951 100644
--- a/burnman/solidsolution.py
+++ b/burnman/solidsolution.py
@@ -3,13 +3,11 @@
# Released under GPL v2 or later.
import numpy as np
-from burnman.mineral import Mineral
-from burnman.processchemistry import ProcessSolidSolutionChemistry
-from burnman.solutionmodel import SolutionModel
-import constants
-import warnings
-kd = lambda x,y : 1 if x==y else 0
+from burnman import Mineral
+from solutionmodel import SolutionModel
+from solutionmodel import kd
+
class SolidSolution(Mineral):
"""
@@ -27,19 +25,40 @@ class SolidSolution(Mineral):
and P derivatives in J/K/mol and m^3/mol.
"""
- # init sets up matrices to speed up calculations for when P, T, X is defined.
- def __init__(self, base_material, solution_model = SolutionModel() ):
+ def __init__(self, endmembers, solution_model=SolutionModel()):
+ """
+ Set up matrices to speed up calculations for when P, T, X is defined.
+
+ Parameters
+ ----------
+ endmembers: list of :class:`burnman.Mineral`
+ List of endmembers in this solid solution.
+ solution_model: :class:`burnman.SolutionModel`
+ SolutionModel to use.
+ """
+
# Initialise the solid solution inputs
- self.base_material = base_material
+ self.base_material = endmembers
self.solution_model = solution_model
# Number of endmembers in the solid solution
- self.n_endmembers=len(base_material)
+ self.n_endmembers = len(endmembers)
for i in range(self.n_endmembers):
self.base_material[i][0].set_method(self.base_material[i][0].params['equation_of_state'])
- def set_composition( self, molar_fraction ):
+ def get_endmembers(self):
+ return self.base_material
+
+ def set_composition(self, molar_fraction ):
+ """
+ Set the composition for this solid solution.
+
+ Parameters
+ ----------
+ molar_fraction: list of float
+ molar abundance for each endmember, needs to sum to one.
+ """
assert(len(self.base_material) == len(molar_fraction))
assert(sum(molar_fraction) > 0.9999)
assert(sum(molar_fraction) < 1.0001)
diff --git a/burnman/solutionmodel.py b/burnman/solutionmodel.py
index 152c1cc..e12dba3 100644
--- a/burnman/solutionmodel.py
+++ b/burnman/solutionmodel.py
@@ -8,8 +8,13 @@ import burnman
from burnman.processchemistry import *
import constants
-kd = lambda x,y : 1 if x==y else 0
-class SolutionModel:
+"""
+kronecker delta function for integers
+"""
+kd = lambda x, y: 1 if x == y else 0
+
+
+class SolutionModel(object):
"""
This is the base class for a solution model, intended for use
in defining solid solutions and performing thermodynamic calculations
@@ -22,6 +27,12 @@ class SolutionModel:
different endmember values.
"""
+ def __init__(self):
+ """
+ Does nothing.
+ """
+ pass
+
def excess_gibbs_free_energy( self, pressure, temperature, molar_fractions):
"""
Given a list of molar fractions of different phases,
@@ -97,7 +108,7 @@ class SolutionModel:
return 0.0
-class IdealSolution ( SolutionModel ):
+class IdealSolution (SolutionModel):
"""
A very simple class representing an ideal solution model.
Calculate the excess gibbs free energy due to configurational
@@ -156,7 +167,6 @@ class IdealSolution ( SolutionModel ):
lna[e]=lna[e] + self.endmember_configurational_entropies[e]/constants.gas_constant
return lna
-
def _ideal_activities ( self, molar_fractions ):
site_occupancies=np.dot(molar_fractions, self.endmember_occupancies)
activities=np.empty(shape=(self.n_endmembers))
@@ -171,7 +181,7 @@ class IdealSolution ( SolutionModel ):
return activities
-class AsymmetricRegularSolution ( IdealSolution ):
+class AsymmetricRegularSolution (IdealSolution):
"""
Solution model implementing the asymmetric regular solution model formulation (Holland and Powell, 2003)
"""
@@ -258,7 +268,8 @@ class AsymmetricRegularSolution ( IdealSolution ):
H_excess=np.dot(self.alpha.T,molar_fractions)*np.dot(phi.T,np.dot(self.Wh,phi))
return H_excess + pressure*self.excess_volume ( pressure, temperature, molar_fractions )
-class SymmetricRegularSolution ( AsymmetricRegularSolution ):
+
+class SymmetricRegularSolution (AsymmetricRegularSolution):
"""
Solution model implementing the symmetric regular solution model
"""
diff --git a/tests/test_eos.py b/tests/test_eos.py
index d118661..bf45d61 100644
--- a/tests/test_eos.py
+++ b/tests/test_eos.py
@@ -36,7 +36,7 @@ class eos(BurnManTest):
rock = mypericlase()
pressure = 0.
temperature = 300.
- eoses = [burnman.slb.SLB2(), burnman.slb.SLB3(), burnman.birch_murnaghan.BM2(), burnman.birch_murnaghan.BM3()]
+ eoses = [burnman.eos.SLB2(), burnman.eos.SLB3(), burnman.eos.BM2(), burnman.eos.BM3()]
for i in eoses:
Volume_test = i.volume(pressure, temperature, rock.params)
@@ -56,7 +56,7 @@ class eos(BurnManTest):
Cv_test = i.heat_capacity_v(pressure, temperature, rock.params['V_0'], rock.params)
Grun_test = i.grueneisen_parameter(pressure, temperature, rock.params['V_0'], rock.params)
- eoses_thermal = [burnman.slb.SLB2(), burnman.slb.SLB3()]
+ eoses_thermal = [burnman.eos.SLB2(), burnman.eos.SLB3()]
for i in eoses_thermal:
Cp_test = i.heat_capacity_p(pressure, temperature, rock.params['V_0'], rock.params)
self.assertFloatEqual(Cp_test, 37.076768469502042)
More information about the CIG-COMMITS
mailing list