ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/minimizers/SDMinimizer.cpp
Revision: 1830
Committed: Thu Dec 2 05:17:10 2004 UTC (19 years, 9 months ago) by tim
File size: 2297 byte(s)
Log Message:
change endl to std::endl

File Contents

# User Rev Content
1 tim 1492 #include "minimizers/OOPSEMinimizer.hpp"
2     #include "utils/Utility.hpp"
3 gezelter 1490
4     SDMinimizer::SDMinimizer(SimInfo *theInfo, ForceFields* the_ff ,
5     MinimizerParameterSet * param)
6     :OOPSEMinimizer(theInfo, the_ff, param){
7    
8     direction.resize(ndim);
9     stepSize = paramSet->getStepSize();
10     }
11    
12     void SDMinimizer::init(){
13    
14     calcG();
15    
16     for(int i = 0; i < direction.size(); i++){
17     direction[i] = -curG[i];
18     }
19     }
20    
21     int SDMinimizer::step(){
22     int lsStatus;
23    
24     prevF = curF;
25    
26     //optimize along the search direction and reset minimum point value
27     lsStatus = doLineSearch(direction, stepSize);
28    
29     if (lsStatus < 0)
30     return -1;
31     else
32     return 1;
33     }
34    
35     void SDMinimizer::prepareStep(){
36    
37     for(int i = 0; i < direction.size(); i++){
38     direction[i] = -curG[i];
39     }
40     }
41     int SDMinimizer::checkConvg(){
42     double fTol;
43     double relativeFTol; // relative tolerance
44     double deltaF;
45     double gTol;
46     double relativeGTol;
47     double gnorm;
48    
49    
50     // test function tolerance test
51     fTol =paramSet->getFTol();
52     relativeFTol = fTol * std::max(1.0,fabs(curF)); // relative tolerance
53     deltaF = prevF - curF;
54    
55     if (fabs(deltaF) <= relativeFTol) {
56    
57     if (bVerbose){
58 tim 1830 cout << "function value tolerance test passed" << std::endl;
59 gezelter 1490 cout << "ftol = " << fTol
60 tim 1830 << "\tdeltaf = " << deltaF<< std::endl;
61 gezelter 1490 }
62     return CONVG_FTOL;
63     }
64    
65     //gradient tolerance test
66     gTol = paramSet->getGTol();
67     relativeGTol = gTol * std::max(1.0,fabs(curF));
68    
69     #ifndef IS_MPI
70     gnorm = sqrt(dotProduct(curG, curG));
71     #else
72     double localDP;
73     double globalDP;
74    
75     localDP = dotProduct(curG, curG);
76     MPI_Allreduce(&localDP, &globalDP, 1, MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
77     gnorm = sqrt(globalDP);
78     #endif
79    
80     if (gnorm <= relativeGTol) {
81 tim 1830 cout << "gradient tolerance test" << std::endl;
82 gezelter 1490 cout << "gnorm = " << gnorm
83 tim 1830 << "\trelativeGTol = " << relativeGTol<< std::endl;
84 gezelter 1490 return CONVG_GTOL;
85     }
86    
87     //absolute gradient tolerance test
88    
89     if (gnorm <= gTol) {
90 tim 1830 cout << "absolute gradient tolerance test" << std::endl;
91 gezelter 1490 cout << "gnorm = " << gnorm
92 tim 1830 << "\tgTol = " << gTol<< std::endl;
93 gezelter 1490 return CONVG_ABSGTOL;
94     }
95    
96     return CONVG_UNCONVG;
97     }
98    

Properties

Name Value
svn:executable *