Skip to content

Commit

Permalink
small updates to resistances and cvector + noise fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LemurPwned committed Jan 30, 2025
1 parent f7c2da0 commit 3547db3
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 7 deletions.
41 changes: 41 additions & 0 deletions cmtj/utils/resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,47 @@ def Rxx_parallel_bilayer_expr():
return Rlin_func, R_func


def GMR_expr():
"""Get the symbolic expression for the GMR.
:returns: GMR function
"""
GMR_s = sym.Symbol(r"\mathrm{GMR}")
theta1 = sym.Symbol(r"\theta_1")
phi1 = sym.Symbol(r"\phi_1")
m1 = sym.Matrix(
[
sym.sin(theta1) * sym.cos(phi1),
sym.sin(theta1) * sym.sin(phi1),
sym.cos(theta1),
]
)
theta2 = sym.Symbol(r"\theta_2")
phi2 = sym.Symbol(r"\phi_2")
m2 = sym.Matrix(
[
sym.sin(theta2) * sym.cos(phi2),
sym.sin(theta2) * sym.sin(phi2),
sym.cos(theta2),
]
)
Rf = GMR_s * (1 - m1.dot(m2)) / 2
dRdt1 = sym.diff(Rf, theta1)
dRdp1 = sym.diff(Rf, phi1)
dRdt2 = sym.diff(Rf, theta2)
dRdp2 = sym.diff(Rf, phi2)
linearised_terms = sym.symbols(r"\partial\theta_1, \partial\phi_1, \partial\theta_2, \partial\phi_2")
dRf = (
dRdt1 * linearised_terms[0]
+ dRdp1 * linearised_terms[1]
+ dRdt2 * linearised_terms[2]
+ dRdp2 * linearised_terms[3]
)

Rf_func = sym.lambdify([GMR_s, [theta1, phi1, theta2, phi2]], Rf)
dRf_func = sym.lambdify([GMR_s, [theta1, phi1, theta2, phi2], linearised_terms], dRf)
return Rf_func, dRf_func


