Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

colvarvalue Class Reference

Value of a collective variable: this is a metatype which can be set at runtime. By default it is set to be a scalar number, and can be treated like that in all operations (this is done by most implementations). More...

#include <colvarvalue.h>

List of all members.

Public Types

enum  Type {
  type_notset, type_scalar, type_vector, type_unitvector,
  type_quaternion
}
 Possible types of value. More...

Public Member Functions

 colvarvalue ()
 Default constructor: this class defaults to a scalar number and always behaves like it unless you change its type.
 colvarvalue (Type const &vti)
 Constructor from a type specification.
 colvarvalue (cvm::real const &x)
 Copy constructor from real base type.
 colvarvalue (cvm::rvector const &v)
 Copy constructor from rvector base type (Note: this sets automatically a type , if you want a you must set it explicitly).
 colvarvalue (cvm::rvector const &v, Type const &vti)
 Copy constructor from rvector base type (additional argument to make possible to choose a .
 colvarvalue (cvm::quaternion const &q)
 Copy constructor from quaternion base type.
 colvarvalue (colvarvalue const &x)
 Copy constructor from another .
void reset ()
 Set to the null value for the data type currently defined.
void apply_constraints ()
 If the variable has constraints (e.g. unitvector or quaternion), transform it to satisfy them; use it when the is not calculated from objects, but manipulated by you.
Type type () const
 Get the current type.
void type (Type const &vti)
 Set the type explicitly.
void type (colvarvalue const &x)
 Set the type after another .
cvm::real norm2 () const
 Square norm of this colvarvalue.
cvm::real norm () const
 Norm of this colvarvalue.
colvarvalue inverse () const
 Return the value whose scalar product with this value is 1.
cvm::real dist2 (colvarvalue const &x2) const
 Square distance between this and another.
colvarvalue dist2_grad (colvarvalue const &x2) const
 Derivative with respect to this of the square distance.
colvarvalueoperator= (colvarvalue const &x)
 Assignment operator (type of x is checked).
void operator+= (colvarvalue const &x)
void operator-= (colvarvalue const &x)
void operator *= (cvm::real const &a)
void operator/= (cvm::real const &a)
 operator cvm::real () const
 operator cvm::rvector () const
 operator cvm::quaternion () const
bool is_scalar ()
 Special case when the variable is a real number, and all operations are defined.
void undef_op () const
 Undefined operation.
void error_lside (Type const &vt) const
void error_rside (Type const &vt) const
size_t output_width (size_t const &real_width)

Static Public Member Functions

bool type_checking ()
void check_types (colvarvalue const &x1, colvarvalue const &x2)
 Ensure that the two types are the same within a binary operator.
void inner_opt (colvarvalue const &x, std::vector< colvarvalue >::iterator &xv, std::vector< colvarvalue >::iterator const &xv_end, std::vector< cvm::real >::iterator &inner)
 Optimized routine for the inner product of one collective variable with an array.
void inner_opt (colvarvalue const &x, std::list< colvarvalue >::iterator &xv, std::list< colvarvalue >::iterator const &xv_end, std::vector< cvm::real >::iterator &inner)
 Optimized routine for the inner product of one collective variable with an array.
void p2leg_opt (colvarvalue const &x, std::vector< colvarvalue >::iterator &xv, std::vector< colvarvalue >::iterator const &xv_end, std::vector< cvm::real >::iterator &inner)
 Optimized routine for the second order Legendre polynomial, (3cos^2(w)-1)/2, of one collective variable with an array.
void p2leg_opt (colvarvalue const &x, std::list< colvarvalue >::iterator &xv, std::list< colvarvalue >::iterator const &xv_end, std::vector< cvm::real >::iterator &inner)
 Optimized routine for the second order Legendre polynomial of one collective variable with an array.

Public Attributes

cvm::real real_value
 Real data member.
cvm::rvector rvector_value
 Vector data member.
cvm::quaternion quaternion_value
 Quaternion data member.
Type value_type
 Current type of this colvarvalue object.

Static Public Attributes

std::string const type_desc [colvarvalue::type_quaternion+1]
 Runtime description of value types.
size_t const dof_num [colvarvalue::type_quaternion+1]
 Number of degrees of freedom for each type.


Detailed Description

Value of a collective variable: this is a metatype which can be set at runtime. By default it is set to be a scalar number, and can be treated like that in all operations (this is done by most implementations).

allows to be treat different data types. By default, a variable is a scalar number. If you want to use it as another type, you should declare and initialize a variable as

 colvarvalue x (colvarvalue::type_xxx); 
where type_xxx is a value within the enum. Alternatively, initialize x with (colvarvalue::type_xxx) at a later stage.

Given a colvarvalue variable x which is not yet assigned (and thus has not yet a type) it is also possible to correctly assign the type with

 x = y; 
if y is correctly set. Otherwise, an error will be raised if the of x is different from the of y.

Also, every operator (either unary or binary) on a object performs one or more checks on the to avoid errors such as initializing a three-dimensional vector with a scalar number (legal otherwise).

Special case: when reading from a stream, there is no way to detect the and safely handle errors at the same time. Hence, when using

 is >> x; 
x MUST already have a type correcly set up for properly parsing the stream. An error will be raised otherwise. Usually this is not the problem, because objects are first initialized in the configuration, and the stream operation will be performed only when reading restart files.

No problem of course with the output streams:

 os << x;
will print a different output according to the value of colvarvalue::value_type, and the width of such output is returned by colvarvalue::output_width()

Note on performance: at every operation between two objects, their two flags will be checked for a match. In a long array of objects this is time consuming: a few static functions are defined ("xxx_opt" functions) within the class, which only check the matching once for a large array, and execute different loops according to the type. You should do the same for every time consuming loop involving operations on objects if you want e.g. to optimize your colvar bias.

Definition at line 57 of file colvarvalue.h.


Member Enumeration Documentation

enum colvarvalue::Type
 

Possible types of value.

These three cover most possibilities of data type one can devise. If you need to implement a new colvar with a very complex data type, it's better to put an allocatable class here

Enumeration values:
type_notset  Undefined type.
type_scalar  Scalar number, implemented as (default).
type_vector  3-dimensional vector, implemented as
type_unitvector  3-dimensional unit vector, implemented as
type_quaternion  4-dimensional unit vector representing a rotation, implemented as

Definition at line 66 of file colvarvalue.h.

Referenced by error_lside(), and error_rside().

00066             {
00068     type_notset,
00070     type_scalar,
00072     type_vector,
00074     type_unitvector,
00076     type_quaternion
00077   };


Constructor & Destructor Documentation

colvarvalue::colvarvalue  )  [inline]
 

