diff --git a/mumaxplus/strayfield.py b/mumaxplus/strayfield.py index 2e82d435..a8e9c239 100644 --- a/mumaxplus/strayfield.py +++ b/mumaxplus/strayfield.py @@ -99,3 +99,8 @@ def switch_radius(self): @switch_radius.setter def switch_radius(self, value=-1): self._impl.switching_radius = value + + @property + def kernel(self): + """Return the StrayFieldKernel.""" + return self._impl.kernel diff --git a/src/bindings/wrap_strayfield.cpp b/src/bindings/wrap_strayfield.cpp index 03beb074..70ead9cb 100644 --- a/src/bindings/wrap_strayfield.cpp +++ b/src/bindings/wrap_strayfield.cpp @@ -24,5 +24,6 @@ void wrap_strayfield(py::module& m) { }) .def_property("order", &StrayField::order, &StrayField::setOrder) .def_property("epsilon", &StrayField::eps, &StrayField::setEps) - .def_property("switching_radius", &StrayField::switchingradius, &StrayField::setSwitchingradius); + .def_property("switching_radius", &StrayField::switchingradius, &StrayField::setSwitchingradius) + .def_property_readonly("kernel", [](const StrayField& sf) {return fieldToArray(sf.kernel().field());}); } diff --git a/src/physics/strayfield.cpp b/src/physics/strayfield.cpp index 196da723..5e01005c 100644 --- a/src/physics/strayfield.cpp +++ b/src/physics/strayfield.cpp @@ -135,4 +135,4 @@ bool StrayField::assuredZero() const { throw std::invalid_argument("Cannot calculate strayfield since magnet is neither " "a Ferromagnet, a (non-collinear) " "Antiferromagnet/Ferrimagnet, nor an Altermagnet."); -} +} \ No newline at end of file diff --git a/src/physics/strayfield.hpp b/src/physics/strayfield.hpp index 8607ccf0..8ad89316 100644 --- a/src/physics/strayfield.hpp +++ b/src/physics/strayfield.hpp @@ -4,6 +4,7 @@ #include #include "fieldquantity.hpp" +#include "strayfieldkernel.hpp" class Parameter; class Magnet; @@ -65,6 +66,9 @@ class StrayFieldExecutor { /** Return the switching radius of the executor. */ virtual double switchingradius() const = 0; + /** Return the strayfieldkernel as a field */ + virtual const StrayFieldKernel& kernel() const = 0; + protected: /** Source of the stray field*/ const Magnet* magnet_; @@ -152,6 +156,9 @@ class StrayField : public FieldQuantity { /** Return true if one can be sure that the stray field is exactly zero. */ bool assuredZero() const; + /** Return the strayfieldkernel as a field */ + const StrayFieldKernel& kernel() const { return executor_->kernel();} + private: std::shared_ptr system_; const Magnet* magnet_; diff --git a/src/physics/strayfieldbrute.cu b/src/physics/strayfieldbrute.cu index e6113955..e45eb5fa 100644 --- a/src/physics/strayfieldbrute.cu +++ b/src/physics/strayfieldbrute.cu @@ -73,4 +73,4 @@ Field StrayFieldBruteExecutor::exec() const { cudaLaunch(ncells, k_demagfield, h.cu(), hostmag.cu(), kernel_.field().cu(), msat.cu()); } return h; -} +} \ No newline at end of file diff --git a/src/physics/strayfieldbrute.hpp b/src/physics/strayfieldbrute.hpp index eb966b34..e7e2368d 100644 --- a/src/physics/strayfieldbrute.hpp +++ b/src/physics/strayfieldbrute.hpp @@ -41,6 +41,8 @@ class StrayFieldBruteExecutor : public StrayFieldExecutor { /** Return the switching radius. */ double switchingradius() const { return kernel_.switchingradius();} + const StrayFieldKernel& kernel() const { return kernel_;}; + private: StrayFieldKernel kernel_; }; diff --git a/src/physics/strayfieldfft.cu b/src/physics/strayfieldfft.cu index 1b04ad72..4fc4bc0c 100644 --- a/src/physics/strayfieldfft.cu +++ b/src/physics/strayfieldfft.cu @@ -238,4 +238,4 @@ Field StrayFieldFFTExecutor::exec() const { Field h(system_, 3); cudaLaunch(h.grid().ncells(), k_unpad, h.cu(), mpad->cu()); return h; -} +} \ No newline at end of file diff --git a/src/physics/strayfieldfft.hpp b/src/physics/strayfieldfft.hpp index 8068a9e4..a426be23 100644 --- a/src/physics/strayfieldfft.hpp +++ b/src/physics/strayfieldfft.hpp @@ -45,6 +45,8 @@ class StrayFieldFFTExecutor : public StrayFieldExecutor { /** Return the switching radius. */ double switchingradius() const { return kernel_.switchingradius();} + const StrayFieldKernel& kernel() const { return kernel_;}; + private: StrayFieldKernel kernel_; int3 fftSize; diff --git a/test/test_demag.py b/test/test_demag.py index 54553460..3d8f1048 100644 --- a/test/test_demag.py +++ b/test/test_demag.py @@ -81,7 +81,7 @@ def test_Nxx_radius(self): nx, ny, nz = 126, 64, 8 world = World((1e-9, 1e-9, 1e-9)) magnet = Ferromagnet(world, Grid((nx, ny, nz))) - mumaxplus_result = _cpp._demag_kernel(magnet._impl, 11, 5e-10, 5e-9)[0,nz:,ny:, nx:] # Nxx component + mumaxplus_result = _cpp._demag_kernel(magnet._impl, 11, 5e-10, 5e-9)[0,nz:,ny:, nx:] # Nxx # avoid fake errors when both values are super small mask = ~((np.abs(self.exact_Nxx) < 5e-15) & (np.abs(mumaxplus_result) < 5e-15)) @@ -137,4 +137,4 @@ def test_Nxy_aspect(self): mumaxplus_result = self.kernel_aspect[3,:,ny_aspect+1:, nx_aspect+1:] # Nxy component err = np.max(relative_error(mumaxplus_result, self.exact_aspect_Nxy)) - assert err < 1e-5 \ No newline at end of file + assert err < 1e-5