Skip to content
Draft
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
2 changes: 1 addition & 1 deletion core/include/engine/HTST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Calculate( Data::HTST_Info & htst_info, int n_eigenmodes_keep = 0 );
// Calculate the 'a' component of the prefactor
void Calculate_Perpendicular_Velocity(
const vectorfield & spins, const scalarfield & mu_s, const MatrixX & hessian, const MatrixX & basis,
const MatrixX & eigenbasis, VectorX & a );
const MatrixX & eigenbasis, VectorX & perpendicular_velocity );

// Calculate the Velocity matrix
void Calculate_Dynamical_Matrix(
Expand Down
34 changes: 17 additions & 17 deletions core/include/engine/Indexing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace Indexing
inline int
idx_from_translations( const intfield & n_cells, const int n_cell_atoms, const std::array<int, 3> & translations )
{
auto & Na = n_cells[0];
auto & Nb = n_cells[1];
auto & Nc = n_cells[2];
auto & N = n_cell_atoms;
const auto & Na = n_cells[0];
const auto & Nb = n_cells[1];
const auto & Nc = n_cells[2];
const auto & N = n_cell_atoms;

auto & da = translations[0];
auto & db = translations[1];
auto & dc = translations[2];
const auto & da = translations[0];
const auto & db = translations[1];
const auto & dc = translations[2];

return da * N + db * N * Na + dc * N * Na * Nb;
}
Expand Down Expand Up @@ -61,10 +61,10 @@ inline int idx_from_translations(
const intfield & n_cells, const int n_cell_atoms, const std::array<int, 3> & translations_i,
const std::array<int, 3> & translations )
{
auto & Na = n_cells[0];
auto & Nb = n_cells[1];
auto & Nc = n_cells[2];
auto & N = n_cell_atoms;
const auto & Na = n_cells[0];
const auto & Nb = n_cells[1];
const auto & Nc = n_cells[2];
const auto & N = n_cell_atoms;

int da = translations_i[0] + translations[0];
int db = translations_i[1] + translations[1];
Expand Down Expand Up @@ -220,9 +220,9 @@ __inline__ __device__ int cu_idx_from_pair(
return -1;

// Number of cells
auto & Na = n_cells[0];
auto & Nb = n_cells[1];
auto & Nc = n_cells[2];
const auto & Na = n_cells[0];
const auto & Nb = n_cells[1];
const auto & Nc = n_cells[2];

// Invalid index if translations reach out over the lattice bounds
if( std::abs( pair.translations[0] ) > Na || std::abs( pair.translations[1] ) > Nb
Expand Down Expand Up @@ -360,9 +360,9 @@ inline int idx_from_pair(
return -1;

// Number of cells
auto & Na = n_cells[0];
auto & Nb = n_cells[1];
auto & Nc = n_cells[2];
const auto & Na = n_cells[0];
const auto & Nb = n_cells[1];
const auto & Nc = n_cells[2];

// Invalid index if translations reach out over the lattice bounds
if( std::abs( pair.translations[0] ) > Na || std::abs( pair.translations[1] ) > Nb
Expand Down
1 change: 1 addition & 0 deletions core/include/engine/Manifoldmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Engine
// TODO: cleanly separate these two cases!
namespace Manifoldmath
{

// Get the norm of a vectorfield (interpreted as a 3N-vector)
scalar norm( const vectorfield & vf );
// Normalize a vectorfield (interpreted as a 3N-vector)
Expand Down
33 changes: 12 additions & 21 deletions core/include/engine/Method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Method
* The constructor does not allocate any large arrays. The solvers should allocate
* what they need in Solver_Initialise.
*/
Method( std::shared_ptr<Data::Parameters_Method> parameters, int idx_img, int idx_chain );
Method( const std::shared_ptr<Data::Parameters_Method> & parameters, int noi, int nos, int idx_img, int idx_chain );

virtual ~Method() = default;

Expand All @@ -54,22 +54,22 @@ class Method
*/
virtual scalar getForceMaxAbsComponent() final;

// Maximum norm of the torque - needs to be updated at each calculation
virtual scalar getTorqueMaxNorm() final;

/*
* Maximum of the absolutes of all components of the force for all images the method uses
* The default is that this returns simply {getForceMaxAbsComponent()}
*/
virtual std::vector<scalar> getForceMaxAbsComponent_All();

// Maximum norm of the torque - needs to be updated at each calculation
virtual scalar getTorqueMaxNorm() final;

// Maximum of the norm of the torque for all images the method uses
virtual std::vector<scalar> getTorqueMaxNorm_All();

// ------------------------------------------------------

// Method name as string
virtual std::string Name();
virtual std::string Name() = 0;

// Solver name as string
virtual std::string SolverName();
Expand All @@ -78,37 +78,28 @@ class Method
// ------------------------------------------------------

// One iteration of the Method
virtual void Iteration();
virtual void Iteration() = 0;

// Initialize arrays etc. before `Iterate` starts
virtual void Initialize();
// Finalize (e.g. output informaiton) after `Iterate` has finished
virtual void Finalize();
virtual void Finalize() = 0;

// Log messages at Start, after Steps and at End of Iterate
virtual void Message_Start();
virtual void Message_Step();
virtual void Message_End();

/*
* A hook into `Iterate` before an Iteration.
* Override this function if special actions are needed
* before each `Solver_Iteration`
*/
virtual void Hook_Pre_Iteration();
virtual void Message_Start() = 0;
virtual void Message_Step() = 0;
virtual void Message_End() = 0;

/*
* A hook into `Iterate` after an Iteration.
* Override this function if special actions are needed
* after each `Solver_Iteration`
*/
virtual void Hook_Post_Iteration();
virtual void Post_Iteration_Hook() = 0;

/*
* Save current data
* Override to specialize what a Method should save
*/
virtual void Save_Current( std::string starttime, int iteration, bool initial = false, bool final = false );
virtual void Save_Current( std::string starttime, int iteration, bool initial = false, bool final = false ) = 0;

/*
* Lock systems in order to prevent otherwise access
Expand Down
9 changes: 1 addition & 8 deletions core/include/engine/Method_EMA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,16 @@ class Method_EMA : public Method
// Method name as string
std::string Name() override;

// Solver name as string
std::string SolverName() override;

private:
// Iteration does one time step of the oscillation
// S(t) = S(0) + cos(omega * t) * direction
void Iteration() override;

// Save the current Step's Data: spins and energy
void Save_Current( std::string starttime, int iteration, bool initial = false, bool final = false ) override;
// A hook into the Method before an Iteration of the Solver
void Hook_Pre_Iteration() override;
// A hook into the Method after an Iteration of the Solver
void Hook_Post_Iteration() override;
void Post_Iteration_Hook() override;

// Sets iteration_allowed to false for the corresponding method
void Initialize() override;
// Sets iteration_allowed to false for the corresponding method
void Finalize() override;

Expand Down
4 changes: 1 addition & 3 deletions core/include/engine/Method_GNEB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ class Method_GNEB : public Method_Solver<solver>

// Save the current Step's Data: images and images' energies and reaction coordinates
void Save_Current( std::string starttime, int iteration, bool initial = false, bool final = false ) override;
// A hook into the Method before an Iteration of the Solver
void Hook_Pre_Iteration() override;
// A hook into the Method after an Iteration of the Solver
void Hook_Post_Iteration() override;
void Post_Iteration_Hook() override;

// A helper method that calculates the interpolated energies, split up into the different energy contributions
void Calculate_Interpolated_Energy_Contributions();
Expand Down
4 changes: 1 addition & 3 deletions core/include/engine/Method_LLG.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class Method_LLG : public Method_Solver<solver>
// Save the current Step's Data: spins and energy
void Save_Current( std::string starttime, int iteration, bool initial = false, bool final = false ) override;
// A hook into the Method before an Iteration of the Solver
void Hook_Pre_Iteration() override;
// A hook into the Method after an Iteration of the Solver
void Hook_Post_Iteration() override;
void Post_Iteration_Hook() override;

// Sets iteration_allowed to false for the corresponding method
void Finalize() override;
Expand Down
6 changes: 1 addition & 5 deletions core/include/engine/Method_MC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ class Method_MC : public Method

// Save the current Step's Data: spins and energy
void Save_Current( std::string starttime, int iteration, bool initial = false, bool final = false ) override;
// A hook into the Method before an Iteration of the Solver
void Hook_Pre_Iteration() override;
// A hook into the Method after an Iteration of the Solver
void Hook_Post_Iteration() override;
void Post_Iteration_Hook() override;

// Sets iteration_allowed to false for the corresponding method
void Initialize() override;
// Sets iteration_allowed to false for the corresponding method
void Finalize() override;

Expand Down
4 changes: 1 addition & 3 deletions core/include/engine/Method_MMF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class Method_MMF : public Method_Solver<solver>

// Save the current Step's Data: images and images' energies and reaction coordinates
void Save_Current( std::string starttime, int iteration, bool initial = false, bool final = false ) override;
// A hook into the Method before an Iteration of the Solver
void Hook_Pre_Iteration() override;
// A hook into the Method after an Iteration of the Solver
void Hook_Post_Iteration() override;
void Post_Iteration_Hook() override;

// Sets iteration_allowed to false
void Finalize() override;
Expand Down
29 changes: 13 additions & 16 deletions core/include/engine/Method_Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ class Method_Solver : public Method
{
public:
// Constructor to be used in derived classes
Method_Solver( std::shared_ptr<Data::Parameters_Method> parameters, int idx_img, int idx_chain )
: Method( parameters, idx_img, idx_chain )
Method_Solver( std::shared_ptr<Data::Parameters_Method> parameters, int noi, int nos, int idx_img, int idx_chain )
: Method( parameters, noi, nos, idx_img, idx_chain )
{
this->Initialize_Solver();
}

virtual ~Method_Solver() = default;
~Method_Solver() override = default;

// // `Iterate` uses the `Solver_Iteration` function to evolve given systems according to the
// // `Calculate_Force` implementation of the Method-Subclass.
Expand All @@ -65,11 +66,11 @@ class Method_Solver : public Method
// virtual void Iterate() override;

// Solver name as string
virtual std::string SolverName() override;
virtual std::string SolverFullName() override;
std::string SolverName() override;
std::string SolverFullName() override;

// Iteration represents one iteration of a certain Solver
virtual void Iteration() override;
void Iteration() override;

protected:
// Prepare random numbers for thermal fields, if needed
Expand Down Expand Up @@ -124,14 +125,14 @@ class Method_Solver : public Method
return Method::ContinueIterating() && !this->Converged();
}

// Initialise contains the initialisations of arrays etc. for a certain solver
virtual void Initialize() override;
virtual void Finalize() override;
// Initialize arrays etc. before `Iterate` starts
void Initialize_Solver();
void Finalize() override;

// Log message blocks
virtual void Message_Start() override;
virtual void Message_Step() override;
virtual void Message_End() override;
void Message_Start() override;
void Message_Step() override;
void Message_End() override;

//////////// DEPONDT ////////////////////////////////////////////////////////////
// Temporaries for virtual forces
Expand Down Expand Up @@ -238,10 +239,6 @@ bool Method_Solver<solver>::Converged()
return converged;
}

// Default implementation: do nothing
template<Solver solver>
void Method_Solver<solver>::Initialize(){};

// Default implementation: do nothing
template<Solver solver>
void Method_Solver<solver>::Finalize(){};
Expand Down
4 changes: 2 additions & 2 deletions core/include/engine/Solver_Depondt.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
template<>
inline void Method_Solver<Solver::Depondt>::Initialize()
inline void Method_Solver<Solver::Depondt>::Initialize_Solver()
{
this->forces = std::vector<vectorfield>( this->noi, vectorfield( this->nos, { 0, 0, 0 } ) );
this->forces_virtual = std::vector<vectorfield>( this->noi, vectorfield( this->nos, { 0, 0, 0 } ) );
Expand All @@ -13,7 +13,7 @@ inline void Method_Solver<Solver::Depondt>::Initialize()

this->configurations_predictor = std::vector<std::shared_ptr<vectorfield>>( this->noi );
for( int i = 0; i < this->noi; i++ )
configurations_predictor[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos, { 0, 0, 0 } ) );
configurations_predictor[i] = std::make_shared<vectorfield>( this->nos );

this->temp1 = vectorfield( this->nos, { 0, 0, 0 } );
}
Expand Down
10 changes: 5 additions & 5 deletions core/include/engine/Solver_Heun.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
template<>
inline void Method_Solver<Solver::Heun>::Initialize()
inline void Method_Solver<Solver::Heun>::Initialize_Solver()
{
this->forces = std::vector<vectorfield>( this->noi, vectorfield( this->nos, { 0, 0, 0 } ) );
this->forces_virtual = std::vector<vectorfield>( this->noi, vectorfield( this->nos, { 0, 0, 0 } ) );

this->forces_predictor = std::vector<vectorfield>( this->noi, vectorfield( this->nos, { 0, 0, 0 } ) );
this->forces_virtual_predictor = std::vector<vectorfield>( this->noi, vectorfield( this->nos, { 0, 0, 0 } ) );

this->configurations_temp = std::vector<std::shared_ptr<vectorfield>>( this->noi );
this->configurations_temp.resize( this->noi );
for( int i = 0; i < this->noi; i++ )
configurations_temp[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos ) );
configurations_temp[i] = std::make_shared<vectorfield>( this->nos );

this->configurations_predictor = std::vector<std::shared_ptr<vectorfield>>( this->noi );
this->configurations_predictor.resize( this->noi );
for( int i = 0; i < this->noi; i++ )
configurations_predictor[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos ) );
configurations_predictor[i] = std::make_shared<vectorfield>( this->nos );

this->temp1 = vectorfield( this->nos, { 0, 0, 0 } );
}
Expand Down
2 changes: 1 addition & 1 deletion core/include/engine/Solver_LBFGS_Atlas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using namespace Utility;

template<>
inline void Method_Solver<Solver::LBFGS_Atlas>::Initialize()
inline void Method_Solver<Solver::LBFGS_Atlas>::Initialize_Solver()
{
this->n_lbfgs_memory = 3; // how many updates the solver tracks to estimate the hessian
this->atlas_updates = std::vector<field<vector2field>>(
Expand Down
2 changes: 1 addition & 1 deletion core/include/engine/Solver_LBFGS_OSO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using namespace Utility;

template<>
inline void Method_Solver<Solver::LBFGS_OSO>::Initialize()
inline void Method_Solver<Solver::LBFGS_OSO>::Initialize_Solver()
{
this->n_lbfgs_memory = 3; // how many previous iterations are stored in the memory
this->delta_a = std::vector<field<vectorfield>>(
Expand Down
14 changes: 7 additions & 7 deletions core/include/engine/Solver_RK4.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
template<>
inline void Method_Solver<Solver::RungeKutta4>::Initialize()
inline void Method_Solver<Solver::RungeKutta4>::Initialize_Solver()
{
this->forces = std::vector<vectorfield>( this->noi, vectorfield( this->nos, { 0, 0, 0 } ) );
this->forces_virtual = std::vector<vectorfield>( this->noi, vectorfield( this->nos, { 0, 0, 0 } ) );
Expand All @@ -9,27 +9,27 @@ inline void Method_Solver<Solver::RungeKutta4>::Initialize()

this->configurations_temp = std::vector<std::shared_ptr<vectorfield>>( this->noi );
for( int i = 0; i < this->noi; i++ )
this->configurations_temp[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos ) );
this->configurations_temp[i] = std::make_shared<vectorfield>( this->nos );

this->configurations_predictor = std::vector<std::shared_ptr<vectorfield>>( this->noi );
for( int i = 0; i < this->noi; i++ )
this->configurations_predictor[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos ) );
this->configurations_predictor[i] = std::make_shared<vectorfield>( this->nos );

this->configurations_k1 = std::vector<std::shared_ptr<vectorfield>>( this->noi );
for( int i = 0; i < this->noi; i++ )
this->configurations_k1[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos ) );
this->configurations_k1[i] = std::make_shared<vectorfield>( this->nos );

this->configurations_k2 = std::vector<std::shared_ptr<vectorfield>>( this->noi );
for( int i = 0; i < this->noi; i++ )
this->configurations_k2[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos ) );
this->configurations_k2[i] = std::make_shared<vectorfield>( this->nos );

this->configurations_k3 = std::vector<std::shared_ptr<vectorfield>>( this->noi );
for( int i = 0; i < this->noi; i++ )
this->configurations_k3[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos ) );
this->configurations_k3[i] = std::make_shared<vectorfield>( this->nos );

this->configurations_k4 = std::vector<std::shared_ptr<vectorfield>>( this->noi );
for( int i = 0; i < this->noi; i++ )
this->configurations_k4[i] = std::shared_ptr<vectorfield>( new vectorfield( this->nos ) );
this->configurations_k4[i] = std::make_shared<vectorfield>( this->nos );

this->temp1 = vectorfield( this->nos, { 0, 0, 0 } );
}
Expand Down
Loading