Changeset 27a5bf
- Timestamp:
- Apr 21, 2008, 2:19:23 PM (17 years ago)
- Children:
- 9b2f5d
- Parents:
- 2026d4
- git-author:
- Frederik Heber <heber@…> (04/18/08 14:15:13)
- git-committer:
- Frederik Heber <heber@…> (04/21/08 14:19:23)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified pcp/src/run.c ¶
r2026d4 r27a5bf 1281 1281 struct Energy *E = P->Lat.E; 1282 1282 int i; 1283 double *R_ion, *R_old, *R_old_old , *FIon;1284 double norm = 0.;1285 int is,ia,k,index ;1283 double *R_ion, *R_old, *R_old_old;//, *FIon; 1284 //double norm = 0.; 1285 int is,ia,k,index = 0; 1286 1286 int OuterStop; 1287 // update ion positions from vector coordinates 1288 index=0; 1289 for (is=0; is < I->Max_Types; is++) // for all elements 1290 for (ia=0; ia < I->I[is].Max_IonsOfType; ia++) { // for all ions of element 1291 R_ion = &I->I[is].R[NDIM*ia]; 1292 R_old = &I->I[is].R_old[NDIM*ia]; 1293 R_old_old = &I->I[is].R_old_old[NDIM*ia]; 1294 for (k=0;k<NDIM;k++) { // for all dimensions 1295 R_old_old[k] = R_old[k]; 1296 R_old[k] = R_ion[k]; 1297 R_ion[k] = gsl_vector_get (v, index++); 1298 } 1299 } 1300 // recalculate ionic forces (do electronic minimisation) 1301 R->OuterStep++; 1302 if (P->Call.out[NormalOut]) fprintf(stderr,"(%i) Commencing Fletcher-Reeves step %i ... \n",P->Par.me, R->OuterStep); 1303 R->NewRStep++; 1304 OutputIonCoordinates(P); 1305 UpdateWaveAfterIonMove(P); 1306 for (i=MAXOLD-1; i > 0; i--) // store away old energies 1307 E->TotalEnergyOuter[i] = E->TotalEnergyOuter[i-1]; 1308 UpdateToNewWaves(P); 1309 E->TotalEnergyOuter[0] = E->TotalEnergy[0]; 1310 OuterStop = CalculateForce(P); 1311 UpdateIonsU(P); 1312 CorrectVelocity(P); 1313 CalculateEnergyIonsU(P); 1314 /* if ((P->R.ScaleTempStep > 0) && ((R->OuterStep-1) % P->R.ScaleTempStep == 0)) 1315 ScaleTemp(P);*/ 1316 if ((R->OuterStep-1) % P->R.OutSrcStep == 0) 1317 OutputVisSrcFiles(P, Occupied); 1318 if ((R->OuterStep-1) % P->R.OutVisStep == 0) { 1319 /* // recalculate density for the specific wave function ... 1320 CalculateOneDensityR(Lat, LevS, Dens0, PsiDat, Dens0->DensityArray[ActualDensity], R->FactorDensityR, 0); 1321 // ... and output (wherein ActualDensity is used instead of TotalDensity) 1322 OutputVis(P); 1323 OutputIonForce(P); 1324 EnergyOutput(P, 1);*/ 1325 } 1326 // sum up mean force 1327 for (is=0; is < I->Max_Types; is++) 1328 for (ia=0; ia < I->I[is].Max_IonsOfType; ia++) { 1329 FIon = &I->I[is].FIon[NDIM*ia]; 1330 norm += sqrt(RSP3(FIon,FIon)); 1331 } 1332 if (P->Par.me == 0) fprintf(stderr,"(%i) Mean Force over all Ions %e\n",P->Par.me, norm); 1333 return norm; 1287 double diff = 0., tmp; 1288 //debug (P, "StructOpt_f"); 1289 if (CheckForChangedPositions(P,v)) { 1290 // update ion positions from vector coordinates 1291 for (is=0; is < I->Max_Types; is++) // for all elements 1292 for (ia=0; ia < I->I[is].Max_IonsOfType; ia++) { // for all ions of element 1293 R_ion = &I->I[is].R[NDIM*ia]; 1294 R_old = &I->I[is].R_old[NDIM*ia]; 1295 R_old_old = &I->I[is].R_old_old[NDIM*ia]; 1296 tmp = 0.; 1297 for (k=0;k<NDIM;k++) { // for all dimensions 1298 R_old_old[k] = R_old[k]; 1299 R_old[k] = R_ion[k]; 1300 tmp += (R_ion[k]-gsl_vector_get (v, index))*(R_ion[k]-gsl_vector_get (v, index)); 1301 R_ion[k] = gsl_vector_get (v, index++); 1302 } 1303 diff += sqrt(tmp); 1304 } 1305 if (P->Call.out[ValueOut]) fprintf(stderr,"(%i) Summed Difference to former position %lg\n", P->Par.me, diff); 1306 // recalculate ionic forces (do electronic minimisation) 1307 //R->OuterStep++; 1308 R->NewRStep++; 1309 UpdateWaveAfterIonMove(P); 1310 for (i=MAXOLD-1; i > 0; i--) // store away old energies 1311 E->TotalEnergyOuter[i] = E->TotalEnergyOuter[i-1]; 1312 UpdateToNewWaves(P); 1313 E->TotalEnergyOuter[0] = E->TotalEnergy[0]; 1314 OuterStop = CalculateForce(P); 1315 //UpdateIonsU(P); 1316 //CorrectVelocity(P); 1317 //CalculateEnergyIonsU(P); 1318 /* if ((P->R.ScaleTempStep > 0) && ((R->OuterStep-1) % P->R.ScaleTempStep == 0)) 1319 ScaleTemp(P);*/ 1320 if ((R->OuterStep-1) % P->R.OutSrcStep == 0) 1321 OutputVisSrcFiles(P, Occupied); 1322 /*if ((R->OuterStep-1) % P->R.OutVisStep == 0) { 1323 // recalculate density for the specific wave function ... 1324 CalculateOneDensityR(Lat, LevS, Dens0, PsiDat, Dens0->DensityArray[ActualDensity], R->FactorDensityR, 0); 1325 // ... and output (wherein ActualDensity is used instead of TotalDensity) 1326 OutputVis(P); 1327 OutputIonForce(P); 1328 EnergyOutput(P, 1); 1329 }*/ 1330 } 1331 GetOuterStop(P); 1332 //if (P->Call.out[LeaderOut] && (P->Par.me == 0)) fprintf(stderr,"(%i) Absolute Force summed over all Ions %e\n",P->Par.me, norm); 1333 return R->MeanForce[0]; 1334 //if (P->Call.out[LeaderOut] && (P->Par.me == 0)) fprintf(stderr,"(%i) Struct_optf returning: %lg\n",P->Par.me,E->TotalEnergy[0]); 1335 //return E->TotalEnergy[0]; 1334 1336 } 1335 1337 … … 1339 1341 struct Ions *I = &P->Ion; 1340 1342 double *FIon; 1341 int is,ia,k, index=0; 1343 int is,ia,k, index=0; 1344 //debug (P, "StructOpt_df"); 1345 // look through coordinate vector if positions have changed sind last StructOpt_f call 1346 if (CheckForChangedPositions(P,v)) {// if so, recalc to update forces 1347 debug (P, "Calling StructOpt_f to update"); 1348 StructOpt_f(v, params); 1349 } 1342 1350 for (is=0; is < I->Max_Types; is++) // for all elements 1343 1351 for (ia=0; ia < I->I[is].Max_IonsOfType; ia++) { // for all ions of element … … 1346 1354 gsl_vector_set (df, index++, FIon[k]); 1347 1355 } 1348 } 1356 } 1357 if (P->Call.out[LeaderOut] && (P->Par.me == 0)) { 1358 fprintf(stderr,"(%i) Struct_Optdf returning",P->Par.me); 1359 gsl_vector_fprintf(stderr, df, "%lg"); 1360 } 1349 1361 } 1350 1362 … … 1362 1374 void UpdateIon_PRCG(struct Problem *P) 1363 1375 { 1364 struct RunStruct *Run = &P->R;1376 //struct RunStruct *Run = &P->R; 1365 1377 struct Ions *I = &P->Ion; 1366 1378 size_t np = NDIM*I->Max_TotalIons; // d.o.f = number of ions times number of dimensions … … 1378 1390 /* Starting point */ 1379 1391 x = gsl_vector_alloc (np); 1392 //fprintf(stderr,"(%i) d.o.f. = %i\n", P->Par.me, (int)np); 1380 1393 1381 1394 index=0; … … 1397 1410 s = gsl_multimin_fdfminimizer_alloc (T, np); 1398 1411 1399 gsl_multimin_fdfminimizer_set (s, &minex_func, x, 0.1, 1e-4); 1400 1412 gsl_multimin_fdfminimizer_set (s, &minex_func, x, 0.1, 0.001); 1413 1414 fprintf(stderr,"(%i) Commencing Structure optimization with PRCG: dof %d\n", P->Par.me,(int)np); 1401 1415 do { 1402 1416 iter++; … … 1406 1420 break; 1407 1421 1408 status = gsl_multimin_test_gradient (s->gradient, 1e- 4);1422 status = gsl_multimin_test_gradient (s->gradient, 1e-2); 1409 1423 1410 1424 if (status == GSL_SUCCESS) … … 1413 1427 //if (P->Call.out[NormalOut]) fprintf(stderr,"(%i) Commencing '%s' step %i ... \n",P->Par.me, gsl_multimin_fdfminimizer_name(s), P->R.StructOptStep); 1414 1428 if ((P->Call.out[NormalOut]) && (P->Par.me == 0)) fprintf (stderr, "(%i) %5d %10.5f\n", P->Par.me, (int)iter, s->f); 1415 } while (status == GSL_CONTINUE && iter < Run->MaxOuterStep); 1429 //gsl_vector_fprintf(stderr, s->dx, "%lg"); 1430 OutputVis(P, P->R.Lev0->Dens->DensityArray[TotalDensity]); 1431 //OutputIonCoordinates(P, 0); 1432 P->R.StructOptStep++; 1433 } while ((status == GSL_CONTINUE) && (P->R.StructOptStep < P->R.MaxStructOptStep)); 1416 1434 1417 1435 gsl_vector_free(x); 1418 1436 gsl_multimin_fdfminimizer_free (s); 1437 } 1438 1439 /** Simplex implementation for the structure optimization. 1440 * We follow the example from the GSL manual. 1441 * \param *P Problem at hand 1442 */ 1443 void UpdateIon_Simplex(struct Problem *P) 1444 { 1445 struct RunStruct *Run = &P->R; 1446 struct Ions *I = &P->Ion; 1447 size_t np = NDIM*I->Max_TotalIons; // d.o.f = number of ions times number of dimensions 1448 int is, ia, k, index; 1449 double *R; 1450 1451 const gsl_multimin_fminimizer_type *T; 1452 gsl_multimin_fminimizer *s; 1453 gsl_vector *x, *ss; 1454 gsl_multimin_function minex_func; 1455 1456 size_t iter = 0; 1457 int status; 1458 double size; 1459 1460 ss = gsl_vector_alloc (np); 1461 gsl_vector_set_all(ss, .2); 1462 /* Starting point */ 1463 x = gsl_vector_alloc (np); 1464 //fprintf(stderr,"(%i) d.o.f. = %i\n", P->Par.me, (int)np); 1465 1466 index=0; 1467 for (is=0; is < I->Max_Types; is++) // for all elements 1468 for (ia=0; ia < I->I[is].Max_IonsOfType; ia++) { // for all ions of element 1469 R = &I->I[is].R[NDIM*ia]; 1470 for (k=0;k<NDIM;k++) // for all dimensions 1471 gsl_vector_set (x, index++, R[k]); 1472 } 1473 1474 /* Initialize method and iterate */ 1475 minex_func.f = &StructOpt_f; 1476 minex_func.n = np; 1477 minex_func.params = (void *)P; 1478 1479 T = gsl_multimin_fminimizer_nmsimplex; 1480 s = gsl_multimin_fminimizer_alloc (T, np); 1481 1482 gsl_multimin_fminimizer_set (s, &minex_func, x, ss); 1483 1484 fprintf(stderr,"(%i) Commencing Structure optimization with NM simplex: dof %d\n", P->Par.me, (int)np); 1485 do { 1486 iter++; 1487 status = gsl_multimin_fminimizer_iterate(s); 1488 1489 if (status) 1490 break; 1491 1492 size = gsl_multimin_fminimizer_size (s); 1493 status = gsl_multimin_test_size (size, 1e-4); 1494 1495 if (status == GSL_SUCCESS) 1496 if (P->Par.me == 0) fprintf (stderr,"(%i) converged to minimum at\n", P->Par.me); 1497 1498 if (P->Call.out[MinOut]) fprintf(stderr,"(%i) Commencing '%s' step %i ... \n",P->Par.me, gsl_multimin_fminimizer_name(s), P->R.StructOptStep); 1499 if ((P->Call.out[MinOut]) && (P->Par.me == 0)) fprintf (stderr, "(%i) %5d %10.5f %10.5f\n", P->Par.me, (int)iter, s->fval, size); 1500 OutputVis(P, P->R.Lev0->Dens->DensityArray[TotalDensity]); 1501 //OutputIonCoordinates(P, 0); 1502 P->R.StructOptStep++; 1503 } while ((status == GSL_CONTINUE) && (Run->OuterStep < Run->MaxOuterStep)); 1504 1505 gsl_vector_free(x); 1506 gsl_vector_free(ss); 1507 gsl_multimin_fminimizer_free (s); 1419 1508 } 1420 1509 … … 1638 1727 struct RunStruct *R = &P->R; 1639 1728 struct Ions *I = &P->Ion; 1729 struct Energy *E = P->Lat.E; 1640 1730 int OuterStop = 0; 1731 int i; 1732 1641 1733 SpeedMeasure(P, SimTime, StartTimeDo); 1734 // initial calculations (bring density on BO surface and output start energies, coordinates, densities, ...) 1642 1735 SpeedMeasure(P, InitSimTime, StartTimeDo); 1643 1736 R->OuterStep = 0; … … 1645 1738 CalculateEnergyIonsU(P); 1646 1739 OuterStop = CalculateForce(P); 1647 R->OuterStep++;1740 //R->OuterStep++; 1648 1741 P->Speed.InitSteps++; 1649 1742 SpeedMeasure(P, InitSimTime, StopTimeDo); 1743 1744 //OutputIonCoordinates(P, 1); 1745 OutputVis(P, P->R.Lev0->Dens->DensityArray[TotalDensity]); 1650 1746 OutputIonForce(P); 1651 1747 EnergyOutput(P, 1); 1652 if (R->MaxOuterStep > 0) { 1653 debug(P,"Commencing Fletcher-Reeves minimisation on ionic structure ..."); 1654 UpdateIon_PRCG(P); 1748 1749 // if desired perform beforehand a structure relaxation/optimization 1750 if (I->StructOpt) { 1751 debug(P,"Commencing minimisation on ionic structure ..."); 1752 R->StructOptStep = 0; 1753 //UpdateIon_PRCG(P); 1754 //UpdateIon_Simplex(P); 1755 while ((R->MeanForce[0] > 1e-4) && (R->StructOptStep < R->MaxStructOptStep)) { 1756 R->StructOptStep++; 1757 //OutputIonCoordinates(P, 1); 1758 UpdateIons(P); 1759 UpdateWaveAfterIonMove(P); 1760 for (i=MAXOLD-1; i > 0; i--) // store away old energies 1761 E->TotalEnergyOuter[i] = E->TotalEnergyOuter[i-1]; 1762 UpdateToNewWaves(P); 1763 E->TotalEnergyOuter[0] = E->TotalEnergy[0]; 1764 OuterStop = CalculateForce(P); 1765 CalculateEnergyIonsU(P); 1766 if ((R->StructOptStep-1) % P->R.OutSrcStep == 0) 1767 OutputVisSrcFiles(P, Occupied); 1768 if ((R->StructOptStep-1) % P->R.OutVisStep == 0) { 1769 OutputVis(P, P->R.Lev0->Dens->DensityArray[TotalDensity]); 1770 OutputIonForce(P); 1771 EnergyOutput(P, 1); 1772 } 1773 if (P->Par.me == 0) fprintf(stderr,"(%i) Mean force is %lg\n", P->Par.me, R->MeanForce[0]); 1774 } 1775 //OutputIonCoordinates(P, 1); 1655 1776 } 1656 1777 if (I->StructOpt && !OuterStop) { … … 1658 1779 OuterStop = CalculateForce(P); 1659 1780 } 1660 /* while (!OuterStop && R->OuterStep <= R->MaxOuterStep) { 1781 1782 // and now begin with the molecular dynamics simulation 1783 debug(P,"Commencing MD simulation ..."); 1784 while (!OuterStop && R->OuterStep < R->MaxOuterStep) { 1661 1785 R->OuterStep++; 1662 if (P->Call.out[NormalOut]) fprintf(stderr,"(%i) Commencing MD steps %i ... \n",P->Par.me, R->OuterStep); 1663 P->R.t += P->R.delta_t; // increase current time by delta_t 1786 if (P->Par.me == 0) { 1787 if (R->OuterStep > 1) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b\b\b"); 1788 fprintf(stderr,"Time: %f fs\r", R->t*Atomictime2Femtoseconds); 1789 fflush(stderr); 1790 } 1791 OuterStop = CalculateForce(P); 1792 P->R.t += P->R.delta_t; // increase current time by delta_t 1664 1793 R->NewRStep++; 1665 if (P->Ion.StructOpt == 1) { 1666 UpdateIons(P); 1667 OutputIonCoordinates(P); 1668 } else { 1669 UpdateIonsR(P); 1670 } 1794 1795 UpdateIonsU(P); 1796 CorrectVelocity(P); 1797 Thermostats(P, I->Thermostat); 1798 CalculateEnergyIonsU(P); 1799 1800 UpdateIonsR(P); 1801 //OutputIonCoordinates(P, 1); 1802 1671 1803 UpdateWaveAfterIonMove(P); 1672 for (i=MAXOLD-1; i > 0; i--) 1804 for (i=MAXOLD-1; i > 0; i--) // store away old energies 1673 1805 E->TotalEnergyOuter[i] = E->TotalEnergyOuter[i-1]; 1674 1806 UpdateToNewWaves(P); 1675 1807 E->TotalEnergyOuter[0] = E->TotalEnergy[0]; 1676 OuterStop = CalculateForce(P); 1677 UpdateIonsU(P); 1678 CorrectVelocity(P); 1679 CalculateEnergyIonsU(P); 1680 if ((P->R.ScaleTempStep > 0) && ((R->OuterStep-1) % P->R.ScaleTempStep == 0)) 1681 ScaleTemp(P); 1808 //if ((P->R.ScaleTempStep > 0) && ((R->OuterStep-1) % P->R.ScaleTempStep == 0)) 1809 // ScaleTemp(P); 1682 1810 if ((R->OuterStep-1) % P->R.OutSrcStep == 0) 1683 1811 OutputVisSrcFiles(P, Occupied); 1684 1812 if ((R->OuterStep-1) % P->R.OutVisStep == 0) { 1685 // recalculate density for the specific wave function ... 1686 //CalculateOneDensityR(Lat, LevS, Dens0, PsiDat, Dens0->DensityArray[ActualDensity], R->FactorDensityR, 0); 1687 // ... and output (wherein ActualDensity is used instead of TotalDensity) 1688 //OutputVis(P); 1689 //OutputIonForce(P); 1690 //EnergyOutput(P, 1); 1691 } 1692 }*/ 1813 OutputVis(P, P->R.Lev0->Dens->DensityArray[TotalDensity]); 1814 OutputIonForce(P); 1815 EnergyOutput(P, 1); 1816 } 1817 ResetForces(P); 1818 } 1693 1819 SpeedMeasure(P, SimTime, StopTimeDo); 1694 // hack to output each orbital before and after spread-minimisation1695 /* if (P->Files.MeOutVis) P->Files.OutputPosType = (enum ModeType *) Realloc(P->Files.OutputPosType,sizeof(enum ModeType)*(P->Files.OutVisStep+P->Lat.Psi.MaxPsiOfType*2),"OutputVis");1696 OutputVisAllOrbital(P, 0, 2, Occupied);1697 CalculateHamiltonian(P);1698 if (P->Files.MeOutVis) P->Files.OutVisStep -= (P->Lat.Psi.MaxPsiOfType)*2;1699 OutputVisAllOrbital(P, 1, 2, Occupied);*/1700 1820 CloseOutputFiles(P); 1701 1821 }
Note:
See TracChangeset
for help on using the changeset viewer.