Example #1
0
int VibronicState::getTotalQuantaCount()
{
  int count=0;
  for (int nm=0; nm<getV().size(); nm++)
    count+=getV()[nm];
  return count;
}
Example #2
0
void Balancer::startBalacing()
{
    //test if battery has recovered after last balancing
    if(!isStable(balancerStartStableCount) || !AnalogInputs::isOutStable())
        return;

    if(minCell < 0) {
        minCell = getCellMinV();
    }
    AnalogInputs::ValueType vmin = getV(minCell);

    //test if we can still discharge
    bool off = true;
    AnalogInputs::ValueType VdisMin =  ProgramData::currentProgramData.getVoltagePerCell(ProgramData::VDischarge);
    for(int i = 0; i < cells; i++) {
        //save voltage values
        AnalogInputs::ValueType v = getV(i);
        if(v < VdisMin) {
            off = true;
            break;
        }
        if(v > vmin) {
            off = false;
        }
        Von_[i] = Voff_[i] = v;
    }

    savedVon = false;
    startBalanceTimeSecondsU16_ = Time::getSecondsU16();
    if(off) {
        endBalancing();
    } else {
        setBalance(calculateBalance());
    }
}
Example #3
0
// Returns voltage at given input node.
nr_double_t digital::getVin (int input) {
  if (delay) {
    return real (getV (NODE_IN1 + input, Tdelay));
  } else {
    return real (getV (NODE_IN1 + input));
  }
}
Example #4
0
void Balancer::startBalacing()
{
    //test if battery has recovered after last balancing
    if(!isStable(balancerStartStableCount))
        return;

    minCell_ = getCellMinV();
    AnalogInputs::ValueType vmin = getV(minCell_);

    //test if we can still discharge
    bool off = true;
    if(vmin >= ProgramData::currentProgramData.getVoltagePerCell(ProgramData::VDischarge)) {
        for(int i = 0; i < cells_; i++) {
            //save voltage values
            Von_[i] = Voff_[i] = getV(i);
            if(Von_[i] - vmin > settings.balancerError_)
                off = false;
        }
    }

    savedVon_ = false;
    startBalanceTime_ = timer.getMiliseconds();
    if(off) {
        endBalancing();
    } else {
        setBalance(calculateBalance());
    }
}
Example #5
0
void Balancer::trySaveVon() {
    if(savedVon_)
        return;
    savedVon_ = true;
    AnalogInputs::ValueType vmin = getV(minCell_);
    for(uint8_t c = 0; c < cells_; c++) {
        Von_[c] = getV(c);
    }
}
Example #6
0
void vcvs::calcTR (nr_double_t t) {
  nr_double_t T = getPropertyDouble ("T");
  if (T > 0.0) {
    T = t - T;
    nr_double_t g = getPropertyDouble ("G");
    nr_double_t v = getV (NODE_4, T) - getV (NODE_1, T);
    setE (VSRC_1, g * v);
  }
}
Example #7
0
void vccs::calcTR (nr_double_t t) {
  nr_double_t T = getPropertyDouble ("T");
  if (T > 0.0) {
    T = t - T;
    nr_double_t g = getPropertyDouble ("G");
    nr_double_t v = getV (NODE_1, T) - getV (NODE_4, T);
    setI (NODE_2, -g * v);
    setI (NODE_3, +g * v);
  }
}
Example #8
0
void opamp::calcDC (void) {
  nr_double_t g    = getPropertyDouble ("G");
  nr_double_t uMax = getPropertyDouble ("Umax");
  nr_double_t Uin  = real (getV (NODE_INP) - getV (NODE_INM));
  nr_double_t Uout = uMax * M_2_PI * atan (Uin * g * M_PI_2 / uMax);
  gv = g / (1 + sqr (M_PI_2 / uMax * g * Uin)) + GMin;
  setC (VSRC_1, NODE_INP, +gv);
  setC (VSRC_1, NODE_INM, -gv);
  setE (VSRC_1, Uin * gv - Uout);
}
Example #9
0
AnalogInputs::ValueType Balancer::getPresumedV(uint8_t cell)
{
    if(balance == 0)
        return getV(cell);

    if(savedVon)
        return (getV(cell) + Voff_[cell]) - Von_[cell] ;
    else
        return Voff_[cell];
}
Example #10
0
int AccumulateLayer::setActivity() {
   const PVLayerLoc * loc = getLayerLoc();
   int nx = loc->nx;
   int ny = loc->ny;
   int nf = loc->nf;
   int num_neurons = nx*ny*nf;
   int status = PV_SUCCESS;
   memset(clayer->activity->data, 0, sizeof(pvdata_t)*getNumExtended());
   if( status == PV_SUCCESS ) status = applyVThresh_ANNLayer(num_neurons, getV(), AMin, VThresh, AShift, VWidth, getCLayer()->activity->data, nx, ny, nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up);
   if( status == PV_SUCCESS ) status = applyVMax_ANNLayer(num_neurons, getV(), AMax, getCLayer()->activity->data, nx, ny, nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up);
   return status;
}
void dcblock::calcTR (nr_double_t) {
  nr_double_t c = getPropertyDouble ("C");
  nr_double_t g, i;
  nr_double_t v = real (getV (NODE_1) - getV (NODE_2));

  setState (qState, c * v);
  integrate (qState, c, g, i);
  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
  setI (NODE_1 , -i);
  setI (NODE_2 , +i);
}
Example #12
0
// adds to G the edge from x to y, if it is not there.
void Graph::addEdge(int x, int y, int distance) {
    if (x >= getV()) {
        throw "x vertex must be part of graph!";
    }

    if (y >= getV()) {
        throw "y vertex must be part of graph!";
    }

    this->matrix[x][y] = distance;
    this->matrix[y][x] = distance;
}
Example #13
0
void tline::calcTR (nr_double_t t) {
  nr_double_t l = getPropertyDouble ("L");
  nr_double_t a = getPropertyDouble ("Alpha");
  nr_double_t z = getPropertyDouble ("Z");
  nr_double_t T = l / C0;
  a = log (a) / 2;
  if (T > 0.0) {
    T = t - T;
    a = exp (-a / 2 * l);
    setE (VSRC_1, a * (getV (NODE_2, T) + z * getJ (VSRC_2, T)));
    setE (VSRC_2, a * (getV (NODE_1, T) + z * getJ (VSRC_1, T)));
  }
}
Example #14
0
int CPTestInputLayer::updateState(double timed, double dt) {
   update_timer->start();
//#ifdef PV_USE_OPENCL
//   if(gpuAccelerateFlag) {
//      updateStateOpenCL(timed, dt);
//      //HyPerLayer::updateState(time, dt);
//   }
//   else {
//#endif
      const int nx = clayer->loc.nx;
      const int ny = clayer->loc.ny;
      const int nf = clayer->loc.nf;
      const PVHalo * halo = &clayer->loc.halo;
      const int numNeurons = getNumNeurons();
      const int nbatch = clayer->loc.nbatch;

      //pvdata_t * GSynExc   = getChannel(CHANNEL_EXC);
      //pvdata_t * GSynInh   = getChannel(CHANNEL_INH);
      pvdata_t * GSynHead   = GSyn[0];
      pvdata_t * V = getV();
      pvdata_t * activity = clayer->activity->data;

      CPTestInputLayer_update_state(nbatch, numNeurons, nx, ny, nf, halo->lt, halo->rt, halo->dn, halo->up, V, VThresh, AMax, AMin, GSynHead, activity);
//#ifdef PV_USE_OPENCL
//   }
//#endif

   update_timer->stop();
   return PV_SUCCESS;
}
Example #15
0
int MaskError::updateState(double time, double dt)
{
   const PVLayerLoc * loc = getLayerLoc();

   int nx = loc->nx;
   int ny = loc->ny;
   int nf = loc->nf;
   int num_neurons = nx*ny*nf;
   //Reset pointer of gSynHead to point to the inhib channel
   pvdata_t * GSynExt = getChannel(CHANNEL_EXC);
   pvdata_t * GSynInh = getChannel(CHANNEL_INH);

   pvdata_t * A = getCLayer()->activity->data;
   pvdata_t * V = getV();

#ifdef PV_USE_OPENMP_THREADS
#pragma omp parallel for
#endif
   for(int ni = 0; ni < num_neurons; ni++){
      int next = kIndexExtended(ni, nx, ny, nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up);
      //expected - actual only if expected isn't 0
      if(GSynExt[ni] == 0){
         A[next] = 0;
      }
      else{
         A[next] = GSynExt[ni] - GSynInh[ni];
      }
   }
   return PV_SUCCESS;
}
Example #16
0
int BinaryThresh::updateState(double time, double dt)
{
   const PVLayerLoc * loc = getLayerLoc();

   int nx = loc->nx;
   int ny = loc->ny;
   int nf = loc->nf;
   int num_neurons = nx*ny*nf;
   //Reset pointer of gSynHead to point to the inhib channel
   pvdata_t * GSynExt = getChannel(CHANNEL_EXC);
   pvdata_t * GSynInh = getChannel(CHANNEL_INH);

   pvdata_t * A = getCLayer()->activity->data;
   pvdata_t * V = getV();

#ifdef PV_USE_OPENMP_THREADS
#pragma omp parallel for
#endif
   for(int ni = 0; ni < num_neurons; ni++){
      int next = kIndexExtended(ni, nx, ny, nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up);
      //Activity is either 0 or 1 based on if it's active
      A[next] = GSynExt[ni] == 0 ? 0 : 1;
   }
   return PV_SUCCESS;
}
Example #17
0
int IncrementLayer::doUpdateState(double timef, double dt, bool * inited, double * next_update_time, double first_update_time, double display_period, const PVLayerLoc * loc, pvdata_t * A, pvdata_t * V, pvdata_t * Vprev, int num_channels, pvdata_t * gSynHead) {
   int status = PV_SUCCESS;
   int nx = loc->nx;
   int ny = loc->ny;
   int nf = loc->nf;
   int num_neurons = nx*ny*nf;
   int nbatch = loc->nbatch;

   if( *inited ) {
      if( timef >= *next_update_time ) {
         *next_update_time += display_period;
         pvdata_t * Vprev1 = Vprev;
         pvdata_t * V = getV();
         for( int k=0; k<num_neurons; k++ ) {
            *(Vprev1++) = *(V++);
         }
      }
      status = applyGSyn_HyPerLayer(num_neurons, V, gSynHead);
      if( status == PV_SUCCESS ) status = setActivity_IncrementLayer(num_neurons, A, V, Vprev, nx, ny, nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up); // setActivity();
   }
   else {
      if( timef >= first_update_time ) {
         status = updateV_PtwiseLinearTransferLayer(num_neurons, V, num_channels, gSynHead, A, numVertices, verticesV, verticesA, slopes, nx, ny, nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up); // updateV();
         resetGSynBuffers_HyPerLayer(num_neurons, num_channels, gSynHead);
         *inited = true;
      }
   }
   return status;

}
Example #18
0
int MLPForwardLayer::updateState(double time, double dt)
{
   //update_timer->start();

   const PVLayerLoc * loc = getLayerLoc();
   int nx = loc->nx;
   int ny = loc->ny;
   int nf = loc->nf;
   int num_neurons = nx*ny*nf;
   //Reset pointer of gSynHead to point to the excitatory channel
   pvdata_t * GSynExt = getChannel(CHANNEL_EXC);

   pvdata_t * V = getV();
#ifdef PV_USE_OPENMP_THREADS
#pragma omp parallel for
#endif
   for(int ni = 0; ni < num_neurons*loc->nbatch; ni++){
      //int next = kIndexExtended(ni, nx, ny, nf, loc->nb);
      double p = randState->uniformRandom();
      if(p <= dropoutChance){
         //Set dropout flag
         dropout[ni] = true;
      }
      else{
         dropout[ni] = false;
      }
      V[ni] = GSynExt[ni] * potentialScale;
      //if(strcmp(name, "ForwardLayerFinal") == 0){
      //   std::cout << "Neuron: " << ni << " V: " << V[ni] << "\n";
      //}
   }
   //A never updated, TODO see if you can remove A buffer
   //update_timer->stop();
   return PV_SUCCESS;
}
Example #19
0
	void transformNormals(const Mat4& transformation){
		const Vec4 u = transformation * getU();
		const Vec4 v = transformation * getV();
		const Vec4 n = transformation * getN();
		setOrientation(u,v,n);
		setPosition(position);
	}
