diff --git a/source/module_cell/atom_spec.cpp b/source/module_cell/atom_spec.cpp index f00a062c1d..0bf5045f2d 100644 --- a/source/module_cell/atom_spec.cpp +++ b/source/module_cell/atom_spec.cpp @@ -102,51 +102,54 @@ void Atom::bcast_atom(void) Parallel_Common::bcast_bool(this->flag_empty_element); Parallel_Common::bcast_double(mass); - if (GlobalV::MY_RANK != 0) + if (na > 0) { - assert(na != 0); - this->tau.resize(na, ModuleBase::Vector3(0, 0, 0)); - this->dis.resize(na, ModuleBase::Vector3(0, 0, 0)); - this->taud.resize(na, ModuleBase::Vector3(0, 0, 0)); - this->vel.resize(na, ModuleBase::Vector3(0, 0, 0)); - this->mag.resize(na, 0); - this->angle1.resize(na, 0); - this->angle2.resize(na, 0); - this->m_loc_.resize(na, ModuleBase::Vector3(0, 0, 0)); - this->mbl.resize(na, ModuleBase::Vector3(0, 0, 0)); - this->lambda.resize(na, ModuleBase::Vector3(0, 0, 0)); - this->constrain.resize(na, ModuleBase::Vector3(0, 0, 0)); - } + if (GlobalV::MY_RANK != 0) + { + assert(na != 0); + this->tau.resize(na, ModuleBase::Vector3(0, 0, 0)); + this->dis.resize(na, ModuleBase::Vector3(0, 0, 0)); + this->taud.resize(na, ModuleBase::Vector3(0, 0, 0)); + this->vel.resize(na, ModuleBase::Vector3(0, 0, 0)); + this->mag.resize(na, 0); + this->angle1.resize(na, 0); + this->angle2.resize(na, 0); + this->m_loc_.resize(na, ModuleBase::Vector3(0, 0, 0)); + this->mbl.resize(na, ModuleBase::Vector3(0, 0, 0)); + this->lambda.resize(na, ModuleBase::Vector3(0, 0, 0)); + this->constrain.resize(na, ModuleBase::Vector3(0, 0, 0)); + } - for (int i = 0; i < na; i++) - { - Parallel_Common::bcast_double(tau[i].x); - Parallel_Common::bcast_double(tau[i].y); - Parallel_Common::bcast_double(tau[i].z); - Parallel_Common::bcast_double(taud[i].x); - Parallel_Common::bcast_double(taud[i].y); - Parallel_Common::bcast_double(taud[i].z); - Parallel_Common::bcast_double(dis[i].x); - Parallel_Common::bcast_double(dis[i].y); - Parallel_Common::bcast_double(dis[i].z); - Parallel_Common::bcast_double(vel[i].x); - Parallel_Common::bcast_double(vel[i].y); - Parallel_Common::bcast_double(vel[i].z); - Parallel_Common::bcast_double(mag[i]); - Parallel_Common::bcast_double(angle1[i]); - Parallel_Common::bcast_double(angle2[i]); - Parallel_Common::bcast_double(m_loc_[i].x); - Parallel_Common::bcast_double(m_loc_[i].y); - Parallel_Common::bcast_double(m_loc_[i].z); - Parallel_Common::bcast_int(mbl[i].x); - Parallel_Common::bcast_int(mbl[i].y); - Parallel_Common::bcast_int(mbl[i].z); - Parallel_Common::bcast_double(lambda[i].x); - Parallel_Common::bcast_double(lambda[i].y); - Parallel_Common::bcast_double(lambda[i].z); - Parallel_Common::bcast_int(constrain[i].x); - Parallel_Common::bcast_int(constrain[i].y); - Parallel_Common::bcast_int(constrain[i].z); + for (int i = 0; i < na; i++) + { + Parallel_Common::bcast_double(tau[i].x); + Parallel_Common::bcast_double(tau[i].y); + Parallel_Common::bcast_double(tau[i].z); + Parallel_Common::bcast_double(taud[i].x); + Parallel_Common::bcast_double(taud[i].y); + Parallel_Common::bcast_double(taud[i].z); + Parallel_Common::bcast_double(dis[i].x); + Parallel_Common::bcast_double(dis[i].y); + Parallel_Common::bcast_double(dis[i].z); + Parallel_Common::bcast_double(vel[i].x); + Parallel_Common::bcast_double(vel[i].y); + Parallel_Common::bcast_double(vel[i].z); + Parallel_Common::bcast_double(mag[i]); + Parallel_Common::bcast_double(angle1[i]); + Parallel_Common::bcast_double(angle2[i]); + Parallel_Common::bcast_double(m_loc_[i].x); + Parallel_Common::bcast_double(m_loc_[i].y); + Parallel_Common::bcast_double(m_loc_[i].z); + Parallel_Common::bcast_int(mbl[i].x); + Parallel_Common::bcast_int(mbl[i].y); + Parallel_Common::bcast_int(mbl[i].z); + Parallel_Common::bcast_double(lambda[i].x); + Parallel_Common::bcast_double(lambda[i].y); + Parallel_Common::bcast_double(lambda[i].z); + Parallel_Common::bcast_int(constrain[i].x); + Parallel_Common::bcast_int(constrain[i].y); + Parallel_Common::bcast_int(constrain[i].z); + } } return; diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 81608ce609..30ae5c504b 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -504,7 +504,18 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn ModuleBase::WARNING("read_atom_positions", " atom number < 0."); return false; } - if (na > 0) + else if (na == 0) + { + std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl; + std::cout << " Warning: atom number is 0 for atom type: " << atoms[it].label << std::endl; + std::cout << " If you are confident that this is not a mistake, please ignore this warning." << std::endl; + std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl; + ofs_running << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl; + ofs_running << " Warning: atom number is 0 for atom type: " << atoms[it].label << std::endl; + ofs_running << " If you are confident that this is not a mistake, please ignore this warning." << std::endl; + ofs_running << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl; + } + else if (na > 0) { atoms[it].tau.resize(na, ModuleBase::Vector3(0,0,0)); atoms[it].dis.resize(na, ModuleBase::Vector3(0,0,0)); @@ -891,6 +902,12 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn ofs_running << std::endl; ModuleBase::GlobalFunc::OUT(ofs_running,"TOTAL ATOM NUMBER",nat); + if (nat == 0) + { + ModuleBase::WARNING("read_atom_positions","no atom in the system!"); + return false; + } + // mohan add 2010-06-30 //xiaohui modify 2015-03-15, cancel outputfile "STRU_READIN.xyz" //this->print_cell_xyz("STRU_READIN.xyz"); diff --git a/source/module_hamilt_pw/hamilt_pwdft/forces.cpp b/source/module_hamilt_pw/hamilt_pwdft/forces.cpp index c1fcd2299c..dd24ce82c7 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/forces.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/forces.cpp @@ -595,21 +595,24 @@ void Forces::cal_force_ew(const UnitCell& ucell, } for (int it = 0; it < ucell.ntype; it++) { - double dzv; - if (PARAM.inp.use_paw) + if (ucell.atoms[it].na != 0) { -#ifdef USE_PAW - dzv = GlobalC::paw_cell.get_val(it); -#endif - } - else - { - dzv = ucell.atoms[it].ncpp.zv; - } + double dzv; + if (PARAM.inp.use_paw) + { + #ifdef USE_PAW + dzv = GlobalC::paw_cell.get_val(it); + #endif + } + else + { + dzv = ucell.atoms[it].ncpp.zv; + } - for (int ig = igb; ig < ig_end; ++ig) - { // accumulate aux - aux[ig] += dzv * conj(p_sf->strucFac(it, ig)); + for (int ig = igb; ig < ig_end; ++ig) + { // accumulate aux + aux[ig] += dzv * conj(p_sf->strucFac(it, ig)); + } } } } @@ -714,30 +717,33 @@ void Forces::cal_force_ew(const UnitCell& ucell, last_it = it; } - const auto ig_loop = [&](int ig_beg, int ig_end) { - for (int ig = ig_beg; ig < ig_end; ig++) - { - const ModuleBase::Vector3 gcar = rho_basis->gcar[ig]; - const double arg = ModuleBase::TWO_PI * (gcar * ucell.atoms[it].tau[ia]); - double sinp, cosp; - ModuleBase::libm::sincos(arg, &sinp, &cosp); - double sumnb = -cosp * aux[ig].imag() + sinp * aux[ig].real(); - forceion(iat, 0) += gcar[0] * sumnb; - forceion(iat, 1) += gcar[1] * sumnb; - forceion(iat, 2) += gcar[2] * sumnb; - } - }; + if (ucell.atoms[it].na != 0) + { + const auto ig_loop = [&](int ig_beg, int ig_end) { + for (int ig = ig_beg; ig < ig_end; ig++) + { + const ModuleBase::Vector3 gcar = rho_basis->gcar[ig]; + const double arg = ModuleBase::TWO_PI * (gcar * ucell.atoms[it].tau[ia]); + double sinp, cosp; + ModuleBase::libm::sincos(arg, &sinp, &cosp); + double sumnb = -cosp * aux[ig].imag() + sinp * aux[ig].real(); + forceion(iat, 0) += gcar[0] * sumnb; + forceion(iat, 1) += gcar[1] * sumnb; + forceion(iat, 2) += gcar[2] * sumnb; + } + }; - // skip ig_gge0 point by separating ig loop into two part - ig_loop(0, ig_gap); - ig_loop(ig_gap + 1, rho_basis->npw); + // skip ig_gge0 point by separating ig loop into two part + ig_loop(0, ig_gap); + ig_loop(ig_gap + 1, rho_basis->npw); - forceion(iat, 0) *= it_fact; - forceion(iat, 1) *= it_fact; - forceion(iat, 2) *= it_fact; + forceion(iat, 0) *= it_fact; + forceion(iat, 1) *= it_fact; + forceion(iat, 2) *= it_fact; - ++iat; - ucell.step_iait(&ia, &it); + ++iat; + ucell.step_iait(&ia, &it); + } } // means that the processor contains G=0 term. @@ -771,7 +777,7 @@ void Forces::cal_force_ew(const UnitCell& ucell, int T2 = 0; while (iat2 < this->nat) { - if (iat1 != iat2) + if (iat1 != iat2 && ucell.atoms[T2].na != 0 && ucell.atoms[T1].na != 0) { ModuleBase::Vector3 d_tau = ucell.atoms[T1].tau[I1] - ucell.atoms[T2].tau[I2]; diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_ewa.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_ewa.cpp index fd6bf8dc0a..5dbe2cd6b4 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_ewa.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_ewa.cpp @@ -137,25 +137,28 @@ void Stress_Func::stress_ewa(const UnitCell& ucell, while (ijat < ijat_end) { - //calculate tau[na]-tau[nb] - d_tau = ucell.atoms[it].tau[i] - ucell.atoms[jt].tau[j]; - //generates nearest-neighbors shells - H_Ewald_pw::rgen(d_tau, rmax, irr, ucell.latvec, ucell.G, r, r2, nrm); - for(int nr=0 ; nr