Changeset 961b75


Ignore:
Timestamp:
Apr 21, 2008, 2:19:24 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
b74e5e
Parents:
e00f47
git-author:
Frederik Heber <heber@…> (04/18/08 15:15:13)
git-committer:
Frederik Heber <heber@…> (04/21/08 14:19:24)
Message:

ParseForParameter() has new parameter repetition, which reads the repetition-th occurence of the given keyword

Location:
pcp/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • pcp/src/init.c

    re00f47 r961b75  
    12991299 * \param type Type of the Parameter to be read
    13001300 * \param value address of the value to be read (must have been allocated)
     1301 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
    13011302 * \param critical necessity of this keyword being specified (optional, critical)
    13021303 * \return 1 - found, 0 - not found
    13031304 * \sa ReadMainParameterFile Calling routine
    13041305 */
    1305 int ParseForParameter(int verbose, FILE *file, const char *const name, int sequential, int const xth, int const yth, enum value_type type, void *value, enum necessity critical) {
     1306int ParseForParameter(int verbose, FILE *file, const char *const name, int sequential, int const xth, int const yth, enum value_type type, void *value, int repetition, enum necessity critical) {
    13061307        int i,j;        // loop variables
    13071308        int me, length, maxlength = -1;
    13081309        long file_position = ftell(file);       // mark current position
    1309         char *dummy1, *dummy, *free_dummy;              // pointers in the line that is read in per step
     1310        char *dummy2, *dummy1, *dummy, *free_dummy;             // pointers in the line that is read in per step
     1311
     1312  if (repetition == 0)
     1313    Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
     1314
     1315  // allocated memory and rank in multi-process word
    13101316        dummy1 = free_dummy = (char *) Malloc(256 * sizeof(char),"ParseForParameter: MemAlloc for dummy1 failed");
    13111317        MPI_Comm_rank(MPI_COMM_WORLD, &me);
    13121318
    13131319        //fprintf(stderr,"(%i) Parsing for %s\n",me,name);     
    1314 
    13151320        int line = 0;   // marks line where parameter was found
    13161321        int found = (type >= grid) ? 0 : (-yth + 1);    // marks if yth parameter name was found
    1317         while((found != 1)) {
     1322        while((found != repetition)) {
    13181323                dummy1 = dummy = free_dummy;
    13191324                do {
     
    13481353                if (name != NULL) {
    13491354                        dummy = strchr(dummy1,'\t');    // set dummy on first tab or space which ever nearer
    1350       if (dummy == NULL) {
    1351         dummy = strchr(dummy1, ' ');  // if not found seek for space
    1352         while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' ')))    // skip some more tabs and spaces if necessary
    1353           dummy++;
     1355      dummy2 = strchr(dummy1, ' ');  // if not found seek for space
     1356      if ((dummy != NULL) || (dummy2 != NULL)) {
     1357        if ((dummy == NULL) || ((dummy2 != NULL) && (dummy2 < dummy)))
     1358          dummy = dummy2;
    13541359      }
    13551360                        if (dummy == NULL) {
     
    13591364                    //Error(FileOpenParams, NULL);                     
    13601365                        } else {
    1361                                 //fprintf(stderr,"(%i) found tab at %i\n",me,(char *)dummy-(char *)dummy1);
     1366                                //fprintf(stderr,"(%i) found tab at %li\n",me,(long)((char *)dummy-(char *)dummy1));
    13621367                        }
    13631368                } else dummy = dummy1;
    13641369                // ... and check if it is the keyword!
    1365                 if ((name == NULL) || ((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0))) {
     1370                if ((name == NULL) || ((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0) && (dummy-dummy1 == strlen(name)))) {
    13661371                        found++; // found the parameter!
    13671372                        //fprintf(stderr,"(%i) found %s at line %i\n",me, name, line);         
    13681373                       
    1369                         if (found == 1) {
     1374                        if (found == repetition) {
    13701375                                for (i=0;i<xth;i++) {   // i = rows
    13711376                                        if (type >= grid) {
     
    14131418                                                        // otherwise we must skip all interjacent tabs and spaces and find next value
    14141419                                                        dummy1 = dummy;
    1415                                                         dummy = strchr(dummy1, '\t');   // seek for tab or space
    1416               if (dummy == NULL) {
    1417                 dummy = strchr(dummy1, ' ');  // if not found seek for space
    1418                 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' ')))    // skip some more tabs and spaces if necessary
    1419                   dummy++;
     1420                                                        dummy = strchr(dummy1, '\t');   // seek for tab or space (space if appears sooner)
     1421              dummy2 = strchr(dummy1, ' ');
     1422              //fprintf(stderr,"dummy (%p) is %c\t dummy2 (%p) is %c\n", dummy, (dummy == NULL ? '-' : *dummy), dummy2, (dummy2 == NULL ? '-' : *dummy2));
     1423              if ((dummy != NULL) || (dummy2 != NULL)) {
     1424                if ((dummy == NULL) || ((dummy2 != NULL) && (dummy2 < dummy)))
     1425                  dummy = dummy2;
     1426                //while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' ')))    // skip some more tabs and spaces if necessary
     1427                //  dummy++;
    14201428              }
    14211429/*                                                      while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' ')))                // skip some more tabs and spaces if necessary
    14221430                                                                dummy++;*/
    1423                                                         if (dummy == NULL) { // if still zero returned ...
     1431              //fprintf(stderr,"dummy is %c\n", *dummy);
     1432              dummy2 = strchr(dummy1, '#');
     1433              if ((dummy == NULL) || ((dummy2 != NULL) && (dummy1 >= dummy2))) { // if still zero returned or in comment area ...
    14241434                                                                dummy = strchr(dummy1, '\n');    // ... at line end then
    1425                                                                 if ((j < yth-1) && (type < 4)) {        // check if xth value or not yet
    1426                                                                         if (verbose) fprintf(stderr,"(%i)Error: EoL at %i and still missing %i value(s) for parameter %s\n", me, line, yth-j, name);
    1427                   Free(free_dummy, "ParseForParameter: free_dummy");
    1428                                                                         return 0;
     1435                                                                if ((i < xth-1) && (type < 4)) {        // check if xth value or not yet
     1436                  if (critical) {
     1437                    if (verbose) fprintf(stderr,"(%i)Error: EoL or comment at %i and still missing %i value(s) for parameter %s\n", me, line, yth-j, name);
     1438                    Free(free_dummy, "ParseForParameter: free_dummy");
     1439                    Error(InitReading, name);
     1440                  } else {
     1441                    //if (!sequential)
     1442                    fseek(file, file_position, SEEK_SET);  // rewind to start position
     1443                    Free(free_dummy, "ParseForParameter: free_dummy");
     1444                    return 0;
     1445                  }
    14291446                                                            //Error(FileOpenParams, NULL);                     
    14301447                                                                }
     
    14821499        }       
    14831500  if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
     1501        if (!sequential) fseek(file, file_position, SEEK_SET);  // rewind to start position
    14841502  Free(free_dummy, "ParseForParameter: free_dummy");
    1485         if (!sequential) fseek(file, file_position, SEEK_SET);  // rewind to start position
    14861503        //fprintf(stderr, "(%i) End of Parsing\n\n",me);
    14871504       
     
    15031520  FILE *file;
    15041521  int i, di, me;
    1505   double BField[NDIM_NDIM];
     1522  //double BField[NDIM];
    15061523 
    15071524  MPI_Comm_rank(MPI_COMM_WORLD, &me);
     
    15161533
    15171534  P->Files.filename = MallocString(MAXDUMMYSTRING,"ReadParameters: filename");
    1518         ParseForParameter(P->Call.out[ReadOut],file, "mainname", 0, 1, 1, string_type, P->Files.filename, critical);
     1535        ParseForParameter(P->Call.out[ReadOut],file, "mainname", 0, 1, 1, string_type, P->Files.filename, 1, critical);
    15191536  //debug(P,"mainname");
    15201537  CreateMainname(P, filename);
    15211538  P->Files.default_path = MallocString(MAXDUMMYSTRING,"ReadParameters: default_path");
    1522   ParseForParameter(P->Call.out[ReadOut],file, "defaultpath", 0, 1, 1, string_type, P->Files.default_path, critical);
     1539  ParseForParameter(P->Call.out[ReadOut],file, "defaultpath", 0, 1, 1, string_type, P->Files.default_path, 1, critical);
    15231540  P->Files.pseudopot_path = MallocString(MAXDUMMYSTRING,"ReadParameters: pseudopot_path");
    1524   ParseForParameter(P->Call.out[ReadOut],file, "pseudopotpath", 0, 1, 1, string_type, P->Files.pseudopot_path, critical);
    1525   ParseForParameter(P->Call.out[ReadOut],file,"ProcPEGamma", 0, 1, 1, int_type, &(P->Par.proc[PEGamma]), critical);
    1526   ParseForParameter(P->Call.out[ReadOut],file,"ProcPEPsi", 0, 1, 1, int_type, &(P->Par.proc[PEPsi]), critical);
     1541  ParseForParameter(P->Call.out[ReadOut],file, "pseudopotpath", 0, 1, 1, string_type, P->Files.pseudopot_path, 1, critical);
     1542  ParseForParameter(P->Call.out[ReadOut],file,"ProcPEGamma", 0, 1, 1, int_type, &(P->Par.proc[PEGamma]), 1, critical);
     1543  ParseForParameter(P->Call.out[ReadOut],file,"ProcPEPsi", 0, 1, 1, int_type, &(P->Par.proc[PEPsi]), 1, critical);
    15271544  if (P->Call.proc[PEPsi]) { /* Kommandozeilenoption */
    15281545    P->Par.proc[PEPsi]  = P->Call.proc[PEPsi];
     
    15321549    Run
    15331550  */
    1534   if (!ParseForParameter(P->Call.out[ReadOut],file,"Seed", 0, 1, 1, int_type, &(R->Seed), optional))
     1551  if (!ParseForParameter(P->Call.out[ReadOut],file,"Seed", 0, 1, 1, int_type, &(R->Seed), 1, optional))
    15351552    R->Seed = 1;
    1536   if (!ParseForParameter(P->Call.out[ReadOut],file,"WaveNr", 0, 1, 1, int_type, &(R->WaveNr), optional))
     1553  if (!ParseForParameter(P->Call.out[ReadOut],file,"WaveNr", 0, 1, 1, int_type, &(R->WaveNr), 1, optional))
    15371554    R->WaveNr = 0;
    1538   if (!ParseForParameter(P->Call.out[ReadOut],file,"Lambda", 0, 1, 1, double_type, &R->Lambda, optional))
     1555  if (!ParseForParameter(P->Call.out[ReadOut],file,"Lambda", 0, 1, 1, double_type, &R->Lambda, 1, optional))
    15391556    R->Lambda = 1.;
    15401557
    1541   if(!ParseForParameter(P->Call.out[ReadOut],file,"DoOutOrbitals", 0, 1, 1, int_type, &F->DoOutOrbitals, optional)) {
     1558  if(!ParseForParameter(P->Call.out[ReadOut],file,"DoOutOrbitals", 0, 1, 1, int_type, &F->DoOutOrbitals, 1, optional)) {
    15421559    F->DoOutOrbitals = 0;
    15431560  } else {
     
    15451562    if (F->DoOutOrbitals > 1) F->DoOutOrbitals = 1;
    15461563  }
    1547   ParseForParameter(P->Call.out[ReadOut],file,"DoOutVis", 0, 1, 1, int_type, &F->DoOutVis, critical);
     1564  ParseForParameter(P->Call.out[ReadOut],file,"DoOutVis", 0, 1, 1, int_type, &F->DoOutVis, 1, critical);
    15481565  if (F->DoOutVis < 0) F->DoOutVis = 0;
    1549   if (F->DoOutVis > 1) F->DoOutVis = 1;
    1550   if (!ParseForParameter(P->Call.out[ReadOut],file,"VectorPlane", 0, 1, 1, int_type, &R->VectorPlane, optional))
     1566  if (F->DoOutVis > 2) F->DoOutVis = 1;
     1567  if (!ParseForParameter(P->Call.out[ReadOut],file,"VectorPlane", 0, 1, 1, int_type, &R->VectorPlane, 1, optional))
    15511568    R->VectorPlane = -1;
    15521569  if (R->VectorPlane < -1 || R->VectorPlane > 2) {
     
    15541571    R->VectorPlane = -1;
    15551572  }
    1556   if (!ParseForParameter(P->Call.out[ReadOut],file,"VectorCut", 0, 1, 1, double_type, &R->VectorCut, optional))
     1573  if (!ParseForParameter(P->Call.out[ReadOut],file,"VectorCut", 0, 1, 1, double_type, &R->VectorCut, 1, optional))
    15571574    R->VectorCut = 0.;
    1558   ParseForParameter(P->Call.out[ReadOut],file,"DoOutMes", 0, 1, 1, int_type, &F->DoOutMes, critical);
     1575  ParseForParameter(P->Call.out[ReadOut],file,"DoOutMes", 0, 1, 1, int_type, &F->DoOutMes, 1, critical);
    15591576  if (F->DoOutMes < 0) F->DoOutMes = 0;
    15601577  if (F->DoOutMes > 1) F->DoOutMes = 1;
    1561   if (!ParseForParameter(P->Call.out[ReadOut],file,"DoOutCurr", 0, 1, 1, int_type, &F->DoOutCurr, optional))
     1578  if (!ParseForParameter(P->Call.out[ReadOut],file,"DoOutCurr", 0, 1, 1, int_type, &F->DoOutCurr, 1, optional))
    15621579    F->DoOutCurr = 0;
     1580  if (!ParseForParameter(P->Call.out[ReadOut],file,"DoOutNICS", 0, 1, 1, int_type, &F->DoOutNICS, 1, optional))
     1581    F->DoOutNICS = 0;
    15631582  if (F->DoOutCurr < 0) F->DoOutCurr = 0;
    15641583  if (F->DoOutCurr > 1) F->DoOutCurr = 1;
    1565   ParseForParameter(P->Call.out[ReadOut],file,"AddGramSch", 0, 1, 1, int_type, &R->UseAddGramSch, critical);
     1584  ParseForParameter(P->Call.out[ReadOut],file,"AddGramSch", 0, 1, 1, int_type, &R->UseAddGramSch, 1, critical);
    15661585  if (R->UseAddGramSch < 0) R->UseAddGramSch = 0;
    15671586  if (R->UseAddGramSch > 2) R->UseAddGramSch = 2;
    15681587  if(P->Call.out[ReadOut]) fprintf(stderr,"(%i)UseAddGramSch = %i\n",me,R->UseAddGramSch);
    1569   if(!ParseForParameter(P->Call.out[ReadOut],file,"CommonWannier", 0, 1, 1, int_type, &R->CommonWannier, optional)) {
     1588  if(!ParseForParameter(P->Call.out[ReadOut],file,"CommonWannier", 0, 1, 1, int_type, &R->CommonWannier, 1, optional)) {
    15701589    R->CommonWannier = 0;
    15711590  } else {
     
    15731592    if (R->CommonWannier > 4) R->CommonWannier = 4;
    15741593  }
    1575   if(!ParseForParameter(P->Call.out[ReadOut],file,"SawtoothStart", 0, 1, 1, double_type, &P->Lat.SawtoothStart, optional)) {
     1594  if(!ParseForParameter(P->Call.out[ReadOut],file,"SawtoothStart", 0, 1, 1, double_type, &P->Lat.SawtoothStart, 1, optional)) {
    15761595    P->Lat.SawtoothStart = 0.01;
    15771596  } else {
     
    15791598    if (P->Lat.SawtoothStart > 1.) P->Lat.SawtoothStart = 1.;
    15801599  }
    1581   if (!ParseForParameter(P->Call.out[ReadOut],file,"DoBrent", 0, 1, 1, int_type, &R->DoBrent, optional)) {
     1600  if (!ParseForParameter(P->Call.out[ReadOut],file,"DoBrent", 0, 1, 1, int_type, &R->DoBrent, 1, optional)) {
    15821601    R->DoBrent = 0;
    15831602  } else {
     
    15871606   
    15881607 
    1589         ParseForParameter(P->Call.out[ReadOut],file,"MaxOuterStep", 0, 1, 1, int_type, &R->MaxOuterStep, critical);
     1608  if (!ParseForParameter(P->Call.out[ReadOut],file,"MaxOuterStep", 0, 1, 1, int_type, &R->MaxOuterStep, 1, optional))
     1609    R->MaxOuterStep = 0;
     1610  if (!ParseForParameter(P->Call.out[ReadOut],file,"MaxStructOptStep", 0, 1, 1, int_type, &R->MaxStructOptStep, 1, optional)) {
     1611    if (R->MaxOuterStep != 0) { // if StructOptStep not explicitely specified, then use OuterStep
     1612      R->MaxStructOptStep = R->MaxOuterStep;
     1613    } else {
     1614      R->MaxStructOptStep = 100;
     1615    }
     1616  }
    15901617  // the following values are MD specific and should be dropped in further revisions
    1591         if (!ParseForParameter(P->Call.out[ReadOut],file,"Deltat", 0, 1, 1, double_type, &R->delta_t, optional))
    1592     R->delta_t = 0;
    1593         if (!ParseForParameter(P->Call.out[ReadOut],file,"OutVisStep", 0, 1, 1, int_type, &R->OutVisStep, optional))
     1618        if (!ParseForParameter(P->Call.out[ReadOut],file,"Deltat", 0, 1, 1, double_type, &R->delta_t, 1, optional))
     1619    R->delta_t = 1.;
     1620        if (!ParseForParameter(P->Call.out[ReadOut],file,"OutVisStep", 0, 1, 1, int_type, &R->OutVisStep, 1, optional))
    15941621    R->OutVisStep = 10;
    1595         if (!ParseForParameter(P->Call.out[ReadOut],file,"OutSrcStep", 0, 1, 1, int_type, &R->OutSrcStep, optional))
     1622        if (!ParseForParameter(P->Call.out[ReadOut],file,"OutSrcStep", 0, 1, 1, int_type, &R->OutSrcStep, 1, optional))
    15961623    R->OutSrcStep = 5;
    1597         if (!ParseForParameter(P->Call.out[ReadOut],file,"TargetTemp", 0, 1, 1, double_type, &R->TargetTemp, optional))
     1624        if (!ParseForParameter(P->Call.out[ReadOut],file,"TargetTemp", 0, 1, 1, double_type, &R->TargetTemp, 1, optional))
    15981625    R->TargetTemp = 0;
    1599         if (!ParseForParameter(P->Call.out[ReadOut],file,"ScaleTempStep", 0, 1, 1, int_type, &R->ScaleTempStep, optional))
    1600     R->ScaleTempStep = 25;
    16011626   
    1602   if (!ParseForParameter(P->Call.out[ReadOut],file,"EpsWannier", 0, 1, 1, double_type, &R->EpsWannier, optional))
     1627  if (!ParseForParameter(P->Call.out[ReadOut],file,"EpsWannier", 0, 1, 1, double_type, &R->EpsWannier, 1, optional))
    16031628    R->EpsWannier = 1e-8;
    16041629 
     
    16071632  //if (R->MaxOuterStep <= 0) R->MaxOuterStep = 1;
    16081633  if(P->Call.out[NormalOut]) fprintf(stderr,"(%i)MaxOuterStep = %i\n",me,R->MaxOuterStep);
    1609   if(P->Call.out[NormalOut]) fprintf(stderr,"(%i)t = %g\n",me,R->t);
    1610   ParseForParameter(P->Call.out[ReadOut],file,"MaxPsiStep", 0, 1, 1, int_type, &R->MaxPsiStep, critical);
     1634  if(P->Call.out[NormalOut]) fprintf(stderr,"(%i)Deltat = %g\n",me,R->delta_t);
     1635  ParseForParameter(P->Call.out[ReadOut],file,"MaxPsiStep", 0, 1, 1, int_type, &R->MaxPsiStep, 1, critical);
    16111636  if (R->MaxPsiStep <= 0) R->MaxPsiStep = 3;
    16121637  if(P->Call.out[NormalOut]) fprintf(stderr,"(%i)MaxPsiStep = %i\n",me,R->MaxPsiStep);
    16131638 
    1614   ParseForParameter(P->Call.out[ReadOut],file,"MaxMinStep", 0, 1, 1, int_type, &R->MaxMinStep, critical);
    1615         ParseForParameter(P->Call.out[ReadOut],file,"RelEpsTotalE", 0, 1, 1, double_type, &R->RelEpsTotalEnergy, critical);
    1616         ParseForParameter(P->Call.out[ReadOut],file,"RelEpsKineticE", 0, 1, 1, double_type, &R->RelEpsKineticEnergy, critical);
    1617   ParseForParameter(P->Call.out[ReadOut],file,"MaxMinStopStep", 0, 1, 1, int_type, &R->MaxMinStopStep, critical);
    1618   ParseForParameter(P->Call.out[ReadOut],file,"MaxMinGapStopStep", 0, 1, 1, int_type, &R->MaxMinGapStopStep, critical);
     1639  ParseForParameter(P->Call.out[ReadOut],file,"MaxMinStep", 0, 1, 1, int_type, &R->MaxMinStep, 1, critical);
     1640        ParseForParameter(P->Call.out[ReadOut],file,"RelEpsTotalE", 0, 1, 1, double_type, &R->RelEpsTotalEnergy, 1, critical);
     1641        ParseForParameter(P->Call.out[ReadOut],file,"RelEpsKineticE", 0, 1, 1, double_type, &R->RelEpsKineticEnergy, 1, critical);
     1642  ParseForParameter(P->Call.out[ReadOut],file,"MaxMinStopStep", 0, 1, 1, int_type, &R->MaxMinStopStep, 1, critical);
     1643  ParseForParameter(P->Call.out[ReadOut],file,"MaxMinGapStopStep", 0, 1, 1, int_type, &R->MaxMinGapStopStep, 1, critical);
    16191644  if (R->MaxMinStep <= 0) R->MaxMinStep = R->MaxPsiStep;
    16201645  if (R->MaxMinStopStep < 1) R->MaxMinStopStep = 1;
     
    16221647  if(P->Call.out[NormalOut]) fprintf(stderr,"(%i)MaxMinStep = %i\tRelEpsTotalEnergy: %e\tRelEpsKineticEnergy %e\tMaxMinStopStep %i\n",me,R->MaxMinStep,R->RelEpsTotalEnergy,R->RelEpsKineticEnergy,R->MaxMinStopStep);
    16231648 
    1624   ParseForParameter(P->Call.out[ReadOut],file,"MaxInitMinStep", 0, 1, 1, int_type, &R->MaxInitMinStep, critical);
    1625         ParseForParameter(P->Call.out[ReadOut],file,"InitRelEpsTotalE", 0, 1, 1, double_type, &R->InitRelEpsTotalEnergy, critical);
    1626         ParseForParameter(P->Call.out[ReadOut],file,"InitRelEpsKineticE", 0, 1, 1, double_type, &R->InitRelEpsKineticEnergy, critical);
    1627   ParseForParameter(P->Call.out[ReadOut],file,"InitMaxMinStopStep", 0, 1, 1, int_type, &R->InitMaxMinStopStep, critical);
    1628   ParseForParameter(P->Call.out[ReadOut],file,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &R->InitMaxMinGapStopStep, critical);
     1649  ParseForParameter(P->Call.out[ReadOut],file,"MaxInitMinStep", 0, 1, 1, int_type, &R->MaxInitMinStep, 1, critical);
     1650        ParseForParameter(P->Call.out[ReadOut],file,"InitRelEpsTotalE", 0, 1, 1, double_type, &R->InitRelEpsTotalEnergy, 1, critical);
     1651        ParseForParameter(P->Call.out[ReadOut],file,"InitRelEpsKineticE", 0, 1, 1, double_type, &R->InitRelEpsKineticEnergy, 1, critical);
     1652  ParseForParameter(P->Call.out[ReadOut],file,"InitMaxMinStopStep", 0, 1, 1, int_type, &R->InitMaxMinStopStep, 1, critical);
     1653  ParseForParameter(P->Call.out[ReadOut],file,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &R->InitMaxMinGapStopStep, 1, critical);
    16291654  if (R->MaxInitMinStep <= 0) R->MaxInitMinStep = R->MaxPsiStep;
    16301655  if (R->InitMaxMinStopStep < 1) R->InitMaxMinStopStep = 1;
     
    16331658 
    16341659  // Unit cell and magnetic field
    1635   ParseForParameter(P->Call.out[ReadOut],file, "BoxLength", 0, 3, 3, lower_trigrid, &P->Lat.RealBasis, critical); /* Lattice->RealBasis */
    1636   ParseForParameter(P->Call.out[ReadOut],file, "DoPerturbation", 0, 1, 1, int_type, &R->DoPerturbation, optional);
     1660  ParseForParameter(P->Call.out[ReadOut],file, "BoxLength", 0, 3, 3, lower_trigrid, &P->Lat.RealBasis, 1, critical); /* Lattice->RealBasis */
     1661  ParseForParameter(P->Call.out[ReadOut],file, "DoPerturbation", 0, 1, 1, int_type, &R->DoPerturbation, 1, optional);
    16371662  if (!R->DoPerturbation) {
    1638     if (!ParseForParameter(P->Call.out[ReadOut],file, "BField", 0, 1, 3, grid, &BField, optional)) { // old parameter for perturbation with field direction
     1663    if (!ParseForParameter(P->Call.out[ReadOut],file, "BField", 0, 1, 3, grid, &R->BField, 1, optional)) { // old parameter for perturbation with field direction
    16391664      if (P->Call.out[ReadOut]) fprintf(stderr,"(%i) No perturbation specified.\n", P->Par.me);
    1640       if (F->DoOutCurr) {
    1641         if (P->Call.out[ReadOut]) fprintf(stderr,"(%i) DoOutCurr= 1 though no DoPerturbation specified: setting DoOutCurr = 0\n", P->Par.me);
     1665      if (F->DoOutCurr || F->DoOutNICS) {
     1666        if (P->Call.out[ReadOut]) fprintf(stderr,"(%i) DoOutCurr/DoOutNICS = 1 though no DoPerturbation specified: setting DoOutCurr = 0\n", P->Par.me);
    16421667        F->DoOutCurr = 0;
     1668        F->DoOutNICS = 0;
    16431669        R->DoPerturbation = 0;
    16441670      }
     
    16531679  RMatReci3(P->Lat.InvBasis,  P->Lat.RealBasis);
    16541680
    1655   if (!ParseForParameter(P->Call.out[ReadOut],file,"DoFullCurrent", 0, 1, 1, int_type, &R->DoFullCurrent, optional))
     1681  if (!ParseForParameter(P->Call.out[ReadOut],file,"DoFullCurrent", 0, 1, 1, int_type, &R->DoFullCurrent, 1, optional))
    16561682    R->DoFullCurrent = 0;
    16571683  if (R->DoFullCurrent < 0) R->DoFullCurrent = 0;
     
    16621688  }
    16631689
    1664         ParseForParameter(P->Call.out[ReadOut],file,"ECut", 0, 1, 1, double_type, &P->Lat.ECut, critical);
     1690        ParseForParameter(P->Call.out[ReadOut],file,"ECut", 0, 1, 1, double_type, &P->Lat.ECut, 1, critical);
    16651691  if(P->Call.out[NormalOut]) fprintf(stderr,"(%i) ECut = %e -> %e Rydberg\n", me, P->Lat.ECut, 2.*P->Lat.ECut);
    1666   ParseForParameter(P->Call.out[ReadOut],file,"MaxLevel", 0, 1, 1, int_type, &P->Lat.MaxLevel, critical);
    1667   ParseForParameter(P->Call.out[ReadOut],file,"Level0Factor", 0, 1, 1, int_type, &P->Lat.Lev0Factor, critical);
     1692  ParseForParameter(P->Call.out[ReadOut],file,"MaxLevel", 0, 1, 1, int_type, &P->Lat.MaxLevel, 1, critical);
     1693  ParseForParameter(P->Call.out[ReadOut],file,"Level0Factor", 0, 1, 1, int_type, &P->Lat.Lev0Factor, 1, critical);
    16681694  if (P->Lat.Lev0Factor < 2) {
    16691695    if(P->Call.out[ReadOut]) fprintf(stderr,"(%i) Set Lev0Factor to 2!\n",me);
    16701696    P->Lat.Lev0Factor = 2;
    16711697  }
    1672   ParseForParameter(P->Call.out[ReadOut],file,"RiemannTensor", 0, 1, 1, int_type, &di, critical);
     1698  ParseForParameter(P->Call.out[ReadOut],file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
    16731699  if (di >= 0 && di < 2) {
    16741700    P->Lat.RT.Use = (enum UseRiemannTensor)di;
     
    16911717              P->Lat.MaxLevel = 3;
    16921718            }
    1693             ParseForParameter(P->Call.out[ReadOut],file,"RiemannLevel", 0, 1, 1, int_type, &P->Lat.RT.RiemannLevel, critical);
     1719            ParseForParameter(P->Call.out[ReadOut],file,"RiemannLevel", 0, 1, 1, int_type, &P->Lat.RT.RiemannLevel, 1, critical);
    16941720                  if(P->Call.out[ReadOut]) fprintf(stderr,"(%i)!RiemannLevel = %i\n",me,P->Lat.RT.RiemannLevel);
    16951721            if (P->Lat.RT.RiemannLevel < 2) {
     
    17011727              P->Lat.RT.RiemannLevel = P->Lat.MaxLevel-1;
    17021728            }
    1703             ParseForParameter(P->Call.out[ReadOut],file,"LevRFactor", 0, 1, 1, int_type, &P->Lat.LevRFactor, critical);
     1729            ParseForParameter(P->Call.out[ReadOut],file,"LevRFactor", 0, 1, 1, int_type, &P->Lat.LevRFactor, 1, critical);
    17041730            if(P->Call.out[ReadOut]) fprintf(stderr,"(%i)!LevRFactor = %i\n",me,P->Lat.LevRFactor);
    17051731            if (P->Lat.LevRFactor < 2) {
     
    17111737            break;
    17121738  }
    1713   ParseForParameter(P->Call.out[ReadOut],file,"PsiType", 0, 1, 1, int_type, &di, critical);
     1739  ParseForParameter(P->Call.out[ReadOut],file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
    17141740  if (di >= 0 && di < 2) {
    17151741    P->Lat.Psi.Use = (enum UseSpinType)di;
     
    17221748  switch (P->Lat.Psi.Use) {
    17231749  case UseSpinDouble:
    1724         ParseForParameter(P->Call.out[ReadOut],file,"MaxPsiDouble", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxNoDouble], critical);
    1725     if (!ParseForParameter(P->Call.out[ReadOut],file,"AddPsis", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxAdd], optional))
     1750        ParseForParameter(P->Call.out[ReadOut],file,"MaxPsiDouble", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxNoDouble], 1, critical);
     1751    if (!ParseForParameter(P->Call.out[ReadOut],file,"AddPsis", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxAdd], 1, optional))
    17261752      P->Lat.Psi.GlobalNo[PsiMaxAdd] = 0;
    17271753    if (P->Lat.Psi.GlobalNo[PsiMaxAdd] != 0)
     
    17351761  case UseSpinUpDown:
    17361762    if (P->Par.proc[PEPsi] % 2) Error(SomeError,"UseSpinUpDown & P->Par.proc[PEGamma] % 2");
    1737     ParseForParameter(P->Call.out[ReadOut],file,"PsiMaxNoUp", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxNoUp], critical);
    1738     ParseForParameter(P->Call.out[ReadOut],file,"PsiMaxNoDown", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxNoDown], critical);
    1739     if (!ParseForParameter(P->Call.out[ReadOut],file,"AddPsis", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxAdd], optional))
     1763    ParseForParameter(P->Call.out[ReadOut],file,"PsiMaxNoUp", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxNoUp], 1, critical);
     1764    ParseForParameter(P->Call.out[ReadOut],file,"PsiMaxNoDown", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxNoDown], 1, critical);
     1765    if (!ParseForParameter(P->Call.out[ReadOut],file,"AddPsis", 0, 1, 1, int_type, &P->Lat.Psi.GlobalNo[PsiMaxAdd], 1, optional))
    17401766      P->Lat.Psi.GlobalNo[PsiMaxAdd] = 0;
    17411767    if (P->Lat.Psi.GlobalNo[PsiMaxAdd] != 0)
  • pcp/src/init.h

    re00f47 r961b75  
    2929
    3030/* Einlesen der Parameterdatei */
    31 int ParseForParameter(int verbose, FILE *file, const char *const name, int sequential, int const xth, int const yth, enum value_type type, void *value, enum necessity critical);
     31int ParseForParameter(int verbose, FILE *file, const char *const name, int sequential, int const xth, int const yth, enum value_type type, void *value, int repetition, enum necessity critical);
    3232void ReadParameters(struct Problem *const  P, const char *const filename);
    3333
  • pcp/src/ions.c

    re00f47 r961b75  
    2929#include <string.h>
    3030#include <unistd.h>
     31#include <gsl/gsl_randist.h>
    3132#include "mymath.h"
    3233
     
    5051#include "init.h"
    5152
     53/** Parses for a given keyword the ion coordinates and velocites.
     54 * \param *P Problem at hand, contains pointer to Ion and IonType structure
     55 * \param *source
     56 * \param *keyword keyword string
     57 * \param repetition which repeated version of the keyword shall be read by ReadParameters()
     58 * \param relative whether atom coordinates are relative to unit cell size or absolute
     59 * \param Bohr conversion factor to atomiclength (e.g. 1.0 if coordinates in bohr radius, 0.529... if given in Angstrom)
     60 * \param sigma variance of maxwell-boltzmann distribution
     61 * \param *R where to put the read coordinates
     62 * \param *U where to put the read velocities
     63 * \param *IMT whether its MoveType#FixedIon or not
     64 * \return if 1 - success, 0 - failure
     65 */
     66int ParseIonsCoordinatesAndVelocities(struct Problem *P, FILE *source, char *keyword, int repetition, int relative, double sigma, double *R, double *U, int *IMT)
     67{
     68  //struct RunStruct *Run = &P->R;
     69  struct Ions *I = &P->Ion;
     70  struct Lattice *L = &P->Lat;
     71  int k;
     72  double R_trafo[3];
     73  gsl_rng * r;
     74  const gsl_rng_type * T;
     75  double Bohr = (I->IsAngstroem) ? ANGSTROEMINBOHRRADIUS : 1.;
     76 
     77  gsl_rng_env_setup();
     78  T = gsl_rng_default;
     79  r = gsl_rng_alloc (T);
     80  if (ParseForParameter(P->Call.out[ReadOut],source, keyword, 0, 1, 1, double_type, &R_trafo[0], repetition, optional) &&
     81    ParseForParameter(P->Call.out[ReadOut],source, keyword, 0, 2, 1, double_type, &R_trafo[1], repetition, optional) &&
     82    ParseForParameter(P->Call.out[ReadOut],source, keyword, 0, 3, 1, double_type, &R_trafo[2], repetition, optional) &&
     83    ParseForParameter(P->Call.out[ReadOut],source, keyword, 0, 4, 1, int_type, IMT, repetition, optional)) {
     84    // if read successful, then try also parsing velocities
     85    if ((ParseForParameter(P->Call.out[ReadOut],source, keyword, 0, 5, 1, double_type, &U[0], repetition, optional)) &&
     86      (ParseForParameter(P->Call.out[ReadOut],source, keyword, 0, 6, 1, double_type, &U[1], repetition, optional)) &&
     87      (ParseForParameter(P->Call.out[ReadOut],source, keyword, 0, 7, 1, double_type, &U[2], repetition, optional))) {
     88      //nothing
     89    } else {  // if no velocities specified, set to maxwell-boltzmann distributed
     90      if ((I->Thermostat != None)) {
     91        if (P->Par.me == 0) fprintf(stderr, "(%i) Missing velocities of ion %s: Maxwell-Boltzmann with %lg\n", P->Par.me, keyword, sigma);
     92        for (k=0;k<NDIM;k++)
     93          U[k] = gsl_ran_gaussian (r, sigma);
     94      } else {
     95        for (k=0;k<NDIM;k++)
     96          U[k] = 0.;
     97      }
     98    }
     99    // change if coordinates were relative
     100    if (relative) {
     101      //fprintf(stderr,"(%i)Ion coordinates are relative %i ... \n",P->Par.me, relative);
     102      RMat33Vec3(R, L->RealBasis, R_trafo); // multiply with real basis
     103    } else {
     104      for (k=0;k<NDIM;k++) // otherweise just copy to vector
     105        R[k] = R_trafo[k];
     106    }
     107    // check if given MoveType is valid
     108    if (*IMT < 0 || *IMT >= MaxIonMoveType) {
     109      fprintf(stderr,"Bad Ion MoveType set to MoveIon for %s\n", keyword);
     110      *IMT = 0;
     111    }
     112    if (!relative) {
     113      //fprintf(stderr,"converting with %lg\n", Bohr);
     114      SM(R, Bohr, NDIM); // convert angstroem to bohrradius
     115      SM(U, Bohr, NDIM); // convert angstroem to bohrradius
     116    }
     117    // finally periodicly correct coordinates to remain in unit cell
     118    RMat33Vec3(R_trafo, L->InvBasis, R);
     119    for (k=0; k <NDIM; k++) { // periodic correction until within unit cell
     120      while (R_trafo[k] < 0)
     121        R_trafo[k] += 1.0;
     122      while (R_trafo[k] >= 1.0)
     123        R_trafo[k] -= 1.0;
     124    }
     125    RMat33Vec3(R, L->RealBasis, R_trafo);
     126    // print coordinates if desired
     127    if ((P->Call.out[ReadOut])) {
     128      fprintf(stderr,"(%i) coordinates of Ion %s: (x,y,z) = (",P->Par.me, keyword);
     129      for(k=0;k<NDIM;k++) {
     130        fprintf(stderr,"%lg ",R[k]);
     131        if (k != NDIM-1) fprintf(stderr,", ");
     132        else fprintf(stderr,")\n");
     133      }
     134    }
     135    gsl_rng_free (r);
     136    return 1;
     137  } else {
     138    for (k=0;k<NDIM;k++) {
     139      U[k] = R[k] = 0.;
     140    }
     141    *IMT = 0;
     142    gsl_rng_free (r);
     143    return 0;
     144  }
     145}
     146
    52147/** Readin of the ion section of parameter file.
    53148 * Among others the following paramaters are read from file:
     
    60155        struct Ions *I = &P->Ion;
    61156  //struct RunStruct *Run = &P->R;
    62   int i,it,j,IMT,BorAng, d,me, count;
    63   struct Lattice *L = &P->Lat;
    64   int k;
     157  int i,it,j,IMT,d,me, count;
    65158  int relative; // whether read-in coordinate are relative (1) or absolute 
    66159  double Bohr = ANGSTROEMINBOHRRADIUS; /* Angstroem */
    67160  double sigma, R[3], U[3];
    68 
     161  struct IonConstrained *ptr = NULL;
     162     
    69163  I->Max_TotalIons = 0;
    70164  I->TotalZval = 0;
    71165  MPI_Comm_rank(MPI_COMM_WORLD, &me);
    72   ParseForParameter(P->Call.out[ReadOut],source,"RCut", 0, 1, 1, double_type, &I->R_cut, critical);
    73   ParseForParameter(P->Call.out[ReadOut],source,"IsAngstroem", 0, 1, 1, int_type, &BorAng, critical);
     166  ParseForParameter(P->Call.out[ReadOut],source,"RCut", 0, 1, 1, double_type, &I->R_cut, 1, critical);
     167  ParseForParameter(P->Call.out[ReadOut],source,"IsAngstroem", 0, 1, 1, int_type, &I->IsAngstroem, 1, critical);
    74168  if (!I->IsAngstroem) {
    75         Bohr = 1.0;
    76         } else {  // adapt RealBasis (is in Angstroem as well)
     169    Bohr = 1.0;
     170  } else {  // adapt RealBasis (is in Angstroem as well)
    77171    SM(P->Lat.RealBasis, Bohr, NDIM_NDIM);
    78172    RMatReci3(P->Lat.InvBasis,  P->Lat.RealBasis);
    79173  }
    80   ParseForParameter(P->Call.out[ReadOut],source,"MaxTypes", 0, 1, 1, int_type, &I->Max_Types, critical);
     174  ParseForParameter(P->Call.out[ReadOut],source,"MaxTypes", 0, 1, 1, int_type, &I->Max_Types, 1, critical);
    81175  I->I = (struct IonType *) Malloc(sizeof(struct IonType)*I->Max_Types, "IonsInitRead: IonType");
    82   if (!ParseForParameter(P->Call.out[ReadOut],source,"RelativeCoord", 0, 1, 1, int_type, &relative, optional))
     176  if (!ParseForParameter(P->Call.out[ReadOut],source,"RelativeCoord", 0, 1, 1, int_type, &relative, 1, optional))
    83177    relative = 0;
    84   if (!ParseForParameter(P->Call.out[ReadOut],source,"StructOpt", 0, 1, 1, int_type, &I->StructOpt, optional))
     178  if (!ParseForParameter(P->Call.out[ReadOut],source,"StructOpt", 0, 1, 1, int_type, &I->StructOpt, 1, optional))
    85179    I->StructOpt = 0;
    86 
     180 
     181  //InitThermostats(P, source);
     182 
    87183  /* Ions Data */
    88184  I->RLatticeVec = NULL;
     
    95191    I->I[i].Name = MallocString(255, "IonsInitRead: Name");
    96192    I->I[i].Symbol = MallocString(255, "IonsInitRead: Symbol");
    97                 ParseForParameter(P->Call.out[ReadOut],source, name, 0, 1, 1, int_type, &I->I[i].Max_IonsOfType, critical);
    98                 ParseForParameter(P->Call.out[ReadOut],source, name, 0, 2, 1, int_type, &I->I[i].Z, critical);
    99                 ParseForParameter(P->Call.out[ReadOut],source, name, 0, 3, 1, double_type, &I->I[i].rgauss, critical);
    100                 ParseForParameter(P->Call.out[ReadOut],source, name, 0, 4, 1, int_type, &I->I[i].l_max, critical);
    101                 ParseForParameter(P->Call.out[ReadOut],source, name, 0, 5, 1, int_type, &I->I[i].l_loc, critical);
    102                 ParseForParameter(P->Call.out[ReadOut],source, name, 0, 6, 1, double_type, &I->I[i].IonMass, critical);
    103     if(!ParseForParameter(P->Call.out[ReadOut],source, name, 0, 7, 1, string_type, &I->I[i].Name[0], optional))
     193                ParseForParameter(P->Call.out[ReadOut],source, name, 0, 1, 1, int_type, &I->I[i].Max_IonsOfType, 1, critical);
     194                ParseForParameter(P->Call.out[ReadOut],source, name, 0, 2, 1, int_type, &I->I[i].Z, 1, critical);
     195                ParseForParameter(P->Call.out[ReadOut],source, name, 0, 3, 1, double_type, &I->I[i].rgauss, 1, critical);
     196                ParseForParameter(P->Call.out[ReadOut],source, name, 0, 4, 1, int_type, &I->I[i].l_max, 1, critical);
     197                ParseForParameter(P->Call.out[ReadOut],source, name, 0, 5, 1, int_type, &I->I[i].l_loc, 1, critical);
     198                ParseForParameter(P->Call.out[ReadOut],source, name, 0, 6, 1, double_type, &I->I[i].IonMass, 1, critical);
     199    if(!ParseForParameter(P->Call.out[ReadOut],source, name, 0, 7, 1, string_type, &I->I[i].Name[0], 1, optional))
    104200      sprintf(&I->I[i].Name[0],"type%i",i);
    105     if(!ParseForParameter(P->Call.out[ReadOut],source, name, 0, 8, 1, string_type, &I->I[i].Symbol[0], optional))
     201    if(!ParseForParameter(P->Call.out[ReadOut],source, name, 0, 8, 1, string_type, &I->I[i].Symbol[0], 1, optional))
    106202      sprintf(&I->I[i].Symbol[0],"t%i",i);
    107203    if (P->Call.out[ReadOut]) fprintf(stderr,"(%i) Element name: %s, symbol: %s\n",P->Par.me, I->I[i].Name, I->I[i].Symbol);
     204    I->I[i].moment = (double **) Malloc(sizeof(double *) * I->I[i].Max_IonsOfType, "IonsInitRead: moment");
    108205    I->I[i].sigma = (double **) Malloc(sizeof(double *) * I->I[i].Max_IonsOfType, "IonsInitRead: sigma");
    109206    I->I[i].sigma_rezi = (double **) Malloc(sizeof(double *) * I->I[i].Max_IonsOfType, "IonsInitRead: sigma_rezi");
     
    111208    I->I[i].sigma_rezi_PAS = (double **) Malloc(sizeof(double *) * I->I[i].Max_IonsOfType, "IonsInitRead: sigma_rezi_PAS");
    112209    for (it=0;it<I->I[i].Max_IonsOfType;it++) {
     210      I->I[i].moment[it] = (double *) Malloc(sizeof(double) * NDIM*NDIM, "IonsInitRead: moment");
    113211      I->I[i].sigma[it] = (double *) Malloc(sizeof(double) * NDIM*NDIM, "IonsInitRead: sigma");
    114212      I->I[i].sigma_rezi[it] = (double *) Malloc(sizeof(double) * NDIM*NDIM, "IonsInitRead: sigma_rezi");
     
    117215    }
    118216    //I->I[i].IonFac = I->I[i].IonMass;
    119     I->I[i].IonFac = 1/I->I[i].IonMass;
     217    I->I[i].IonMass *= Units2Electronmass;  // in config given in amu not in "atomic units" (electron mass, m_e = 1)
     218                                            // proportional factor between electron and proton mass
     219    I->I[i].IonFac = Units2Electronmass/I->I[i].IonMass;
    120220    I->TotalMass += I->I[i].Max_IonsOfType*I->I[i].IonMass;
     221    sigma = sqrt(P->R.TargetTemp/I->I[i].IonMass);
    121222    I->I[i].ZFactor = -I->I[i].Z*4.*PI;
    122223    I->I[i].alpha = (double *) Malloc(sizeof(double) * I->I[i].Max_IonsOfType, "IonsInitRead: alpha");
     
    124225    I->I[i].R_old = (double *) Malloc(sizeof(double) *NDIM* I->I[i].Max_IonsOfType, "IonsInitRead: R_old");
    125226    I->I[i].R_old_old = (double *) Malloc(sizeof(double) *NDIM* I->I[i].Max_IonsOfType, "IonsInitRead: R_old_old");
     227    I->I[i].Constraints = (struct IonConstrained **) Malloc(sizeof(struct IonConstrained *)*I->I[i].Max_IonsOfType, "IonsInitRead: **Constraints");
     228    for (it=0;it<I->I[i].Max_IonsOfType;it++)
     229      I->I[i].Constraints[it] = NULL;
    126230    I->I[i].FIon = (double *) Malloc(sizeof(double) * NDIM * I->I[i].Max_IonsOfType, "IonsInitRead: FIon");
    127231    I->I[i].FIon_old = (double *) Malloc(sizeof(double) * NDIM * I->I[i].Max_IonsOfType, "IonsInitRead: FIon_old");
     
    136240    I->I[i].FIonL = (double *) Malloc(sizeof(double) * NDIM * I->I[i].Max_IonsOfType, "IonsInitRead: FIonL");
    137241    I->I[i].FIonNL = (double *) Malloc(sizeof(double) * NDIM * I->I[i].Max_IonsOfType, "IonsInitRead: FIonNL");
     242    I->I[i].FMagnetic = (double *) Malloc(sizeof(double) * NDIM * I->I[i].Max_IonsOfType, "IonsInitRead: FMagnetic");
     243    I->I[i].FConstraint = (double *) Malloc(sizeof(double) * NDIM * I->I[i].Max_IonsOfType, "IonsInitRead: FConstraint");
    138244    I->I[i].FEwald = (double *) Malloc(sizeof(double) * NDIM * I->I[i].Max_IonsOfType, "IonsInitRead: FEwald");
    139245    I->I[i].alpha = (double *) Malloc(sizeof(double) * I->I[i].Max_IonsOfType, "IonsInitRead: alpha");
     246    // now parse ion coordination
    140247    for (j=0; j < I->I[i].Max_IonsOfType; j++) {
    141248      I->I[i].alpha[j] = 2.;
    142249        sprintf(name,"Ion_Type%i_%i",i+1,j+1);
    143                         ParseForParameter(P->Call.out[ReadOut],source, name, 0, 1, 1, double_type, &R[0], critical);
    144                         ParseForParameter(P->Call.out[ReadOut],source, name, 0, 2, 1, double_type, &R[1], critical);
    145                         ParseForParameter(P->Call.out[ReadOut],source, name, 0, 3, 1, double_type, &R[2], critical);
    146                         ParseForParameter(P->Call.out[ReadOut],source, name, 0, 4, 1, int_type, &IMT, critical);
    147       // change if coordinates were relative
    148       if (relative) {
    149         //fprintf(stderr,"(%i)Ion coordinates are relative %i ... \n",P->Par.me, relative);
    150         RMat33Vec3(&I->I[i].R[0+NDIM*j], L->RealBasis, R); // multiply with real basis
     250      for (d=0; d <NDIM; d++) // transfor to old and old_old coordinates as well
     251        I->I[i].FMagnetic[d+j*NDIM] = 0.;
     252      // first ones are starting positions
     253      if ((count = ParseIonsCoordinatesAndVelocities(P, source, name, 1, relative, sigma, &I->I[i].R[NDIM*j], &I->I[i].U[NDIM*j], &IMT))) {
     254        for (d=0; d <NDIM; d++) // transfor to old and old_old coordinates as well
     255          I->I[i].R_old_old[d+NDIM*j] = I->I[i].R_old[d+NDIM*j] = I->I[i].R[d+NDIM*j];
     256        I->I[i].IMT[j] = IMT;
     257        if (P->Call.out[ReadOut]) fprintf(stderr, "(%i) R[%d,%d] = (%lg, %lg, %lg)\n", P->Par.me, i,j,I->I[i].R[0+NDIM*j],I->I[i].R[1+NDIM*j],I->I[i].R[2+NDIM*j]);
     258        if (P->Call.out[ReadOut]) fprintf(stderr, "(%i) U[%d,%d] = (%lg, %lg, %lg)\n", P->Par.me, i,j,I->I[i].U[0+NDIM*j],I->I[i].U[1+NDIM*j],I->I[i].U[2+NDIM*j]);
     259        if (P->Call.out[ReadOut]) fprintf(stderr, "(%i) IMT[%d,%d] = %i\n", P->Par.me, i,j,I->I[i].IMT[j]);
    151260      } else {
    152         for (k=0;k<NDIM;k++) // and copy to old vector
    153           I->I[i].R[k+NDIM*j] = R[k];
    154       }
    155       if (IMT < 0 || IMT >= MaxIonMoveType) {
    156                                 fprintf(stderr,"Bad Ion MoveType set to MoveIon for Ion (%i,%i)\n",i,j);
    157                                 IMT = 0;
    158       }
    159        
    160       if ((P->Call.out[ReadOut])) {  // rotate coordinates
    161         fprintf(stderr,"(%i) coordinates of Ion %i: (x,y,z) = (",P->Par.me,j);
    162         for(k=0;k<NDIM;k++) {
    163           fprintf(stderr,"%lg ",I->I[i].R[k+NDIM*j]);
    164           if (k != NDIM-1) fprintf(stderr,", ");
    165           else fprintf(stderr,")\n");
     261        Error(SomeError, "Could not find or parse coordinates of an ion");
     262      }
     263      // following ones are constrained motions
     264      while (ParseIonsCoordinatesAndVelocities(P, source, name, ++count, relative, sigma, R, U, &IMT)) {
     265        if (P->Call.out[ReadOut]) fprintf(stderr, "(%i) Constrained read %d ...\n", P->Par.me, count-1);
     266        ptr = AddConstraintItem(&I->I[i], j);  // allocate memory
     267        for (d=0; d< NDIM; d++) { // fill the constraint item
     268          ptr->R[d] = R[d];
     269          ptr->U[d] = U[d];
    166270        }
    167       }
    168 
    169       I->I[i].IMT[j] = (enum IonMoveType)IMT;
    170       SM(&I->I[i].R[NDIM*j], 1./Bohr, NDIM);
    171       RMat33Vec3(R, L->InvBasis, &I->I[i].R[NDIM*j]);
    172       for (d=0; d <NDIM; d++) {
    173                                 while (R[d] < 0)
    174                                   R[d] += 1.0;
    175                                 while (R[d] >= 1.0)
    176                                   R[d] -= 1.0;
    177       }
    178       RMat33Vec3(&I->I[i].R[NDIM*j], L->RealBasis, R);
    179       for (d=0; d <NDIM; d++) {
    180                                 I->I[i].R_old_old[d+NDIM*j] = I->I[i].R_old[d+NDIM*j] = I->I[i].R[d+NDIM*j];
    181       }
     271        ptr->IMT = IMT;
     272        ptr->step = count-1;
     273        if (P->Call.out[ReadOut]) fprintf(stderr, "(%i) R[%d,%d] = (%lg, %lg, %lg)\n", P->Par.me, i,j,ptr->R[0],ptr->R[1],ptr->R[2]);
     274        if (P->Call.out[ReadOut]) fprintf(stderr, "(%i) U[%d,%d] = (%lg, %lg, %lg)\n", P->Par.me, i,j,ptr->U[0],ptr->U[1],ptr->U[2]);
     275        if (P->Call.out[ReadOut]) fprintf(stderr, "(%i) IMT[%d,%d] = %i\n", P->Par.me, i,j,ptr->IMT);
     276      }
     277      //if (P->Call.out[ReadOut])
     278      fprintf(stderr,"(%i) A total of %d additional constrained moves for ion (%d,%d) was parsed.\n", P->Par.me, count-2, i,j);
     279
    182280      I->Max_TotalIons++;
    183281    }
  • pcp/src/ions.h

    re00f47 r961b75  
    121121/* Functions */
    122122void IonsInitRead(struct Problem *P, FILE *source);
    123 void InitThermostats(struct Problem *P, FILE *source);
    124123void CalculateEwald(struct Problem *P, int first);
    125124void RemoveIonsRead(struct Ions *I);
     
    138137void ResetForces(struct Problem *P);
    139138void CorrectVelocity(struct Problem *P);
     139struct IonConstrained * AddConstraintItem(struct IonType *I, int ion);
     140int RemoveConstraintItem(struct IonType *I, int ion);
    140141#endif
  • pcp/src/output.c

    re00f47 r961b75  
    606606    }
    607607    // ... and parse critical ...
    608     readnr += ParseForParameter(0,SrcPsiDoc,"Mintype",0,1,1,int_type,(int *)&read_type, test ? optional : critical);
    609     readnr += ParseForParameter(0,SrcPsiDoc,"LevelNo",0,1,1,int_type,&LevelNo, test ? optional : critical);
    610     readnr += 3*ParseForParameter(0,SrcPsiDoc,"GridNodes",0,3,1,row_int,&N[0], test ? optional : critical);
    611     readnr += 2*ParseForParameter(0,SrcPsiDoc,"PsiNo",0,2,1,row_int,&GlobalNo[0], test ? optional : critical);
     608    readnr += ParseForParameter(0,SrcPsiDoc,"Mintype",0,1,1,int_type,(int *)&read_type, 1, test ? optional : critical);
     609    readnr += ParseForParameter(0,SrcPsiDoc,"LevelNo",0,1,1,int_type,&LevelNo,1, test ? optional : critical);
     610    readnr += 3*ParseForParameter(0,SrcPsiDoc,"GridNodes",0,3,1,row_int,&N[0], 1, test ? optional : critical);
     611    readnr += 2*ParseForParameter(0,SrcPsiDoc,"PsiNo",0,2,1,row_int,&GlobalNo[0], 1, test ? optional : critical);
    612612    // and optional items ...
    613     if (ParseForParameter(0,SrcPsiDoc,"Epsilon",0,2,1,row_double,&Eps[0],optional))
     613    if (ParseForParameter(0,SrcPsiDoc,"Epsilon",0,2,1,row_double,&Eps[0],1,optional))
    614614      if ((P->Call.ReadSrcFiles == 1) && ((Eps[1] < R->RelEpsKineticEnergy) || (Eps[0] < R->RelEpsTotalEnergy))) {
    615615        //fprintf(stderr,"(%i) Eps %lg %lg\tRelEps %lg %lg\n", P->Par.me, Eps[0], Eps[1], R->RelEpsTotalEnergy, R->RelEpsKineticEnergy);
  • pcp/src/perturbed.c

    re00f47 r961b75  
    23142314  int wished = -1;
    23152315  FILE *file =  fopen(P->Call.MainParameterFile,"r");
    2316   if (!ParseForParameter(1,file,"Orbital",0,1,1,int_type,&wished, optional)) {
     2316  if (!ParseForParameter(1,file,"Orbital",0,1,1,int_type,&wished, 1, optional)) {
    23172317    fprintf(stderr,"Desired Orbital missing!\n");
    23182318    wished = -1;
  • pcp/src/pseudo.c

    re00f47 r961b75  
    506506        if (P->Call.out[ReadOut]) fprintf(stderr,"%s was found\n",cpiInputFileName);
    507507    int zeile = 1;
    508     ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &PP->zval[it], critical);
    509     ParseForParameter(0,cpiInputFile, NULL, 1, 2, zeile, int_type, &PP->nang[it], critical);
     508    ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &PP->zval[it], 1, critical);
     509    ParseForParameter(0,cpiInputFile, NULL, 1, 2, zeile, int_type, &PP->nang[it], 1, critical);
    510510    I->TotalZval += PP->zval[it]*(I->I[it].Max_IonsOfType);
    511511    PP->core[it] = (double *) Malloc(sizeof(double)*2, "InitPseudoRead: ");
    512512    PP->rc[it] = (double *) Malloc(sizeof(double)*2, "InitPseudoRead: ");
    513     ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &PP->core[it][0], critical);
    514     ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &PP->rc[it][0], critical);
    515     ParseForParameter(0,cpiInputFile, NULL, 0, 3, zeile, double_type, &PP->core[it][1], critical);
    516     ParseForParameter(0,cpiInputFile, NULL, 1, 4, zeile, double_type, &PP->rc[it][1], critical);
     513    ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &PP->core[it][0], 1, critical);
     514    ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &PP->rc[it][0], 1, critical);
     515    ParseForParameter(0,cpiInputFile, NULL, 0, 3, zeile, double_type, &PP->core[it][1], 1, critical);
     516    ParseForParameter(0,cpiInputFile, NULL, 1, 4, zeile, double_type, &PP->rc[it][1], 1, critical);
    517517    PP->rcl[it] = (double **) Malloc(sizeof(double*)*3, "InitPseudoRead: ");
    518518    PP->al[it] =  (double **) Malloc(sizeof(double*)*3, "InitPseudoRead: ");
     
    526526      PP->bl[it][il] = (double *) Malloc(sizeof(double)*3, "InitPseudoRead: ");
    527527      for (ib = 0; ib < 3; ib++) {
    528                     ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &PP->rcl[it][il][ib], critical);
    529                     ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &PP->al[it][il][ib], critical);
    530                     ParseForParameter(0,cpiInputFile, NULL, 1, 3, zeile, double_type, &PP->bl[it][il][ib], critical);
     528                    ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &PP->rcl[it][il][ib], 1, critical);
     529                    ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &PP->al[it][il][ib], 1, critical);
     530                    ParseForParameter(0,cpiInputFile, NULL, 1, 3, zeile, double_type, &PP->bl[it][il][ib], 1, critical);
    531531                                if (PP->rcl[it][il][ib] < MYEPSILON)
    532532                                  PP->rcl[it][il][ib] = 0.0;
     
    535535      }
    536536    }
    537     ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, int_type, &PP->mmax[it], critical);
    538     ParseForParameter(0,cpiInputFile, NULL, 1, 2, zeile, double_type, &PP->clog[it], critical);
     537    ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, int_type, &PP->mmax[it], 1, critical);
     538    ParseForParameter(0,cpiInputFile, NULL, 1, 2, zeile, double_type, &PP->clog[it], 1, critical);
    539539    if (PP->mmax[it] > PP->Mmax) PP->Mmax = PP->mmax[it];
    540540    PP->clog[it] = log(PP->clog[it]);
     
    547547      PP->v_loc[it][il] = (double *) Malloc(sizeof(double)*PP->mmax[it], "InitPseudoRead: ");
    548548      for (j=0;j< PP->mmax[it];j++) {
    549                     ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, int_type, &m, critical);
    550                     ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &PP->r[it][j], critical);
    551                     ParseForParameter(0,cpiInputFile, NULL, 0, 3, zeile, double_type, &PP->R[it][il][j], critical);
    552                     ParseForParameter(0,cpiInputFile, NULL, 1, 4, zeile, double_type, &PP->v_loc[it][il][j], critical);
     549                    ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, int_type, &m, 1, critical);
     550                    ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &PP->r[it][j], 1, critical);
     551                    ParseForParameter(0,cpiInputFile, NULL, 0, 3, zeile, double_type, &PP->R[it][il][j], 1, critical);
     552                    ParseForParameter(0,cpiInputFile, NULL, 1, 4, zeile, double_type, &PP->v_loc[it][il][j], 1, critical);
    553553      }
    554554      if (il < PP->nang[it]-1) {
    555                     ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, int_type, &PP->mmax[it], critical);
    556                     ParseForParameter(0,cpiInputFile, NULL, 1, 2, zeile, double_type, &PP->clog[it], critical);
     555                    ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, int_type, &PP->mmax[it], 1, critical);
     556                    ParseForParameter(0,cpiInputFile, NULL, 1, 2, zeile, double_type, &PP->clog[it], 1, critical);
    557557                                PP->clog[it] = log(PP->clog[it]);
    558558      }
     
    560560    I->I[it].corecorr = NotCoreCorrected;
    561561    count = 0;
    562     count += ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &dummyr, optional);
    563     count += ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &dummycorewave, optional);
     562    count += ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &dummyr, 1, optional);
     563    count += ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &dummycorewave, 1, optional);
    564564    //fprintf(stderr,"(%i) %lg %lg\n",P->Par.me,dummyr,dummycorewave);
    565565    if (count == 2) {
     
    570570      PP->corecorr = CoreCorrected;
    571571      PP->corewave[it][0] = dummycorewave/(4.*PI);
    572             ParseForParameter(0,cpiInputFile, NULL, 0, 3, zeile, double_type, &dummyr, critical);
    573             ParseForParameter(0,cpiInputFile, NULL, 1, 4, zeile, double_type, &dummycorewave, critical);
     572            ParseForParameter(0,cpiInputFile, NULL, 0, 3, zeile, double_type, &dummyr, 1, critical);
     573            ParseForParameter(0,cpiInputFile, NULL, 1, 4, zeile, double_type, &dummycorewave, 1, critical);
    574574      for (j=1;j < PP->mmax[it]; j++) {
    575                     ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &PP->r[it][j], critical);
    576                     ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &PP->corewave[it][j], critical);
    577                     ParseForParameter(0,cpiInputFile, NULL, 0, 3, zeile, double_type, &dummyr, critical);
    578                     ParseForParameter(0,cpiInputFile, NULL, 1, 4, zeile, double_type, &dummycorewave, critical);
     575                    ParseForParameter(0,cpiInputFile, NULL, 0, 1, zeile, double_type, &PP->r[it][j], 1, critical);
     576                    ParseForParameter(0,cpiInputFile, NULL, 0, 2, zeile, double_type, &PP->corewave[it][j], 1, critical);
     577                    ParseForParameter(0,cpiInputFile, NULL, 0, 3, zeile, double_type, &dummyr, 1, critical);
     578                    ParseForParameter(0,cpiInputFile, NULL, 1, 4, zeile, double_type, &dummycorewave, 1, critical);
    579579                                PP->corewave[it][j] /= (4.*PI);
    580580      }
  • pcp/src/wannier.c

    re00f47 r961b75  
    13191319        sprintf(tagname,"Psi%d_Lev%d",i,R->LevSNo);
    13201320        signal = 0;
    1321         if (!ParseForParameter(0,SpreadFile,tagname,0,3,1,row_double,WannierCentre,optional)) {
     1321        if (!ParseForParameter(0,SpreadFile,tagname,0,3,1,row_double,WannierCentre,1,optional)) {
    13221322          //Error(SomeError,"ParseWannierFile: Parsing WannierCentre failed");
    13231323          if (MPI_Bcast(&signal,1,MPI_INT,0,P->Par.comm_ST) != MPI_SUCCESS)
     
    13251325          return 0;
    13261326        }
    1327         if (!ParseForParameter(0,SpreadFile,tagname,0,4,1,double_type,&WannierCentre[NDIM],optional)) {
     1327        if (!ParseForParameter(0,SpreadFile,tagname,0,4,1,double_type,&WannierCentre[NDIM],1,optional)) {
    13281328          //Error(SomeError,"ParseWannierFile: Parsing WannierSpread failed");
    13291329          if (MPI_Bcast(&signal,1,MPI_INT,0,P->Par.comm_ST) != MPI_SUCCESS)
Note: See TracChangeset for help on using the changeset viewer.