Skip to content

Commit

Permalink
Core: fix bug from previous commit.
Browse files Browse the repository at this point in the history
Also added a few more try/catch blocks around the `Spin_System` functions.
  • Loading branch information
GPMueller committed Jan 20, 2021
1 parent 1742cd9 commit b549587
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions core/src/data/Spin_System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Spin_System::Spin_System(
std::unique_ptr<Parameters_Method_LLG> llg_params, std::unique_ptr<Parameters_Method_MC> mc_params,
std::unique_ptr<Parameters_Method_EMA> ema_params, std::unique_ptr<Parameters_Method_MMF> mmf_params,
bool iteration_allowed )
: iteration_allowed( iteration_allowed ),
singleshot_allowed( false ),
hamiltonian( std::move( hamiltonian ) ),
geometry( geometry ),
llg_parameters( std::move( llg_params ) ),
mc_parameters( std::move( mc_params ) ),
ema_parameters( std::move( ema_params ) ),
mmf_parameters( std::move( mmf_params ) )
try : iteration_allowed( iteration_allowed ),
singleshot_allowed( false ),
hamiltonian( std::move( hamiltonian ) ),
geometry( geometry ),
llg_parameters( std::move( llg_params ) ),
mc_parameters( std::move( mc_params ) ),
ema_parameters( std::move( ema_params ) ),
mmf_parameters( std::move( mmf_params ) )
{
// Get Number of Spins
this->nos = this->geometry->nos;
Expand All @@ -43,9 +43,14 @@ Spin_System::Spin_System(
this->M = Vector3{ 0, 0, 0 };
this->effective_field = vectorfield( this->nos );
}
catch( ... )
{
spirit_rethrow( "Spin system initialisation failed" );
}

// Copy Constructor
Spin_System::Spin_System( Spin_System const & other )
try
{
this->nos = other.nos;
this->spins = std::shared_ptr<vectorfield>( new vectorfield( *other.spins ) );
Expand All @@ -65,13 +70,13 @@ Spin_System::Spin_System( Spin_System const & other )

if( other.hamiltonian->Name() == "Heisenberg" )
{
this->hamiltonian
= std::make_shared<Engine::Hamiltonian>( *(Engine::Hamiltonian_Heisenberg *)( other.hamiltonian.get() ) );
this->hamiltonian = std::make_shared<Engine::Hamiltonian_Heisenberg>(
static_cast<Engine::Hamiltonian_Heisenberg &>( *other.hamiltonian ) );
}
else if( other.hamiltonian->Name() == "Gaussian" )
{
this->hamiltonian
= std::make_shared<Engine::Hamiltonian>( *(Engine::Hamiltonian_Gaussian *)( other.hamiltonian.get() ) );
this->hamiltonian = std::make_shared<Engine::Hamiltonian_Gaussian>(
static_cast<Engine::Hamiltonian_Gaussian &>( *other.hamiltonian ) );
}

this->llg_parameters = std::make_shared<Data::Parameters_Method_LLG>( *other.llg_parameters );
Expand All @@ -81,9 +86,14 @@ Spin_System::Spin_System( Spin_System const & other )

this->iteration_allowed = false;
}
catch( ... )
{
spirit_rethrow( "Copy-assigning spin system failed" );
}

// Copy assignment operator
Spin_System & Spin_System::operator=( Spin_System const & other )
try
{
if( this != &other )
{
Expand Down Expand Up @@ -124,21 +134,36 @@ Spin_System & Spin_System::operator=( Spin_System const & other )

return *this;
}
catch( ... )
{
spirit_rethrow( "Copy-assigning spin system failed" );
return *this;
}

void Spin_System::UpdateEnergy()
try
{
this->E_array = this->hamiltonian->Energy_Contributions( *this->spins );
scalar sum = 0;
for( auto & E : E_array )
sum += E.second;
this->E = sum;
}
catch( ... )
{
spirit_rethrow( "Spin_System::UpdateEnergy failed" );
}

void Spin_System::UpdateEffectiveField()
try
{
this->hamiltonian->Gradient( *this->spins, this->effective_field );
Engine::Vectormath::scale( this->effective_field, -1 );
}
catch( ... )
{
spirit_rethrow( "Spin_System::UpdateEffectiveField failed" );
}

void Spin_System::Lock() noexcept
try
Expand Down

0 comments on commit b549587

Please sign in to comment.