8 #include "ColumnEnergyProbe.hpp" 9 #include "columns/HyPerCol.hpp" 41 ioParam_reductionInterval(ioFlag);
45 void ColumnEnergyProbe::ioParam_reductionInterval(
enum ParamsIOFlag ioFlag) {
46 parent->parameters()->ioParamValue(
47 ioFlag, name,
"reductionInterval", &mSkipInterval, mSkipInterval,
false );
56 for (
auto &s : mOutputStreams) {
57 *s <<
"time,index,energy\n";
61 if (!mOutputStreams.empty()) {
62 *mOutputStreams[0] <<
"Probe_name,time,index,energy\n";
71 int status = PV_SUCCESS;
74 if (newNumValues < 0) {
76 if (parent->columnId() == 0) {
78 "%s: %s cannot be used as a term of the energy " 79 "probe (getNumValue() returned a " 80 "negative number).\n",
82 probe->getDescription_c());
84 MPI_Barrier(parent->getCommunicator()->communicator());
93 if (this->parent->columnId() == 0) {
95 "Failed to add terms to %s: new probe \"%s\" " 96 "returns %d values, but previous " 97 "probes return %d values\n",
103 MPI_Barrier(this->parent->getCommunicator()->communicator());
108 int newNumTerms = numTerms + (size_t)1;
109 if (newNumTerms <= numTerms) {
110 if (this->parent->columnId() == 0) {
112 "How did you manage to add %zu terms to %s? " 113 "Unable to add any more!\n",
117 MPI_Barrier(this->parent->getCommunicator()->communicator());
122 if (newTermsArray == NULL) {
124 "%s: unable to add term %zu (\"%s\"): %s\n",
126 numTerms + (
size_t)1,
131 terms = newTermsArray;
132 terms[numTerms] = probe;
133 numTerms = newNumTerms;
142 if (mLastTimeValue == timevalue || --mSkipTimer > 0) {
143 mLastTimeValue = timevalue;
146 mSkipTimer = mSkipInterval + 1;
149 memset(valuesBuffer, 0, numValues *
sizeof(*valuesBuffer));
150 double energy1[numValues];
151 for (
int n = 0; n < numTerms; n++) {
155 for (
int b = 0; b < numValues; b++) {
156 valuesBuffer[b] += coeff * energy1[b];
163 if (mOutputStreams.empty()) {
164 return Response::SUCCESS;
169 pvAssert(nbatch == (
int)mOutputStreams.size());
171 for (
int b = 0; b < nbatch; b++) {
172 auto stream = *mOutputStreams[b];
174 stream <<
"\"" << name <<
"\",";
176 stream.printf(
"%10f, %d, %10.9f\n", timevalue, b, valuesBuffer[b]);
179 return Response::SUCCESS;
virtual bool needRecalc(double timevalue) override
int addTerm(BaseProbe *probe)
Adds a probe to the energy calculation.
char const * getProbeOutputFilename()
int initializeColumnEnergyProbe(const char *probename, HyPerCol *hc)
virtual double referenceUpdateTime() const override
virtual Response::Status outputState(double timevalue) override
int initialize(const char *name, HyPerCol *hc)
virtual ~ColumnEnergyProbe()
double * getValuesBuffer()
bool isWritingToFile() const
virtual void outputHeader() override
virtual void calcValues(double timevalue) override
void getValues(double timevalue, double *valuesVector)
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override