22 #include "tools/Communicator.h"
33 void ActionWithVessel::registerKeywords(
Keywords& keys){
34 keys.
add(
"optional",
"TOL",
"this keyword can be used to speed up your calculation. When accumulating sums in which the individual "
35 "terms are numbers inbetween zero and one it is assumed that terms less than a certain tolerance "
36 "make only a small contribution to the sum. They can thus be safely ignored as can the the derivatives "
37 "wrt these small quantities.");
38 keys.
reserve(
"hidden",
"NL_TOL",
"this keyword can be used to speed up your calculation. It must be used in conjuction with the TOL "
39 "keyword and the value for NL_TOL must be set less than the value for TOL. This keyword ensures that "
40 "quantities, which are much less than TOL and which will thus not added to the sums being accumulated "
41 "are not calculated at every step. They are only calculated when the neighbor list is updated.");
42 keys.
addFlag(
"SERIAL",
false,
"do the calculation in serial. Do not parallelize");
50 contributorsAreUnlocked(false),
51 weightHasDerivatives(false)
89 functions.push_back( dynamic_cast<Vessel*>(bv) );
106 parse(thiskey,input);
110 for(
unsigned i=1;;++i){
119 parse(thiskey, input);
120 if(input.size()!=0)
addVessel(thiskey,input);
131 unsigned tmpnval,nvals=2, bufsize=0;
132 for(
unsigned i=0;i<
functions.size();++i){
136 tmpnval=
functions[i]->getNumberOfTerms();
137 plumed_massert( tmpnval>1 ,
"There should always be at least two terms - one for the value and one for the weight");
138 if(tmpnval>nvals) nvals=tmpnval;
173 plumed_massert(
read,
"you must have a call to readVesselKeywords somewhere" );
176 if(
serial){ stride=1; rank=0; }
210 for(
unsigned k=0;k<
thisval.size();++k){
223 for(
unsigned j=0;j<
functions.size();++j){
247 const unsigned& off,
const double& df,
Vessel* valout ){
248 plumed_dbg_assert( off<stride );
263 forcesToApply.assign( forcesToApply.size(),0.0 );
264 bool wasforced=
false;
268 for(
unsigned j=0;j<forcesToApply.size();++j) forcesToApply[j]+=
tmpforces[j];
275 plumed_merror(
"If your function is periodic you need to add a retrieveDomain function so that ActionWithVessel can retrieve the domain");
BridgeVessel * addBridgingVessel(ActionWithVessel *tome)
Add a bridging vessel to the list of vessels.
void setupMPICommunication(Communicator &comm)
Setup MPI communication if things are activated/deactivated on different nodes.
bool parseNumbered(const std::string &key, const int no, T &t)
Parse one numbered keyword as generic type.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
unsigned current
The numerical index of the task we are curently performing.
unsigned current_buffer_start
The buffers we use for mpi summing DistributionFunction objects.
Vessel * create(std::string keyword, const VesselOptions &da)
Create a distribution function of the specified type.
Log & log
Reference to the log stream.
std::vector< double > buffer
std::vector< Vessel * > functions
Pointers to the functions we are using on each value.
void chainRuleForElementDerivatives(const unsigned &, const unsigned &, const double &, Vessel *)
Merge the derivatives.
std::vector< bool > thisval_wasset
A boolean that makes sure we don't accumulate very wrong derivatives.
void deactivate(const unsigned ii)
Make a particular element inactive.
bool read
This is used to ensure that we have properly read the action.
virtual unsigned getNumberOfDerivatives()=0
Get the number of derivatives for final calculated quantity.
void error(const std::string &msg) const
Crash calculation and print documentation.
std::vector< double > tmpforces
Tempory storage for forces.
virtual void mergeDerivatives(const unsigned &ider, const double &df)
void add(const std::string &t, const std::string &k, const std::string &d)
Add a new keyword of type t with name k and description d.
void addVessel(const std::string &name, const std::string &input, const int numlab=0, const std::string thislab="")
Add a vessel to the list of vessels.
virtual void calculate()=0
Calculate an Action.
friend class BridgeVessel
double nl_tolerance
Tolerance for quantities being put in neighbor lists.
void runAllTasks()
Calculate the values of all the vessels.
bool getForcesFromVessels(std::vector< double > &forcesToApply)
Retrieve the forces from all the vessels (used in apply)
void readVesselKeywords()
Complete the setup of this object (this routine must be called after construction of ActionWithValue)...
std::vector< double > thisval
The value of the current element in the sum.
void setOutputAction(ActionWithVessel *myOutputAction)
Setup the action we are outputting to.
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
This class holds the keywords and their documentation.
int Get_rank() const
Obtain the rank of the present process.
This class allows you to calculate the vessel in one ActionWithVessel.
virtual void retrieveDomain(std::string &min, std::string &max)
What are the domains of the base quantities.
void clearAfterTask()
Clear tempory data that is calculated for each task.
This class is used to bring the relevant information to the Action constructor.
bool numbered(const std::string &k) const
Check if numbered keywords are allowed for this action.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Base class for all the input Actions.
VesselRegister & vesselRegister()
void accumulateDerivative(const unsigned &ider, const double &df)
This is used to accumulate the derivatives when we merge using chainRuleForElementDerivatives.
bool calculateAllVessels()
This loops over all the vessels calculating them and also sets all the element derivatives equal to z...
virtual void prepare()
Prepare an Action for calculation This can be used by Action if they need some special preparation be...
virtual void deactivate_task()
Activate the jth colvar Deactivate the current task in future loops.
std::string getKeyword(const unsigned i) const
Return the ith keyword.
void reserve(const std::string &t, const std::string &k, const std::string &d, const bool isvessel=false)
Reserve a keyword.
bool style(const std::string &k, const std::string &t) const
Check if the keyword with name k has style t.
virtual void performTask(const unsigned &j)=0
Calculate one of the functions in the distribution.
DynamicList< unsigned > taskList
The list of tasks we have to perform.
unsigned current_buffer_stride
This class is used to pass the input to Vessels.
unsigned getNumberOfVessels() const
Get the number of vessels.
bool exists(const std::string &k) const
Check if there is a keyword with name k.
virtual void doJobsRequiredBeforeTaskList()
Do any jobs that are required before the task list is undertaken.
unsigned bufstart
The start of this Vessel's buffer in buffer in the underlying ActionWithVessel.
void checkRead()
Check that readin was fine.
bool serial
Do all calculations in serial.
unsigned fullSize() const
Return the total number of elements in the list.
int Get_size() const
Obtain the number of processes.
std::vector< double > derivatives
Vector of derivatives for the object.
virtual void clearDerivativesAfterTask(const unsigned &)
double tolerance
The tolerance on the accumulators.
const Keywords & keywords
bool contributorsAreUnlocked
The terms in the series are locked.
void resizeFunctions()
Resize all the functions when the number of derivatives change.
void Sum(T *, int)
Wrapper for MPI_Allreduce with MPI_SUM.
unsigned getNumberActive() const
Return the number of elements that are currently active.
void addFlag(const std::string &k, const bool def, const std::string &d)
Add a falg with name k that is by default on if def is true and off if def is false. d should provide a description of the flag.
void finishComputations()
Finish running all the calculations.
unsigned size() const
Return the number of defined keywords.
This is used to create PLMD::Action objects that are computed by calculating the same function multip...