<commit_before>/*
relaxation.cpp

Copyright (c) 2014, 2015, 2016 <NAME>

This file is distributed under the terms of the MIT license.
Please see the file 'LICENCE.txt' in the root directory 
or http://opensource.org/licenses/mit-license.php for information.
*/

#include "mpi_common.h"
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <boost/lexical_cast.hpp>

#ifdef _OPENMP
#include <omp.h>
#endif 

#include "conductivity.h"
#include "dynamical.h"
#include "error.h"
#include "fcs_phonon.h"
#include "integration.h"
#include "kpoint.h"
#include "memory.h"
#include "parsephon.h"
#include "phonon_dos.h"
#include "thermodynamics.h"
#include "phonon_velocity.h"
#include "relaxation.h"
#include "selfenergy.h"
#include "symmetry_core.h"
#include "system.h"
#include "write_phonons.h"
#include "timer.h"
#include "constants.h"
#include "mathfunctions.h"
#include "integration.h"

using namespace PHON_NS;

Relaxation::Relaxation(PHON *phon): Pointers(phon) {
    im = std::complex<double>(0.0, 1.0);
}

Relaxation::~Relaxation(){};

void Relaxation::setup_relaxation()
{

    nk = kpoint->nk;
    ns = dynamical->neval;
    nks = ns*nk;
    int nk_tmp[3];

    if (mympi->my_rank == 0) {
        std::cout << std::endl;
        std::cout << " ------------------------------------------------------------" << std::endl << std::endl;
        std::cout << " Now, move on to phonon lifetime calculations." << std::endl;
    }

    setup_mode_analysis();
    setup_cubic();

    use_tuned_ver = true;
    nk_tmp[0] = kpoint->nkx;
    nk_tmp[1] = kpoint->nky;
    nk_tmp[2] = kpoint->nkz;
    store_exponential_for_acceleration(nk_tmp, nk_represent, exp_phase, exp_phase3);

    if (ks_analyze_mode) {

        if (kpoint->kpoint_mode == 2 && use_triplet_symmetry) {
            use_triplet_symmetry = false;
            if (mympi->my_rank == 0) {
                std::cout << std::endl;
                std::cout << " TRISYM was automatically set to 0." << std::endl;
                std::cout << std::endl;
            }
        }

        MPI_Bcast(&calc_realpart, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);
        MPI_Bcast(&atom_project_mode, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);
        MPI_Bcast(&calc_fstate_k, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);
        MPI_Bcast(&calc_fstate_omega, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);

        if (mympi->my_rank == 0) {
            if (calc_fstate_omega) sym_permutation = false;
        }
        MPI_Bcast(&sym_permutation, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);

        if (quartic_mode > 0) {

            // This is for quartic vertexes.

            if (mympi->my_rank == 0) {
                std::cout << " QUARTIC = 1 : Frequency shift due to the loop diagram associated with" << std::endl;
                std::cout << "               quartic anharmonicity will be calculated." << std::endl;
                std::cout << "               Please check the accuracy of the quartic IFCs " << std::endl;
                std::cout << "               before doing serious calculations." << std::endl;
                std::cout << std::endl;
            }

            setup_quartic();
        }

        if (calc_realpart && integration->ismear != 0) {
            error->exit("setup_relaxation", "Sorry. REALPART = 1 can be used only with ISMEAR = 0");
        }
        
        dynamical->modify_eigenvectors();
    }
    
    if (kpoint->kpoint_mode == 2) {
        generate_triplet_k(use_triplet_symmetry, sym_permutation);
    }
}

