Skip to content

Commit

Permalink
Core: minor cleanup
Browse files Browse the repository at this point in the history
 - more `const`ifying `auto &`s
 - replacing `push_back`s with `emplace_back`s
  • Loading branch information
GPMueller committed Feb 9, 2023
1 parent dbc178e commit b5b8112
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
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
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
16 changes: 8 additions & 8 deletions core/src/engine/HTST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void Calculate( Data::HTST_Info & htst_info, int n_eigenmodes_keep )
const scalar epsilon = 1e-4;
const scalar epsilon_force = 1e-8;

auto & image_minimum = *htst_info.minimum->spins;
auto & image_sp = *htst_info.saddle_point->spins;
const auto & image_minimum = *htst_info.minimum->spins;
const auto & image_sp = *htst_info.saddle_point->spins;

int nos = image_minimum.size();

Expand Down Expand Up @@ -317,12 +317,12 @@ void Calculate( Data::HTST_Info & htst_info, int n_eigenmodes_keep )

scalar Calculate_Zero_Volume( const std::shared_ptr<Data::Spin_System> system )
{
int nos = system->geometry->nos;
auto & n_cells = system->geometry->n_cells;
auto & spins = *system->spins;
auto & spin_positions = system->geometry->positions;
auto & geometry = *system->geometry;
auto & bravais_vectors = system->geometry->bravais_vectors;
int nos = system->geometry->nos;
const auto & n_cells = system->geometry->n_cells;
const auto & spins = *system->spins;
const auto & spin_positions = system->geometry->positions;
const auto & geometry = *system->geometry;
const auto & bravais_vectors = system->geometry->bravais_vectors;

// Dimensionality of the zero mode
int zero_mode_dimensionality = 0;
Expand Down
49 changes: 24 additions & 25 deletions core/src/engine/Manifoldmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Engine
{
namespace Manifoldmath
{

void project_parallel( vectorfield & vf1, const vectorfield & vf2 )
{
scalar proj = Vectormath::dot( vf1, vf2 );
Expand Down Expand Up @@ -288,8 +289,7 @@ void tangent_basis_spherical( const vectorfield & vf, MatrixX & basis )

void sparse_tangent_basis_spherical( const vectorfield & vf, SpMatrixX & basis )
{
typedef Eigen::Triplet<scalar> T;
std::vector<T> triplet_list;
std::vector<Eigen::Triplet<scalar>> triplet_list;
triplet_list.reserve( vf.size() * 3 );

Vector3 tmp, etheta, ephi, res;
Expand All @@ -300,29 +300,29 @@ void sparse_tangent_basis_spherical( const vectorfield & vf, SpMatrixX & basis )
tmp = Vector3{ 1, 0, 0 };
res = ( tmp - tmp.dot( vf[i] ) * vf[i] ).normalized();

triplet_list.push_back( T( 3 * i, 2 * i, res[0] ) );
triplet_list.push_back( T( 3 * i + 1, 2 * i, res[1] ) );
triplet_list.push_back( T( 3 * i + 2, 2 * i, res[2] ) );
triplet_list.emplace_back( 3 * i, 2 * i, res[0] );
triplet_list.emplace_back( 3 * i + 1, 2 * i, res[1] );
triplet_list.emplace_back( 3 * i + 2, 2 * i, res[2] );

tmp = Vector3{ 0, 1, 0 };
res = ( tmp - tmp.dot( vf[i] ) * vf[i] ).normalized();
triplet_list.push_back( T( 3 * i, 2 * i + 1, res[0] ) );
triplet_list.push_back( T( 3 * i + 1, 2 * i + 1, res[1] ) );
triplet_list.push_back( T( 3 * i + 2, 2 * i + 1, res[2] ) );
triplet_list.emplace_back( 3 * i, 2 * i + 1, res[0] );
triplet_list.emplace_back( 3 * i + 1, 2 * i + 1, res[1] );
triplet_list.emplace_back( 3 * i + 2, 2 * i + 1, res[2] );
}
else if( vf[i][2] < -1 + 1e-8 )
{
tmp = Vector3{ 1, 0, 0 };
res = ( tmp - tmp.dot( vf[i] ) * vf[i] ).normalized();
triplet_list.push_back( T( 3 * i, 2 * i, res[0] ) );
triplet_list.push_back( T( 3 * i + 1, 2 * i, res[1] ) );
triplet_list.push_back( T( 3 * i + 2, 2 * i, res[2] ) );
triplet_list.emplace_back( 3 * i, 2 * i, res[0] );
triplet_list.emplace_back( 3 * i + 1, 2 * i, res[1] );
triplet_list.emplace_back( 3 * i + 2, 2 * i, res[2] );

tmp = Vector3{ 0, -1, 0 };
res = ( tmp - tmp.dot( vf[i] ) * vf[i] ).normalized();
triplet_list.push_back( T( 3 * i, 2 * i + 1, res[0] ) );
triplet_list.push_back( T( 3 * i + 1, 2 * i + 1, res[1] ) );
triplet_list.push_back( T( 3 * i + 2, 2 * i + 1, res[2] ) );
triplet_list.emplace_back( 3 * i, 2 * i + 1, res[0] );
triplet_list.emplace_back( 3 * i + 1, 2 * i + 1, res[1] );
triplet_list.emplace_back( 3 * i + 2, 2 * i + 1, res[2] );
}
else
{
Expand All @@ -334,13 +334,13 @@ void sparse_tangent_basis_spherical( const vectorfield & vf, SpMatrixX & basis )
ephi = Vector3{ -vf[i][1] / rxy, vf[i][0] / rxy, 0 };

res = ( etheta - etheta.dot( vf[i] ) * vf[i] ).normalized();
triplet_list.push_back( T( 3 * i, 2 * i, res[0] ) );
triplet_list.push_back( T( 3 * i + 1, 2 * i, res[1] ) );
triplet_list.push_back( T( 3 * i + 2, 2 * i, res[2] ) );
triplet_list.emplace_back( 3 * i, 2 * i, res[0] );
triplet_list.emplace_back( 3 * i + 1, 2 * i, res[1] );
triplet_list.emplace_back( 3 * i + 2, 2 * i, res[2] );
res = ( ephi - ephi.dot( vf[i] ) * vf[i] ).normalized();
triplet_list.push_back( T( 3 * i, 2 * i + 1, res[0] ) );
triplet_list.push_back( T( 3 * i + 1, 2 * i + 1, res[1] ) );
triplet_list.push_back( T( 3 * i + 2, 2 * i + 1, res[2] ) );
triplet_list.emplace_back( 3 * i, 2 * i + 1, res[0] );
triplet_list.emplace_back( 3 * i + 1, 2 * i + 1, res[1] );
triplet_list.emplace_back( 3 * i + 2, 2 * i + 1, res[2] );
}
}
basis.setFromTriplets( triplet_list.begin(), triplet_list.end() );
Expand Down Expand Up @@ -382,7 +382,7 @@ void tangent_basis_righthanded( const vectorfield & vf, MatrixX & basis )

for( int i = 0; i < size; ++i )
{
auto & axis = vf[i];
const auto & axis = vf[i];

// Choose orthogonalisation basis for Grahm-Schmidt
// We will need two vectors with which the axis always forms the
Expand Down Expand Up @@ -517,20 +517,19 @@ void sparse_hessian_bordered_3N(
lambda[i] = image[i].normalized().dot( gradient[i] );

// Construct hessian_out
typedef Eigen::Triplet<scalar> T;
std::vector<T> tripletList;
std::vector<Eigen::Triplet<scalar>> tripletList;
tripletList.reserve( hessian.nonZeros() + 3 * nos );

// Iterate over non zero entries of hesiian
for( int k = 0; k < hessian.outerSize(); ++k )
{
for( SpMatrixX::InnerIterator it( hessian, k ); it; ++it )
{
tripletList.push_back( T( it.row(), it.col(), it.value() ) );
tripletList.emplace_back( it.row(), it.col(), it.value() );
}
int j = k % 3;
int i = ( k - j ) / 3;
tripletList.push_back( T( k, k, -lambda[i] ) ); // Correction to the diagonal
tripletList.emplace_back( k, k, -lambda[i] ); // Correction to the diagonal
}
hessian_out.setFromTriplets( tripletList.begin(), tripletList.end() );
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/engine/Manifoldmath.cu
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,27 @@ void Tangents(

for( int idx_img = 0; idx_img < noi; ++idx_img )
{
auto & image = *configurations[idx_img];
const auto & image = *configurations[idx_img];

// First Image
if( idx_img == 0 )
{
auto & image_plus = *configurations[idx_img + 1];
const auto & image_plus = *configurations[idx_img + 1];
Vectormath::set_c_a( 1, image_plus, tangents[idx_img] );
Vectormath::add_c_a( -1, image, tangents[idx_img] );
}
// Last Image
else if( idx_img == noi - 1 )
{
auto & image_minus = *configurations[idx_img - 1];
const auto & image_minus = *configurations[idx_img - 1];
Vectormath::set_c_a( 1, image, tangents[idx_img] );
Vectormath::add_c_a( -1, image_minus, tangents[idx_img] );
}
// Images Inbetween
else
{
auto & image_plus = *configurations[idx_img + 1];
auto & image_minus = *configurations[idx_img - 1];
const auto & image_plus = *configurations[idx_img + 1];
const auto & image_minus = *configurations[idx_img - 1];

// Energies
scalar E_mid = 0, E_plus = 0, E_minus = 0;
Expand Down

0 comments on commit b5b8112

Please sign in to comment.