Default constructor: this class defaults to a scalar number and always behaves like it unless you change its type.

Definition at line 104 of file colvarvalue.h.

Referenced by dist2_grad(), and inverse().

00105     : real_value (0.0), value_type (type_scalar)
00106   {}

colvarvalue::colvarvalue Type const &  vti  )  [inline]
 

Constructor from a type specification.

Definition at line 109 of file colvarvalue.h.

00110     : value_type (vti)
00111   {
00112     reset();
00113   }

colvarvalue::colvarvalue cvm::real const &  x  )  [inline]
 

Copy constructor from real base type.

Definition at line 116 of file colvarvalue.h.

00117     : real_value (x), value_type (type_scalar)
00118   {}

colvarvalue::colvarvalue cvm::rvector const &  v  )  [inline]
 

Copy constructor from rvector base type (Note: this sets automatically a type , if you want a you must set it explicitly).

Definition at line 123 of file colvarvalue.h.

00124     : rvector_value (v), value_type (type_vector)
00125   {}

colvarvalue::colvarvalue cvm::rvector const &  v,
Type const &  vti
[inline]
 

Copy constructor from rvector base type (additional argument to make possible to choose a .

Definition at line 130 of file colvarvalue.h.

00131     : rvector_value (v), value_type (vti)
00132   {}

colvarvalue::colvarvalue cvm::quaternion const &  q  )  [inline]
 

Copy constructor from quaternion base type.

Definition at line 135 of file colvarvalue.h.

00136     : quaternion_value (q), value_type (type_quaternion)
00137   {}

colvarvalue::colvarvalue colvarvalue const &  x  )  [inline]
 

Copy constructor from another .

Definition at line 140 of file colvarvalue.h.

References quaternion_value, real_value, rvector_value, and value_type.

00141     : value_type (x.value_type)
00142   {
00143     reset();
00144 
00145     switch (x.value_type) {
00146     case type_scalar:
00147       real_value = x.real_value;
00148       break;
00149     case type_vector: 
00150     case type_unitvector:
00151       rvector_value = x.rvector_value;
00152       break;
00153     case type_quaternion:
00154       quaternion_value = x.quaternion_value;
00155       break;
00156     case type_notset:
00157     default:
00158       break;
00159     }
00160   }


Member Function Documentation

void colvarvalue::apply_constraints  )  [inline]
 

If the variable has constraints (e.g. unitvector or quaternion), transform it to satisfy them; use it when the is not calculated from objects, but manipulated by you.

Definition at line 331 of file colvarvalue.h.

References colvarmodule::quaternion::norm2(), colvarmodule::rvector::norm2(), quaternion_value, rvector_value, type_notset, type_quaternion, type_scalar, type_unitvector, and type_vector.

Referenced by colvar::calc_runave(), operator>>(), and colvar::update().

00332 {
00333   switch (value_type) {
00334   case colvarvalue::type_scalar:
00335     break;
00336   case colvarvalue::type_vector:
00337     break;
00338   case colvarvalue::type_unitvector:
00339     rvector_value /= std::sqrt (rvector_value.norm2());
00340     break;
00341   case colvarvalue::type_quaternion:
00342     quaternion_value /= std::sqrt (quaternion_value.norm2());
00343     break;
00344   case colvarvalue::type_notset:
00345   default:
00346     break;
00347   }  
00348 }

void colvarvalue::check_types colvarvalue const &  x1,
colvarvalue const &  x2
[inline, static]
 

Ensure that the two types are the same within a binary operator.

Definition at line 694 of file colvarvalue.h.