Example #20
0
	void setPosition(const Vec4& pos){
		position = pos;
		const Vec4 eyeVector = position - Vec4::origin();
		matrix.cArray[12] = -eyeVector * getU();
		matrix.cArray[13] = -eyeVector * getV();
		matrix.cArray[14] = -eyeVector * getN();
	}
Example #21
0
void Tetrahedron::getCubaturePositions(
    Math::CVecR3 res[Math::Simplex::Tetrahedron<1>::ncp]) const {
    static const std::size_t ncp = Math::Simplex::Tetrahedron<1>::ncp;
    for (std::size_t c = 0; c < ncp; c++) {
        for (std::size_t i = 0; i < 3; i++) {
            res[c](i) = 0.0;
        }
    }
    // Evaluates Lagrange's functions in positions specified by the
    // simplex coordinates of tet.
    Math::Real **lagrEv;
    lagrEv = new Math::Real*[ncp];
    for (std::size_t i = 0; i < ncp; i++) {
        lagrEv[i] = new Math::Real[numberOfCoordinates()];
    }
    for (std::size_t c = 0; c < ncp; c++) {
        for (std::size_t i = 0; i < numberOfCoordinates(); i++) {
            lagrEv[c][i]= getTet().getLagr(i).eval(
                              getTet().cubatureCoordinate(c));
        }
    }
    // Computes nodes.
    for (std::size_t c = 0; c < ncp; c++) {
        for (std::size_t i = 0; i < numberOfCoordinates(); i++) {
            res[c] += *(getV(i)) * lagrEv[c][i];
        }
    }
    for (std::size_t i = 0; i < ncp; i++) {
        delete[] lagrEv[i];
    }
    delete[] lagrEv;
}
void TestYuv444FileSaver::testRgb888ToYuv444() {
	auto vector = Utility::Yuv444FileSaver::Rgb888ToYuv444(pixel);
	QVERIFY(vector.getY() == 16);
	QVERIFY(vector.getU() == 128);
	QVERIFY(vector.getV() == 128);

}
Example #23
0
 bool isPalindrome(string s) {
     int i = 0;
     int j = s.size() - 1;
     while(i < j){
         while(i < s.size() && !isChar(s[i])) i++;
         while(0 <= j && !isChar(s[j])) j--;
         if(j <= i) return true;
         if(getV(s[i]) == getV(s[j])){
             i++;
             j--;
         }else{
             return false;
         }
     }
     return true;
 }
