22#ifdef ESPRESSO_THERMAL_STONER_WOHLFARTH
27#include "constraints/Constraints.hpp"
28#include "constraints/HomogeneousMagneticField.hpp"
32#include "system/System.hpp"
33#include "thermostat.hpp"
71 auto const phi = x[0];
72 auto const *params =
reinterpret_cast<double const *
>(my_func_data);
73 auto const theta = params[0];
74 auto const h = params[1];
76 grad[0] = std::sin(2. * (phi - theta)) + 2. * h * std::sin(phi);
78 return -0.5 - 0.5 * std::cos(2. * (phi - theta)) - 2. * h * std::cos(phi);
95 double ani_param,
double tau0_inv,
96 double dt,
double const &noise) {
98 auto constexpr pi = std::numbers::pi_v<double>;
99 auto constexpr two_pi = 2. * pi;
103 auto const h_crit = std::pow(std::pow(std::sin(theta), 2. / 3.) +
104 std::pow(std::cos(theta), 2. / 3.),
106 nlopt::opt opt(nlopt::LD_MMA, 1);
107 double params[] = {theta, h};
112 std::vector<double> phi(1);
117 opt.optimize(phi, min1);
118 auto const phi_min1 = std::fmod(phi[0], two_pi);
119 auto solution = phi_min1;
120 if (std::fabs(h) < h_crit) {
124 opt.optimize(phi, max1);
125 auto const phi_max1 = std::fmod(phi[0], two_pi);
126 phi[0] = std::fmod(phi_max1 + pi, two_pi);
128 opt.optimize(phi, max2);
130 auto const b1 = std::abs(max1 - min1) * ani_param;
131 auto const b2 = std::abs(max2 - min1) * ani_param;
132 auto const b_min = (b1 < b2) ? b1 : b2;
134 auto const tau_inv = tau0_inv * exp(-b_min);
136 auto const p12 = 1. - exp(-dt * tau_inv);
140 phi[0] = std::fmod(phi_min1 + pi +
eps_phi, two_pi);
143 opt.optimize(phi, min2);
144 auto const phi_min2 = std::fmod(phi[0], two_pi);
148 return std::fmod(solution + two_pi, two_pi);
162 for (
auto const &constraint : constraints) {
163 auto ptr = std::dynamic_pointer_cast<HomogeneousMagneticField>(constraint);
180 double const kT,
double const noise) {
181 auto constexpr pi = std::numbers::pi_v<double>;
185 auto const kernel = [&](
bool flip) {
192 auto const flip = noise < p12;
202 kernel(flip == (dist_0 < dist_pi));
220 double const kT,
double const noise) {
222 auto constexpr pi = std::numbers::pi_v<double>;
223 auto constexpr pi_half = pi / 2.;
228 auto theta = std::acos(e_h * e_k);
229 if (theta > pi_half) {
234 auto const rot_axis =
240 auto const mom = e_h * std::cos(phi) + rot_axis * std::sin(phi);
242 auto const [quat, dipm] =
260 auto const kT = thermostat->kT;
261 cell_structure->for_each_local_particle([&](
Particle &p) {
270 auto const &langevin = *thermostat->langevin;
271 auto const e_k = p_ref->calc_director();
272 auto const ext_fld_dpl = ext_fld + p.
dip_fld();
273 auto const random_ints =
274 Random::philox_4_uint64s<RNGSalt::THERMAL_STONER_WOHLFARTH>(
275 langevin.rng_counter(), langevin.rng_seed(), p.
id());
277 if (ext_fld_dpl.norm2() == 0.) {
Vector implementation and trait types for boost qvm interoperability.
This file contains everything related to the global cell structure / cell system.
void integrate_magnetodynamics()
Run magnetodynamics update for local virtual particles.
Vector normalized() const
__device__ void vector_product(float const *a, float const *b, float *out)
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
constexpr double uniform(uint64_t in)
Uniformly map unsigned integer to double.
Random number generation using Philox.
Particle * get_reference_particle(CellStructure &cell_structure, Particle const &p)
Get real particle tracked by a virtual site.
This file contains all subroutines required to process rotational motion.
std::pair< Utils::Quaternion< double >, double > convert_dip_to_quat(const Utils::Vector3d &dip)
convert a dipole moment to quaternions and dipolar strength
static double phi_objective(unsigned n, const double *x, double *grad, void *my_func_data)
Objective (energy) function for the Stoner-Wohlfarth phi minimisation.
void stoner_wohlfarth_no_field(Particle &p, Utils::Vector3d const &e_k, double const kT, double const noise)
Simplified Stoner-Wohlfarth update in field-free case.
static constexpr double eps_abs
static constexpr double eps_rel
static double get_phi_at_energy_min(double theta, double h, double phi0, double ani_param, double tau0_inv, double dt, double const &noise)
Find the in-plane angle phi corresponding to the correct energy minimum for the thermal Stoner-Wohlfa...
static auto get_external_field(Constraints::Constraints const &constraints)
Collect external homogeneous magnetic field from active constraints.
static constexpr double eps_phi
static void stoner_wohlfarth_main(Particle &p, Utils::Vector3d const &e_k, Utils::Vector3d const &ext_fld_dpl, double const kT, double const noise)
Update virtual site dipole moment according to the full in-field (incl.
Struct holding all information for one particle.
auto const & dip_fld() const
auto const & magnetic_anisotropy_energy() const
auto const & stoner_wohlfarth_phi_0() const
auto const & magnetic_anisotropy_field_inv() const
auto const & quat() const
auto const & stoner_wohlfarth_tau0_inv() const
auto const & saturation_magnetization() const
auto const & stoner_wohlfarth_dt_incr() const
auto const & stoner_wohlfarth_is_enabled() const
auto const & dipm() const