References colvarmodule::fatal_error(), colvarmodule::log(), type_desc, and value_type.

Referenced by dist2(), dist2_grad(), inner_opt(), operator *(), operator+(), operator+=(), operator-(), operator-=(), and p2leg_opt().

00696 {
00697   if (x1.value_type != x2.value_type) {
00698     cvm::log ("x1 type = "+cvm::to_str (x1.value_type)+
00699               ", x2 type = "+cvm::to_str (x2.value_type)+"\n");
00700     cvm::fatal_error ("Performing an operation between two colvar "
00701                       "values with different types, \""+
00702                       colvarvalue::type_desc[x1.value_type]+
00703                       "\" and \""+
00704                       colvarvalue::type_desc[x2.value_type]+
00705                       "\".\n");
00706   }
00707 }

cvm::real colvarvalue::dist2 colvarvalue const &  x2  )  const [inline]
 

Square distance between this and another.

Definition at line 633 of file colvarvalue.h.

References check_types(), colvarmodule::quaternion::dist2(), norm2(), quaternion_value, real_value, rvector_value, type_checking(), type_notset, type_quaternion, type_scalar, type_unitvector, type_vector, and undef_op().

Referenced by colvar::cvc::dist2(), and colvar::dist2().

00634 {
00635   if (colvarvalue::type_checking())
00636     colvarvalue::check_types (*this, x2);
00637 
00638   switch (this->value_type) {
00639   case colvarvalue::type_scalar:
00640     return (this->real_value - x2.real_value)*(this->real_value - x2.real_value);
00641   case colvarvalue::type_vector:
00642     return (this->rvector_value - x2.rvector_value).norm2();
00643   case colvarvalue::type_unitvector:
00644     // angle between (*this) and x2 is the distance
00645     return std::acos (this->rvector_value * x2.rvector_value) * std::acos (this->rvector_value * x2.rvector_value);
00646   case colvarvalue::type_quaternion:
00647     // angle between (*this) and x2 is the distance, the quaternion
00648     // object has it implemented internally
00649     return this->quaternion_value.dist2 (x2.quaternion_value);
00650   case colvarvalue::type_notset:
00651   default:
00652     this->undef_op();
00653     return 0.0;
00654   };
00655 }

colvarvalue colvarvalue::dist2_grad colvarvalue const &  x2  )  const [inline]
 

Derivative with respect to this of the square distance.

Definition at line 658 of file colvarvalue.h.

References check_types(), colvarvalue(), colvarmodule::quaternion::dist2_grad(), quaternion_value, real_value, rvector_value, type_checking(), type_notset, type_quaternion, type_scalar, type_unitvector, type_vector, undef_op(), colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z.

Referenced by colvar::cvc::dist2_lgrad(), and colvar::cvc::dist2_rgrad().

00659 {
00660   if (colvarvalue::type_checking())
00661     colvarvalue::check_types (*this, x2);
00662 
00663   switch (this->value_type) {
00664   case colvarvalue::type_scalar:
00665     return 2.0 * (this->real_value - x2.real_value);
00666   case colvarvalue::type_vector:
00667     return 2.0 * (this->rvector_value - x2.rvector_value);
00668   case colvarvalue::type_unitvector:
00669     {
00670       cvm::rvector const &v1 = this->rvector_value;
00671       cvm::rvector const &v2 = x2.rvector_value;
00672       cvm::real const cos_t = v1 * v2;
00673       cvm::real const sin_t = std::sqrt (1.0 - cos_t*cos_t);
00674       return colvarvalue ( 2.0 * sin_t *
00675                            cvm::rvector ( (-1.0) * sin_t * v2.x +
00676                                           cos_t/sin_t * (v1.x - cos_t*v2.x),
00677                                           (-1.0) * sin_t * v2.y +
00678                                           cos_t/sin_t * (v1.y - cos_t*v2.y),
00679                                           (-1.0) * sin_t * v2.z +
00680                                           cos_t/sin_t * (v1.z - cos_t*v2.z)
00681                                           ),
00682                            colvarvalue::type_unitvector );
00683     }
00684   case colvarvalue::type_quaternion:
00685     return this->quaternion_value.dist2_grad (x2.quaternion_value);
00686   case colvarvalue::type_notset:
00687   default:
00688     this->undef_op();
00689     return colvarvalue (colvarvalue::type_notset);
00690   };
00691 }

void colvarvalue::error_lside Type const &  vt  )  const
 

Trying to assign this object to another object set with a different type

Definition at line 34 of file colvarvalue.C.

References colvarmodule::fatal_error(), and Type.

Referenced by operator=().

00035 {
00036   cvm::fatal_error ("Trying to use a colvar value with type \""+
00037                     type_desc[vt]+"\" as one of type \""+
00038                     type_desc[this->value_type]+"\".\n");
00039 }    

void colvarvalue::error_rside Type const &  vt  )  const
 

Trying to assign another object set with a different type to this object

Definition at line 26 of file colvarvalue.C.

References colvarmodule::fatal_error(), and Type.

Referenced by operator cvm::quaternion(), operator cvm::real(), and operator cvm::rvector().

