1- # This file is part of BurnMan - a thermoelastic and thermodynamic toolkit for the Earth and Planetary Sciences
1+ # This file is part of BurnMan - a thermoelastic and thermodynamic toolkit for
2+ # the Earth and Planetary Sciences
23# Copyright (C) 2012 - 2025 by the BurnMan team, released under the GNU
34# GPL v2 or later.
45
@@ -31,7 +32,7 @@ def helmholtz_energy(temperature, volume, params):
3132 A = params ["anharmonic_prefactor_model" ].value (x , params )
3233 theta_model = params ["debye_temperature_model" ]
3334 anharmonic_model = params ["anharmonic_thermal_model" ]
34- debye_T = theta_model (x , params )
35+ debye_T = theta_model . value (x , params )
3536 F_a = anharmonic_model .nondimensional_helmholtz_energy (
3637 temperature , debye_T , params
3738 )
@@ -46,7 +47,7 @@ def entropy(temperature, volume, params):
4647 A = params ["anharmonic_prefactor_model" ].value (x , params )
4748 theta_model = params ["debye_temperature_model" ]
4849 anharmonic_model = params ["anharmonic_thermal_model" ]
49- debye_T = theta_model (x , params )
50+ debye_T = theta_model . value (x , params )
5051 S_a = anharmonic_model .nondimensional_entropy (temperature , debye_T , params )
5152 return A * S_a
5253
@@ -56,7 +57,7 @@ def heat_capacity_v(temperature, volume, params):
5657 A = params ["anharmonic_prefactor_model" ].value (x , params )
5758 theta_model = params ["debye_temperature_model" ]
5859 anharmonic_model = params ["anharmonic_thermal_model" ]
59- debye_T = theta_model (x , params )
60+ debye_T = theta_model . value (x , params )
6061 Cv_a = anharmonic_model .nondimensional_heat_capacity (
6162 temperature , debye_T , params
6263 )
@@ -69,7 +70,7 @@ def pressure(temperature, volume, params):
6970 dAdV = params ["anharmonic_prefactor_model" ].dVrel (x , params ) / params ["V_0" ]
7071 theta_model = params ["debye_temperature_model" ]
7172 anharmonic_model = params ["anharmonic_thermal_model" ]
72- debye_T = theta_model (x , params )
73+ debye_T = theta_model . value (x , params )
7374 F_a = anharmonic_model .nondimensional_helmholtz_energy (
7475 temperature , debye_T , params
7576 )
@@ -93,12 +94,11 @@ def isothermal_bulk_modulus(temperature, volume, params):
9394 A = params ["anharmonic_prefactor_model" ].value (x , params )
9495 dAdV = params ["anharmonic_prefactor_model" ].dVrel (x , params ) / params ["V_0" ]
9596 d2AdV2 = (
96- params ["anharmonic_prefactor_model" ].d2dVrel2 (x , params )
97- / params ["V_0" ] ** 2
97+ params ["anharmonic_prefactor_model" ].dVrel2 (x , params ) / params ["V_0" ] ** 2
9898 )
9999 theta_model = params ["debye_temperature_model" ]
100100 anharmonic_model = params ["anharmonic_thermal_model" ]
101- debye_T = theta_model (x , params )
101+ debye_T = theta_model . value (x , params )
102102
103103 F_a = anharmonic_model .nondimensional_helmholtz_energy (
104104 temperature , debye_T , params
@@ -123,7 +123,7 @@ def isothermal_bulk_modulus(temperature, volume, params):
123123 d2AdV2 * (F_a - F_a0 )
124124 + 2 * dAdV * (F_ad - F_ad0 ) * theta_model .dVrel (x , params ) / params ["V_0" ]
125125 + A * (F_add - F_add0 ) * (theta_model .dVrel (x , params ) / params ["V_0" ]) ** 2
126- + A * (F_ad - F_ad0 ) * theta_model .d2dVrel2 (x , params ) / params ["V_0" ] ** 2
126+ + A * (F_ad - F_ad0 ) * theta_model .dVrel2 (x , params ) / params ["V_0" ] ** 2
127127 )
128128
129129 @staticmethod
@@ -133,7 +133,7 @@ def dSdV(temperature, volume, params):
133133 dAdV = params ["anharmonic_prefactor_model" ].dVrel (x , params ) / params ["V_0" ]
134134 theta_model = params ["debye_temperature_model" ]
135135 anharmonic_model = params ["anharmonic_thermal_model" ]
136- debye_T = theta_model (x , params )
136+ debye_T = theta_model . value (x , params )
137137
138138 S_a = anharmonic_model .nondimensional_entropy (temperature , debye_T , params )
139139 S_ad = anharmonic_model .nondimensional_dentropy_dTheta (
@@ -143,3 +143,66 @@ def dSdV(temperature, volume, params):
143143 aK_T = dAdV * S_a + A * (theta_model .dVrel (x , params ) / params ["V_0" ]) * S_ad
144144
145145 return aK_T
146+
147+ @staticmethod
148+ def validate_parameters (params ):
149+ # Check for all required keys
150+ expected_keys = [
151+ "debye_temperature_model" ,
152+ "anharmonic_prefactor_model" ,
153+ "anharmonic_thermal_model" ,
154+ "V_0" ,
155+ "T_0" ,
156+ ]
157+ for key in expected_keys :
158+ if key not in params :
159+ raise AttributeError (f"params dictionary must contain an '{ key } ' key" )
160+
161+ # Validate the three models:
162+ models = [
163+ params ["debye_temperature_model" ],
164+ params ["anharmonic_prefactor_model" ],
165+ params ["anharmonic_thermal_model" ],
166+ ]
167+ for model in models :
168+ model .validate_parameters (params )
169+
170+ # Check that the required methods are present in the
171+ # debye_temperature_model
172+ expected_methods = ["value" , "dVrel" , "dVrel2" ]
173+ for method in expected_methods :
174+ if not hasattr (params ["debye_temperature_model" ], method ) or not callable (
175+ getattr (params ["debye_temperature_model" ], method )
176+ ):
177+ raise AttributeError (
178+ f"params['debye_temperature_model'] must have a { method } method that takes arguments Vrel and params"
179+ )
180+
181+ # Check that the required methods are present in the
182+ # anharmonic_prefactor_model
183+ expected_methods = ["value" , "dVrel" , "dVrel2" ]
184+ for method in expected_methods :
185+ if not hasattr (
186+ params ["anharmonic_prefactor_model" ], method
187+ ) or not callable (getattr (params ["anharmonic_prefactor_model" ], method )):
188+ raise AttributeError (
189+ f"params['anharmonic_prefactor_model'] must have a { method } method that takes arguments Vrel and params"
190+ )
191+
192+ # Check that the required methods are present in the
193+ # anharmonic_thermal_model
194+ expected_methods = [
195+ "nondimensional_helmholtz_energy" ,
196+ "nondimensional_dhelmholtz_dTheta" ,
197+ "nondimensional_d2helmholtz_dTheta2" ,
198+ "nondimensional_entropy" ,
199+ "nondimensional_dentropy_dTheta" ,
200+ "nondimensional_heat_capacity" ,
201+ ]
202+ for method in expected_methods :
203+ if not hasattr (params ["anharmonic_thermal_model" ], method ) or not callable (
204+ getattr (params ["anharmonic_thermal_model" ], method )
205+ ):
206+ raise AttributeError (
207+ f"params['anharmonic_thermal_model'] must have a { method } method that takes arguments temperature, debye_T, and params"
208+ )
0 commit comments