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

colvar_grid_scalar Class Reference

Class for accumulating a scalar function on a grid. More...

#include <colvargrid.h>

Inheritance diagram for colvar_grid_scalar:

colvar_grid< cvm::real > colvarparse List of all members.

Public Member Functions

 colvar_grid_scalar ()
 Default constructor.
 colvar_grid_scalar (colvar_grid_scalar const &g)
 Copy constructor (needed because of the grad pointer).
 ~colvar_grid_scalar ()
 Destructor.
 colvar_grid_scalar (std::vector< int > const &nx_i)
 Constructor from specific sizes arrays.
 colvar_grid_scalar (std::vector< colvar * > &colvars, bool margin=0)
 Constructor from a vector of colvars.
void acc_value (std::vector< int > const &ix, cvm::real const &new_value, size_t const &imult=0)
 Accumulate the value.
const cvm::realgradient_finite_diff (const std::vector< int > &ix0)
 Return the gradient of the scalar field from finite differences.
virtual cvm::real value_output (std::vector< int > const &ix, size_t const &imult=0)
 Return the value of the function at ix divided by its number of samples (if the count grid is defined).
virtual void value_input (std::vector< int > const &ix, cvm::real const &new_value, size_t const &imult=0, bool add=false)
 Get the value from a formatted output and transform it into the internal representation (it may have been rescaled or manipulated).
std::istream & read_restart (std::istream &is)
 Read the grid from a restart.
std::ostream & write_restart (std::ostream &os)
 Write the grid to a restart.
cvm::real maximum_value ()
 Return the highest value.
cvm::real minimum_value ()
 Return the lowest value.

Public Attributes

colvar_grid_countsamples
 Provide the associated sample count by which each binned value should be divided.

Detailed Description

Class for accumulating a scalar function on a grid.

Definition at line 840 of file colvargrid.h.


Constructor & Destructor Documentation

colvar_grid_scalar::colvar_grid_scalar  ) 
 

Default constructor.

Definition at line 50 of file colvargrid.C.

References cvm.

00051   : colvar_grid<cvm::real>(), samples (NULL), grad (NULL)
00052 {}

colvar_grid_scalar::colvar_grid_scalar colvar_grid_scalar const &  g  ) 
 

Copy constructor (needed because of the grad pointer).

Definition at line 54 of file colvargrid.C.

References cvm.

00055   : colvar_grid<cvm::real> (g), samples (NULL), grad (NULL)
00056 {
00057   grad = new cvm::real[nd];
00058 }

colvar_grid_scalar::~colvar_grid_scalar  ) 
 

Destructor.

Definition at line 72 of file colvargrid.C.

00073 {
00074   if (grad) {
00075     delete [] grad;
00076     grad = NULL;
00077   }
00078 }

colvar_grid_scalar::colvar_grid_scalar std::vector< int > const &  nx_i  ) 
 

Constructor from specific sizes arrays.

Definition at line 60 of file colvargrid.C.

References cvm.

00061   : colvar_grid<cvm::real> (nx_i, 0.0, 1), samples (NULL)
00062 {
00063   grad = new cvm::real[nd];
00064 }

colvar_grid_scalar::colvar_grid_scalar std::vector< colvar * > &  colvars,
bool  margin = 0
 

Constructor from a vector of colvars.

Definition at line 66 of file colvargrid.C.

References cvm.

00067   : colvar_grid<cvm::real> (colvars, 0.0, 1, margin), samples (NULL)
00068 {
00069   grad = new cvm::real[nd];
00070 }


Member Function Documentation

void colvar_grid_scalar::acc_value std::vector< int > const &  ix,
cvm::real const &  new_value,
size_t const &  imult = 0
[inline]
 

Accumulate the value.

Definition at line 865 of file colvargrid.h.

References colvar_grid< cvm::real >::address(), colvar_grid_count::incr_count(), and samples.

Referenced by colvarbias_meta::project_hills().

00868   {
00869     // only legal value of imult here is 0
00870     data[address (ix)] += new_value;
00871     if (samples)
00872       samples->incr_count (ix);
00873   }

const cvm::real* colvar_grid_scalar::gradient_finite_diff const std::vector< int > &  ix0  )  [inline]
 

Return the gradient of the scalar field from finite differences.

Definition at line 876 of file colvargrid.h.

References colvar_grid< cvm::real >::address(), colvarmodule::fatal_error(), and colvar_grid< cvm::real >::wrap().