00027 {
00028   cvm::fatal_error ("Trying to assign a colvar value with type \""+
00029                     type_desc[this->value_type]+"\" to one with type \""+
00030                     type_desc[vt]+"\".\n");
00031 }    

void colvarvalue::inner_opt colvarvalue const &  x,
std::list< colvarvalue >::iterator &  xv,
std::list< colvarvalue >::iterator const &  xv_end,
std::vector< cvm::real >::iterator &  inner
[static]
 

Optimized routine for the inner product of one collective variable with an array.

Definition at line 76 of file colvarvalue.C.

References check_types(), quaternion_value, real_value, rvector_value, type_quaternion, type_scalar, type_unitvector, type_vector, undef_op(), and value_type.

00080 {
00081   // doing type check only once, here
00082   colvarvalue::check_types (x, *xv);
00083 
00084   std::list<colvarvalue>::iterator &xvi = xv;
00085   std::vector<cvm::real>::iterator  &ii = inner;
00086 
00087   switch (x.value_type) {
00088   case colvarvalue::type_scalar:
00089     while (xvi != xv_end) {
00090       *(ii++) += (xvi++)->real_value * x.real_value;
00091     }
00092     break;
00093   case colvarvalue::type_vector:
00094   case colvarvalue::type_unitvector:
00095     while (xvi != xv_end) {
00096       *(ii++) += (xvi++)->rvector_value * x.rvector_value;
00097     }
00098     break;
00099   case colvarvalue::type_quaternion:
00100     while (xvi != xv_end) {
00101       *(ii++) += ((xvi++)->quaternion_value).cosine (x.quaternion_value);
00102     }
00103     break;
00104   default:
00105     x.undef_op();
00106   };
00107 }

void colvarvalue::inner_opt colvarvalue const &  x,
std::vector< colvarvalue >::iterator &  xv,
std::vector< colvarvalue >::iterator const &  xv_end,
std::vector< cvm::real >::iterator &  inner
[static]
 

Optimized routine for the inner product of one collective variable with an array.

Definition at line 43 of file colvarvalue.C.

References check_types(), quaternion_value, real_value, rvector_value, type_quaternion, type_scalar, type_unitvector, type_vector, undef_op(), and value_type.

Referenced by colvar::calc_coor_acf(), and colvar::calc_vel_acf().

00047 {
00048   // doing type check only once, here
00049   colvarvalue::check_types (x, *xv);
00050 
00051   std::vector<colvarvalue>::iterator &xvi = xv;
00052   std::vector<cvm::real>::iterator    &ii = inner;
00053 
00054   switch (x.value_type) {
00055   case colvarvalue::type_scalar:
00056     while (xvi != xv_end) {
00057       *(ii++) += (xvi++)->real_value * x.real_value;
00058     }
00059     break;
00060   case colvarvalue::type_vector:
00061   case colvarvalue::type_unitvector:
00062     while (xvi != xv_end) {
00063       *(ii++) += (xvi++)->rvector_value * x.rvector_value;
00064     }
00065     break;
00066   case colvarvalue::type_quaternion:
00067     while (xvi != xv_end) {
00068       *(ii++) += ((xvi++)->quaternion_value).cosine (x.quaternion_value);
00069     }
00070     break;
00071   default:
00072     x.undef_op();
00073   };
00074 }

colvarvalue colvarvalue::inverse  )  const [inline]
 

Return the value whose scalar product with this value is 1.

Definition at line 369 of file colvarvalue.h.

References colvarvalue(), colvarmodule::quaternion::q0, colvarmodule::quaternion::q1, colvarmodule::quaternion::q2, colvarmodule::quaternion::q3, quaternion_value, real_value, rvector_value, type_notset, type_quaternion, type_scalar, type_vector, undef_op(), colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z.

Referenced by colvar::calc().

00370 {
00371   switch (value_type) {
00372   case colvarvalue::type_scalar:
00373     return colvarvalue (1.0/real_value);
00374   case colvarvalue::type_vector:
00375     return colvarvalue (cvm::rvector (1.0/rvector_value.x,
00376                                       1.0/rvector_value.y,
00377                                       1.0/rvector_value.z));
00378   case colvarvalue::type_quaternion:
00379     return colvarvalue (cvm::quaternion (1.0/quaternion_value.q0,
00380                                          1.0/quaternion_value.q1,
00381                                          1.0/quaternion_value.q2,
00382                                          1.0/quaternion_value.q3));
00383   case colvarvalue::type_notset:
00384   default:
00385     undef_op();
00386   }  
00387   return colvarvalue();
00388 }

bool colvarvalue::is_scalar  )  [inline]
 

Special case when the variable is a real number, and all operations are defined.

Definition at line 248 of file colvarvalue.h.

00249   {
00250     return (value_type == type_scalar);
00251   }

cvm::real colvarvalue::norm  )  const [inline]
 

Norm of this colvarvalue.

Definition at line 201 of file colvarvalue.h.

00202   {
00203     return std::sqrt (this->norm2());
00204   }

cvm::real colvarvalue::norm2  )  const [inline]
 

