ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/types/PolynomialBondType.hpp
(Generate patch)

Comparing branches/new_design/OOPSE-3.0/src/types/PolynomialBondType.hpp (file contents):
Revision 1745 by tim, Wed Nov 17 01:11:36 2004 UTC vs.
Revision 1798 by tim, Tue Nov 30 03:32:12 2004 UTC

# Line 25 | Line 25
25  
26   /**
27   * @file PolynomialBondType.hpp
28 < * @author    tlin
29 < * @date  11/01/2004
28 > * @author    teng lin
29 > * @date  11/16/2004
30   * @version 1.0
31   */
32  
33   #ifndef TYPES_POLYNOMIALBONDTYPE_HPP
34   #define TYPES_POLYNOMIALBONDTYPE_HPP
35  
36 +
37 + #include "math/Polynomial.hpp"
38 + #include "types/BondType.hpp"
39 +
40   namespace oopse {
41  
42 + /**
43 + * @class PolynomialBondType PolynomialBondType.hpp "types/PolynomialBondType.hpp"
44 + * @todo documentation
45 + */
46   class PolynomialBondType : public BondType{
47  
48      public:
49 <        PolynomialBondType();
49 >        PolynomialBondType() {}
50 >        PolynomialBondType(double r0, const std::vector<int>& power,
51 >            const std::vector<double>& coeff) : BondType(r0){
52 >        }
53  
54 <        void calcForce(double r, double & V, double & dVdr) = 0;
54 >        void setCoefficient(int power, double coefficient) {
55 >            polynomial_.setCoefficient(power, coefficient);
56 >        }
57 >
58 >        double getCoefficient(int power) {
59 >            return polynomial_.getCoefficient(power);
60 >        }
61          
62 +        void calcForce(double r, double & V, double & dVdr) {
63 +            double delta = r - r0;
64 +            V = polynomial_.evaluate(delta);
65 +            dVdr = polynomial_.evaluateDerivative(delta);
66 +
67 +        }
68 +
69 +        friend std::ostream& operator <<(std::ostream& os, PolynomialBondType& pbt);
70 +        
71      private:
72          
73 +        DoublePolynomial polynomial_;
74   };
75  
76 + std::ostream& operator <<(std::ostream& os, PolynomialBondType& pbt) {
77 +    typename DoublePolynomial::PolynomialIterator i;
78  
79 +    i = pbt.polynomial_.begin();
80 +    
81 +    if (i == pbt.polynomial_.end()) {
82 +        os << "This PolynomialBondType contains nothing" << std::endl;
83 +        return os;
84 +    }
85 +
86 +    os << "This PolynomialBondType contains below terms:" << std::endl;    
87 +    
88 +    while(true){
89 +        os << i->second << "*" << "(r - " << pbt.getEquilibriumBondLength() << ")" << "^" << i->first;
90 +
91 +        if (++i == pbt.polynomial_.end()) {
92 +            //if we reach the end of the polynomial pair, write out a newline and then escape the loop
93 +            os << std::endl;
94 +            break;
95 +        } else {
96 +            //otherwise, write out a "+"
97 +            os << " + ";
98 +        }
99 +    }
100 +    
101 +    return os;
102 + }
103 +
104 +
105   } //end namespace oopse
106 < #endif //TYPES_POLYNOMIALBONDTYPE_HPP
106 > #endif //TYPES_POLYNOMIALBONDTYPE_HPP

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines