8 #include "AdaptiveTimeScaleProbe.hpp" 9 #include "columns/Messages.hpp" 13 AdaptiveTimeScaleProbe::AdaptiveTimeScaleProbe(
char const *name, HyPerCol *hc) {
17 AdaptiveTimeScaleProbe::AdaptiveTimeScaleProbe() {}
19 AdaptiveTimeScaleProbe::~AdaptiveTimeScaleProbe() {
delete mAdaptiveTimeScaleController; }
21 int AdaptiveTimeScaleProbe::initialize(
char const *name, HyPerCol *hc) {
38 parent->parameters()->ioParamStringRequired(ioFlag, name,
"targetName", &targetName);
42 parent->parameters()->ioParamValue(ioFlag, name,
"baseMax", &mBaseMax, mBaseMax);
46 parent->parameters()->ioParamValue(ioFlag, name,
"baseMin", &mBaseMin, mBaseMin);
50 parent->parameters()->ioParamValue(ioFlag, name,
"tauFactor", &tauFactor, tauFactor);
54 parent->parameters()->ioParamValue(ioFlag, name,
"growthFactor", &mGrowthFactor, mGrowthFactor);
59 if (ioFlag != PARAMS_IO_READ) {
62 pvAssert(!parent->parameters()->presentAndNotBeenRead(name,
"textOutputFlag"));
63 if (parent->parameters()->
present(name,
"writeTimeScales")) {
64 bool writeTimeScales = (parent->parameters()->
value(name,
"writeTimeScales") != 0);
66 WarnLog() << getDescription()
67 <<
" sets writeTimeScales, which is obsolete. Use textOutputFlag instead.\n";
69 else if (parent->parameters()->
present(name,
"textOutputFlag")) {
70 Fatal() <<
"writeTimeScales is obsolete as it is redundant with textOutputFlag. " 71 << getDescription() <<
" sets these flags to opposite values.\n";
75 Fatal() <<
"writeTimeScales is obsolete as it is redundant with textOutputFlag. " 76 << getDescription() <<
" sets writeTimeScales to " 77 << (writeTimeScales ?
"true" :
"false")
78 <<
" but the default value of textOutputFlag is " 85 pvAssert(!parent->parameters()->presentAndNotBeenRead(name,
"textOutputFlag"));
87 parent->parameters()->ioParamValue(
90 "writeTimeScaleFieldnames",
91 &mWriteTimeScaleFieldnames,
92 mWriteTimeScaleFieldnames);
97 std::shared_ptr<CommunicateInitInfoMessage const> message) {
102 mTargetProbe = message->lookup<
BaseProbe>(std::string(targetName));
103 if (mTargetProbe ==
nullptr) {
104 if (parent->getCommunicator()->commRank() == 0) {
105 Fatal() << getDescription() <<
": targetName \"" << targetName
106 <<
"\" is not a probe in the HyPerCol.\n";
108 MPI_Barrier(parent->getCommunicator()->communicator());
111 return Response::SUCCESS;
114 Response::Status AdaptiveTimeScaleProbe::allocateDataStructures() {
115 auto status = ColProbe::allocateDataStructures();
120 if (parent->getCommunicator()->commRank() == 0) {
121 Fatal() << getDescription() <<
": target probe \"" << mTargetProbe->getDescription()
122 <<
"\" does not have the correct numValues (" << mTargetProbe->
getNumValues()
125 MPI_Barrier(parent->getCommunicator()->communicator());
128 allocateTimeScaleController();
129 return Response::SUCCESS;
132 void AdaptiveTimeScaleProbe::allocateTimeScaleController() {
140 mWriteTimeScaleFieldnames,
141 parent->getCommunicator());
149 mAdaptiveTimeScaleController->registerData(checkpointer);
150 return Response::SUCCESS;
153 Response::Status AdaptiveTimeScaleProbe::respond(std::shared_ptr<BaseMessage const> message) {
154 Response::Status status = ColProbe::respond(message);
155 if (message ==
nullptr) {
158 else if (
auto castMessage = std::dynamic_pointer_cast<AdaptTimestepMessage const>(message)) {
159 return respondAdaptTimestep(castMessage);
167 AdaptiveTimeScaleProbe::respondAdaptTimestep(std::shared_ptr<AdaptTimestepMessage const> message) {
169 return Response::SUCCESS;
179 std::vector<double> rawProbeValues;
180 if (triggerLayer !=
nullptr 181 && triggerLayer->
needUpdate(timeValue + triggerOffset, parent->getDeltaTime())) {
185 mTargetProbe->
getValues(timeValue, &rawProbeValues);
189 std::vector<double> timeSteps =
190 mAdaptiveTimeScaleController->calcTimesteps(timeValue, rawProbeValues);
195 if (!mOutputStreams.empty()) {
196 mAdaptiveTimeScaleController->writeTimestepInfo(timeValue, mOutputStreams);
198 return Response::SUCCESS;
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual void ioParam_baseMin(enum ParamsIOFlag ioFlag)
baseMin: Specifies the minimum timescale allowed.
virtual void ioParam_tauFactor(enum ParamsIOFlag ioFlag)
tauFactor: If Specifies the coefficient on the effective decay rate used to compute the timescale...
virtual void calcValues(double timeValue) override
int present(const char *groupName, const char *paramName)
virtual void ioParam_baseMax(enum ParamsIOFlag ioFlag)
baseMax: Specifies the initial maximum timescale allowed. The maximum timescale is allowed to increas...
double value(const char *groupName, const char *paramName)
virtual void ioParam_targetName(enum ParamsIOFlag ioFlag) override
targetName: the name of the probe that this probe attaches to. The target probe's values are used as ...
static bool completed(Status &a)
virtual void ioParam_growthFactor(enum ParamsIOFlag ioFlag)
dtChangeMin: Specifies the percentage by which the maximum timescale increases when the timescale rea...
int initialize(const char *name, HyPerCol *hc)
double * getValuesBuffer()
virtual void ioParam_writeTimeScaleFieldnames(enum ParamsIOFlag ioFlag)
writeTimeScaleFieldnames: A flag to determine if fieldnames are written to the HyPerCol_timescales fi...
virtual bool needUpdate(double simTime, double dt)
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override
virtual Response::Status registerData(Checkpointer *checkpointer) override
void getValues(double timevalue, double *valuesVector)
virtual Response::Status registerData(Checkpointer *checkpointer) override
virtual Response::Status outputState(double timeValue) override
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override
bool getTextOutputFlag() const
virtual void ioParam_writeTimeScales(enum ParamsIOFlag ioFlag)
writeTimeScales is obsolete, as it is redundant with textOutputFlag.
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override