PetaVision  Alpha
AdaptiveTimeScaleController.hpp
1 /*
2  * AdaptiveTimeScaleController.hpp
3  *
4  * Created on: Aug 18, 2016
5  * Author: pschultz
6  */
7 
8 #ifndef ADAPTIVETIMESCALECONTROLLER_HPP_
9 #define ADAPTIVETIMESCALECONTROLLER_HPP_
10 
11 #include "checkpointing/CheckpointEntry.hpp"
12 #include "checkpointing/CheckpointerDataInterface.hpp"
13 #include "columns/Communicator.hpp"
14 #include "io/PrintStream.hpp"
15 #include "structures/MPIBlock.hpp"
16 #include <vector>
17 
18 namespace PV {
19 
21  public:
22  struct TimeScaleInfo {
23  std::vector<double> mTimeScale;
24  std::vector<double> mTimeScaleMax;
25  std::vector<double> mTimeScaleTrue;
26  };
27 
29  char const *name,
30  int batchWidth,
31  double baseMax,
32  double baseMin,
33  double tauFactor,
34  double growthFactor,
35  bool writeTimeScaleFieldnames,
36  Communicator *comm);
37  virtual ~AdaptiveTimeScaleController();
38  virtual Response::Status registerData(Checkpointer *checkpointer) override;
39  virtual std::vector<double>
40  calcTimesteps(double timeValue, std::vector<double> const &rawTimeScales);
41  void writeTimestepInfo(double timeValue, std::vector<PrintStream *> &streams);
42 
43  // Data members
44  protected:
45  char *mName;
46  int mBatchWidth;
47  double mBaseMax;
48  double mBaseMin;
49  double mTauFactor;
50  double mGrowthFactor;
51  bool mWriteTimeScaleFieldnames;
52  Communicator *mCommunicator;
53 
54  TimeScaleInfo mTimeScaleInfo, mOldTimeScaleInfo;
55  std::vector<double> mOldTimeScale;
56  std::vector<double> mOldTimeScaleTrue;
57 };
58 
60  public:
62  std::string const &name,
63  MPIBlock const *mpiBlock,
65  : CheckpointEntry(name, mpiBlock), mTimeScaleInfoPtr(timeScaleInfoPtr) {}
67  std::string const &objName,
68  std::string const &dataName,
69  MPIBlock const *mpiBlock,
71  : CheckpointEntry(objName, dataName, mpiBlock), mTimeScaleInfoPtr(timeScaleInfoPtr) {}
72  virtual void write(std::string const &checkpointDirectory, double simTime, bool verifyWritesFlag)
73  const override;
74  virtual void read(std::string const &checkpointDirectory, double *simTimePtr) const override;
75  virtual void remove(std::string const &checkpointDirectory) const override;
76 
77  private:
79 };
80 
81 } /* namespace PV */
82 
83 #endif /* ADAPTIVETIMESCALECONTROLLER_HPP_ */