Skip to content

Commit

Permalink
Clearn up codes. (Need more refactoring)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttadano committed Feb 23, 2018
1 parent 01ddb34 commit 69d3f41
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 206 deletions.
75 changes: 47 additions & 28 deletions anphon/conductivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,74 @@
*/

#include "mpi_common.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include "conductivity.h"
#include "constants.h"
#include "dynamical.h"
#include "error.h"
#include "integration.h"
#include "isotope.h"
#include "kpoint.h"
#include "mathfunctions.h"
#include "memory.h"
#include "parsephon.h"
#include "phonon_dos.h"
#include "thermodynamics.h"
#include "phonon_velocity.h"
#include "relaxation.h"
#include "system.h"
#include "write_phonons.h"
#include "constants.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <set>
#include <vector>
#include "mathfunctions.h"
#include "isotope.h"
#include "phonon_dos.h"

using namespace PHON_NS;

Conductivity::Conductivity(PHON *phon): Pointers(phon)
{
set_default_variables();
}

Conductivity::~Conductivity()
{
deallocate_variables();
};

void Conductivity::set_default_variables()
{
calc_kappa_spec = 0;
ntemp = 0;
damping3 = nullptr;
kappa = nullptr;
kappa_spec = nullptr;
Temperature = nullptr;
vel = nullptr;
}

void Conductivity::deallocate_variables()
{
if (damping3) {
memory->deallocate(damping3);
}
if (kappa) {
memory->deallocate(kappa);
}
if (kappa_spec) {
memory->deallocate(kappa_spec);
}
if (Temperature) {
memory->deallocate(Temperature);
}
if (vel) {
memory->deallocate(vel);
}
}


void Conductivity::setup_kappa()
{
unsigned int i, j, k;
unsigned int nks_total, nks_each_thread, nrem;

nk = kpoint->nk;
ns = dynamical->neval;
Expand All @@ -56,9 +88,9 @@ void Conductivity::setup_kappa()
Temperature[i] = system->Tmin + static_cast<double>(i) * system->dT;
}

nks_total = kpoint->nk_irred * ns;
nks_each_thread = nks_total / mympi->nprocs;
nrem = nks_total - nks_each_thread * mympi->nprocs;
unsigned int nks_total = kpoint->nk_irred * ns;
unsigned int nks_each_thread = nks_total / mympi->nprocs;
unsigned int nrem = nks_total - nks_each_thread * mympi->nprocs;

if (nrem > 0) {
memory->allocate(damping3, (nks_each_thread + 1) * mympi->nprocs, ntemp);
Expand Down Expand Up @@ -190,22 +222,9 @@ void Conductivity::prepare_restart()
vks_done.clear();
}

void Conductivity::finish_kappa()
{
if (mympi->my_rank == 0) {
memory->deallocate(vel);
memory->deallocate(kappa);
if (calc_kappa_spec) {
memory->deallocate(kappa_spec);
}
}
memory->deallocate(damping3);
memory->deallocate(Temperature);
}

void Conductivity::calc_anharmonic_imagself()
{
unsigned int nks_g;
unsigned int i, j;
unsigned int knum, snum;
unsigned int *nks_thread;
Expand All @@ -216,7 +235,7 @@ void Conductivity::calc_anharmonic_imagself()

// Distribute (k,s) to individual MPI threads

nks_g = vks_job.size();
unsigned int nks_g = vks_job.size();
vks_l.clear();

unsigned int icount = 0;
Expand Down Expand Up @@ -304,11 +323,11 @@ void Conductivity::write_result_gamma(const unsigned int ik, const unsigned int
double ***vel_in, double **damp_in)
{
unsigned int np = mympi->nprocs;
unsigned int j, k, iks_g;
unsigned int k, iks_g;
unsigned int nk_equiv;
unsigned int ktmp;

for (j = 0; j < np; ++j) {
for (unsigned int j = 0; j < np; ++j) {

iks_g = ik * np + j + nshift;

Expand Down Expand Up @@ -368,7 +387,7 @@ void Conductivity::compute_kappa()
snum = iks % ns;
if (relaxation->is_imaginary[iks / ns][snum]) {
for (i = 0; i < ntemp; ++i) {
lifetime[iks][i] = 0.0;;
lifetime[iks][i] = 0.0;
}
} else {
for (i = 0; i < ntemp; ++i) {
Expand Down
16 changes: 9 additions & 7 deletions anphon/conductivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace PHON_NS
void prepare_restart();
void calc_anharmonic_imagself();
void compute_kappa();
void finish_kappa();

int calc_kappa_spec;
unsigned int ntemp;
Expand All @@ -35,21 +34,24 @@ namespace PHON_NS
double *Temperature;

private:
void set_default_variables();
void deallocate_variables();

double ***vel;
unsigned int nk, ns;
int nshift_restart;
std::vector<int> vks, vks_l, vks_done;
std::set<int> vks_job;

void write_result_gamma(const unsigned int,
const unsigned int,
void write_result_gamma(unsigned int,
unsigned int,
double ***,
double **);
void average_self_energy_at_degenerate_point(const int,
const int,
void average_self_energy_at_degenerate_point(int,
int,
double **);
void compute_frequency_resolved_kappa(const int,
void compute_frequency_resolved_kappa(int,
double ****,
const int);
int);
};
}
1 change: 0 additions & 1 deletion anphon/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#pragma once

#include <string>
#include "pointers.h"

namespace PHON_NS
Expand Down
4 changes: 3 additions & 1 deletion anphon/isotope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ void Isotope::setup_isotope_scattering()
if (mympi->my_rank == 0) {
if (!isotope_factor) {
memory->allocate(isotope_factor, nkd);
set_isotope_factor_from_database(nkd, system->symbol_kd, isotope_factor);
set_isotope_factor_from_database(nkd,
system->symbol_kd,
isotope_factor);
}
}

Expand Down
5 changes: 1 addition & 4 deletions anphon/mpi_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

#include "mpi_common.h"
#include <iostream>
#include <string>
#include <cstring>

Expand All @@ -21,9 +20,7 @@ MyMPI::MyMPI(PHON *phon, MPI_Comm comm): Pointers(phon)
MPI_Comm_size(comm, &nprocs);
}

MyMPI::~MyMPI()
{
}
MyMPI::~MyMPI() {}

void MyMPI::MPI_Bcast_string(std::string &str, int root, MPI_Comm comm)
{
Expand Down
6 changes: 0 additions & 6 deletions anphon/phonons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,6 @@ void PHON::execute_RTA()
writes->write_kappa();
writes->write_selfenergy_isotope();
}

relaxation->finish_relaxation();

if (!relaxation->ks_analyze_mode) {
conductivity->finish_kappa();
}
}

void PHON::execute_self_consistent_phonon()
Expand Down

0 comments on commit 69d3f41

Please sign in to comment.