void Relaxation::finish_relaxation()
{
    memory->deallocate(vec_for_v3);
    memory->deallocate(invmass_for_v3);
    memory->deallocate(evec_index);
    memory->deallocate(fcs_group);

    if (use_tuned_ver) {
        if (tune_type == 0) {
            memory->deallocate(exp_phase);
        } else if (tune_type == 1) {
            memory->deallocate(exp_phase3);
        }
    }
<commit_msg>Fixed an issue regarding the calculation of momentum-resolved final state amplitude<commit_after>/*
relaxation.cpp

Copyright (c) 2014, 2015, 2016 <NAME>

This file is distributed under the terms of the MIT license.
Please see the file 'LICENCE.txt' in the root directory 
or http://opensource.org/licenses/mit-license.php for information.
*/

#include "mpi_common.h"
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <boost/lexical_cast.hpp>

#ifdef _OPENMP
#include <omp.h>
#endif 

#include "conductivity.h"
#include "dynamical.h"
#include "error.h"
#include "fcs_phonon.h"
#include "integration.h"
#include "kpoint.h"
#include "memory.h"
#include "parsephon.h"
#include "phonon_dos.h"
#include "thermodynamics.h"
#include "phonon_velocity.h"
#include "relaxation.h"
#include "selfenergy.h"
#include "symmetry_core.h"
#include "system.h"
#include "write_phonons.h"
#include "timer.h"
#include "constants.h"
#include "mathfunctions.h"
#include "integration.h"

using namespace PHON_NS;

Relaxation::Relaxation(PHON *phon): Pointers(phon) {
    im = std::complex<double>(0.0, 1.0);
}

Relaxation::~Relaxation(){};

void Relaxation::setup_relaxation()
{

    nk = kpoint->nk;
    ns = dynamical->neval;
    nks = ns*nk;
    int nk_tmp[3];

    if (mympi->my_rank == 0) {
        std::cout << std::endl;
        std::cout << " ------------------------------------------------------------" << std::endl << std::endl;
        std::cout << " Now, move on to phonon lifetime calculations." << std::endl;
    }

    setup_mode_analysis();
    setup_cubic();

    if (ks_analyze_mode) {

        if (kpoint->kpoint_mode == 2 && use_triplet_symmetry) {
            use_triplet_symmetry = false;
            if (mympi->my_rank == 0) {
                std::cout << std::endl;
                std::cout << " TRISYM was automatically set to 0." << std::endl;
                std::cout << std::endl;
            }
        }

        MPI_Bcast(&calc_realpart, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);
        MPI_Bcast(&atom_project_mode, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);
        MPI_Bcast(&calc_fstate_k, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);
        MPI_Bcast(&calc_fstate_omega, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);

        if (mympi->my_rank == 0) {
            if (calc_fstate_omega) sym_permutation = false;
        }
        MPI_Bcast(&sym_permutation, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD);

        if (quartic_mode > 0) {

            // This is for quartic vertexes.

            if (mympi->my_rank == 0) {
                std::cout << " QUARTIC = 1 : Frequency shift due to the loop diagram associated with" << std::endl;
                std::cout << "               quartic anharmonicity will be calculated." << std::endl;
                std::cout << "               Please check the accuracy of the quartic IFCs " << std::endl;
                std::cout << "               before doing serious calculations." << std::endl;
                std::cout << std::endl;
            }

            setup_quartic();
        }

        if (calc_realpart && integration->ismear != 0) {
            error->exit("setup_relaxation", "Sorry. REALPART = 1 can be used only with ISMEAR = 0");
        }
        
        dynamical->modify_eigenvectors();
    }
   
    if (calc_fstate_k) {
        use_tuned_ver = false;
    } else {
        use_tuned_ver = true;
        nk_tmp[0] = kpoint->nkx;
        nk_tmp[1] = kpoint->nky;
        nk_tmp[2] = kpoint->nkz;
        store_exponential_for_acceleration(nk_tmp, nk_represent, exp_phase, exp_phase3);
    }
    
    if (kpoint->kpoint_mode == 2) {
        generate_triplet_k(use_triplet_symmetry, sym_permutation);
    }
}

void Relaxation::finish_relaxation()
{
    memory->deallocate(vec_for_v3);
    memory->deallocate(invmass_for_v3);
    memory->deallocate(evec_index);
    memory->deallocate(fcs_group);

    if (use_tuned_ver) {
        if (tune_type == 0) {
            memory->deallocate(exp_phase);
        } else if (tune_type == 1) {
            memory->deallocate(exp_phase3);
        }
    }

{'fraction_non_alphanumeric': 0.148375, 'fraction_numerical': 0.012, 'mean_word_length': 2.523117569352708, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '313768', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2689, 'n_words': 585}