Square norm of this colvarvalue.

Definition at line 352 of file colvarvalue.h.

References colvarmodule::quaternion::norm2(), type_notset, type_quaternion, type_scalar, type_unitvector, and type_vector.

Referenced by colvar::calc_coor_acf(), colvar::rmsd::calc_value(), colvar::inertia::calc_value(), colvar::gyration::calc_value(), colvar::calc_vel_acf(), dist2(), and colvar::distance_dir::dist2().

00353 {
00354   switch (value_type) {
00355   case colvarvalue::type_scalar:
00356     return (this->real_value)*(this->real_value);
00357   case colvarvalue::type_vector:
00358   case colvarvalue::type_unitvector:
00359     return (this->rvector_value).norm2();
00360   case colvarvalue::type_quaternion:
00361     return (this->quaternion_value).norm2();
00362   case colvarvalue::type_notset:
00363   default:
00364     return 0.0;
00365   }  
00366 }

void colvarvalue::operator *= cvm::real const &  a  )  [inline]
 

Definition at line 459 of file colvarvalue.h.

References quaternion_value, real_value, rvector_value, type_notset, type_quaternion, type_scalar, type_unitvector, type_vector, and undef_op().

00460 {
00461   switch (value_type) {
00462   case colvarvalue::type_scalar:
00463     real_value *= a;
00464     break;
00465   case colvarvalue::type_vector:
00466   case colvarvalue::type_unitvector:
00467     rvector_value *= a;
00468     break;
00469   case colvarvalue::type_quaternion:
00470     quaternion_value *= a;
00471     break;
00472   case colvarvalue::type_notset:
00473   default:
00474     undef_op();
00475   }
00476 }

colvarvalue::operator cvm::quaternion  )  const [inline]
 

Definition at line 241 of file colvarvalue.h.

References error_rside().

00242   {
00243     if (value_type != type_quaternion) error_rside (type_quaternion);
00244     return quaternion_value;
00245   }

colvarvalue::operator cvm::real  )  const [inline]
 

Definition at line 226 of file colvarvalue.h.

References error_rside(), and type_scalar.

00227   {
00228     if (value_type != type_scalar) error_rside (type_scalar);
00229     return real_value;
00230   }

colvarvalue::operator cvm::rvector  )  const [inline]
 

Definition at line 233 of file colvarvalue.h.

References error_rside(), and type_vector.

00234   {
00235     if ( (value_type != type_vector) && (value_type != type_unitvector))
00236       error_rside (type_vector);
00237     return rvector_value;
00238   }

void colvarvalue::operator+= colvarvalue const &  x  )  [inline]
 

Definition at line 418 of file colvarvalue.h.

References check_types(), quaternion_value, real_value, rvector_value, type_checking(), type_notset, type_quaternion, type_scalar, type_unitvector, type_vector, and undef_op().

00419 {
00420   if (colvarvalue::type_checking())
00421     colvarvalue::check_types (*this, x);
00422 
00423   switch (this->value_type) {
00424   case colvarvalue::type_scalar:
00425     this->real_value += x.real_value;
00426     break;
00427   case colvarvalue::type_vector:
00428   case colvarvalue::type_unitvector:
00429     this->rvector_value += x.rvector_value;
00430     break;
00431   case colvarvalue::type_quaternion:
00432     this->quaternion_value += x.quaternion_value;
00433     break;
00434   case colvarvalue::type_notset:
00435   default:
00436     undef_op();
00437   }
00438 }

void colvarvalue::operator-= colvarvalue const &  x  )  [inline]
 

Definition at line 440 of file colvarvalue.h.

References check_types(), quaternion_value, real_value, rvector_value, type_checking(), type_notset, type_quaternion, type_scalar, type_unitvector, type_vector, and undef_op().

00441 {
00442   if (colvarvalue::type_checking())
00443     colvarvalue::check_types (*this, x);
00444 
00445   switch (value_type) {
00446   case colvarvalue::type_scalar:
00447     real_value -= x.real_value; break;
00448   case colvarvalue::type_vector:
00449   case colvarvalue::type_unitvector:
00450     rvector_value -= x.rvector_value; break;
00451   case colvarvalue::type_quaternion:
00452     quaternion_value -= x.quaternion_value; break;
00453   case colvarvalue::type_notset:
00454   default:
00455     undef_op();
00456   }
00457 }

void colvarvalue::operator/= cvm::real const &  a  )  [inline]
 

Definition at line 478 of file colvarvalue.h.

References quaternion_value, real_value, rvector_value, type_notset, type_quaternion, type_scalar, type_unitvector, type_vector, and undef_op().

00479 {
00480   switch (value_type) {
00481   case colvarvalue::type_scalar:
00482     real_value /= a; break;
00483   case colvarvalue::type_vector:
00484   case colvarvalue::type_unitvector:
00485     rvector_value /= a; break;
00486   case colvarvalue::type_quaternion:
00487     quaternion_value /= a; break;
00488   case colvarvalue::type_notset:
00489   default:
00490     undef_op();
00491   }
00492 }

colvarvalue & colvarvalue::operator= colvarvalue const &  x  )  [inline]
 

