Skip to content

Commit

Permalink
Merge pull request #37847 from mantidproject/crystal-field-mag-bug
Browse files Browse the repository at this point in the history
Correct bug of missing 'Hmag' field in CrystalField interface
  • Loading branch information
SilkeSchomann authored Aug 23, 2024
2 parents c57b75b + 1379022 commit 1adc22a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- The method `cf.getMagneticMoment()` no longer ignores the `Hmag` field, which is now
correctly considered in the calculations of the magnetic moment.
2 changes: 1 addition & 1 deletion scripts/Inelastic/CrystalField/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def toString(self):
out += ",Temperature=%s" % (self._physpropTemperature)
else: # either susceptibility or M(T)
out += ",inverse=%s" % (1 if self._suscInverseFlag else 0)
out += (",Hmag=%s" % (self._hmag)) if self._typeid == self.MAGNETISATION else ""
out += (",Hmag=%s" % (self._hmag)) if self._typeid == self.MAGNETICMOMENT else ""
if self._typeid == self.SUSCEPTIBILITY and self._lambda != 0:
out += ",Lambda=%s" % (self._lambda)
if self._typeid == self.SUSCEPTIBILITY and self._chi0 != 0:
Expand Down
10 changes: 10 additions & 0 deletions scripts/test/CrystalFieldTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,16 @@ def test_api_CrystalField_physical_properties(self):
self.assertAlmostEqual(chi_powder[10] * 10, 1 / invmt_powder_SI[10], 2)
self.assertAlmostEqual(chi_powder[15] * 10, 1 / invmt_powder_SI[15], 2)

# Test different Hmag
_, h_mag_10 = cf.getMagneticMoment(Hmag=10, Temperature=np.linspace(1, 300, 50), Hdir="powder", Unit="bohr")
self.assertAlmostEqual(h_mag_10[5], 0.323607, 5)
self.assertAlmostEqual(h_mag_10[10], 0.182484, 5)
self.assertAlmostEqual(h_mag_10[15], 0.129909, 5)
_, h_mag_5 = cf.getMagneticMoment(Hmag=5, Temperature=np.linspace(1, 300, 50), Hdir="powder", Unit="bohr")
self.assertAlmostEqual(h_mag_5[5], 0.16923426, 6)
self.assertAlmostEqual(h_mag_5[10], 0.09228022, 6)
self.assertAlmostEqual(h_mag_5[15], 0.06525625, 6)

# Test M(H) calculations
Hmag_SI, mag_SI = cf.getMagneticMoment(np.linspace(0, 30, 15), Temperature=10, Hdir=[0, 1, -1], Unit="SI")
self.assertAlmostEqual(mag_SI[1], 1.8139, 3)
Expand Down

0 comments on commit 1adc22a

Please sign in to comment.