def Rxx_series_bilayer_expr():
"""Get the symbolic expressions for the series and linearised resistance of a bilayer system.
Expand Down
5 changes: 5 additions & 0 deletions core/cvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ template <typename T> class CVector {
ss << "[x:" << this->x << ", y:" << this->y << ", z:" << this->z << "]";
return ss.str();
}

static CVector<T> fromSpherical(T theta, T phi, T r = 1.0) {
return CVector<T>(r * sin(theta) * cos(phi), r * sin(theta) * sin(phi),
r * cos(theta));
}
};

#endif // CORE_CVECTOR_HPP_
5 changes: 3 additions & 2 deletions core/noise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ template <typename T = double> class OneFNoise {
}
};

std::mt19937 generator(std::random_device{}());
// std::mt19937 generator(std::random_device{}());
template <typename T = double> class BufferedAlphaNoise : public NullTicker<T> {
protected:
std::vector<std::complex<float>> bufferWhite, bufferColoured;
Expand All @@ -148,6 +148,7 @@ template <typename T = double> class BufferedAlphaNoise : public NullTicker<T> {
inv; // configs for forward and inverse real fft
unsigned int internalCounter = 0;
unsigned int refills = 0;
std::mt19937 generator;

public:
/**
Expand All @@ -160,7 +161,7 @@ template <typename T = double> class BufferedAlphaNoise : public NullTicker<T> {
*/
BufferedAlphaNoise(unsigned int bufferSize, T alpha, T std, T scale)
: bufferSize(bufferSize), alpha(alpha), scale(scale) {

this->generator = std::mt19937(std::random_device{}());
this->bufferColoured.resize(2 * bufferSize);
this->bufferWhite.resize(2 * bufferSize);
this->result.resize(bufferSize);
Expand Down
2 changes: 1 addition & 1 deletion docs/api/core.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: cmtj
::: cmtj.core
43 changes: 41 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
[![pages-build-deployment](https://github.com/LemurPwned/cmtj/actions/workflows/pages/pages-build-deployment/badge.svg?branch=gh-pages)](https://github.com/LemurPwned/cmtj/actions/workflows/pages/pages-build-deployment)
[![Version](https://img.shields.io/pypi/v/cmtj)](https://pypi.org/project/cmtj/)
[![License](https://img.shields.io/pypi/l/cmtj.svg)](https://github.com/LemurPwned/cmtj/blob/master/LICENSE)
[![Streamlit](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](http://cmtj-simulations.streamlit.app/)
[![Streamlit](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://cmtj-app.streamlit.app/spectrum)
![Downloads](https://img.shields.io/pypi/dm/cmtj.svg)

## Table of contents

- [CMTJ](#cmtj)
- [Table of contents](#table-of-contents)
- [Short description](#short-description)
- [What can you simulate?](#what-can-you-simulate)
- [Web GUI](#web-gui)
- [Quickstart](#quickstart)
- [Installation :rocket:](#installation-rocket)
Expand All @@ -34,9 +35,47 @@ The `cmtj` name may be misleading -- the MTJ (Magnetic Tunnel Junctions) are not
The library allows for macromagnetic simulation of various multilayer spintronic structures. The package uses C++ implementation of (s)LLGS (stochastic Landau-Lifschitz-Gilbert-Slonczewski) equation with various field contributions included for instance: anisotropy, interlayer exchange coupling, demagnetisation, dipole fields etc.
It is also possible to connect devices in parallel or in series to have electrically coupled arrays.

### What can you simulate?

Below is a brief list of examples (it's not exhaustive! Check the docs for more).

**Magnetic devices:**

- Magnetic Tunnel Junctions
- Voltage-Driven Magnetic Tunnel Junctions
- Spin-Torque Oscillators
- VCMA sensors and devices
- Magnetic Tunnel Junction Arrays
- SOT devices
- Current-Driven SOT
- Advanced device coupling
- Reservoirs (dipole coupling)
- Electrically coupled MTJs
- Base equations
- Landau-Lifshitz-Gilbert-Slonczewski equation
- Stochastic Landau-Lifshitz-Gilbert-Slonczewski equation
- Landau-Lifshitz-Gilbert-Bloch equation
- Domain wall motion

**Experimental methods:**

Some of the experimental methods available:

- PIMM
- Spin-Diode
- CIMS
- R(H), M(H)

## Web GUI

Check out the [streamlit hosted demo here](http://cmtj-simulations.streamlit.app/). You can simulate PIMM spectra and Spin-Diode spectra there. Let us know if you have any issues with the demo.
Check out the [streamlit hosted demo here](https://cmtj-app.streamlit.app/spectrum).
You can simulate:

- PIMM spectra and Spin-Diode spectra
- Try some optimization fitting
- Fit multi-domain or multi-level M(H) or R(H) loops in [Domain mode](https://cmtj-app.streamlit.app)

Let us know if you have any issues with the demo.

## Quickstart

Expand Down
5 changes: 3 additions & 2 deletions python/cmtj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ PYBIND11_MODULE(cmtj, m) {
[](const DVector& v, const int key) { return v[key]; })
.def("__len__", [](const DVector& v) { return 3; })
.def("__str__", py::overload_cast<>(&DVector::toString))
.def("__repr__", py::overload_cast<>(&DVector::toString));
.def("__repr__", py::overload_cast<>(&DVector::toString))
.def_static("fromSpherical", &DVector::fromSpherical, "theta"_a, "phi"_a, "r"_a = 1.0);

py::implicitly_convertible<std::list<double>, DVector>();
py::implicitly_convertible<std::vector<double>, DVector>();
Expand Down Expand Up @@ -240,7 +241,7 @@ PYBIND11_MODULE(cmtj, m) {
.def_readonly("cellSurface", &DLayer::cellSurface)
.def_readonly("demagTensor", &DLayer::demagTensor)
// noise
.def("setAlphaNoise", &DLayer::setAlphaNoise)
.def("setAlphaNoise", &DLayer::setAlphaNoise, "alpha"_a, "std"_a, "scale"_a, "axis"_a = Axis::all)
.def("setOneFNoise", &DLayer::setOneFNoise)
// getters
.def("getId", &DLayer::getId)
Expand Down

0 comments on commit 3547db3

Please sign in to comment.