[cig-commits] [commit] split_mt: Changed set_method reset algorithm (2f2135d)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Mon Jan 5 10:13:57 PST 2015


Repository : https://github.com/geodynamics/burnman

On branch  : split_mt
Link       : https://github.com/geodynamics/burnman/compare/bd8b3a9ea891dbc57e449c581f3cc3d6f889921f...2f2135d73e33f046ca97f57d708d24062cef996d

>---------------------------------------------------------------

commit 2f2135d73e33f046ca97f57d708d24062cef996d
Author: Bob Myhill <myhill.bob at gmail.com>
Date:   Mon Jan 5 19:13:41 2015 +0100

    Changed set_method reset algorithm


>---------------------------------------------------------------

2f2135d73e33f046ca97f57d708d24062cef996d
 burnman/eos/hp.py                           |  2 +-
 burnman/eos/modified_tait.py                |  2 +-
 burnman/mineral.py                          | 14 ++++++--------
 misc/ref/endmember_benchmarks.py.out        |  4 ++--
 misc/ref/example_compare_all_methods.py.out | 10 ++++------
 misc/ref/example_fit_data.py.out            |  4 ++--
 misc/ref/paper_fit_data.py.out              |  4 ++--
 tests/test_endmembers.py                    | 16 +++++++++++++---
 8 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/burnman/eos/hp.py b/burnman/eos/hp.py
index e71192a..f21dc4c 100644
--- a/burnman/eos/hp.py
+++ b/burnman/eos/hp.py
@@ -135,7 +135,7 @@ class HP_TMT(eos.EquationOfState):
         Returns the gibbs free energy [J/mol] as a function of pressure [Pa]
         and temperature [K].
         """
-       # Calculate temperature and pressure integrals
+        # Calculate temperature and pressure integrals
         a, b, c = mt.tait_constants(params)
         Pth=self.__relative_thermal_pressure(temperature,params)
 
diff --git a/burnman/eos/modified_tait.py b/burnman/eos/modified_tait.py
index f00ae00..bc8012a 100644
--- a/burnman/eos/modified_tait.py
+++ b/burnman/eos/modified_tait.py
@@ -56,7 +56,7 @@ class MT(eos.EquationOfState):
     An instance "m" of a Mineral can be assigned this 
     equation of state with the command m.set_method('mt')
     (or by initialising the class with the param 
-    equation_of_state = 'mt'
+    equation_of_state = 'mt').
     """
 
     def volume(self, pressure,temperature,params):
diff --git a/burnman/mineral.py b/burnman/mineral.py
index 4f7f22a..5ed89c2 100644
--- a/burnman/mineral.py
+++ b/burnman/mineral.py
@@ -65,16 +65,14 @@ class Mineral(Material):
             raise Exception("Please derive your method from object (see python old style classes)")
 
         if self.method is not None and type(new_method) is not type(self.method):
-            # Reset everything but params
-            for key, elem in self.__dict__.items():
-                if key != 'params':
-                    elem = float('nan')
-
-            # Set new EoS
-            self.params['equation_of_state']=equation_of_state
 
             # Warn user that they are changing the EoS
-            warnings.warn('Overriding database equation of state. From ' + self.method.__class__.__name__ + ' to ' + new_method.__class__.__name__, stacklevel=2)
+            warnings.warn('Warning, you are changing the method to ' + new_method.__class__.__name__ + ' even though the material is designed to be used with the method ' + self.method.__class__.__name__ + '.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).', stacklevel=2)
+
+            try:
+                self.pressure=self.temperature=float('nan')
+            except AttributeError:
+                pass
 
         self.method = new_method
 
diff --git a/misc/ref/endmember_benchmarks.py.out b/misc/ref/endmember_benchmarks.py.out
index edcf29a..f8d371a 100644
--- a/misc/ref/endmember_benchmarks.py.out
+++ b/misc/ref/endmember_benchmarks.py.out
@@ -1,4 +1,4 @@
-<stdin>:55: UserWarning: Overriding database equation of state. From HP_TMT to MT
+<stdin>:55: UserWarning: Warning, you are changing the method to MT even though the material is designed to be used with the method HP_TMT.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
 Benchmarks for SLB2011 database with method slb3
 ['H', 'S', 'V', 'C_p', 'alpha', 'beta', 'rho']
 [0.00017156026591432655, 0.0002055800239183733, -6.4391026211448567e-05, 0.00014642709264959587, 0.00027680790069709911, 0.0043841690680523288, -0.0013546021287755491, -0.00014635661915870913]
@@ -21,7 +21,7 @@ Benchmarks for HP2011 database with method hp_tmt
 Maximum error in HP2011 database:
 alpha : 2.82198466083e-05 % at 0.0001 GPa and 1000.0 K
 
-Benchmarks for HP2011 database with method mt
+Benchmarks for HP2011 database with method hp_tmt
 ['V', 'beta', 'rho']
 [7.7820925661860693e-07, 3.5713065344384812e-05, -2.292568834341453e-05]
 [4.0270311222739116e-06, 3.7028365245184261e-08, -2.2393157908795917e-05]