Example #24
0
int GMSH_CutParametricPlugin::fillXYZ()
{
  std::vector<std::string> expressions(3), variables(2);
  for(int i = 0; i < 3; i++)
    expressions[i] = CutParametricOptions_String[i].def;
  variables[0] = "u";
  variables[1] = "v";
  mathEvaluator f(expressions, variables);
  if(expressions.empty()) return 0;

  int nbU = (int)CutParametricOptions_Number[2].def;
  int nbV = (int)CutParametricOptions_Number[5].def;
  x.resize(nbU * nbV);
  y.resize(nbU * nbV);
  z.resize(nbU * nbV);
  std::vector<double> val(2), res(3);
  for(int i = 0; i < nbU; ++i){
    val[0] = getU(i);
    for(int j = 0; j < nbV; ++j){
      val[1] = getV(j);
      if(f.eval(val, res)){
        x[i * nbV + j] = res[0];
        y[i * nbV + j] = res[1];
        z[i * nbV + j] = res[2];
      }
    }
  }
  return 1;
}
void Utility::Yuv422FileSaver::savePlanar() {
	for(std::size_t k=0; k<video_->getNumberOfFrames()&&isRunning_; k++) {
		QVector<unsigned char> uBuffer;
		QVector<unsigned char> vBuffer;
		auto frame=video_->getFrame(k);
		for(int i=0; i<width_*height_; i+=2) {
			int y1=i/width_;
			int x1=i%width_;
			int y2=(i+1)/width_;
			int x2=(i+1)%width_;

			if(!frame->valid(x1,y1)||!frame->valid(x2,y2)) {
				qDebug()<<"Wrong pixel coordinates";
				continue;
			}

			auto vec=Rgb888ToYuv422(frame->pixel(x1,y1),frame->pixel(x2,y2));
			dataStream_<<vec.getY1()<<vec.getY2();
			uBuffer.push_back(vec.getU());
			vBuffer.push_back(vec.getV());
		}
		while (!uBuffer.isEmpty()) {
			dataStream_<<uBuffer.takeFirst();
		}
		while (!vBuffer.isEmpty()) {
			dataStream_<<vBuffer.takeFirst();
		}
	}
}
Example #26
0
void Balancer::trySaveVon() {
    if(savedVon)
        return;
    savedVon = true;
    for(uint8_t c = 0; c < cells; c++) {
        Von_[c] = getV(c);
    }
}
Example #27
0
void Balancer::trySaveVon() {
    if(savedVon)
        return;
    savedVon = true;
    for(uint8_t c = 0; c < MAX_BALANCE_CELLS; c++) {
        Von_[c] = getV(c);
    }
}
void TestYuv411FileSaver::testRgb888ToYuv411() {
	auto vector = Utility::Yuv411FileSaver::Rgb888ToYuv411(pixel1,pixel2,pixel3,pixel4);
	QVERIFY(vector.getY1() == 16);
	QVERIFY(vector.getU() == 128);
	QVERIFY(vector.getV() == 128);
	QVERIFY(vector.getY2() == 16);
	QVERIFY(vector.getY3() == 16);
	QVERIFY(vector.getY4() == 16);
}
Example #29
0
void assign(char a,char b){
	int k = getV(b), x;
	if(a == 'r') x = 0;
	else if(a == 'g') x = 1;
	else if(a == 'y') x = 2;
	else if(a == 'b') x = 3;
	else x = 4;
	city[ic][x] = k;
}
Example #30
0
File: my.cpp Project: wuhua988/icm
DispatchStatus
demo::A::___getV(ServerRequest& __inS)
{
  OutputStream& __os = __inS.outgoing();
  ::std::string __ret = getV();
  __inS.initReply ();
  __os.write_string(__ret);
  return DispatchOK;
}