ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/minimizers/SDMinimizer.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-4/src/minimizers/SDMinimizer.cpp (file contents):
Revision 1883 by tim, Thu Dec 2 05:17:10 2004 UTC vs.
Revision 1884 by tim, Tue Dec 14 19:08:44 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines