Skip to content

Commit

Permalink
Merge branch 'spin-torque' into dipole
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-evans committed Sep 13, 2016
2 parents 5652042 + 785e2ab commit 7622e51
Show file tree
Hide file tree
Showing 20 changed files with 1,734 additions and 44 deletions.
2 changes: 1 addition & 1 deletion hdr/material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ using std::string;
extern double gamma_SI;

// Unrolled material parameters for speed
extern std::vector <double> MaterialMuSSIArray;
extern std::vector <double> mu_s_array;
extern std::vector <zkval_t> MaterialScalarAnisotropyArray;
extern std::vector <zkten_t> MaterialTensorAnisotropyArray;
extern std::vector <double> material_second_order_anisotropy_constant_array;
Expand Down
97 changes: 97 additions & 0 deletions hdr/spintorque.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//-----------------------------------------------------------------------------
//
// This header file is part of the VAMPIRE open source package under the
// GNU GPL (version 2) licence (see licence file for details).
//
// (c) R F L Evans 2014. All rights reserved.
//
//-----------------------------------------------------------------------------
//
// Spin torque calculation is done in 'stacks'. Each stack represents a
// number of microcells perpendicular to the current direction
//
// ---------------------------
// | | | | | | | | | | | | | |
// | | | | | | | | | | | | | |
// | | | | | | | | | | | | | |
// ---------------------------
// | | | | | | | | | | | | | |
// e- -> | | | | | | | | | | | | | |
// | | | | | | | | | | | | | |
// ---------------------------
// | | | | | | | | | | | | | |
// | | | | | | | | | | | | | |
// | | | | | | | | | | | | | |
// ---------------------------
// ^
// |
// Starting parameters (stack[0])
//
// Spin accumulation is calculated along each stack (in parallel). The
// microcells in each stack are atomically thin, and definable in size.
// The code is written so that the current direction within the sample can
// be chosen to be either in the x,y or z direction, and the atoms are
// assigned to cells accordingly.
//
// The first cell in the stack contains no atoms, and is given initial
// values for the spin transport parameters.
//
//
// System headers
#include <string>
#include <vector>

// Program headers

#ifndef SPINTORQUE_H_
#define SPINTORQUE_H_

//-----------------------------------------------------------------------------
// Namespace for variables and functions to calculate spin torque
//-----------------------------------------------------------------------------
namespace st{

//-----------------------------------------------------------------------------
// Variables used for the spin torque calculation
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Function to initialise spin torque calculation
//-----------------------------------------------------------------------------
void initialise(const double system_dimensions_x,
const double system_dimensions_y,
const double system_dimensions_z,
const std::vector<double>& atom_coords_x,
const std::vector<double>& atom_coords_y,
const std::vector<double>& atom_coords_z,
const std::vector<int>& atom_type_array,
const int num_local_atoms);

//-----------------------------------------------------------------------------
// Function to copy spin torque fields to external field array
//-----------------------------------------------------------------------------
void get_spin_torque_fields(std::vector<double>& x_total_external_field_array,
std::vector<double>& y_total_external_field_array,
std::vector<double>& z_total_external_field_array,
const int start_index,
const int end_index);

//-----------------------------------------------------------------------------
// Function for updating spin torque fields
//-----------------------------------------------------------------------------
void update_spin_torque_fields(const std::vector<double>& x_spin_array,
const std::vector<double>& y_spin_array,
const std::vector<double>& z_spin_array,
const std::vector<int>& atom_type_array,
const std::vector<double>& mu_s_array);

//-----------------------------------------------------------------------------
// Function for matching spin torque material parameters
//-----------------------------------------------------------------------------
bool match_material(std::string const word, std::string const value, std::string const unit, int const line, int const super_index);
bool match_input_parameter(std::string const key, std::string const word, std::string const value, std::string const unit, int const line);


} // end of st namespace

#endif // SPINTORQUE_H_
8 changes: 8 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ obj/simulate/cmc.o \
obj/simulate/cmc_mc.o \
obj/simulate/sim.o \
obj/simulate/standard_programs.o \
obj/spintorque/data.o \
obj/spintorque/field.o \
obj/spintorque/initialise.o \
obj/spintorque/interface.o \
obj/spintorque/magnetization.o \
obj/spintorque/matrix.o \
obj/spintorque/output.o \
obj/spintorque/spinaccumulation.o \
obj/statistics/data.o \
obj/statistics/initialize.o \
obj/statistics/magnetization.o \
Expand Down
Empty file added obj/spintorque/.gitignore
Empty file.
14 changes: 14 additions & 0 deletions src/create/create_system2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "ltmp.hpp"
#include "material.hpp"
#include "sim.hpp"
#include "spintorque.hpp"
#include "vio.hpp"
#include "vmath.hpp"
#include "vmpi.hpp"
Expand Down Expand Up @@ -312,6 +313,18 @@ int create(){
atoms::num_atoms
);