Assignment operator (type of x is checked).

Definition at line 391 of file colvarvalue.h.

References error_lside(), quaternion_value, real_value, rvector_value, type_notset, type_quaternion, type_scalar, type_unitvector, type_vector, undef_op(), and value_type.

00392 {
00393   if (this->value_type != type_notset)
00394     if (this->value_type != x.value_type) 
00395       error_lside (x.value_type);
00396 
00397   this->value_type = x.value_type;
00398   
00399   switch (this->value_type) {
00400   case colvarvalue::type_scalar:
00401     this->real_value = x.real_value;
00402     break;
00403   case colvarvalue::type_vector:
00404   case colvarvalue::type_unitvector:
00405     this->rvector_value = x.rvector_value;
00406     break;
00407   case colvarvalue::type_quaternion:
00408     this->quaternion_value = x.quaternion_value;
00409     break;
00410   case colvarvalue::type_notset:
00411   default:
00412     undef_op();
00413     break;
00414   }
00415   return *this;
00416 }

size_t colvarvalue::output_width size_t const &  real_width  ) 
 

�Give the number of characters required to output this colvarvalue, given the current type assigned and the number of characters for a real number

Definition at line 245 of file colvarvalue.C.

References type_notset, type_quaternion, type_scalar, type_unitvector, and type_vector.

Referenced by colvar::parse_analysis(), and colvar::write_traj_label().

00246 {
00247   switch (this->value_type) {
00248   case colvarvalue::type_scalar:
00249     return real_width;
00250   case colvarvalue::type_vector:
00251   case colvarvalue::type_unitvector:
00252     return cvm::rvector::output_width (real_width);
00253   case colvarvalue::type_quaternion:
00254     return cvm::quaternion::output_width (real_width);
00255   case colvarvalue::type_notset:
00256   default:
00257     return 0;
00258   }
00259 }

void colvarvalue::p2leg_opt colvarvalue const &  x,
std::list< colvarvalue >::iterator &  xv,
std::list< colvarvalue >::iterator const &  xv_end,
std::vector< cvm::real >::iterator &  inner
[static]
 

Optimized routine for the second order Legendre polynomial of one collective variable with an array.

Definition at line 152 of file colvarvalue.C.

References check_types(), colvarmodule::fatal_error(), colvarmodule::rvector::norm(), quaternion_value, rvector_value, type_quaternion, type_scalar, type_unitvector, type_vector, undef_op(), and value_type.

00156 {
00157   // doing type check only once, here
00158   colvarvalue::check_types (x, *xv);
00159 
00160   std::list<colvarvalue>::iterator &xvi = xv;
00161   std::vector<cvm::real>::iterator  &ii = inner;
00162 
00163   switch (x.value_type) {
00164   case colvarvalue::type_scalar:
00165     cvm::fatal_error ("Error: cannot calculate Legendre polynomials "
00166                       "for scalar variables.\n");
00167     break;
00168   case colvarvalue::type_vector:
00169     while (xvi != xv_end) {
00170       cvm::real const cosine = 
00171         ((xvi)->rvector_value * x.rvector_value) /
00172         ((xvi)->rvector_value.norm() * x.rvector_value.norm());
00173       xvi++;
00174       *(ii++) += 1.5*cosine*cosine - 0.5;
00175     }
00176     break;
00177   case colvarvalue::type_unitvector:
00178     while (xvi != xv_end) {
00179       cvm::real const cosine = (xvi++)->rvector_value * x.rvector_value;
00180       *(ii++) += 1.5*cosine*cosine - 0.5;
00181     }
00182     break;
00183   case colvarvalue::type_quaternion:
00184     while (xvi != xv_end) {
00185       cvm::real const cosine = (xvi++)->quaternion_value.cosine (x.quaternion_value);
00186       *(ii++) += 1.5*cosine*cosine - 0.5;
00187     }
00188     break;
00189   default:
00190     x.undef_op();
00191   };
00192 }

void colvarvalue::p2leg_opt colvarvalue const &  x,
std::vector< colvarvalue >::iterator &  xv,
std::vector< colvarvalue >::iterator const &  xv_end,
std::vector< cvm::real >::iterator &  inner
[static]
 

Optimized routine for the second order Legendre polynomial, (3cos^2(w)-1)/2, of one collective variable with an array.

Definition at line 110 of file colvarvalue.C.

References check_types(), colvarmodule::fatal_error(), colvarmodule::rvector::norm(), quaternion_value, rvector_value, type_quaternion, type_scalar, type_unitvector, type_vector, undef_op(), and value_type.

Referenced by colvar::calc_p2coor_acf().

