Ignore:
Timestamp:
May 23, 2008, 9:17:19 AM (18 years ago)
Author:
Frederik Heber <heber@…>
Children:
6145aa7
Parents:
6c96f4
Message:

Lots of for loops now count in reverse order where it does not matter, some 3 -> NDIM

for(i=0;i<var;i++) is slower than for (i=var;i--;) if the order of the i's is not important (note: i-- is also a value and it stops when on i == 0 automatically)
in builder.cpp there were some remnant 3 actually meant to be NDIM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/builder.cpp

    r6c96f4 rf75030  
    5959 * \param *mol the molecule to add to
    6060 */
    61 void AddAtoms(periodentafel *periode, molecule *mol)
     61static void AddAtoms(periodentafel *periode, molecule *mol)
    6262{
    6363  atom *first, *second, *third, *fourth;
     
    113113          cout << Verbose(0) << "Enter relative coordinates." << endl;
    114114          first->x.AskPosition(mol->cell_size, false);
    115           for (int i=0;i<3;i++) {
     115          for (int i=NDIM;i--;) {
    116116            first->x.x[i] += second->x.x[i];
    117117          }
     
    227227        atoms = new (vector*[128]);
    228228        valid = true;
    229         for(int i=0;i<128;i++)
     229        for(int i=128;i--;)
    230230          atoms[i] = NULL;
    231231        int i=0, j=0;
     
    256256 * \param *mol the molecule with all the atoms
    257257 */
    258 void CenterAtoms(molecule *mol)
     258static void CenterAtoms(molecule *mol)
    259259{
    260260  vector x, y;
     
    285285    case 'c':
    286286      cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
    287       for (int i=0;i<3;i++) {
     287      for (int i=0;i<NDIM;i++) {
    288288        cout << Verbose(0) << "Enter axis " << i << " boundary: ";
    289289        cin >> y.x[i];
     
    295295    case 'd':
    296296      cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
    297       for (int i=0;i<3;i++) {
     297      for (int i=0;i<NDIM;i++) {
    298298        cout << Verbose(0) << "Enter axis " << i << " boundary: ";
    299299        cin >> x.x[i];
     
    311311 * \param *mol the molecule with all the atoms
    312312 */
    313 void AlignAtoms(periodentafel *periode, molecule *mol)
     313static void AlignAtoms(periodentafel *periode, molecule *mol)
    314314{
    315315  atom *first, *second, *third;
     
    359359      cout << Verbose(0) << "Element is " << param.type->name << endl;
    360360      mol->GetAlignVector(&param);
    361       for (int i=0;i<3;i++) {
     361      for (int i=NDIM;i--;) {
    362362        x.x[i] = gsl_vector_get(param.x,i);
    363         n.x[i] = gsl_vector_get(param.x,i+3);
     363        n.x[i] = gsl_vector_get(param.x,i+NDIM);
    364364      }
    365365      gsl_vector_free(param.x);
     
    379379 * \param *mol the molecule with all the atoms
    380380 */
    381 void MirrorAtoms(molecule *mol)
     381static void MirrorAtoms(molecule *mol)
    382382{
    383383  atom *first, *second, *third;
     
    426426 * \param *mol the molecule with all the atoms
    427427 */
    428 void RemoveAtoms(molecule *mol)
     428static void RemoveAtoms(molecule *mol)
    429429{
    430430  atom *first, *second;
     
    484484 * \param *mol the molecule with all the atoms
    485485 */
    486 void MeasureAtoms(periodentafel *periode, molecule *mol)
     486static void MeasureAtoms(periodentafel *periode, molecule *mol)
    487487{
    488488  atom *first, *second, *third;
     
    507507    case 'a':
    508508      first = mol->AskAtom("Enter first atom: ");
    509       for (int i=0;i<256;i++)
     509      for (int i=MAX_ELEMENTS;i--;)
    510510        min[i] = 0.;
    511511       
     
    523523        //cout << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;         
    524524      }
    525       for (int i=0;i<256;i++)
     525      for (int i=MAX_ELEMENTS;i--;)
    526526        if (min[i] != 0.) cout << Verbose(0) << "Minimum Bond length between " << first->type->name << " Atom " << first->nr << " and next Ion of type " << (periode->FindElement(i))->name << ": " << min[i] << " a.u." << endl;
    527527      break;
     
    530530      first = mol->AskAtom("Enter first atom: ");
    531531      second = mol->AskAtom("Enter second atom: ");
    532       for (int i=0;i<NDIM;i++)
     532      for (int i=NDIM;i--;)
    533533        min[i] = 0.;
    534534      x.CopyVector((const vector *)&first->x);
     
    560560 * \param *configuration configuration structure for the to be written config files of all fragments
    561561 */
    562 void FragmentAtoms(molecule *mol, config *configuration)
     562static void FragmentAtoms(molecule *mol, config *configuration)
    563563{
    564564  int Order1;
     
    581581/** Is called always as option 'T' in the menu.
    582582 */
    583 void testroutine(molecule *mol)
     583static void testroutine(molecule *mol)
    584584{
    585585  // the current test routine checks the functionality of the KeySet&Graph concept:
     
    654654 * \param *mol pointer to molecule structure with all the atoms and coordinates
    655655 */
    656 void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol)
     656static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol)
    657657{
    658658  char filename[MAXSTRINGSIZE];
     
    709709 * \return exit code (0 - successful, all else - something's wrong)
    710710 */
    711 int ParseCommandLineOptions(int argc, char **argv, molecule *&mol, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&ElementsFileName)
     711static int ParseCommandLineOptions(int argc, char **argv, molecule *&mol, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&ElementsFileName)
    712712{
    713713  element *finder;
     
    846846              ExitFlag = 1;
    847847              cout << Verbose(1) << "Translating all ions to new origin." << endl;
    848               for (int i=0;i<3;i++)
     848              for (int i=NDIM;i--;)
    849849                x.x[i] = atof(argv[argptr+i]);
    850850              mol->Translate((const vector *)&x);
     
    855855              cout << Verbose(1) << "Adding new atom." << endl;
    856856              first = new atom;
    857               for (int i=0;i<3;i++)
     857              for (int i=NDIM;i--;)
    858858                first->x.x[i] = atof(argv[argptr+1+i]);
    859859              finder = periode->start;
     
    872872              j = -1;
    873873              cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
    874               factor = (double *) Malloc(sizeof(double)*NDIM, "main: *factor");
     874              factor = new double[NDIM];
    875875              factor[0] = atof(argv[argptr]);
    876876              if (argc > argptr+1)
     
    881881              factor[2] = atof(argv[argptr]);
    882882              mol->Scale(&factor);
    883               for (int i=0;i<3;i++) {
     883              for (int i=0;i<NDIM;i++) {
    884884                j += i+1;
    885                 x.x[i] = atof(argv[3+i]);
     885                x.x[i] = atof(argv[NDIM+i]);
    886886                mol->cell_size[j]*=factor[i];
    887887              }
    888               Free((void **)&factor, "main: *factor");
     888              delete[](factor);
    889889              argptr+=1;
    890890              break;
     
    894894              cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
    895895              j=-1;
    896               for (int i=0;i<3;i++) {
     896              for (int i=0;i<NDIM;i++) {
    897897                j += i+1;
    898898                x.x[i] = atof(argv[argptr++]);
     
    914914              // translate each coordinate by boundary
    915915              j=-1;
    916               for (int i=0;i<3;i++) {
     916              for (int i=0;i<NDIM;i++) {
    917917                j += i+1;
    918918                x.x[i] = atof(argv[argptr++]);
     
    10561056        second = mol->AskAtom("Enter second (shifting) atom: ");
    10571057        min_bond = 0.;
    1058         for (int i=0;i<3;i++)
     1058        for (int i=NDIM;i--;)
    10591059          min_bond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
    10601060        min_bond = sqrt(min_bond);
     
    10621062        cout << Verbose(0) << "Enter new bond length [a.u.]: ";
    10631063        cin >> bond;
    1064         for (int i=0;i<3;i++) {
     1064        for (int i=NDIM;i--;) {
    10651065          second->x.x[i] -= (second->x.x[i]-first->x.x[i])/min_bond*(min_bond-bond);
    10661066        }
     
    11071107          for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    11081108            x.AddVector(&y); // per factor one cell width further
    1109             for (int k=0;k<count;k++) { // go through every atom of the original cell
     1109            for (int k=count;k--;) { // go through every atom of the original cell
    11101110              first = new atom(); // create a new body
    11111111              first->x.CopyVector(Vectors[k]);  // use coordinate of original atom
Note: See TracChangeset for help on using the changeset viewer.