Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mumaxplus/strayfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/bindings/wrap_strayfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());});
}
2 changes: 1 addition & 1 deletion src/physics/strayfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
7 changes: 7 additions & 0 deletions src/physics/strayfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>

#include "fieldquantity.hpp"
#include "strayfieldkernel.hpp"

class Parameter;
class Magnet;
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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<const System> system_;
const Magnet* magnet_;
Expand Down
2 changes: 1 addition & 1 deletion src/physics/strayfieldbrute.cu
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ Field StrayFieldBruteExecutor::exec() const {
cudaLaunch(ncells, k_demagfield, h.cu(), hostmag.cu(), kernel_.field().cu(), msat.cu());
}
return h;
}
}
2 changes: 2 additions & 0 deletions src/physics/strayfieldbrute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};
2 changes: 1 addition & 1 deletion src/physics/strayfieldfft.cu
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,4 @@ Field StrayFieldFFTExecutor::exec() const {
Field h(system_, 3);
cudaLaunch(h.grid().ncells(), k_unpad, h.cu(), mpad->cu());
return h;
}
}
2 changes: 2 additions & 0 deletions src/physics/strayfieldfft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/test_demag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
assert err < 1e-5