Skip to content

Commit

Permalink
Improvements for Hopfion visualisation etc.
Browse files Browse the repository at this point in the history
Improved performance of GL by copying spins data etc. only if a simulation is running.
Added basis_atoms to geometry.
Added format enum for Vector Files (e.g. Spin Configurations, in order to be able to read in CSV and other formats)
Bugfix: bad file name in Neighbours.cpp.
Bugfix: Hopfion configuration now is nontrivial and has winding number 1.
Bugfix: Method_LLG now saves the effective field into the spin system after each iteration.
  • Loading branch information
GPMueller committed Oct 18, 2016
1 parent 8fd7f3d commit e29946c
Show file tree
Hide file tree
Showing 19 changed files with 313 additions and 126 deletions.
7 changes: 4 additions & 3 deletions core/include/data/Geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace Data
public:
// Constructor
Geometry(const std::vector<std::vector<double>> basis, const std::vector<std::vector<double>> translation_vectors,
const std::vector<int> n_cells, const int n_spins_basic_domain, const std::vector<double> spin_pos);
const std::vector<int> n_cells, const int n_spins_basic_domain, const std::vector<std::vector<double>> basis_atoms,
const std::vector<double> spin_pos);
// Destructor
//~Geometry();

Expand All @@ -36,8 +37,8 @@ namespace Data
const std::vector<int> n_cells;
// Number of spins per basic domain
const int n_spins_basic_domain;
// TODO: array of basis atom positions [n][3]
// std::vector<std::vector<double>> basis_atoms;
// Array of basis atom positions [3][n_basis_atoms]
std::vector<std::vector<double>> basis_atoms;
// Number of Spins total
const int nos;
// number of shells -> moved to Hamiltonian
Expand Down
11 changes: 10 additions & 1 deletion core/include/utility/IO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ namespace Utility
{
namespace IO
{
enum class VectorFileFormat
{
CSV_POS_SPIN,
CSV_SPIN,
WHITESPACE_POS_SPIN,
WHITESPACE_SPIN
};

// ======================== Configparser ========================
// Note that due to the modular structure of the input parsers, input may be given in one or in separate files.
// Input may be given incomplete. In this case a log entry is created and default values are used.
Expand All @@ -39,7 +47,8 @@ namespace Utility
std::unique_ptr<Engine::Hamiltonian_Gaussian> Hamiltonian_Gaussian_from_Config(const std::string configFile, Data::Geometry geometry);

// ========================= Fileparser =========================
void Read_Spin_Configuration(std::shared_ptr<Data::Spin_System> s, const std::string file);
void Read_Spin_Configuration_CSV(std::shared_ptr<Data::Spin_System> s, const std::string file);
void Read_Spin_Configuration(std::shared_ptr<Data::Spin_System> s, const std::string file, VectorFileFormat format = VectorFileFormat::CSV_POS_SPIN);
void Read_SpinChain_Configuration(std::shared_ptr<Data::Spin_System_Chain> c, const std::string file);
//External_Field_from_File ....
void Anisotropy_from_File(const std::string anisotropyFile, Data::Geometry geometry, int & n_indices,
Expand Down
7 changes: 4 additions & 3 deletions core/src/data/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
namespace Data
{
Geometry::Geometry(std::vector<std::vector<double>> basis_i, const std::vector<std::vector<double>> translation_vectors_i,
const std::vector<int> n_cells_i, const int n_spins_basic_domain_i, const std::vector<double> spin_pos_i) :
basis(basis_i), translation_vectors(translation_vectors_i),
n_cells(n_cells_i), n_spins_basic_domain(n_spins_basic_domain_i),
const std::vector<int> n_cells_i, const int n_spins_basic_domain_i, const std::vector<std::vector<double>> basis_atoms_i,
const std::vector<double> spin_pos_i) :
basis(basis_i), translation_vectors(translation_vectors_i), n_cells(n_cells_i),
n_spins_basic_domain(n_spins_basic_domain_i), basis_atoms(basis_atoms_i),
spin_pos(spin_pos_i), nos( n_spins_basic_domain_i * n_cells_i[0] * n_cells_i[1] * n_cells_i[2])
{
// Calculate Bounds of the System
Expand Down
2 changes: 2 additions & 0 deletions core/src/engine/Method_LLG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ namespace Engine

// --- Image Data Update
// Update the system's Energy
// ToDo: copy instead of recalculating
systems[0]->UpdateEnergy();

// ToDo: How to update eff_field without numerical overhead?
systems[0]->effective_field = F_total[0];
// systems[0]->UpdateEffectiveField();

// TODO: In order to update Rx with the neighbouring images etc., we need the state -> how to do this?
Expand Down
4 changes: 2 additions & 2 deletions core/src/engine/Neighbours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ namespace Engine
}
else { output_to_file.reserve(int(1E+08)); }

const int buffer_length = 80, name_length = 29;
const int buffer_length = 80, name_length = 35;
char buffer_file_name[name_length + 2];
char buffer_string_conversion[buffer_length + 2];
//------------------------ End Init ----------------------------------------
Expand Down Expand Up @@ -372,7 +372,7 @@ namespace Engine

for (shell = 0; shell < n_shells; ++shell)
{
snprintf(buffer_file_name, name_length, "output/neighbours_in_shell_%03i.dat", shell + 1);
snprintf(buffer_file_name, name_length, "output/neighbours_in_shell_%03i.dat", (shell + 1));
output_to_file = "List of neighbours in the ";
snprintf(buffer_string_conversion, buffer_length, "%03i-th shell\n Spin Number of |List of \n number|neighbours|neighbours", shell + 1);
output_to_file.append(buffer_string_conversion);
Expand Down
2 changes: 1 addition & 1 deletion core/src/utility/Configurations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace Utility
t = sin(tmp)*sin(T);
t = acos(1.0 - 2.0*t*t);
// ...
F = atan2(py[n], px[n]);
F = atan2(py[n] - pos[1], px[n] - pos[0]);
if (T > M_PI / 2.0) {
f = F + atan(1.0 / (tan(tmp)*cos(T)));
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/utility/IO_Configparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace Utility
double lattice_constant = 1.0;
// Basis: vector {a, b, c}
basis = { std::vector<double>{1,0,0}, std::vector<double>{0,1,0}, std::vector<double>{0,0,1} };
// Atoms in the basis
// Atoms in the basis [dim][n_basis_atoms]
basis_atoms = { std::vector<double>{0}, std::vector<double>{0}, std::vector<double>{0} };
// NoS in the basic domain (= unit cell for periodic lattices)
no_spins_basic_domain = basis_atoms[0].size();
Expand Down Expand Up @@ -173,7 +173,7 @@ namespace Utility
std::string basis_file = "";
// Basis: vector {a, b, c}
std::vector<std::vector<double>> basis = { std::vector<double>{1,0,0}, std::vector<double>{0,1,0}, std::vector<double>{0,0,1} };
// Atoms in the basis
// Atoms in the basis [dim][n_basis_atoms]
std::vector<std::vector<double>> basis_atoms = { std::vector<double>{0}, std::vector<double>{0}, std::vector<double>{0} };
// NoS in the basic domain (= unit cell for periodic lattices)
int no_spins_basic_domain = basis_atoms[0].size();
Expand Down Expand Up @@ -271,7 +271,7 @@ namespace Utility
Log(Log_Level::Parameter, Log_Sender::IO, "Geometry: " + std::to_string(nos) + " spins");

// Return geometry
auto geometry = std::unique_ptr<Data::Geometry>(new Data::Geometry(basis, translation_vectors, n_cells, no_spins_basic_domain, spin_pos));
auto geometry = std::unique_ptr<Data::Geometry>(new Data::Geometry(basis, translation_vectors, n_cells, no_spins_basic_domain, basis_atoms, spin_pos));
Log(Log_Level::Info, Log_Sender::IO, "Geometry: built");
return geometry;
}// end Geometry from Config
Expand Down
60 changes: 42 additions & 18 deletions core/src/utility/IO_Fileparser.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "IO.hpp"
#include "Vectormath.hpp"
#include "IO_Filter_File_Handle.hpp"
#include "Logging.hpp"
#include "Exception.hpp"

#include <iostream>
#include <fstream>
#include <thread>
#include <string>
#include <sstream>
#include "Logging.hpp"
#include "Exception.hpp"

namespace Utility
{
Expand All @@ -35,7 +35,7 @@ namespace Utility
/*
Reads a configuration file into an existing Spin_System
*/
void Read_Spin_Configuration(std::shared_ptr<Data::Spin_System> s, const std::string file)
void Read_Spin_Configuration(std::shared_ptr<Data::Spin_System> s, const std::string file, VectorFileFormat format)
{
std::ifstream myfile(file);
if (myfile.is_open())
Expand All @@ -45,23 +45,47 @@ namespace Utility
std::istringstream iss(line);
std::size_t found;
int i = 0;
while (getline(myfile, line))
if (format == VectorFileFormat::CSV_POS_SPIN)
{
if (i >= s->nos) { Log(Log_Level::Warning, Log_Sender::IO, "NOS mismatch in Read Spin Configuration - Aborting"); myfile.close(); return; }
found = line.find("#");
// Read the line if # is not found (# marks a comment)
if (found == std::string::npos)
auto& spins = *s->spins;
double px, py, pz;
while (getline(myfile, line, ','))
{
//double x, y, z;
iss.clear();
iss.str(line);
auto& spins = *s->spins;
//iss >> x >> y >> z;
iss >> spins[i] >> spins[1 * s->nos + i] >> spins[2 * s->nos + i];
++i;
}// endif (# not found)
// discard line if # is found
}// endif new line (while)
if (i >= s->nos) { Log(Log_Level::Warning, Log_Sender::IO, "NOS mismatch in Read Spin Configuration - Aborting"); myfile.close(); return; }
found = line.find("#");
// Read the line if # is not found (# marks a comment)
if (found == std::string::npos)
{
//double x, y, z;
iss.clear();
iss.str(line);
//iss >> x >> y >> z;
iss >> px >> py >> pz >> spins[i] >> spins[1 * s->nos + i] >> spins[2 * s->nos + i];
++i;
}// endif (# not found)
// discard line if # is found
}// endif new line (while)
}
else
{
auto& spins = *s->spins;
while (getline(myfile, line))
{
if (i >= s->nos) { Log(Log_Level::Warning, Log_Sender::IO, "NOS mismatch in Read Spin Configuration - Aborting"); myfile.close(); return; }
found = line.find("#");
// Read the line if # is not found (# marks a comment)
if (found == std::string::npos)
{
//double x, y, z;
iss.clear();
iss.str(line);
//iss >> x >> y >> z;
iss >> spins[i] >> spins[1 * s->nos + i] >> spins[2 * s->nos + i];
++i;
}// endif (# not found)
// discard line if # is found
}// endif new line (while)
}
if (i < s->nos) { Log(Log_Level::Warning, Log_Sender::IO, "NOS mismatch in Read Spin Configuration"); }
myfile.close();
Log(Log_Level::Info, Log_Sender::IO, "Done");
Expand Down
32 changes: 24 additions & 8 deletions core/src/utility/Vectormath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,30 @@ namespace Utility
}// endfor j
}// endfor dim

// Check for erronous input placing two spins on the same location
for (i = 0; i < pos; ++i) {
for (j = i + 1; j < pos; ++j) {
if (std::abs(spin_pos[0*nos+i] - spin_pos[0*nos+j]) < 1.0E-6) {
if (std::abs(spin_pos[1*nos+i] - spin_pos[1*nos+j]) < 1.0E-6) {
if (std::abs(spin_pos[2*nos+i] - spin_pos[2*nos+j]) < 1.0E-6) {
Log(Utility::Log_Level::Severe, Utility::Log_Sender::All, "Unable to initialize Spin-System, since 2 spins occupy the same space.\nPlease check the config file!");
throw Exception::System_not_Initialized;
// Check for erronous input placing two spins on the same location
std::vector<double> sp(3);
for (int i = 0; i < basis_atoms[0].size(); ++i)
{
for (int j = 0; j < basis_atoms[0].size(); ++j)
{
for (int k1 = -2; k1 < 3; ++k1)
{
for (int k2 = -2; k2 < 3; ++k2)
{
for (int k3 = -2; k3 < 3; ++k3)
{
// Norm is zero if translated basis atom is at position of another basis atom
for (int dim = 0; dim < 3; ++dim)
{
sp[dim] = basis_atoms[dim][i] - ( basis_atoms[dim][j]
+ k1*translation_vectors[dim][0] + k2*translation_vectors[dim][1] + k3*translation_vectors[dim][2] );
}
if ( (i!=j || k1!=0 || k2!=0 || k3!=0) && std::abs(sp[0]) < 1e-9 && std::abs(sp[1]) < 1e-9 && std::abs(sp[2]) < 1e-9)
{
Log(Utility::Log_Level::Severe, Utility::Log_Sender::All, "Unable to initialize Spin-System, since 2 spins occupy the same space.\nPlease check the config file!");
Log.Append_to_File();
throw Exception::System_not_Initialized;
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions input/anisotropic/pairs-example-hopfion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
i j da db dc J
0 0 1 0 0 1.0
0 0 0 1 0 1.0
0 0 0 0 1 1.0
0 0 2 0 0 -0.24
0 0 0 2 0 -0.24
0 0 0 0 2 -0.24
126 changes: 126 additions & 0 deletions input/example-hopfion-anisotropic.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
############ Spirit Configuration ############



### Hamiltonian Type (isotropic or anisotropic)
hamiltonian anisotropic

### Output Folders
llg_output_folder output
gneb_output_folder output
mmf_output_folder output



############### Logging Parameters ###############
log_output_folder .
### Levels of information
# 0 = ALL - Anything
# 1 = SEVERE - Severe error
# 2 = ERROR - Error which can be handled
# 3 = WARNING - Possible unintended behaviour etc
# 4 = PARAMETER - Status information etc
# 5 = INFO - Status information etc
# 6 = DEBUG - Deeper status, eg numerical
### Print messages up to (including) log_print
log_print 6
### Accept messages up to (including) log_accept
log_accept 6
############## End Debug_Parameters ##############



################## Geometry ##################
### Read basis from file
basis_from_config input/basis_sc.cfg

### Keyword translation_vectors ###
### t1.x t1.y t1.z nCells(t1)
### t2.x t2.y t2.z nCells(t2)
### t3.x t3.y t3.z nCells(t3)
translation_vectors
1 0 0 30
0 1 0 30
0 0 1 30

################# End Geometry #################



################ LLG_Parameters ################
### seed for Rendom Number Generator
llg_seed 20006

### Disable saving a seperate "Spins" configuration file after every logstep iteration
llg_save_single_configurations 0

### Number of iterations
llg_n_iterations 2000000
### Number of iterations after which to save
llg_n_iterations_log 2000

### temperature [K]
llg_temperature 0

### damping [none]
llg_damping 0.3E+0

### time step dt
llg_dt 1.0E-3

### Bools 0 = false || 1 = true
llg_renorm 1

### Spin transfer torque parameter proportional to injected current density
llg_stt_magnitude 0.0

### spin current polarisation normal vector
llg_stt_polarisation_normal 1.0 0.0 0.0

### Force convergence parameter
llg_force_convergence 10e-9
############## End LLG_Parameters ##############



################ GNEB_Parameters ################
gneb_spring_constant 1.0

### Bools 0 = false || 1 = true
gneb_renorm 1

### Number of GNEB Energy interpolations
gneb_n_energy_interpolations 10

### Force convergence parameter
gneb_force_convergence 10e-7

### Number of iterations and saves
gneb_n_iterations 200000
gneb_n_iterations_log 200
############## End GNEB_Parameters ##############



############# Hamiltonian_Isotropic #############

### boundary_conditions (in a b c) = 0(open), 1(periodical)
boundary_conditions 1 1 1

### external magnetic field vector[T]
external_field_magnitude 0.0
external_field_normal 0.0 0.0 1.0
### µSpin
mu_s= 2.0

### Uniaxial anisotropy constant [meV]
anisotropy_magnitude 0.0
anisotropy_normal 0.0 0.0 1.0

### Dipole-Dipole radius
dd_radius 0.0

### Pairs
interaction_pairs_file input/anisotropic/pairs-example-hopfion.txt

########### End Hamiltonian_Anisotropic ###########

0 comments on commit e29946c

Please sign in to comment.