diff --git a/src/create_atoms.cpp b/src/create_atoms.cpp index 9c536dcbc6610478c57bf05a5e4e913130b73db3..c3d55d76a41c8b0e53dc0e45598f2a611eab65c4 100644 --- a/src/create_atoms.cpp +++ b/src/create_atoms.cpp @@ -725,6 +725,24 @@ void CreateAtoms::add_lattice() domain->lattice->bbox(1,bboxhi[0],bboxhi[1],bboxhi[2], xmin,ymin,zmin,xmax,ymax,zmax); + // narrow down min/max further by extent of the region, if possible + + if (domain->regions[nregion]->bboxflag) { + const double rxmin = domain->regions[nregion]->extent_xlo; + const double rxmax = domain->regions[nregion]->extent_xhi; + const double rymin = domain->regions[nregion]->extent_ylo; + const double rymax = domain->regions[nregion]->extent_yhi; + const double rzmin = domain->regions[nregion]->extent_zlo; + const double rzmax = domain->regions[nregion]->extent_zhi; + + if (rxmin > xmin) xmin = (rxmin > xmax) ? xmax : rxmin; + if (rxmax < xmax) xmax = (rxmax < xmin) ? xmin : rxmax; + if (rymin > ymin) ymin = (rymin > ymax) ? ymax : rymin; + if (rymax < ymax) ymax = (rymax < ymin) ? ymin : rymax; + if (rzmin > zmin) zmin = (rzmin > zmax) ? zmax : rzmin; + if (rzmax < zmax) zmax = (rzmax < zmin) ? zmin : rzmax; + } + // ilo:ihi,jlo:jhi,klo:khi = loop bounds for lattice overlap of my subbox // overlap = any part of a unit cell (face,edge,pt) in common with my subbox // in lattice space, subbox is a tilted box @@ -751,15 +769,32 @@ void CreateAtoms::add_lattice() // convert lattice coords to box coords // add atom or molecule (on each basis point) if it meets all criteria - double **basis = domain->lattice->basis; - double x[3],lamda[3]; - double *coord; + const double * const * const basis = domain->lattice->basis; + + // rough estimate of total time used for create atoms. + // one inner loop takes about 25ns on a typical desktop CPU core in 2019 + double testimate = 2.5e-8/3600.0; // convert seconds to hours + testimate *= static_cast<double>(khi-klo+1); + testimate *= static_cast<double>(jhi-jlo+1); + testimate *= static_cast<double>(ihi-ilo+1); + testimate *= static_cast<double>(nbasis); + double maxestimate = 0.0; + MPI_Reduce(&testimate,&maxestimate,1,MPI_DOUBLE,MPI_MAX,0,world); + + if ((comm->me == 0) && (maxestimate > 0.01)) { + if (screen) fprintf(screen,"WARNING: create_atoms will take " + "approx. %.2f hours to complete\n",maxestimate); + if (logfile) fprintf(logfile,"WARNING: create_atoms will take " + "approx. %.2f hours to complete\n",maxestimate); + } int i,j,k,m; - for (k = klo; k <= khi; k++) - for (j = jlo; j <= jhi; j++) - for (i = ilo; i <= ihi; i++) + for (k = klo; k <= khi; k++) { + for (j = jlo; j <= jhi; j++) { + for (i = ilo; i <= ihi; i++) { for (m = 0; m < nbasis; m++) { + double *coord; + double x[3],lamda[3]; x[0] = i + basis[m][0]; x[1] = j + basis[m][1]; @@ -794,8 +829,12 @@ void CreateAtoms::add_lattice() if (mode == ATOM) atom->avec->create_atom(basistype[m],x); else add_molecule(x); } + } + } + } } + /* ---------------------------------------------------------------------- add a randomly rotated molecule with its center at center if quat_user set, perform requested rotation