00877   {
00878     cvm::real A0, A1;
00879     std::vector<int> ix;
00880     if (nd != 2) cvm::fatal_error ("Finite differences available in dimension 2 only.");
00881     for (int n = 0; n < nd; n++) {
00882       ix = ix0;
00883       A0 = data[address (ix)];
00884       ix[n]++; wrap (ix);
00885       A1 = data[address (ix)];
00886       ix[1-n]++; wrap (ix);
00887       A1 += data[address (ix)];
00888       ix[n]--; wrap (ix);
00889       A0 += data[address (ix)];
00890       grad[n] = 0.5 * (A1 - A0) / widths[n];
00891     }
00892     return grad; 
00893   }

cvm::real colvar_grid_scalar::maximum_value  )  [inline]
 

Return the highest value.

Definition at line 942 of file colvargrid.h.

Referenced by colvarbias_meta::write_restart().

00943   {
00944     cvm::real max = data[0];
00945     for (size_t i = 0; i < nt; i++) {
00946       if (data[i] > max) max = data[i];
00947     }
00948     return max;
00949   }

cvm::real colvar_grid_scalar::minimum_value  )  [inline]
 

Return the lowest value.

Definition at line 952 of file colvargrid.h.

00953   {
00954     cvm::real min = data[0];
00955     for (size_t i = 0; i < nt; i++) {
00956       if (data[i] < min) min = data[i];
00957     }
00958     return min;
00959   }

std::istream & colvar_grid_scalar::read_restart std::istream &  is  ) 
 

Read the grid from a restart.

Definition at line 80 of file colvargrid.C.

References colvarmodule::debug(), colvarmodule::log(), colvar_grid< cvm::real >::parse_params(), and colvar_grid< cvm::real >::read_raw().

Referenced by colvarbias_meta::read_restart().

00081 {
00082   size_t const start_pos = is.tellg();
00083   std::string key, conf;
00084   if ((is >> key) && (key == std::string ("grid_parameters"))) {
00085     is.seekg (start_pos, std::ios::beg);
00086     is >> colvarparse::read_block ("grid_parameters", conf);
00087     parse_params (conf);
00088   } else {
00089     cvm::log ("Grid parameters are missing in the restart file, using those from the configuration.\n");
00090     is.seekg (start_pos, std::ios::beg);
00091   }
00092   read_raw (is);
00093   if (cvm::debug()) 
00094     cvm::log ("Here\n");
00095   return is;
00096 }

virtual void colvar_grid_scalar::value_input std::vector< int > const &  ix,
cvm::real const &  new_value,
size_t const &  imult = 0,
bool  add = false
[inline, virtual]
 

Get the value from a formatted output and transform it into the internal representation (it may have been rescaled or manipulated).

Reimplemented from colvar_grid< cvm::real >.

Definition at line 914 of file colvargrid.h.

References colvar_grid< cvm::real >::address(), colvarmodule::fatal_error(), colvar_grid_count::new_count(), samples, and colvar_grid< T >::value().

00918   {
00919     if (imult > 0)
00920       cvm::fatal_error ("Error: trying to access a component "
00921                         "larger than 1 in a scalar data grid.\n");
00922     if (add) {
00923       if (samples)
00924         data[address (ix)] += new_value * samples->new_count (ix);
00925       else
00926         data[address (ix)] += new_value;
00927     } else {
00928       if (samples)
00929         data[address (ix)] = new_value * samples->value (ix);
00930       else
00931         data[address (ix)] = new_value;
00932     }
00933   }

virtual cvm::real colvar_grid_scalar::value_output std::vector< int > const &  ix,
size_t const &  imult = 0
[inline, virtual]
 

Return the value of the function at ix divided by its number of samples (if the count grid is defined).

Reimplemented from colvar_grid< cvm::real >.

Definition at line 897 of file colvargrid.h.

References colvar_grid< cvm::real >::address(), colvarmodule::fatal_error(), colvarmodule::real, samples, and colvar_grid< T >::value().

00899   {
00900     if (imult > 0)
00901       cvm::fatal_error ("Error: trying to access a component "
00902                         "larger than 1 in a scalar data grid.\n");
00903     if (samples)
00904       return (samples->value (ix) > 0) ?
00905         (data[address (ix)] / cvm::real (samples->value (ix))) :
00906         0.0;
00907     else
00908       return data[address (ix)];
00909   }

std::ostream & colvar_grid_scalar::write_restart std::ostream &  os  ) 
 

Write the grid to a restart.

Definition at line 98 of file colvargrid.C.

References colvar_grid< cvm::real >::write_params(), and colvar_grid< cvm::real >::write_raw().

Referenced by colvarbias_meta::write_restart().

00099 {
00100   write_params (os);
00101   write_raw (os);
00102   return os;
00103 }


Member Data Documentation

colvar_grid_count* colvar_grid_scalar::samples
 

Provide the associated sample count by which each binned value should be divided.

Definition at line 846 of file colvargrid.h.

Referenced by acc_value(), value_input(), and value_output().


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 04:59:33 2009 for NAMD by  doxygen 1.3.9.1