--- trunk/OOPSE-1.0/utils/sysbuilder/simpleBuilder.cpp 2004/07/28 04:59:35 1424 +++ trunk/OOPSE-1.0/utils/sysbuilder/simpleBuilder.cpp 2004/07/28 20:29:49 1429 @@ -7,16 +7,19 @@ #include #include -#include "simError.h" #include "Globals.hpp" #include "SimInfo.hpp" #include "SimSetup.hpp" -#include "simpleBuilderCmd.hpp" +#include "simpleBuilderCmd.h" #include "StringUtils.hpp" #include "LatticeFactory.hpp" +#include "Vector3d.hpp" +#include "MoLocator.hpp" +#include "Lattice.hpp" using namespace std; +void createMdFile(const string& oldMdFileName, const string& newMdFileName, int numMol); int main( int argc, char* argv[]){ @@ -33,14 +36,14 @@ int main( int argc, char* argv[]){ BaseLattice* simpleLat; int numMol; double latticeConstant; + vector lc; double mass; double density; int nx, ny, nz; double Hmat[3][3]; MoLocator *locator; - double* posX; - double* posY; - double* posZ; + vector latticePos; + vector latticeOrt; int numMolPerCell; int curMolIndex; DumpWriter* writer; @@ -58,32 +61,31 @@ int main( int argc, char* argv[]){ latticeType = UpperCase(args_info.latticetype_arg); if(!LatticeFactory::getInstance()->hasLatticeCreator(latticeType)){ cerr << latticeType << " is an invalid lattice type" << endl; - cerr << LatticeFactory::getInstance()->oString << endl; + cerr << LatticeFactory::getInstance()->toString() << endl; exit(1); } - nx = args_info.nx_args; + nx = args_info.nx_arg; if(nx <= 0){ cerr << "The number of unit cell in h direction must be greater than 0" << endl; exit(1); } - nx = args_info.nx_args; - if(nx <= 0){ + ny = args_info.ny_arg; + if(ny <= 0){ cerr << "The number of unit cell in l direction must be greater than 0" << endl; exit(1); } - nx = args_info.nx_args; - if(nx <= 0){ + nz = args_info.nz_arg; + if(nz <= 0){ cerr << "The number of unit cell in k direction must be greater than 0" << endl; exit(1); } //get input file name - if (args_info.inputs_num) { + if (args_info.inputs_num) inputFileName = args_info.inputs[0]; - cerr << in_name << "\n"; } else { cerr <<"You must specify a input file name.\n" << endl; cmdline_parser_print_help(); @@ -108,7 +110,7 @@ int main( int argc, char* argv[]){ exit(1); } - oldSimSetup = new SimSetup(oldInfo); + oldSimSetup = new SimSetup(); if(oldSimSetup == NULL){ cerr << "error in creating SimSetup" << endl; exit(1); @@ -116,28 +118,28 @@ int main( int argc, char* argv[]){ oldSimSetup->setSimInfo(oldInfo ); oldSimSetup->parseFile(&inputFileName[0] ); - oldSimSetup->createSim(); - if(oldInfo->nComponets >=2){ + if(oldInfo->nComponents >=2){ cerr << "can not build the system with more than two components" << endl; exit(1); } //creat lattice - simpleLat = LatticeFactory::getInstance() ->createLattice(latticeType); + simpleLat = LatticeFactory::getInstance()->createLattice(latticeType); if(simpleLat == NULL){ cerr << "Error in creating lattice" << endl; exit(1); } - numMolPerCell = simpleLat->getNpoints(); + numMolPerCell = simpleLat->getNumSitesPerCell(); //calculate lattice constant latticeConstant = pow(numMolPerCell * mass /density, 1.0/3.0); //set lattice constant - simpleLat->setLatticeConstant(latticeConstant); + lc.push_back(latticeConstant); + simpleLat->setLatticeConstant(lc); //calculate the total numMol = args_info.nx_arg * args_info.ny_arg * args_info.nz_arg * numMolPerCell; @@ -165,7 +167,7 @@ int main( int argc, char* argv[]){ exit(1); } - newSimSetup = new SimSetup(newInfo); + newSimSetup = new SimSetup(); if(newSimSetup == NULL){ cerr << "error in creating SimSetup" << endl; exit(1); @@ -175,48 +177,34 @@ int main( int argc, char* argv[]){ newSimSetup->parseFile(&outMdFileName[0] ); newSimSetup->createSim(); - //set Hamt + //set Hmat newInfo->setBoxM(Hmat); //allocat memory for storing pos, vel and etc - newInfo.getConfiguration()->createArrays(newInfo.n_atoms); - for (int i = 0; i < newInfo.n_atoms; i++) - newInfo.atoms[i]->setCoords(); + newInfo->getConfiguration()->createArrays(newInfo->n_atoms); + for (int i = 0; i < newInfo->n_atoms; i++) + newInfo->atoms[i]->setCoords(); //creat Molocator - locator = new MoLocator(newInfo->compStamps[0]); - - //allocate memory for posX, posY, posZ - - posX = new doule[numMolPerCell]; - if(posX == NULL){ - cerr << "memory allocation error" << endl; - exit(1); - } + locator = new MoLocator(newInfo->compStamps[0], newSimSetup->getForceField()); - posY = new doule[numMolPerCell]; - if(posX == NULL){ - cerr << "memory allocation error" << endl; - exit(1); - } - - posZ = new doule[numMolPerCell]; - if(posX == NULL){ - cerr << "memory allocation error" << endl; - exit(1); - } - //place the molecules curMolIndex = 0; + + //get the orientation of the cell sites + //for the same type of molecule in same lattice, it will not change + latticeOrt = simpleLat->getLatticePointsOrt(); + for(int i =0; i < nx; i++){ for(int j=0; j < ny; j++){ for(int k = 0; k < nz; k++){ - - simpleLat->getLatticePoints(&posX, &posY, &posZ, i, j, k); + //get the position of the cell sites + simpleLat->getLatticePointsPos(latticePos, i, j, k); + for(int l = 0; l < numMolPerCell; l++) - locator->placeMol(posX[l], posY[l], posZ[l], newInfo->molecules[curMolIndex++]); + locator->placeMol(latticePos[l], latticeOrt[l], &(newInfo->molecules[curMolIndex++])); } } } @@ -227,7 +215,7 @@ int main( int argc, char* argv[]){ cerr << "error in creating DumpWriter" << endl; exit(1); } - writer->writeFinal(); + writer->writeFinal(0); //delete objects @@ -243,15 +231,6 @@ int main( int argc, char* argv[]){ if(!newSimSetup) delete newSimSetup; - if (posX) - delete[] posX; - - if (posY) - delete[] posY; - - if (posZ) - delete[] posZ; - if (writer != NULL) delete writer; return 0; @@ -262,17 +241,20 @@ void createMdFile(const string& oldMdFileName, const s ofstream newMdFile; const int MAXLEN = 65535; char buffer[MAXLEN]; + string line; - //create new .md file based on old .md file - oldMdFile.open(oldMdFileName.c_str()) - newMdFile.open(newMdFileName); + oldMdFile.open(oldMdFileName.c_str()); + newMdFile.open(newMdFileName.c_str()); oldMdFile.getline(buffer, MAXLEN); while(!oldMdFile.eof()){ - if(line.find("nMol") < line.size()) - sprintf(buffer, "nMol = %s;", numMol); + if(line.find("nMol") < line.size()){ + + sprintf(buffer, "\t\tnMol = %d;", numMol); + newMdFile << buffer << endl; + } else newMdFile << buffer << endl;