00114 {
00115   // doing type check only once, here
00116   colvarvalue::check_types (x, *xv);
00117 
00118   std::vector<colvarvalue>::iterator &xvi = xv;
00119   std::vector<cvm::real>::iterator    &ii = inner;
00120 
00121   switch (x.value_type) {
00122   case colvarvalue::type_scalar:
00123     cvm::fatal_error ("Error: cannot calculate Legendre polynomials "
00124                       "for scalar variables.\n");
00125     break;
00126   case colvarvalue::type_vector:
00127     while (xvi != xv_end) {
00128       cvm::real const cosine = 
00129         ((xvi)->rvector_value * x.rvector_value) /
00130         ((xvi)->rvector_value.norm() * x.rvector_value.norm());
00131       xvi++;
00132       *(ii++) += 1.5*cosine*cosine - 0.5;
00133     }
00134     break;
00135   case colvarvalue::type_unitvector:
00136     while (xvi != xv_end) {
00137       cvm::real const cosine = (xvi++)->rvector_value * x.rvector_value;
00138       *(ii++) += 1.5*cosine*cosine - 0.5;
00139     }
00140     break;
00141   case colvarvalue::type_quaternion:
00142     while (xvi != xv_end) {
00143       cvm::real const cosine = (xvi++)->quaternion_value.cosine (x.quaternion_value);
00144       *(ii++) += 1.5*cosine*cosine - 0.5;
00145     }
00146     break;
00147   default:
00148     x.undef_op();
00149   };
00150 }

void colvarvalue::reset  )  [inline]
 

Set to the null value for the data type currently defined.

Definition at line 311 of file colvarvalue.h.

References quaternion_value, colvarmodule::real, real_value, rvector_value, type_notset, type_quaternion, type_scalar, type_unitvector, and type_vector.

Referenced by colvar::calc(), colvar::calc_runave(), colvar::reset_bias_force(), and colvar::update().

00312 {
00313   switch (value_type) {
00314   case colvarvalue::type_scalar:
00315     real_value = cvm::real (0.0);
00316     break;
00317   case colvarvalue::type_vector:
00318   case colvarvalue::type_unitvector:
00319     rvector_value = cvm::rvector (0.0, 0.0, 0.0);
00320     break;
00321   case colvarvalue::type_quaternion:
00322     quaternion_value = cvm::quaternion (0.0, 0.0, 0.0, 0.0);
00323     break;
00324   case colvarvalue::type_notset:
00325   default:
00326     break;
00327   }  
00328 }

void colvarvalue::type colvarvalue const &  x  )  [inline]
 

Set the type after another .

Definition at line 190 of file colvarvalue.h.

References value_type.

00191   {
00192     reset();
00193     value_type = x.value_type;
00194     reset();
00195   }

void colvarvalue::type Type const &  vti  )  [inline]
 

Set the type explicitly.

Definition at line 182 of file colvarvalue.h.

00183   {
00184     reset();
00185     value_type = vti;
00186     reset();
00187   }

Type colvarvalue::type  )  const [inline]
 

Get the current type.

Definition at line 176 of file colvarvalue.h.

Referenced by colvar::alpha_angles::alpha_angles(), colvar::angle::angle(), colvar::calc(), colvar::calc_runave(), colvar::colvar(), colvar::communicate_forces(), colvar::coordnum::coordnum(), colvar::dihedPC::dihedPC(), colvar::dihedral::dihedral(), colvar::distance::distance(), colvar::distance_dir::distance_dir(), colvar::distance_inv::distance_inv(), colvar::distance_vec::distance_vec(), colvar::distance_xy::distance_xy(), colvar::distance_z::distance_z(), colvar::eigenvector::eigenvector(), colvar::enable(), colvar::gyration::gyration(), colvar::h_bond::h_bond(), colvar::inertia::inertia(), colvar::inertia_z::inertia_z(), operator<<(), operator>>(), colvar::orientation::orientation(), colvar::orientation_angle::orientation_angle(), colvar::read_restart(), colvar::rmsd::rmsd(), colvar::selfcoordnum::selfcoordnum(), colvar::spin_angle::spin_angle(), colvar::tilt::tilt(), colvar::cvc::type(), and colvar::type().

00177   {
00178     return value_type;
00179   }

bool colvarvalue::type_checking  )  [inline, static]
 

Definition at line 97 of file colvarvalue.h.

Referenced by dist2(), dist2_grad(), operator *(), operator+(), operator+=(), operator-(), and operator-=().

00098   {
00099     return true;
00100   }

void colvarvalue::undef_op  )  const
 

Undefined operation.

Definition at line 19 of file colvarvalue.C.

References colvarmodule::fatal_error(), and type_desc.

Referenced by dist2(), dist2_grad(), inner_opt(), inverse(), operator *(), operator *=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator=(), operator>>(), and p2leg_opt().

00020 {
00021   cvm::fatal_error ("Error: Undefined operation on a colvar of type \""+
00022                     colvarvalue::type_desc[this->value_type]+"\".\n");
00023 }


Member Data Documentation

size_t const colvarvalue::dof_num [static]
 

Initial value:

  { 0, 1, 3, 2, 3 }
Number of degrees of freedom for each type.

Definition at line 15 of file colvarvalue.C.

cvm::quaternion colvarvalue::quaternion_value
 

Quaternion data member.

Definition at line 92 of file colvarvalue.h.

Referenced by apply_constraints(), colvar::orientation::apply_force(), colvar::orientation::calc_value(), colvarvalue(), dist2(), colvar::orientation::dist2(), dist2_grad(), colvar::orientation::dist2_lgrad(), colvar::orientation::dist2_rgrad(), inner_opt(), inverse(), operator *(), operator *=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator=(), operator>>(), p2leg_opt(), and reset().

