Skip to content

Commit

Permalink
Reformat ALM and tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ttadano committed Oct 1, 2021
1 parent c583b62 commit 8ed05bf
Show file tree
Hide file tree
Showing 40 changed files with 2,378 additions and 2,375 deletions.
4 changes: 1 addition & 3 deletions alm/Makefile.osx_clang
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ LIBS = ${LAPACK} -lomp

PROG = alm

CXXSRC= alm.cpp alm_cui.cpp input_parser.cpp input_setter.cpp constraint.cpp fcs.cpp files.cpp \
optimize.cpp cluster.cpp main.cpp rref.cpp \
patterndisp.cpp symmetry.cpp system.cpp timer.cpp writer.cpp
CXXSRC= $(wildcard *.cpp)

OBJS= ${CXXSRC:.cpp=.o}

Expand Down
16 changes: 8 additions & 8 deletions alm/alm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ int ALM::get_displacement_patterns(int *atom_indices,

auto i_atom = 0;
auto i_disp = 0;
for (const auto &displacements : displace->get_pattern_all(order)) {
for (const auto &displacements: displace->get_pattern_all(order)) {
for (size_t j = 0; j < displacements.atoms.size(); ++j) {
atom_indices[i_atom] = displacements.atoms[j];
++i_atom;
Expand Down Expand Up @@ -438,15 +438,15 @@ void ALM::get_fc_origin(double *fc_values,
auto id = 0;

if (permutation) {
for (const auto &it : fcs->get_fc_cart()[fc_order - 1]) {
for (const auto &it: fcs->get_fc_cart()[fc_order - 1]) {
fc_values[id] = it.fc_value;
for (auto i = 0; i < fc_order + 1; ++i) {
elem_indices[id * (fc_order + 1) + i] = it.flattenarray[i];
}
++id;
}
} else {
for (const auto &it : fcs->get_fc_cart()[fc_order - 1]) {
for (const auto &it: fcs->get_fc_cart()[fc_order - 1]) {
if (it.is_ascending_order) {
fc_values[id] = it.fc_value;
for (auto i = 0; i < fc_order + 1; ++i) {
Expand Down Expand Up @@ -496,7 +496,7 @@ void ALM::get_fc_irreducible(double *fc_values,
if (constraint->get_index_bimap(order).empty()) { continue; }

if (order == fc_order - 1) {
for (const auto &it : constraint->get_index_bimap(order)) {
for (const auto &it: constraint->get_index_bimap(order)) {
inew = it.left;
iold = it.right + ishift;

Expand Down Expand Up @@ -535,7 +535,7 @@ void ALM::get_fc_all(double *fc_values,
size_t id = 0;

if (permutation) {
for (const auto &it : fcs->get_fc_cart()[fc_order - 1]) {
for (const auto &it: fcs->get_fc_cart()[fc_order - 1]) {

for (size_t itran = 0; itran < ntran; ++itran) {
for (i = 0; i < fc_order + 1; ++i) {
Expand All @@ -549,7 +549,7 @@ void ALM::get_fc_all(double *fc_values,
}
}
} else {
for (const auto &it : fcs->get_fc_cart()[fc_order - 1]) {
for (const auto &it: fcs->get_fc_cart()[fc_order - 1]) {
if (it.is_ascending_order) {
for (size_t itran = 0; itran < ntran; ++itran) {
for (i = 0; i < fc_order + 1; ++i) {
Expand Down Expand Up @@ -597,11 +597,11 @@ void ALM::get_matrix_elements(double *amat,
constraint);
// This may be inefficient.
auto i = 0;
for (const auto it : amat_vec) {
for (const auto it: amat_vec) {
amat[i++] = it;
}
i = 0;
for (const auto it : bvec_vec) {
for (const auto it: bvec_vec) {
bvec[i++] = it;
}
//amat = amat_vec.data();
Expand Down
216 changes: 108 additions & 108 deletions alm/alm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,180 +22,180 @@
#include "timer.h"

namespace ALM_NS {
class ALM {
public:
ALM();
class ALM {
public:
ALM();

~ALM();
~ALM();

class Cluster *cluster{};
class Cluster *cluster{};

class Fcs *fcs{};
class Fcs *fcs{};

class Symmetry *symmetry{};
class Symmetry *symmetry{};

class Optimize *optimize{};
class Optimize *optimize{};

class Constraint *constraint{};
class Constraint *constraint{};

class Files *files{};
class Files *files{};

class Displace *displace{};
class Displace *displace{};

class Timer *timer{};
class Timer *timer{};

void set_verbosity(int verbosity_in);
void set_verbosity(int verbosity_in);

int get_verbosity() const;
int get_verbosity() const;

void set_output_filename_prefix(std::string prefix) const;
void set_output_filename_prefix(std::string prefix) const;

void set_print_hessian(bool print_hessian) const;
void set_print_hessian(bool print_hessian) const;

void set_print_symmetry(int printsymmetry) const;
void set_print_symmetry(int printsymmetry) const;

void set_datfile_train(const DispForceFile &dat_in) const;
void set_datfile_train(const DispForceFile &dat_in) const;

void set_datfile_validation(const DispForceFile &dat_in) const;
void set_datfile_validation(const DispForceFile &dat_in) const;

void set_symmetry_tolerance(double tolerance) const;
void set_symmetry_tolerance(double tolerance) const;

void set_displacement_param(bool trim_dispsign_for_evenfunc) const;
void set_displacement_param(bool trim_dispsign_for_evenfunc) const;

void set_displacement_basis(std::string str_disp_basis) const;
void set_displacement_basis(std::string str_disp_basis) const;

void set_periodicity(const int is_periodic[3]) const;
void set_periodicity(const int is_periodic[3]) const;

void set_cell(size_t nat,
const double lavec[3][3],
const double xcoord[][3],
const int kind[],
const std::string kdname[]) const;
void set_cell(size_t nat,
const double lavec[3][3],
const double xcoord[][3],
const int kind[],
const std::string kdname[]) const;

void set_magnetic_params(const size_t nat,
const double (*magmom)[3],
const bool lspin,
const int noncollinear,
const int trev_sym_mag,
const std::string str_magmom) const;
void set_magnetic_params(const size_t nat,
const double (*magmom)[3],
const bool lspin,
const int noncollinear,
const int trev_sym_mag,
const std::string str_magmom) const;

void set_u_train(const std::vector<std::vector<double>> &u) const;
void set_u_train(const std::vector<std::vector<double>> &u) const;

void set_f_train(const std::vector<std::vector<double>> &f) const;
void set_f_train(const std::vector<std::vector<double>> &f) const;

void set_validation_data(const std::vector<std::vector<double>> &u,
const std::vector<std::vector<double>> &f) const;
void set_validation_data(const std::vector<std::vector<double>> &u,
const std::vector<std::vector<double>> &f) const;

void set_optimizer_control(const OptimizerControl &optcontrol_in) const;
void set_optimizer_control(const OptimizerControl &optcontrol_in) const;

void set_constraint_mode(const int constraint_flag) const;
void set_constraint_mode(const int constraint_flag) const;

void set_tolerance_constraint(const double tolerance_constraint) const;
void set_tolerance_constraint(const double tolerance_constraint) const;

void set_rotation_axis(const std::string rotation_axis) const;
void set_rotation_axis(const std::string rotation_axis) const;

void set_fc_file(const int order, const std::string fc_file) const;
void set_fc_file(const int order, const std::string fc_file) const;

void set_fc_fix(const int order, const bool fc_fix) const;
void set_fc_fix(const int order, const bool fc_fix) const;

void set_sparse_mode(const int sparse_mode) const;
void set_sparse_mode(const int sparse_mode) const;

void set_forceconstant_basis(const std::string preferred_basis) const;
void set_forceconstant_basis(const std::string preferred_basis) const;

std::string get_forceconstant_basis() const;
std::string get_forceconstant_basis() const;

void set_nmaxsave(const int nmaxsave) const; // NMAXSAVE
void set_nmaxsave(const int nmaxsave) const; // NMAXSAVE

int get_nmaxsave() const;
int get_nmaxsave() const;

//void set_fitting_filenames(std::string dfile,
// std::string ffile) const;
void define(const int maxorder,
const size_t nkd,
const int *nbody_include,
const double *cutoff_radii) const;
//void set_fitting_filenames(std::string dfile,
// std::string ffile) const;
void define(const int maxorder,
const size_t nkd,
const int *nbody_include,
const double *cutoff_radii) const;

//int get_ndata_used() const;
OptimizerControl get_optimizer_control() const;
//int get_ndata_used() const;
OptimizerControl get_optimizer_control() const;

std::vector<std::vector<double>> get_u_train() const;
std::vector<std::vector<double>> get_u_train() const;

std::vector<std::vector<double>> get_f_train() const;
std::vector<std::vector<double>> get_f_train() const;

size_t get_number_of_data() const;
size_t get_number_of_data() const;

size_t get_nrows_sensing_matrix() const;
size_t get_nrows_sensing_matrix() const;

double get_cv_l1_alpha() const;
double get_cv_l1_alpha() const;

Cell get_supercell() const;
Cell get_supercell() const;

std::string *get_kdname() const;
std::string *get_kdname() const;

Spin get_spin() const;
Spin get_spin() const;

void set_str_magmom(std::string);
void set_str_magmom(std::string);

std::string get_str_magmom() const;
std::string get_str_magmom() const;

double ***get_x_image() const;
double ***get_x_image() const;

int *get_periodicity() const;
int *get_periodicity() const;

const std::vector<std::vector<int>> &get_atom_mapping_by_pure_translations() const;
const std::vector<std::vector<int>> &get_atom_mapping_by_pure_translations() const;

int get_maxorder() const;
int get_maxorder() const;

int *get_nbody_include() const;
int *get_nbody_include() const;

size_t get_number_of_displacement_patterns(const int fc_order) const; // harmonic=1, ...
void get_number_of_displaced_atoms(int *numbers,
int fc_order) const; // harmonic=1, ...
int get_displacement_patterns(int *atom_indices,
double *disp_patterns,
int fc_order) const; // harmonic=1, ...
size_t get_number_of_fc_elements(const int fc_order) const; // harmonic=1, ...
size_t get_number_of_irred_fc_elements(const int fc_order); // harmonic=1, ...
size_t get_number_of_displacement_patterns(const int fc_order) const; // harmonic=1, ...
void get_number_of_displaced_atoms(int *numbers,
int fc_order) const; // harmonic=1, ...
int get_displacement_patterns(int *atom_indices,
double *disp_patterns,
int fc_order) const; // harmonic=1, ...
size_t get_number_of_fc_elements(const int fc_order) const; // harmonic=1, ...
size_t get_number_of_irred_fc_elements(const int fc_order); // harmonic=1, ...

size_t get_number_of_fc_origin(const int fc_order, // harmonic = 1
const int permutation) const;
size_t get_number_of_fc_origin(const int fc_order, // harmonic = 1
const int permutation) const;

void get_fc_origin(double *fc_values,
int *elem_indices, // (len(fc_value), fc_order) is flatten.
int fc_order, // harmonic=1, ...
int permutation = 1) const;
void get_fc_origin(double *fc_values,
int *elem_indices, // (len(fc_value), fc_order) is flatten.
int fc_order, // harmonic=1, ...
int permutation = 1) const;


void get_fc_irreducible(double *fc_values,
int *elem_indices, // (len(fc_value), fc_order) is flatten.
int fc_order); // harmonic=1, ...
void get_fc_irreducible(double *fc_values,
int *elem_indices, // (len(fc_value), fc_order) is flatten.
int fc_order); // harmonic=1, ...


void get_fc_all(double *fc_values,
int *elem_indices, // (len(fc_value), fc_order) is flatten.
int fc_order, // harmonic=1, ...
int permutation = 1) const;
void get_fc_all(double *fc_values,
int *elem_indices, // (len(fc_value), fc_order) is flatten.
int fc_order, // harmonic=1, ...
int permutation = 1) const;

void set_fc(double *fc_in) const;
void set_fc(double *fc_in) const;

void get_matrix_elements(double *amat,
double *bvec) const;
void get_matrix_elements(double *amat,
double *bvec) const;

int run_optimize();
int run_optimize();

void run_suggest();
void run_suggest();

void init_fc_table();
void init_fc_table();

private:
class System *system{};
private:
class System *system{};

int verbosity;
bool structure_initialized;
bool ready_to_fit;
std::ofstream *ofs_alm;
std::streambuf *coutbuf;
int verbosity;
bool structure_initialized;
bool ready_to_fit;
std::ofstream *ofs_alm;
std::streambuf *coutbuf;

void init_instances();
};
void init_instances();
};
}
14 changes: 7 additions & 7 deletions alm/alm_cui.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#pragma once

namespace ALM_NS {
class ALMCUI {
public:
ALMCUI();
class ALMCUI {
public:
ALMCUI();

~ALMCUI();
~ALMCUI();

void run(const int narg,
char **arg) const;
};
void run(const int narg,
char **arg) const;
};
}
Loading

0 comments on commit 8ed05bf

Please sign in to comment.