[cig-commits] [commit] split_mt: Changed set_method reset algorithm (e2d8657)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Mon Jan 5 01:34:23 PST 2015
Repository : https://github.com/geodynamics/burnman
On branch : split_mt
Link : https://github.com/geodynamics/burnman/compare/252dfa37a0186b6136d708b751bcf0873dd651da...e2d8657f7d6d508877bb5b35eddaf65f2e244c87
>---------------------------------------------------------------
commit e2d8657f7d6d508877bb5b35eddaf65f2e244c87
Author: Bob Myhill <myhill.bob at gmail.com>
Date: Mon Jan 5 10:34:06 2015 +0100
Changed set_method reset algorithm
>---------------------------------------------------------------
e2d8657f7d6d508877bb5b35eddaf65f2e244c87
burnman/mineral.py | 20 ++++++++++++++------
tests/test_endmembers.py | 3 ---
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/burnman/mineral.py b/burnman/mineral.py
index 4f7f22a..0a7a6fc 100644
--- a/burnman/mineral.py
+++ b/burnman/mineral.py
@@ -65,16 +65,24 @@ 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')
+
+ # 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)
# 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)
+ try:
+ P=self.pressure
+ T=self.temperature
+ self.pressure=self.temperature=float('nan')
+
+ self.method = new_method
+
+ # Reset state
+ self.set_state(P, T)
+ except AttributeError:
+ warnings.warn('State not yet set', stacklevel=2)
self.method = new_method
diff --git a/tests/test_endmembers.py b/tests/test_endmembers.py
index a6814f6..90a1e23 100644
--- a/tests/test_endmembers.py
+++ b/tests/test_endmembers.py
@@ -37,7 +37,6 @@ class test_endmembers(BurnManTest):
fo.set_state(1.e5, 298.15)
volume1=fo.V
fo.set_method('mt')
- fo.set_state(1.e5, 298.15)
volume2=fo.V
self.assertArraysAlmostEqual([volume1], [volume2])
@@ -46,7 +45,6 @@ class test_endmembers(BurnManTest):
fo.set_state(1.e9, 298.15)
volume1=fo.V
fo.set_method('mt')
- fo.set_state(1.e9, 298.15)
volume2=fo.V
self.assertArraysAlmostEqual([volume1], [volume2])
@@ -55,7 +53,6 @@ class test_endmembers(BurnManTest):
fo.set_state(1.e9, 298.15)
K1=fo.K_T
fo.set_method('mt')
- fo.set_state(1.e9, 298.15)
K2=fo.K_T
self.assertArraysAlmostEqual([K1], [K2])
More information about the CIG-COMMITS
mailing list