//----------------------------------------
// Initialise spin torque data
//----------------------------------------
st::initialise(cs::system_dimensions[0],
cs::system_dimensions[1],
cs::system_dimensions[2],
atoms::x_coord_array,
atoms::y_coord_array,
atoms::z_coord_array,
atoms::type_array,
num_local_atoms);

//----------------------------------------
// Initialise local temperature data
//----------------------------------------
Expand All @@ -333,6 +346,7 @@ int create(){
sim::Tmin,
sim::Tmax);


//std::cout << num_atoms << std::endl;
#ifdef MPICF
//std::cout << "Outputting coordinate data" << std::endl;
Expand Down
5 changes: 4 additions & 1 deletion src/main/initialise_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace mp{
double half_dt;

// Unrolled material parameters for speed
std::vector <double> MaterialMuSSIArray(0);
std::vector <double> mu_s_array;
std::vector <zkval_t> MaterialScalarAnisotropyArray(0);
std::vector <zkten_t> MaterialTensorAnisotropyArray(0);
std::vector <double> material_second_order_anisotropy_constant_array(0);
Expand Down Expand Up @@ -581,6 +581,9 @@ int set_derived_parameters(){
MaterialCubicAnisotropyArray.resize(mp::num_materials);
for(int mat=0;mat<mp::num_materials; mat++) MaterialCubicAnisotropyArray.at(mat)=mp::material[mat].Kc;
}
// Unroll material spin moment values for speed
mp::mu_s_array.resize(mp::num_materials);
for(int mat=0;mat<mp::num_materials; mat++) mu_s_array.at(mat)=mp::material[mat].mu_s_SI/9.27400915e-24; // normalise to mu_B

// Loop over materials to check for invalid input and warn appropriately
for(int mat=0;mat<mp::num_materials;mat++){
Expand Down
78 changes: 39 additions & 39 deletions src/simulate/LLGHeun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
//
// Email:[email protected]
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// ----------------------------------------------------------------------------
Expand All @@ -29,7 +29,7 @@
/// @details The LLG integrator...
///
/// @section notes Implementation Notes
/// This is a list of other notes, not related to functionality but rather to implementation.
/// This is a list of other notes, not related to functionality but rather to implementation.
/// Also include references, formulae and other notes here.
///
/// @section License
Expand Down Expand Up @@ -62,33 +62,33 @@ int calculate_spin_fields(const int,const int);
int calculate_external_fields(const int,const int);

namespace LLG_arrays{

// Local arrays for LLG integration
std::vector <double> x_euler_array;
std::vector <double> y_euler_array;
std::vector <double> y_euler_array;
std::vector <double> z_euler_array;

std::vector <double> x_heun_array;
std::vector <double> y_heun_array;
std::vector <double> x_heun_array;
std::vector <double> y_heun_array;
std::vector <double> z_heun_array;

std::vector <double> x_spin_storage_array;
std::vector <double> y_spin_storage_array;
std::vector <double> x_spin_storage_array;
std::vector <double> y_spin_storage_array;
std::vector <double> z_spin_storage_array;

std::vector <double> x_initial_spin_array;
std::vector <double> y_initial_spin_array;
std::vector <double> x_initial_spin_array;
std::vector <double> y_initial_spin_array;
std::vector <double> z_initial_spin_array;

bool LLG_set=false; ///< Flag to define state of LLG arrays (initialised/uninitialised)

}

namespace sim{

/// @brief LLG Initialisation function
///
/// @details Resizes arrays used for Heun integration
/// @details Resizes arrays used for Heun integration
///
/// @section License
/// Use of this code, either in source or compiled form, is subject to license from the authors.
Expand All @@ -100,14 +100,14 @@ namespace sim{
/// @date 07/02/2011
///
/// @return EXIT_SUCCESS
///
///
/// @internal
/// Created: 07/02/2011
/// Revision: ---
///=====================================================================================
///
int LLGinit(){

// check calling of routine if error checking is activated
if(err::check==true){std::cout << "sim::LLG_init has been called" << std::endl;}

Expand Down Expand Up @@ -139,7 +139,7 @@ int LLGinit(){
/// @callgraph
/// @callergraph
///
/// @details Integrates the system using the LLG and Heun solver
/// @details Integrates the system using the LLG and Heun solver
///
/// @section License
/// Use of this code, either in source or compiled form, is subject to license from the authors.
Expand All @@ -151,7 +151,7 @@ int LLGinit(){
/// @date 07/02/2011
///
/// @return EXIT_SUCCESS
///
///
/// @internal
/// Created: 05/02/2011
/// Revision: ---
Expand All @@ -166,14 +166,14 @@ int LLG_Heun(){

// Check for initialisation of LLG integration arrays
if(LLG_set==false) sim::LLGinit();

// Local variables for system integration
const int num_atoms=atoms::num_atoms;
double xyz[3]; // Local Delta Spin Components
double S_new[3]; // New Local Spin Moment
double mod_S; // magnitude of spin moment
double mod_S; // magnitude of spin moment

// Store initial spin positions
// Store initial spin positions
for(int atom=0;atom<num_atoms;atom++){
x_initial_spin_array[atom] = atoms::x_spin_array[atom];
y_initial_spin_array[atom] = atoms::y_spin_array[atom];
Expand All @@ -183,7 +183,7 @@ int LLG_Heun(){
// Calculate fields
calculate_spin_fields(0,num_atoms);
calculate_external_fields(0,num_atoms);

// Calculate Euler Step
for(int atom=0;atom<num_atoms;atom++){

Expand Down Expand Up @@ -211,30 +211,30 @@ int LLG_Heun(){
S_new[0]=S[0]+xyz[0]*mp::dt;
S_new[1]=S[1]+xyz[1]*mp::dt;
S_new[2]=S[2]+xyz[2]*mp::dt;

// Normalise Spin Length
mod_S = 1.0/sqrt(S_new[0]*S_new[0] + S_new[1]*S_new[1] + S_new[2]*S_new[2]);

S_new[0]=S_new[0]*mod_S;
S_new[1]=S_new[1]*mod_S;
S_new[2]=S_new[2]*mod_S;

//Writing of Spin Values to Storage Array
x_spin_storage_array[atom]=S_new[0];
y_spin_storage_array[atom]=S_new[1];
z_spin_storage_array[atom]=S_new[2];
z_spin_storage_array[atom]=S_new[2];
}

// Copy new spins to spin array
for(int atom=0;atom<num_atoms;atom++){
atoms::x_spin_array[atom]=x_spin_storage_array[atom];
atoms::y_spin_array[atom]=y_spin_storage_array[atom];
atoms::z_spin_array[atom]=z_spin_storage_array[atom];
}

// Recalculate spin dependent fields
calculate_spin_fields(0,num_atoms);

// Calculate Heun Gradients
for(int atom=0;atom<num_atoms;atom++){

Expand Down Expand Up @@ -264,10 +264,10 @@ int LLG_Heun(){
S_new[0]=x_initial_spin_array[atom]+mp::half_dt*(x_euler_array[atom]+x_heun_array[atom]);
S_new[1]=y_initial_spin_array[atom]+mp::half_dt*(y_euler_array[atom]+y_heun_array[atom]);
S_new[2]=z_initial_spin_array[atom]+mp::half_dt*(z_euler_array[atom]+z_heun_array[atom]);

// Normalise Spin Length
mod_S = 1.0/sqrt(S_new[0]*S_new[0] + S_new[1]*S_new[1] + S_new[2]*S_new[2]);

S_new[0]=S_new[0]*mod_S;
S_new[1]=S_new[1]*mod_S;
S_new[2]=S_new[2]*mod_S;
Expand All @@ -286,7 +286,7 @@ int LLG_Heun(){
/// @callgraph
/// @callergraph
///
/// @details Integrates the system using the LLG and Heun solver
/// @details Integrates the system using the LLG and Heun solver
///
/// @section License
/// Use of this code, either in source or compiled form, is subject to license from the authors.
Expand All @@ -298,15 +298,15 @@ int LLG_Heun(){
/// @date 05/02/2011
///
/// @return EXIT_SUCCESS
///
///
/// @internal
/// Created: 05/02/2011
/// Revision: ---
///=====================================================================================
///
int LLG_Heun_cuda(){


return EXIT_SUCCESS;
}

Expand Down
Loading

0 comments on commit 7622e51

Please sign in to comment.