Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New drivers #44

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 1.3.2

- Added new `ScalarDrivers` -- Gaussian impulse and Gaussian step.

# 1.3.1

- `CVector` got extra functionality in Python bindings. Operators are now supported.
Expand Down
2 changes: 1 addition & 1 deletion cmtj/utils/resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def calculate_resistance_series(Rx0: List[float], Ry0: List[float],
AMR: List[float], AHE: List[float],
SMR: List[float], m: List[float],
l: List[float], w: List[float]):
"""Calculates the resistance of the system in parallel.
"""Calculates the resistance of the system in series.
Uses Kim's formula from the paper:
https://link.aps.org/doi/10.1103/PhysRevLett.116.097201"""
SxAll, SyAll = compute_resistance(Rx0, Ry0, AMR, AHE, SMR, m, l, w)
Expand Down
48 changes: 45 additions & 3 deletions core/drivers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ enum UpdateType
step,
posine,
halfsine,
trapezoid
trapezoid,
gaussimpulse,
gaussstep
};

template <typename T>
Expand Down Expand Up @@ -124,7 +126,6 @@ class ScalarDriver : public Driver<T>
return 0;
}


public:
explicit ScalarDriver(
UpdateType update = constant,
Expand Down Expand Up @@ -263,6 +264,40 @@ class ScalarDriver : public Driver<T>
-1, -1, -1, -1, timeStart, -1, edgeTime, steadyTime);
}

/**
* @brief Get the Gaussian Impulse Driver object
*
* @param constantValue
* @param amplitude
* @param t0 center of the pulse
* @param sigma sigma of the gaussian
* @return ScalarDriver
*/
static ScalarDriver getGaussianImpulseDriver(T constantValue, T amplitude, T t0, T sigma) {
return ScalarDriver(
gaussimpulse,
constantValue,
amplitude,
-1, -1, -1, -1, t0, -1, sigma);
}

/**
* @brief Get the Gaussian Impulse Driver object
*
* @param constantValue
* @param amplitude
* @param t0 center of the growth
* @param sigma sigma of the gaussian
* @return ScalarDriver
*/
static ScalarDriver getGaussianStepDriver(T constantValue, T amplitude, T t0, T sigma) {
return ScalarDriver(
gaussimpulse,
constantValue,
amplitude,
-1, -1, -1, -1, t0, -1, sigma);
}

T getCurrentScalarValue(T& time) override
{
T returnValue = this->constantValue;
Expand Down Expand Up @@ -293,7 +328,14 @@ class ScalarDriver : public Driver<T>
else if (this->update == trapezoid) {
returnValue += trapezoidalUpdate(this->amplitude, time, this->timeStart, this->edgeTime, this->steadyTime);
}

else if (this->update == gaussimpulse) {
const T gaussImp = this->amplitude * exp(-pow(time - this->timeStart, 2) / (2 * pow(this->edgeTime, 2)));
returnValue += gaussImp;
}
else if (this->update == gaussstep) {
const T gaussStep = 0.5 * this->amplitude * (1 + std::erf((time - this->timeStart) / (sqrt(2) * this->edgeTime)));
returnValue += gaussStep;
}
return returnValue;
}
void setConstantValue(const T& val)
Expand Down
23 changes: 18 additions & 5 deletions python/cmtj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,20 @@ PYBIND11_MODULE(cmtj, m)
"amplitude"_a,
"timeStart"_a,
"edgeTime"_a,
"steadyTime"_a);
"steadyTime"_a)
.def_static("getGaussianImpulseDriver",
&DScalarDriver::getGaussianImpulseDriver,
"constantValue"_a,
"amplitude"_a,
"t0"_a,
"sigma"_a)
.def_static("getGaussianStepDriver",
&DScalarDriver::getGaussianStepDriver,
"constantValue"_a,
"amplitude"_a,
"t0"_a,
"sigma"_a);

py::class_<DNullDriver, DScalarDriver>(m, "NullDriver")
.def(py::init<>());

Expand Down Expand Up @@ -271,8 +284,8 @@ PYBIND11_MODULE(cmtj, m)
"totalTime"_a,
"timeStep"_a = 1e-13,
"writeFrequency"_a = 1e-11)
.def("setMagnetistation", &SeriesStack<double>::setMagnetisation, "junction"_a, "layerId"_a, "mag"_a)
.def("getMagnetistation", &SeriesStack<double>::getMagnetisation, "junction"_a, "layerId"_a)
.def("setMagnetisation", &SeriesStack<double>::setMagnetisation, "junction"_a, "layerId"_a, "mag"_a)
.def("getMagnetisation", &SeriesStack<double>::getMagnetisation, "junction"_a, "layerId"_a)
.def("setCoupledCurrentDriver", &SeriesStack<double>::setCoupledCurrentDriver, "driver"_a)
.def("setExternalFieldDriver", &SeriesStack<double>::setExternalFieldDriver, "driver"_a)
.def("setCouplingStrength", &SeriesStack<double>::setCouplingStrength, "coupling"_a)
Expand All @@ -296,8 +309,8 @@ PYBIND11_MODULE(cmtj, m)
"totalTime"_a,
"timeStep"_a = 1e-13,
"writeFrequency"_a = 1e-11)
.def("setMagnetistation", &ParallelStack<double>::setMagnetisation, "junction"_a, "layerId"_a, "mag"_a)
.def("getMagnetistation", &ParallelStack<double>::getMagnetisation, "junction"_a, "layerId"_a)
.def("setMagnetisation", &ParallelStack<double>::setMagnetisation, "junction"_a, "layerId"_a, "mag"_a)
.def("getMagnetisation", &ParallelStack<double>::getMagnetisation, "junction"_a, "layerId"_a)
.def("setCoupledCurrentDriver", &ParallelStack<double>::setCoupledCurrentDriver, "driver"_a)
.def("setExternalFieldDriver", &ParallelStack<double>::setExternalFieldDriver, "driver"_a)
.def("setCouplingStrength", &ParallelStack<double>::setCouplingStrength, "coupling"_a)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import Extension, find_namespace_packages, setup
from setuptools.command.build_ext import build_ext

__version__ = "1.3.1"
__version__ = "1.3.2"
"""
As per
https://github.com/pybind/python_example
Expand Down