|
| 1 | +#include "sep_cell.h" |
| 2 | + |
| 3 | +#include "source_base/global_function.h" |
| 4 | +#include "source_base/global_variable.h" |
| 5 | +#include "source_base/parallel_common.h" |
| 6 | +#include "source_base/tool_title.h" |
| 7 | +#include "source_cell/unitcell.h" |
| 8 | + |
| 9 | +#include <algorithm> |
| 10 | +#include <string> |
| 11 | + |
| 12 | +namespace GlobalC |
| 13 | +{ |
| 14 | +Sep_Cell sep_cell; |
| 15 | +} |
| 16 | + |
| 17 | +Sep_Cell::Sep_Cell() noexcept : ntype(0), omega(0.0), tpiba2(0.0) |
| 18 | +{ |
| 19 | +} |
| 20 | + |
| 21 | +Sep_Cell::~Sep_Cell() noexcept = default; |
| 22 | + |
| 23 | +void Sep_Cell::init(const int ntype_in) |
| 24 | +{ |
| 25 | + this->ntype = ntype_in; |
| 26 | + this->seps.resize(ntype); |
| 27 | + this->sep_enable.resize(ntype); |
| 28 | + std::fill(this->sep_enable.begin(), this->sep_enable.end(), false); |
| 29 | +} |
| 30 | + |
| 31 | +void Sep_Cell::set_omega(const double omega_in, const double tpiba2_in) |
| 32 | +{ |
| 33 | + this->omega = omega_in; |
| 34 | + this->tpiba2 = tpiba2_in; |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * read sep potential files |
| 39 | + * |
| 40 | + * need to add following lines in STRU file, and order of elements must match ATOMIC_SPECIES. |
| 41 | + * SEP_FILES |
| 42 | + * symbol is_enable r_in r_out r_power enhence_a |
| 43 | + * |
| 44 | + * example |
| 45 | + * Li 0 |
| 46 | + * F 1 F_pbe_50.sep 0.0 2.0 20.0 1.0 |
| 47 | + */ |
| 48 | +int Sep_Cell::read_sep_potentials(std::ifstream& ifpos, |
| 49 | + const std::string& pp_dir, |
| 50 | + std::ofstream& ofs_running, |
| 51 | + UnitCell& ucell) |
| 52 | +{ |
| 53 | + ModuleBase::TITLE("Sep_Cell", "read_sep_potentials"); |
| 54 | + |
| 55 | + if (!ModuleBase::GlobalFunc::SCAN_BEGIN(ifpos, "SEP_FILES")) |
| 56 | + { |
| 57 | + GlobalV::ofs_running << "Cannot find SEP_FILES section in STRU" << std::endl; |
| 58 | + return false; |
| 59 | + } |
| 60 | + |
| 61 | + ifpos.ignore(300, '\n'); |
| 62 | + |
| 63 | + for (int i = 0; i < this->ntype; ++i) |
| 64 | + { |
| 65 | + std::string one_line, atom_label; |
| 66 | + std::getline(ifpos, one_line); |
| 67 | + std::stringstream ss(one_line); |
| 68 | + |
| 69 | + // read the label of the atom |
| 70 | + bool enable_tmp; |
| 71 | + ss >> atom_label >> enable_tmp; |
| 72 | + |
| 73 | + // Validate atom label |
| 74 | + if (atom_label != ucell.atom_label[i]) |
| 75 | + { |
| 76 | + GlobalV::ofs_running << "Sep potential and atom order do not match. " |
| 77 | + << "Expected: " << ucell.atoms[i].label << ", Got: " << atom_label << std::endl; |
| 78 | + return false; |
| 79 | + } |
| 80 | + this->sep_enable[i] = enable_tmp; |
| 81 | + if (this->sep_enable[i]) |
| 82 | + { |
| 83 | + this->seps[i].is_enable = this->sep_enable[i]; |
| 84 | + std::string sep_filename; |
| 85 | + ss >> sep_filename; |
| 86 | + ss >> this->seps[i].r_in >> this->seps[i].r_out >> this->seps[i].r_power >> this->seps[i].enhence_a; |
| 87 | + std::string sep_addr = pp_dir + sep_filename; |
| 88 | + std::ifstream sep_ifs(sep_addr.c_str(), std::ios::in); |
| 89 | + if (!sep_ifs) |
| 90 | + { |
| 91 | + GlobalV::ofs_running << "Cannot find sep potential file: " << sep_addr << std::endl; |
| 92 | + return false; |
| 93 | + } |
| 94 | + this->seps[i].read_sep(sep_ifs); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + return true; |
| 99 | +} |
| 100 | + |
| 101 | +#ifdef __MPI |
| 102 | +void Sep_Cell::bcast_sep_cell() |
| 103 | +{ |
| 104 | + ModuleBase::TITLE("Sep_Cell", "bcast_sep_cell"); |
| 105 | + Parallel_Common::bcast_int(this->ntype); |
| 106 | + |
| 107 | + if (GlobalV::MY_RANK != 0) |
| 108 | + { |
| 109 | + this->seps.resize(this->ntype); |
| 110 | + this->sep_enable.resize(this->ntype); |
| 111 | + } |
| 112 | + for (int i = 0; i < this->ntype; ++i) |
| 113 | + { |
| 114 | + bool tmp = false; |
| 115 | + if (GlobalV::MY_RANK == 0) |
| 116 | + { |
| 117 | + tmp = this->sep_enable[i]; |
| 118 | + } |
| 119 | + Parallel_Common::bcast_bool(tmp); |
| 120 | + if (GlobalV::MY_RANK != 0) |
| 121 | + { |
| 122 | + this->sep_enable[i] = tmp; |
| 123 | + } |
| 124 | + this->seps[i].bcast_sep(); |
| 125 | + } |
| 126 | +} |
| 127 | +#endif // __MPI |
0 commit comments