<commit_before>Potential::Potential(Global& parameters__) : parameters_(parameters__), pseudo_density_order(9)
{
    Timer t("sirius::Potential::Potential");
    
    lmax_ = std::max(parameters_.lmax_rho(), parameters_.lmax_pot());
    sht_ = new SHT(lmax_);

    effective_potential_ = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()), 
                                                         Argument(arg_radial, parameters_.max_num_mt_points()), 
                                                         parameters_.num_gvec());
    for (int j = 0; j < parameters_.num_mag_dims(); j++)
    {
        effective_magnetic_field_[j] = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()), 
                                                                     Argument(arg_radial, parameters_.max_num_mt_points()));
    }
    
    // precompute i^l
    zil_.resize(parameters_.lmax_rho() + 1);
    for (int l = 0; l <= parameters_.lmax_rho(); l++) zil_[l] = pow(complex16(0, 1), l);
    
    zilm_.resize(parameters_.lmmax_rho());
    for (int l = 0, lm = 0; l <= parameters_.lmax_rho(); l++)
    {
        for (int m = -l; m <= l; m++, lm++) zilm_[lm] = zil_[l];
    }

    l_by_lm_.set_dimensions(Utils::lmmax_by_lmax(lmax_));
    l_by_lm_.allocate();
    for (int l = 0, lm = 0; l <= lmax_; l++)
    {
        for (int m = -l; m <= l; m++, lm++) l_by_lm_(lm) = l;
    }
    
    coulomb_potential_ = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()),
                                                                    Argument(arg_radial, parameters_.max_num_mt_points()),
                                                                    parameters_.num_gvec());
    coulomb_potential_->allocate(false);
    
    xc_potential_ = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()),
                                                               Argument(arg_radial, parameters_.max_num_mt_points()));
    xc_potential_->allocate(false);
    
    xc_energy_density_ = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()),
                                                                    Argument(arg_radial, parameters_.max_num_mt_points()));
    xc_energy_density_->allocate(false);

    update();
}

Potential::~Potential()
{
    delete effective_potential_; 
    for (int j = 0; j < parameters_.num_mag_dims(); j++) delete effective_magnetic_field_[j];
    delete sht_;
    delete coulomb_potential_;
    delete xc_potential_;
}

void Potential::update()
{
    // compute values of spherical Bessel functions at MT boundary
    sbessel_mt_.set_dimensions(lmax_ + pseudo_density_order + 2, parameters_.num_atom_types(), 
                               parameters_.num_gvec_shells());
    sbessel_mt_.allocate();

    for (int iat = 0; iat < parameters_.num_atom_types(); iat++)
    {<commit_msg>fix a memory leak<commit_after>Potential::Potential(Global& parameters__) : parameters_(parameters__), pseudo_density_order(9)
{
    Timer t("sirius::Potential::Potential");
    
    lmax_ = std::max(parameters_.lmax_rho(), parameters_.lmax_pot());
    sht_ = new SHT(lmax_);

    effective_potential_ = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()), 
                                                         Argument(arg_radial, parameters_.max_num_mt_points()), 
                                                         parameters_.num_gvec());
    for (int j = 0; j < parameters_.num_mag_dims(); j++)
    {
        effective_magnetic_field_[j] = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()), 
                                                                     Argument(arg_radial, parameters_.max_num_mt_points()));
    }
    
    // precompute i^l
    zil_.resize(parameters_.lmax_rho() + 1);
    for (int l = 0; l <= parameters_.lmax_rho(); l++) zil_[l] = pow(complex16(0, 1), l);
    
    zilm_.resize(parameters_.lmmax_rho());
    for (int l = 0, lm = 0; l <= parameters_.lmax_rho(); l++)
    {
        for (int m = -l; m <= l; m++, lm++) zilm_[lm] = zil_[l];
    }

    l_by_lm_.set_dimensions(Utils::lmmax_by_lmax(lmax_));
    l_by_lm_.allocate();
    for (int l = 0, lm = 0; l <= lmax_; l++)
    {
        for (int m = -l; m <= l; m++, lm++) l_by_lm_(lm) = l;
    }
    
    coulomb_potential_ = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()),
                                                                    Argument(arg_radial, parameters_.max_num_mt_points()),
                                                                    parameters_.num_gvec());
    coulomb_potential_->allocate(false);
    
    xc_potential_ = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()),
                                                               Argument(arg_radial, parameters_.max_num_mt_points()));
    xc_potential_->allocate(false);
    
    xc_energy_density_ = new Periodic_function<double>(parameters_, Argument(arg_lm, parameters_.lmmax_pot()),
                                                                    Argument(arg_radial, parameters_.max_num_mt_points()));
    xc_energy_density_->allocate(false);

    update();
}

Potential::~Potential()
{
    delete effective_potential_; 
    for (int j = 0; j < parameters_.num_mag_dims(); j++) delete effective_magnetic_field_[j];
    delete sht_;
    delete coulomb_potential_;
    delete xc_potential_;
    delete xc_energy_density_;
}

void Potential::update()
{
    // compute values of spherical Bessel functions at MT boundary
    sbessel_mt_.set_dimensions(lmax_ + pseudo_density_order + 2, parameters_.num_atom_types(), 
                               parameters_.num_gvec_shells());
    sbessel_mt_.allocate();

    for (int iat = 0; iat < parameters_.num_atom_types(); iat++)
    {
{'fraction_non_alphanumeric': 0.12117666722380077, 'fraction_numerical': 0.005014206919605549, 'mean_word_length': 2.1965811965811968, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '575949', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1693, 'n_words': 321}