diff --git a/misc/ref/example_compare_all_methods.py.out b/misc/ref/example_compare_all_methods.py.out
index 1480ecf..6818d31 100644
--- a/misc/ref/example_compare_all_methods.py.out
+++ b/misc/ref/example_compare_all_methods.py.out
@@ -1,12 +1,10 @@
-BURNMAN/burnman/composite.py: UserWarning: Overriding database equation of state. From SLB2 to MGD3
+BURNMAN/burnman/composite.py: UserWarning: Warning, you are changing the method to MGD3 even though the material is designed to be used with the method SLB2.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
   phase.set_method(method)
-BURNMAN/burnman/composite.py: UserWarning: Overriding database equation of state. From MGD3 to SLB2
+BURNMAN/burnman/composite.py: UserWarning: Warning, you are changing the method to SLB3 even though the material is designed to be used with the method SLB2.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
   phase.set_method(method)
-BURNMAN/burnman/composite.py: UserWarning: Overriding database equation of state. From SLB2 to SLB3
+BURNMAN/burnman/composite.py: UserWarning: Warning, you are changing the method to BM2 even though the material is designed to be used with the method SLB2.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
   phase.set_method(method)
-BURNMAN/burnman/composite.py: UserWarning: Overriding database equation of state. From SLB3 to BM2
-  phase.set_method(method)
-BURNMAN/burnman/composite.py: UserWarning: Overriding database equation of state. From BM2 to BM3
+BURNMAN/burnman/composite.py: UserWarning: Warning, you are changing the method to BM3 even though the material is designed to be used with the method SLB2.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
   phase.set_method(method)
 Calculations are done for:
 Composite:
diff --git a/misc/ref/example_fit_data.py.out b/misc/ref/example_fit_data.py.out
index e03a3f4..370864f 100644
--- a/misc/ref/example_fit_data.py.out
+++ b/misc/ref/example_fit_data.py.out
@@ -1,5 +1,5 @@
-<stdin>:76: UserWarning: Overriding database equation of state. From BM2 to BM3
-<stdin>:85: UserWarning: Overriding database equation of state. From BM3 to BM2
+<stdin>:76: UserWarning: Warning, you are changing the method to BM3 even though the material is designed to be used with the method BM2.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
+<stdin>:85: UserWarning: Warning, you are changing the method to BM2 even though the material is designed to be used with the method BM3.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
 Optimization terminated successfully.
          Current function value: 14212.177931
          Iterations: 109
diff --git a/misc/ref/paper_fit_data.py.out b/misc/ref/paper_fit_data.py.out
index 5f64f4b..3691b14 100644
--- a/misc/ref/paper_fit_data.py.out
+++ b/misc/ref/paper_fit_data.py.out
@@ -1,5 +1,5 @@
-<stdin>:88: UserWarning: Overriding database equation of state. From BM2 to BM3
-<stdin>:97: UserWarning: Overriding database equation of state. From BM3 to BM2
+<stdin>:88: UserWarning: Warning, you are changing the method to BM3 even though the material is designed to be used with the method BM2.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
+<stdin>:97: UserWarning: Warning, you are changing the method to BM2 even though the material is designed to be used with the method BM3.  This does not overwrite any mineral attributes other than temperature and pressure, which are set to nan. Stale attributes will be preserved unless they are refreshed (for example, by set_state).
 Optimization terminated successfully.
          Current function value: 14212.177931
          Iterations: 117
diff --git a/tests/test_endmembers.py b/tests/test_endmembers.py
index a6814f6..fa77d1c 100644
--- a/tests/test_endmembers.py
+++ b/tests/test_endmembers.py
@@ -1,6 +1,7 @@
 import unittest
 import os, sys
 sys.path.insert(1,os.path.abspath('..'))
+import warnings
 
 import burnman
 from burnman.mineral import Mineral
@@ -36,7 +37,10 @@ class test_endmembers(BurnManTest):
         fo=forsterite()
         fo.set_state(1.e5, 298.15)
         volume1=fo.V
-        fo.set_method('mt')
+        with warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter("always")
+            fo.set_method('mt')
+            assert len(w) == 1
         fo.set_state(1.e5, 298.15)
         volume2=fo.V
         self.assertArraysAlmostEqual([volume1], [volume2])
@@ -45,7 +49,10 @@ class test_endmembers(BurnManTest):
         fo=forsterite()
         fo.set_state(1.e9, 298.15)
         volume1=fo.V
-        fo.set_method('mt')
+        with warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter("always")
+            fo.set_method('mt')
+            assert len(w) == 1
         fo.set_state(1.e9, 298.15)
         volume2=fo.V
         self.assertArraysAlmostEqual([volume1], [volume2])
@@ -54,7 +61,10 @@ class test_endmembers(BurnManTest):
         fo=forsterite()
         fo.set_state(1.e9, 298.15)
         K1=fo.K_T
-        fo.set_method('mt')
+        with warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter("always")
+            fo.set_method('mt')
+            assert len(w) == 1
         fo.set_state(1.e9, 298.15)
         K2=fo.K_T
         self.assertArraysAlmostEqual([K1], [K2])



More information about the CIG-COMMITS mailing list