diff --git a/clean_output.sh b/clean_output.sh old mode 100644 new mode 100755 diff --git a/core/src/engine/Method_LLG.cpp b/core/src/engine/Method_LLG.cpp index c7ea235b2..41ceb5a72 100644 --- a/core/src/engine/Method_LLG.cpp +++ b/core/src/engine/Method_LLG.cpp @@ -134,54 +134,70 @@ namespace Engine // File save if (this->parameters->save_output_any) { - auto writeoutput = [this, starttime, iteration](std::string suffix, bool override_single) + // Convert indices to formatted strings + auto s_img = IO::int_to_formatted_string(this->idx_image, 2); + auto s_iter = IO::int_to_formatted_string(iteration, (int)log10(this->parameters->n_iterations)); + + std::string preSpinsFile = this->parameters->output_folder + "/" + starttime + "_" + "Spins_" + s_img; + std::string preEnergyFile = this->parameters->output_folder + "/" + starttime + "_" + "Energy_" + s_img; + + // Function to write or append image and energy files + auto writeoutput = [this, preSpinsFile, preEnergyFile, iteration](std::string suffix, bool append) { - // Convert indices to formatted strings - auto s_img = IO::int_to_formatted_string(this->idx_image, 2); - auto s_iter = IO::int_to_formatted_string(iteration, 6); - - if (this->systems[0]->llg_parameters->save_output_archive) + // File names + std::string spinsFile = preSpinsFile + suffix + ".txt"; + std::string energyFile = preEnergyFile + suffix + ".txt"; + + // Spin Configuration + if (append) { - // Append Spin configuration to Spin_Archieve_File - auto spinsFile = this->parameters->output_folder + "/" + starttime + "_" + "Spins_" + s_img + suffix + ".txt"; Utility::IO::Append_Spin_Configuration(this->systems[0], iteration, spinsFile); } - - if (this->systems[0]->llg_parameters->save_output_archive && this->parameters->save_output_energy) + else { - // Check if Energy File exists and write Header if it doesn't - auto energyFile = this->parameters->output_folder + "/" + starttime + "_Energy_" + s_img + suffix + ".txt"; - std::ifstream f(energyFile); - if (!f.good()) Utility::IO::Write_Energy_Header(*this->systems[0], energyFile); - // Append Energy to File - Utility::IO::Append_Energy(*this->systems[0], iteration, energyFile); + Utility::IO::Append_Spin_Configuration(this->systems[0], iteration, spinsFile); } - - if (this->systems[0]->llg_parameters->save_output_single || override_single) + // Energy + if (this->parameters->save_output_energy) { - // Save Spin configuration to new "spins" File - auto spinsIterFile = this->parameters->output_folder + "/" + starttime + "_" + "Spins_" + s_img + "_" + s_iter + ".txt"; - Utility::IO::Append_Spin_Configuration(this->systems[0], iteration, spinsIterFile); + if (append) + { + // Check if Energy File exists and write Header if it doesn't + std::ifstream f(energyFile); + if (!f.good()) Utility::IO::Write_Energy_Header(*this->systems[0], energyFile); + // Append Energy to File + Utility::IO::Append_Energy(*this->systems[0], iteration, energyFile); + } + else + { + Utility::IO::Write_Energy_Header(*this->systems[0], energyFile); + Utility::IO::Append_Energy(*this->systems[0], iteration, energyFile); + } } }; - std::string suffix = ""; - + // Initial image before simulation if (initial && this->parameters->save_output_initial) { - auto s_fix = "_" + IO::int_to_formatted_string(iteration, (int)log10(this->parameters->n_iterations)) + "_initial"; - suffix = s_fix; - writeoutput(suffix, true); + writeoutput("_" + s_iter + "_initial", false); } + // Final image after simulation else if (final && this->parameters->save_output_final) { - auto s_fix = "_" + IO::int_to_formatted_string(iteration, (int)log10(this->parameters->n_iterations)) + "_final"; - suffix = s_fix; - writeoutput(suffix, true); + writeoutput("_" + s_iter + "_final", false); } - suffix = "_archive"; - writeoutput(suffix, false); + // Single image file output + if (this->systems[0]->llg_parameters->save_output_single) + { + writeoutput("_" + s_iter, false); + } + + // Archive file (appending) + if (this->systems[0]->llg_parameters->save_output_archive) + { + writeoutput("_archive", true); + } // Save Log Log.Append_to_File(); diff --git a/core/src/engine/Optimizer_SIB.cpp b/core/src/engine/Optimizer_SIB.cpp index 9000fada0..9be3f2603 100644 --- a/core/src/engine/Optimizer_SIB.cpp +++ b/core/src/engine/Optimizer_SIB.cpp @@ -9,7 +9,7 @@ namespace Engine Optimizer_SIB::Optimizer_SIB(std::shared_ptr method) : Optimizer(method) { - this->xi = vectorfield(this->nos); + this->xi = vectorfield(this->nos, {0,0,0}); this->virtualforce = std::vector(this->noi, vectorfield(this->nos)); // [noi][nos] this->spins_temp = std::vector>(this->noi); @@ -24,9 +24,12 @@ namespace Engine for (int i = 0; i < this->noi; ++i) { s = method->systems[i]; - this->epsilon = std::sqrt(2.0*s->llg_parameters->damping / (1.0 + std::pow(s->llg_parameters->damping, 2))*s->llg_parameters->temperature*Constants::k_B); - // Precalculate RNs --> move this up into Iterate and add array dimension n for no of iterations? - Vectormath::get_random_vectorfield(*s, epsilon, xi); + if (s->llg_parameters->temperature > 0) + { + this->epsilon = std::sqrt(2.0*s->llg_parameters->damping / (1.0 + std::pow(s->llg_parameters->damping, 2))*s->llg_parameters->temperature*Constants::k_B); + // Precalculate RNs --> move this up into Iterate and add array dimension n for no of iterations? + Vectormath::get_random_vectorfield(*s, epsilon, xi); + } } // First part of the step @@ -65,11 +68,20 @@ namespace Engine Vectormath::fill (force, {0,0,0}); Vectormath::add_c_a (-0.5 * dtg, gradient, force); Vectormath::add_c_cross(-0.5 * dtg * damping, spins, gradient, force); - Vectormath::add_c_a ( 0.5 * dtg * a_j * damping, s_c_vec, force); - Vectormath::add_c_cross(-0.5 * dtg * a_j, s_c_vec, spins, force); - Vectormath::add_c_a (-0.5 * sqrtdtg, xi, force); - Vectormath::add_c_cross(-0.5 * sqrtdtg * damping, spins, xi, force); + // STT + if (a_j > 0) + { + Vectormath::add_c_a ( 0.5 * dtg * a_j * damping, s_c_vec, force); + Vectormath::add_c_cross( 0.5 * dtg * a_j, s_c_vec, spins, force); + } + + // Temperature + if (llg_params.temperature > 0) + { + Vectormath::add_c_a (-0.5 * sqrtdtg, xi, force); + Vectormath::add_c_cross(-0.5 * sqrtdtg * damping, spins, xi, force); + } }