cvm::real colvarvalue::real_value
 

Real data member.

Definition at line 86 of file colvarvalue.h.

Referenced by colvar::spin_angle::apply_force(), colvar::tilt::apply_force(), colvar::orientation_angle::apply_force(), colvar::alpha_angles::apply_force(), colvar::eigenvector::apply_force(), colvar::rmsd::apply_force(), colvar::inertia_z::apply_force(), colvar::inertia::apply_force(), colvar::gyration::apply_force(), colvar::distance_inv::apply_force(), colvar::distance_xy::apply_force(), colvar::distance_z::apply_force(), colvar::distance::apply_force(), colvar::selfcoordnum::apply_force(), colvar::h_bond::apply_force(), colvar::coordnum::apply_force(), colvar::dihedral::apply_force(), colvar::angle::apply_force(), colvar_grid< size_t >::bin_to_value_scalar(), colvar::calc(), colvar::eigenvector::calc_force_invgrads(), colvar::rmsd::calc_force_invgrads(), colvar::gyration::calc_force_invgrads(), colvar::distance_xy::calc_force_invgrads(), colvar::distance_z::calc_force_invgrads(), colvar::distance::calc_force_invgrads(), colvar::dihedral::calc_force_invgrads(), colvar::angle::calc_force_invgrads(), colvar::rmsd::calc_gradients(), colvar::gyration::calc_gradients(), colvar::distance_inv::calc_gradients(), colvar::distance_xy::calc_gradients(), colvar::distance_z::calc_gradients(), colvar::eigenvector::calc_Jacobian_derivative(), colvar::rmsd::calc_Jacobian_derivative(), colvar::gyration::calc_Jacobian_derivative(), colvar::distance_xy::calc_Jacobian_derivative(), colvar::distance_z::calc_Jacobian_derivative(), colvar::distance::calc_Jacobian_derivative(), colvar::angle::calc_Jacobian_derivative(), colvar::spin_angle::calc_value(), colvar::tilt::calc_value(), colvar::orientation_angle::calc_value(), colvar::dihedPC::calc_value(), colvar::alpha_angles::calc_value(), colvar::eigenvector::calc_value(), colvar::rmsd::calc_value(), colvar::inertia_z::calc_value(), colvar::inertia::calc_value(), colvar::gyration::calc_value(), colvar::distance_inv::calc_value(), colvar::distance_xy::calc_value(), colvar::distance_z::calc_value(), colvar::distance::calc_value(), colvar::selfcoordnum::calc_value(), colvar::h_bond::calc_value(), colvar::coordnum::calc_value(), colvar::dihedral::calc_value(), colvar::angle::calc_value(), colvarvalue(), colvar::cvc::debug_gradients(), dist2(), colvar::spin_angle::dist2(), colvar::dihedral::dist2(), dist2_grad(), colvar::distance_z::dist2_lgrad(), colvar::spin_angle::dist2_lgrad(), colvar::dihedral::dist2_lgrad(), colvar::distance_z::dist2_rgrad(), colvar::spin_angle::dist2_rgrad(), colvar::dihedral::dist2_rgrad(), inner_opt(), inverse(), operator *(), operator *=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator=(), operator>>(), reset(), simple_scalar_dist_functions(), colvar::update(), colvar_grid< size_t >::value_to_bin_scalar(), colvar::distance_z::wrap(), colvar::spin_angle::wrap(), and colvar::dihedral::wrap().

cvm::rvector colvarvalue::rvector_value
 

Vector data member.

Definition at line 89 of file colvarvalue.h.

Referenced by apply_constraints(), colvar::distance_dir::apply_force(), colvar::distance_vec::apply_force(), colvar::distance_dir::calc_value(), colvar::distance_vec::calc_value(), colvarvalue(), dist2(), colvar::distance_dir::dist2(), colvar::distance_vec::dist2(), dist2_grad(), colvar::distance_dir::dist2_lgrad(), colvar::distance_vec::dist2_lgrad(), colvar::distance_dir::dist2_rgrad(), colvar::distance_vec::dist2_rgrad(), inner_opt(), inverse(), operator *(), operator *=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator=(), operator>>(), p2leg_opt(), and reset().

std::string const colvarvalue::type_desc [static]
 

Initial value:

  { "not_set",
    "scalar number",
    "3-dimensional vector",
    "3-dimensional unit vector",
    "4-dimensional unit vector" }
Runtime description of value types.

Definition at line 8 of file colvarvalue.C.

Referenced by check_types(), and undef_op().

Type colvarvalue::value_type
 

Current type of this colvarvalue object.

Definition at line 95 of file colvarvalue.h.

Referenced by check_types(), colvarvalue(), inner_opt(), operator *(), operator+(), operator-(), operator/(), operator=(), p2leg_opt(), and type().


The documentation for this class was generated from the following files:
Generated on Mon May 20 04:07:22 2013 for NAMD by  doxygen 1.3.9.1