- Timestamp:
- Apr 21, 2008, 2:19:24 PM (17 years ago)
- Children:
- 774ae8
- Parents:
- 961b75
- git-author:
- Frederik Heber <heber@…> (04/18/08 15:17:03)
- git-committer:
- Frederik Heber <heber@…> (04/21/08 14:19:24)
- Location:
- pcp/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pcp/src/ions.c
r961b75 rb74e5e 50 50 #include "ions.h" 51 51 #include "init.h" 52 53 /** Readin of Thermostat related values from parameter file. 54 * \param *P Problem at hand 55 * \param *source parameter file 56 */ 57 void InitThermostats(struct Problem *P, FILE *source) 58 { 59 struct FileData *F = &P->Files; 60 struct Ions *I = &P->Ion; 61 char *thermo = MallocString(12, "IonsInitRead: thermo"); 62 int j; 63 64 // initialize the naming stuff and all 65 I->ThermostatImplemented = (int *) Malloc((MaxThermostats)*(sizeof(int)), "IonsInitRead: *ThermostatImplemented"); 66 I->ThermostatNames = (char **) Malloc((MaxThermostats)*(sizeof(char *)), "IonsInitRead: *ThermostatNames"); 67 for (j=0;j<MaxThermostats;j++) 68 I->ThermostatNames[j] = (char *) MallocString(12*(sizeof(char)), "IonsInitRead: ThermostatNames[]"); 69 strcpy(I->ThermostatNames[0],"None"); 70 I->ThermostatImplemented[0] = 1; 71 strcpy(I->ThermostatNames[1],"Woodcock"); 72 I->ThermostatImplemented[1] = 1; 73 strcpy(I->ThermostatNames[2],"Gaussian"); 74 I->ThermostatImplemented[2] = 1; 75 strcpy(I->ThermostatNames[3],"Langevin"); 76 I->ThermostatImplemented[3] = 1; 77 strcpy(I->ThermostatNames[4],"Berendsen"); 78 I->ThermostatImplemented[4] = 1; 79 strcpy(I->ThermostatNames[5],"NoseHoover"); 80 I->ThermostatImplemented[5] = 1; 81 I->Thermostat = -1; 82 if (F->MeOutMes) fprintf(F->TemperatureFile, "# %s\t%s\t%s --- ","Step", "ActualTemp(1)", "ActualTemp(2)"); 83 84 // read desired Thermostat from file along with needed additional parameters 85 if (ParseForParameter(P->Call.out[ReadOut],source,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) { 86 if (strcmp(thermo, I->ThermostatNames[0]) == 0) { // None 87 if (I->ThermostatImplemented[0] == 1) { 88 I->Thermostat = None; 89 } else { 90 if (P->Par.me == 0) 91 fprintf(stderr, "(%i) Warning: %s thermostat not implemented, falling back to None.", P->Par.me, I->ThermostatNames[0]); 92 I->Thermostat = None; 93 } 94 } else if (strcmp(thermo, I->ThermostatNames[1]) == 0) { // Woodcock 95 if (I->ThermostatImplemented[1] == 1) { 96 I->Thermostat = Woodcock; 97 ParseForParameter(P->Call.out[ReadOut],source,"Thermostat", 0, 2, 1, int_type, &P->R.ScaleTempStep, 1, critical); // read scaling frequency 98 } else { 99 if (P->Par.me == 0) 100 fprintf(stderr, "(%i) Warning: %s thermostat not implemented, falling back to None.", P->Par.me, I->ThermostatNames[1]); 101 I->Thermostat = None; 102 } 103 } else if (strcmp(thermo, I->ThermostatNames[2]) == 0) { // Gaussian 104 if (I->ThermostatImplemented[2] == 1) { 105 I->Thermostat = Gaussian; 106 ParseForParameter(P->Call.out[ReadOut],source,"Thermostat", 0, 2, 1, int_type, &P->R.ScaleTempStep, 1, critical); // read collision rate 107 } else { 108 if (P->Par.me == 0) 109 fprintf(stderr, "(%i) Warning: %s thermostat not implemented, falling back to None.", P->Par.me, I->ThermostatNames[2]); 110 I->Thermostat = None; 111 } 112 } else if (strcmp(thermo, I->ThermostatNames[3]) == 0) { // Langevin 113 if (I->ThermostatImplemented[3] == 1) { 114 I->Thermostat = Langevin; 115 ParseForParameter(P->Call.out[ReadOut],source,"Thermostat", 0, 2, 1, double_type, &P->R.TempFrequency, 1, critical); // read gamma 116 if (ParseForParameter(P->Call.out[ReadOut],source,"Thermostat", 0, 3, 1, double_type, &P->R.alpha, 1, optional)) { 117 if (P->Par.me == 0) 118 fprintf(stderr,"(%i) Extended Stochastic Thermostat detected with interpolation coefficient %lg\n", P->Par.me, P->R.alpha); 119 } else { 120 P->R.alpha = 1.; 121 } 122 } else { 123 if (P->Par.me == 0) 124 fprintf(stderr, "(%i) Warning: %s thermostat not implemented, falling back to None.", P->Par.me, I->ThermostatNames[3]); 125 I->Thermostat = None; 126 } 127 } else if (strcmp(thermo, I->ThermostatNames[4]) == 0) { // Berendsen 128 if (I->ThermostatImplemented[4] == 1) { 129 I->Thermostat = Berendsen; 130 ParseForParameter(P->Call.out[ReadOut],source,"Thermostat", 0, 2, 1, double_type, &P->R.TempFrequency, 1, critical); // read \tau_T 131 } else { 132 if (P->Par.me == 0) 133 fprintf(stderr, "(%i) Warning: %s thermostat not implemented, falling back to None.", P->Par.me, I->ThermostatNames[4]); 134 I->Thermostat = None; 135 } 136 } else if (strcmp(thermo, I->ThermostatNames[5]) == 0) { // Nose-Hoover 137 if (I->ThermostatImplemented[5] == 1) { 138 I->Thermostat = NoseHoover; 139 ParseForParameter(P->Call.out[ReadOut],source,"Thermostat", 0, 2, 1, double_type, &P->R.HooverMass, 1, critical); // read Hoovermass 140 P->R.alpha = 0.; 141 } else { 142 if (P->Par.me == 0) 143 fprintf(stderr, "(%i) Warning: %s thermostat not implemented, falling back to None.", P->Par.me, I->ThermostatNames[5]); 144 I->Thermostat = None; 145 } 146 } 147 if (I->Thermostat == -1) { 148 if (P->Par.me == 0) 149 fprintf(stderr,"(%i) Warning: thermostat name was not understood!\n", P->Par.me); 150 I->Thermostat = None; 151 } 152 } else { 153 if ((P->R.MaxOuterStep > 0) && (P->R.TargetTemp != 0)) 154 debug(P, "No thermostat chosen despite finite temperature MD, falling back to None."); 155 I->Thermostat = None; 156 } 157 if (F->MeOutMes) fprintf(F->TemperatureFile, "%s Thermostat\n",I->ThermostatNames[(int)I->Thermostat]); 158 Free(thermo, "InitThermostats: thermo"); 159 } 52 160 53 161 /** Parses for a given keyword the ion coordinates and velocites. … … 179 287 I->StructOpt = 0; 180 288 181 //InitThermostats(P, source);289 InitThermostats(P, source); 182 290 183 291 /* Ions Data */ … … 515 623 fprintf(fout, "MeanForce:\t%e\n", R->MeanForce[0]); 516 624 } 625 626 /** Reads Forces from CallOptions::ForcesFile. 627 * goes through all Ions per IonType and each dimension of #NDIM and parses in one line: 628 * Position IonType::R, total force Ion IonType::FIon, local force IonType::FIonL, 629 * non-local IonType::FIonNL, ewald force IonType::FEwald 630 * \param *P Problem at hand 631 */ 632 void ParseIonForce(struct Problem *P) 633 { 634 //struct RunStruct *Run = &P->R; 635 struct Ions *I = &P->Ion; 636 FILE *finput = NULL; 637 char line[1024]; 638 int i,j; 639 double i1, j1; 640 double R[NDIM]; 641 642 if (P->Call.ForcesFile == NULL) return; 643 finput = fopen(P->Call.ForcesFile, "r"); 644 //fprintf(stderr, "File pointer says %p\n", finput); 645 if (finput == NULL) 646 Error(InitReading, "ForcesFile does not exist."); 647 fscanf(finput, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line); // skip header line 648 for (i=0; i < I->Max_Types; i++) 649 for (j=0; j < I->I[i].Max_IonsOfType; j++) 650 if (feof(finput)) { 651 Error(InitReading, "ForcesFile does not contain enough lines."); 652 } else { 653 //fscanf(finput, "%s\n", line); 654 //if (strlen(line) < 100) { 655 //fprintf(stderr, "i %d, j %d, length of line %ld, line %s.\n", i,j, strlen(line), line); 656 //Error(InitReading, "ForcesFile does not contain enough lines or line is faulty."); 657 //} else 658 //fprintf(stderr, "Parsed line: '%s'\n", line); 659 fscanf(finput, "%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\n", &i1,&j1, 660 &R[0], &R[1], &R[2], 661 &I->I[i].FIon[0+j*NDIM], &I->I[i].FIon[1+j*NDIM], &I->I[i].FIon[2+j*NDIM], 662 &I->I[i].FIonL[0+j*NDIM], &I->I[i].FIonL[1+j*NDIM], &I->I[i].FIonL[2+j*NDIM], 663 &I->I[i].FIonNL[0+j*NDIM], &I->I[i].FIonNL[1+j*NDIM], &I->I[i].FIonNL[2+j*NDIM], 664 &I->I[i].FMagnetic[0+j*NDIM], &I->I[i].FMagnetic[1+j*NDIM], &I->I[i].FMagnetic[2+j*NDIM], 665 &I->I[i].FEwald[0+j*NDIM], &I->I[i].FEwald[1+j*NDIM], &I->I[i].FEwald[2+j*NDIM]); 666 if ((i != (int)i1) || (j != (int)j1)) 667 Error(InitReading, "Line does not match to desired ion."); 668 } 669 fclose(finput); 670 //fprintf(stderr, "MeanForce:\t%e\n", Run->MeanForce[0]); 671 }; 517 672 518 673 /** Frees memory IonType. -
pcp/src/ions.h
r961b75 rb74e5e 121 121 /* Functions */ 122 122 void IonsInitRead(struct Problem *P, FILE *source); 123 void InitThermostats(struct Problem *P, FILE *source); 123 124 void CalculateEwald(struct Problem *P, int first); 124 125 void RemoveIonsRead(struct Ions *I);
Note:
See TracChangeset
for help on using the changeset viewer.