22 #ifndef __PLUMED_tools_Grid_h
23 #define __PLUMED_tools_Grid_h
66 class KernelFunctions;
72 std::vector< std::vector<double> >
der_;
91 Grid(
const std::string& funcl, std::vector<Value*> args,
const std::vector<std::string> & gmin,
92 const std::vector<std::string> & gmax,
const std::vector<unsigned> & nbin,
bool dospline,
93 bool usederiv,
bool doclear=
true);
95 Grid(
const std::string& funcl,
const std::vector<std::string> &names,
const std::vector<std::string> & gmin,
96 const std::vector<std::string> & gmax,
const std::vector<unsigned> & nbin,
bool dospline,
97 bool usederiv,
bool doclear,
const std::vector<bool> &isperiodic,
const std::vector<std::string> &pmin,
98 const std::vector<std::string> &pmax );
100 void Init(
const std::string & funcl,
const std::vector<std::string> &names,
const std::vector<std::string> & gmin,
101 const std::vector<std::string> & gmax,
const std::vector<unsigned> & nbin,
bool dospline,
bool usederiv,
102 bool doclear,
const std::vector<bool> &isperiodic,
const std::vector<std::string> &pmin,
const std::vector<std::string> &pmax);
104 std::vector<std::string>
getMin()
const;
106 std::vector<std::string>
getMax()
const;
108 std::vector<double>
getDx()
const;
112 std::vector<unsigned>
getNbin()
const;
121 std::vector<unsigned>
getIndices(
unsigned index)
const;
122 std::vector<unsigned>
getIndices(
const std::vector<double> & x)
const;
123 unsigned getIndex(
const std::vector<unsigned> & indices)
const;
124 unsigned getIndex(
const std::vector<double> & x)
const;
125 std::vector<double>
getPoint(
unsigned index)
const;
126 std::vector<double>
getPoint(
const std::vector<unsigned> & indices)
const;
127 std::vector<double>
getPoint(
const std::vector<double> & x)
const;
129 void getPoint(
unsigned index,std::vector<double> & point)
const;
130 void getPoint(
const std::vector<unsigned> & indices,std::vector<double> & point)
const;
131 void getPoint(
const std::vector<double> & x,std::vector<double> & point)
const;
134 std::vector<unsigned>
getNeighbors(
unsigned index,
const std::vector<unsigned> & neigh)
const;
135 std::vector<unsigned>
getNeighbors(
const std::vector<unsigned> & indices,
const std::vector<unsigned> & neigh)
const;
136 std::vector<unsigned>
getNeighbors(
const std::vector<double> & x,
const std::vector<unsigned> & neigh)
const;
142 static Grid*
create(
const std::string&,std::vector<Value*>,
IFile&,
bool,
bool,
bool);
145 const std::vector<std::string>&,
const std::vector<std::string>&,
146 const std::vector<unsigned>&,
bool,
bool,
bool);
148 virtual unsigned getSize()
const;
150 virtual double getValue(
unsigned index)
const;
151 virtual double getValue(
const std::vector<unsigned> & indices)
const;
152 virtual double getValue(
const std::vector<double> & x)
const;
159 virtual double getValueAndDerivatives(
const std::vector<unsigned> & indices, std::vector<double>& der)
const;
163 virtual void setValue(
unsigned index,
double value);
164 virtual void setValue(
const std::vector<unsigned> & indices,
double value);
167 virtual void setValueAndDerivatives(
const std::vector<unsigned> & indices,
double value, std::vector<double>& der);
169 virtual void addValue(
unsigned index,
double value);
170 virtual void addValue(
const std::vector<unsigned> & indices,
double value);
173 virtual void addValueAndDerivatives(
const std::vector<unsigned> & indices,
double value, std::vector<double>& der);
198 std::map<unsigned,double>
map_;
199 typedef std::map<unsigned,double>::const_iterator
iterator;
200 std::map< unsigned,std::vector<double> >
der_;
201 typedef std::map<unsigned,std::vector<double> >::const_iterator
iterator_der;
207 SparseGrid(
const std::string& funcl, std::vector<Value*> args,
const std::vector<std::string> & gmin,
208 const std::vector<std::string> & gmax,
209 const std::vector<unsigned> & nbin,
bool dospline,
bool usederiv):
210 Grid(funcl,args,gmin,gmax,nbin,dospline,usederiv,false){}
224 double getValue(
unsigned index)
const;
229 void setValue(
unsigned index,
double value);
233 void addValue(
unsigned index,
double value);
virtual double projectInnerLoop(double &input, double &v)=0
double getValueAndDerivatives(unsigned index, std::vector< double > &der) const
get grid value and derivatives
Grid project(const std::vector< std::string > &proj, WeightBase *ptr2obj)
project a high dimensional grid onto a low dimensional one: this should be changed at some time to en...
unsigned getMaxSize() const
std::map< unsigned, std::vector< double > > der_
void writeToFile(OFile &)
dump grid on file
void addValue(unsigned index, double value)
add to grid value
std::vector< double > dx_
double projectOuterLoop(double &v)
double getValue(unsigned index) const
get grid value
virtual void clear()
clear grid
Grid(const std::string &funcl, std::vector< Value * > args, const std::vector< std::string > &gmin, const std::vector< std::string > &gmax, const std::vector< unsigned > &nbin, bool dospline, bool usederiv, bool doclear=true)
this constructor here is Value-aware
virtual double getValueAndDerivatives(unsigned index, std::vector< double > &der) const
get grid value and derivatives
unsigned getDimension() const
get grid dimension
std::vector< unsigned > nbin_
double projectOuterLoop(double &v)
virtual void addValue(unsigned index, double value)
add to grid value
std::map< unsigned, std::vector< double > >::const_iterator iterator_der
void addValueAndDerivatives(unsigned index, double value, std::vector< double > &der)
add to grid value and derivatives
std::vector< unsigned > getIndices(unsigned index) const
methods to handle grid indices
virtual void setValue(unsigned index, double value)
set grid value
std::map< unsigned, double >::const_iterator iterator
std::vector< double > grid_
std::vector< double > getDx() const
get bin size
virtual double getValue(unsigned index) const
get grid value
virtual void addValueAndDerivatives(unsigned index, double value, std::vector< double > &der)
add to grid value and derivatives
virtual void applyFunctionAllValuesAndDerivatives(double(*func)(double val), double(*funcder)(double valder))
apply function: takes pointer to function that accepts a double and apply
void addKernel(const KernelFunctions &kernel)
add a kernel function to the grid
std::vector< unsigned > getSplineNeighbors(const std::vector< unsigned > &indices) const
get "neighbors" for spline
std::vector< std::string > str_min_
virtual double getMinValue() const
get minimum value
std::vector< std::string > getArgNames() const
get argument names of this grid
virtual unsigned getSize() const
get grid size
std::vector< std::vector< double > > der_
void projectOnLowDimension(double &val, std::vector< int > &varHigh, WeightBase *ptr2obj)
double projectInnerLoop(double &input, double &v)
virtual void writeToFile(OFile &)
dump grid on file
void setValueAndDerivatives(unsigned index, double value, std::vector< double > &der)
set grid value and derivatives
double getBinVolume() const
get bin volume
virtual void scaleAllValuesAndDerivatives(const double &scalef)
Scale all grid values and derivatives by a constant factor.
std::vector< std::string > getMax() const
get upper boundary
virtual void setValueAndDerivatives(unsigned index, double value, std::vector< double > &der)
set grid value and derivatives
unsigned getSize() const
get grid size
unsigned getIndex(const std::vector< unsigned > &indices) const
virtual double projectOuterLoop(double &v)=0
std::vector< std::string > str_max_
std::vector< std::string > getMin() const
get lower boundary
std::vector< unsigned > getNbin() const
get number of bins
void Init(const std::string &funcl, const std::vector< std::string > &names, const std::vector< std::string > &gmin, const std::vector< std::string > &gmax, const std::vector< unsigned > &nbin, bool dospline, bool usederiv, bool doclear, const std::vector< bool > &isperiodic, const std::vector< std::string > &pmin, const std::vector< std::string > &pmax)
this is the real initializator
SparseGrid(const std::string &funcl, std::vector< Value * > args, const std::vector< std::string > &gmin, const std::vector< std::string > &gmax, const std::vector< unsigned > &nbin, bool dospline, bool usederiv)
std::vector< double > getPoint(unsigned index) const
virtual double getMaxValue() const
get maximum value
std::vector< double > max_
void setOutputFmt(std::string ss)
set output format
void writeHeader(OFile &file)
write header for grid file
void setValue(unsigned index, double value)
set grid value
std::vector< unsigned > getNeighbors(unsigned index, const std::vector< unsigned > &neigh) const
get neighbors
std::vector< std::string > argnames
std::map< unsigned, double > map_
double projectInnerLoop(double &input, double &v)
static Grid * create(const std::string &, std::vector< Value * >, IFile &, bool, bool, bool)
read grid from file
std::vector< double > min_
std::vector< bool > getIsPeriodic() const
get if periodic