DistanceConstraint.h 2.45 KB
Newer Older
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
15 16 17
//  DistanceConstraint.h
//
////////////////////////////////////////////////////////////////////////////////
18
// $Id: DistanceConstraint.h,v 1.8 2009-05-15 04:38:48 fgygi Exp $
19 20 21 22 23 24 25

#ifndef DISTANCECONSTRAINT_H
#define DISTANCECONSTRAINT_H

#include "Constraint.h"
#include <cassert>
#include <cmath> // fabs
26

27 28 29 30
class AtomSet;

class DistanceConstraint : public Constraint
{
31
  std::string name1_, name2_;
32 33
  int    ia1_, ia2_, is1_, is2_;
  double m1_, m2_, m1_inv_, m2_inv_;
Francois Gygi committed
34
  double distance_, velocity_, force_, weight_, tol_;
35

36
  public:
37

38
  DistanceConstraint(std::string name, std::string name1, std::string name2,
39
                     double distance, double velocity, double tolerance):
40
  name1_(name1), name2_(name2), distance_(distance),
Francois Gygi committed
41 42 43
  velocity_(velocity), tol_(tolerance), m1_(0.0), m2_(0.0)
  {
    name_ = name;
44 45 46
    names_.resize(2);
    names_[0] = name1_;
    names_[1] = name2_;
Francois Gygi committed
47 48
    force_ = 0.0;
    weight_ = 1.0;
49
  }
50
  ~DistanceConstraint(void) {}
51

52
  std::string type(void) const { return "distance"; }
53 54
  double value(void) const { return distance_; }
  double velocity(void) const { return velocity_; }
Francois Gygi committed
55 56
  double force(void) const { return force_; }
  double weight(void) const { return weight_; }
57 58 59 60 61 62 63 64 65
  double tolerance(void) const { return tol_; }
  void set_value(double value)
  {
    distance_ = fabs(value);
  }
  void set_velocity(double velocity)
  {
    velocity_ = velocity;
  }
66

67
  void setup(const AtomSet& atoms);
68
  int dofs(void) const { return 1; }
69
  void update(double dt);
70 71 72 73 74 75 76
  bool enforce_r(const std::vector<std::vector<double> > &r0,
                 std::vector<std::vector<double> > &rp) const;
  bool enforce_v(const std::vector<std::vector<double> > &r0,
                 std::vector<std::vector<double> > &v0) const;
  void compute_force(const std::vector<std::vector<double> > &r0,
                     const std::vector<std::vector<double> > &f);
  std::ostream& print( std::ostream& os );
77

78 79
};
#endif