Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions source/source_esolver/esolver_of.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace ModuleESolver
ESolver_OF::ESolver_OF()
{
this->classname = "ESolver_OF";
this->task_ = new char[60];
}

ESolver_OF::~ESolver_OF()
Expand All @@ -43,7 +42,6 @@ ESolver_OF::~ESolver_OF()

delete[] this->nelec_;
delete[] this->theta_;
delete[] this->task_;
delete this->ptemp_rho_;

delete this->kedf_manager_;
Expand Down
4 changes: 3 additions & 1 deletion source/source_esolver/esolver_of.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef ESOLVER_OF_H
#define ESOLVER_OF_H

#include <array>

#include "esolver_fp.h"
#include "source_base/opt_dcsrch.h"
#include "source_base/opt_tn.hpp"
Expand Down Expand Up @@ -58,7 +60,7 @@ class ESolver_OF : public ESolver_FP
double** pdEdphi_ = nullptr; // dE/dphi
double** pdLdphi_ = nullptr; // dL/dphi
double** pphi_ = nullptr; // pphi[i] = ppsi.get_pointer(i), which will be freed in ~Psi().
char* task_ = nullptr; // used in line search
std::array<char, 60> task_{}; // used in line search
Comment thread
mohanchen marked this conversation as resolved.
Outdated
int tn_spin_flag_ = -1; // spin flag used in cal_potential, which will be called by opt_tn
int max_dcsrch_ = 200; // max no. of line search
int flag_ = -1; // flag of TN
Expand Down
20 changes: 10 additions & 10 deletions source/source_esolver/esolver_of_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell&
if (this->inp_->nspin == 1)
{
int numDC = 0; // iteration number of line search
strcpy(this->task_, "START");
strcpy(this->task_.data(), "START");
while (true)
{
// update energy
Expand All @@ -122,11 +122,11 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell&
temp_energy += kinetic_energy + pseudopot_energy;

// line search to update theta[0]
this->opt_dcsrch_->dcSrch(temp_energy, dEdtheta[0], this->theta_[0], this->task_);
this->opt_dcsrch_->dcSrch(temp_energy, dEdtheta[0], this->theta_[0], this->task_.data());
numDC++;

// decide what to do next according to the output of line search
if (strncmp(this->task_, "FG", 2) == 0) // continue line search
if (strncmp(this->task_.data(), "FG", 2) == 0) // continue line search
{
// update tempPhi and tempRho
for (int i = 0; i < this->pw_rho->nrxx; ++i)
Expand All @@ -146,20 +146,20 @@ void ESolver_OF::get_step_length(double* dEdtheta, double** ptemp_phi, UnitCell&
break;
}
}
else if (strncmp(this->task_, "CO", 2) == 0) // convergence achieved
else if (strncmp(this->task_.data(), "CO", 2) == 0) // convergence achieved
{
break;
}
else if (strncmp(this->task_, "WA", 2) == 0) // warning of line search
else if (strncmp(this->task_.data(), "WA", 2) == 0) // warning of line search
{
GlobalV::ofs_warning << "ESolver_OF linesearch: WARNING " << this->task_ << std::endl;
std::cout << this->task_ << std::endl;
GlobalV::ofs_warning << "ESolver_OF linesearch: WARNING " << this->task_.data() << std::endl;
std::cout << this->task_.data() << std::endl;
break;
}
else if (strncmp(this->task_, "ER", 2) == 0) // ERROR in line search
else if (strncmp(this->task_.data(), "ER", 2) == 0) // ERROR in line search
{
GlobalV::ofs_warning << "ESolver_OF linesearch: ERROR " << this->task_ << std::endl;
std::cout << this->task_ << std::endl;
GlobalV::ofs_warning << "ESolver_OF linesearch: ERROR " << this->task_.data() << std::endl;
std::cout << this->task_.data() << std::endl;
break;
}
}
Expand Down
Loading