Conjugate-Gradient energy minimization.
#include <iostream>
#include <fstream>
#ifndef LONGFLOAT
const flt force_max = 1e-14;
#else
const flt force_max = 1e-18;
#endif
int main(){
cout <<
"Float size: " <<
sizeof(
flt) <<
" epsilon: " << std::numeric_limits<flt>::epsilon() <<
"\n";
assert(std::numeric_limits<flt>::epsilon() < force_max*10);
const flt Vs = (Ns * pow(sigma,
NDIM) + Nl * pow(sigmal,
NDIM)) * M_PI_2 /
NDIM;
cout << "Using L = " << L << "\n";
boost::shared_ptr<OriginBox> obox(
new OriginBox(L));
boost::shared_ptr<AtomVec> atomptr(
new AtomVec(Nl + Ns, 1.0));
boost::shared_ptr<NListed<EpsSigExpAtom, RepulsionPair> >
boost::shared_ptr<NeighborList> nl = hertzian->neighbor_list();
atoms[i].x = obox->rand_loc();
atoms[i].v = Vec::Zero();
atoms[i].f = Vec::Zero();
atoms[i].a = Vec::Zero();
flt sig = i < Ns ? sigma : sigmal;
}
nl->update_list(true);
cout << "Starting. Neighborlist contains " << nl->numpairs() << " / " <<
(atoms.
size()*(atoms.
size()-1))/2 <<
" pairs\n";
writefile(atoms, *obox);
<< " U: " << hertzian->energy(*obox) << " phi: " << (Vs/obox->V()) << "\n";
for(
flt curP=startP; curP>P0; curP/=10){
cout << "P: " << curP << "\n";
while (true) {
for(
uint j=0; j<1000; j++){
}
i++;
writefile(atoms, *obox);
flt fmag = atoms[k].f.norm();
if(fmag > force_err) force_err = fmag;
}
cout.precision(
sizeof(
flt));
<< " U: " << hertzian->energy(*obox) << " phi: " << (Vs/obox->V()) << "\n";
cout.precision(6);
cout << " Pdiff: " << pdiff << " force_err: " << force_err << "\n";
if(abs(pdiff) < P_frac and force_err < force_max){
cout << "Done!\n";
break;
}
}
}
};
ofstream outf;
outf.open("packing.xyz", ios::out);
outf.precision(24);
outf << atoms.
size() << endl;
outf <<
"L=" << obox.
L() << endl;
if(i < Ns){
outf << "C";
} else {
outf << "O";
}
Vec normloc = obox.
diff(Vec::Zero(), atoms[i].x);
outf << "\t" << normloc[j];
}
outf << endl;
};
ofstream pbcfile;
pbcfile.open("packing.tcl", ios::out);
pbcfile << "set cell [pbc set {";
}
pbcfile << "} -all];\n";
pbcfile << "pbc box -toggle -center origin -color red;\n";
pbcfile << "set natoms [atomselect 0 \"name C\";];\n"
<< "$natoms set radius " << (sigma/2.0) << ";\n"
<< "set natoms [atomselect 0 \"name O\";];\n"
<< "$natoms set radius " << (sigmal/2.0) << ";\n";
};