Exemplo n.º 1
0
void vdc::calcHB (nr_double_t frequency) {
  if (frequency == 0.0) {
    setE (VSRC_1, getPropertyDouble ("U"));
  } else {
    setE (VSRC_1, 0);
  }
}
Exemplo n.º 2
0
void mutual::calcTR (nr_double_t) {
    nr_double_t k  = getPropertyDouble ("k");
    nr_double_t l1 = getPropertyDouble ("L1");
    nr_double_t l2 = getPropertyDouble ("L2");
    nr_double_t i1 = real (getJ (VSRC_1));
    nr_double_t i2 = real (getJ (VSRC_2));
    nr_double_t r11, r12, r21, r22, v11, v22, v12, v21;
    nr_double_t M12 = k * sqrt (l1 * l2);

    // self inductances
    setState  (fState11, i1 * l1);
    integrate (fState11, l1, r11, v11);
    setState  (fState22, i2 * l2);
    integrate (fState22, l2, r22, v22);

    // mutual inductances
    setState  (fState12, i2 * M12);
    integrate (fState12, M12, r12, v12);
    setState  (fState21, i1 * M12);
    integrate (fState21, M12, r21, v21);

    setD (VSRC_1, VSRC_1, -r11);
    setD (VSRC_1, VSRC_2, -r12);
    setD (VSRC_2, VSRC_2, -r22);
    setD (VSRC_2, VSRC_1, -r21);
    setE (VSRC_1, v11 + v12);
    setE (VSRC_2, v22 + v21);
}
Exemplo n.º 3
0
void strafo::initAC (void) {
  nr_double_t t1 = getPropertyDouble ("T1");
  nr_double_t t2 = getPropertyDouble ("T2");

  setVoltageSources (2);
  allocMatrixMNA ();

  setB (NODE_1, VSRC_1, -1.0); setB (NODE_2, VSRC_1, + t1);
  setB (NODE_3, VSRC_1, - t1); setB (NODE_4, VSRC_1, +0.0);
  setB (NODE_5, VSRC_1, +0.0); setB (NODE_6, VSRC_1, +1.0);
  setB (NODE_1, VSRC_2, +0.0); setB (NODE_2, VSRC_2, + t2);
  setB (NODE_3, VSRC_2, - t2); setB (NODE_4, VSRC_2, +1.0);
  setB (NODE_5, VSRC_2, -1.0); setB (NODE_6, VSRC_2, +0.0);

  setC (VSRC_1, NODE_1, +1.0); setC (VSRC_1, NODE_2, - t1);
  setC (VSRC_1, NODE_3, + t1); setC (VSRC_1, NODE_4, +0.0);
  setC (VSRC_1, NODE_5, +0.0); setC (VSRC_1, NODE_6, -1.0);
  setC (VSRC_2, NODE_1, +0.0); setC (VSRC_2, NODE_2, - t2);
  setC (VSRC_2, NODE_3, + t2); setC (VSRC_2, NODE_4, -1.0);
  setC (VSRC_2, NODE_5, +1.0); setC (VSRC_2, NODE_6, +0.0);

  setD (VSRC_1, VSRC_1, 0); setD (VSRC_2, VSRC_2, 0);
  setD (VSRC_1, VSRC_2, 0); setD (VSRC_2, VSRC_1, 0);
  setE (VSRC_1, 0.0);
  setE (VSRC_2, 0.0);
}
Exemplo n.º 4
0
void HD44780gpioPhy::write(uint8_t n, uint8_t x)
{
	if (bits < 4)
		return;

	// if output buffers are disabled, enable them
	if (!writeReady)
	{
		wires->enableOutput(d, bits);
		writeReady = true;
	}

	//set write mode
	setRW(0);
	if (bits == 4)
	{
		iooo_debug(3, "Writing 0x%02x in 4 bit mode\n", x);
		//write higher nibble
		setNibble((x >> 4) & 0x0f);
		setE(n, 1);
		usleep(100);
		setE(n, 0);

		usleep(200);
		//write lower nibble
		setNibble(x & 0x0f);
		setE(n, 1);
		usleep(100);
		setE(n, 0);
	}
Exemplo n.º 5
0
int DivideEachElement(matrix * mtx, double val){
	if(mtx==NULL)
		return -1;
	
	if(!(*mtx))
		return -1;
	//printf("DivideEachElement\n");	

	int i;
	int j;

	for(i=1;i<=(*mtx)->rows;i++){
		for(j=1;j<=(*mtx)->cols;j++){
			setE((*mtx),i,j,ELEM((*mtx),i,j)/val);
		}
	}

	matrix mtxtemp = (*mtx)->Extra;
	while((mtxtemp)!=NULL){
		for(i=1;i<=(mtxtemp)->rows; i++){
			for(j=1;j<=(mtxtemp)->cols;j++){
				setE((mtxtemp),i,j,ELEM((mtxtemp),i,j)/val);					
			}
		}
		(mtxtemp)=(mtxtemp)->Extra;
	}

	if((*mtx)==NULL){
		printf("Error mtx is NULL\n");
		exit(1);
	}

	return 0;
}
Exemplo n.º 6
0
void vac::calcHB (nr_double_t frequency) {
  nr_double_t f = getPropertyDouble ("f");
  if (f == frequency) {
    nr_double_t a = getPropertyDouble ("U");
    nr_double_t p = getPropertyDouble ("Phase");
    setE (VSRC_1, polar (a, rad (p)));
  }
  else {
    setE (VSRC_1, 0);
  }
}
Exemplo n.º 7
0
void cpwstep::initAC (void) {
  setVoltageSources (2);
  setInternalVoltageSource (true);
  allocMatrixMNA ();
  setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
  setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
  setC (VSRC_1, NODE_1, -1.0); setC (VSRC_1, NODE_2, +0.0);
  setC (VSRC_2, NODE_1, +0.0); setC (VSRC_2, NODE_2, -1.0);
  setE (VSRC_1, +0.0); setE (VSRC_2, +0.0);
  checkProperties ();
}
Exemplo n.º 8
0
void pac::calcHB (nr_double_t frequency) {
  nr_double_t f = getPropertyDouble ("f");
  if (f == frequency) {
    nr_double_t p = getPropertyDouble ("P");
    nr_double_t r = getPropertyDouble ("Z");
    nr_double_t u = sqrt (4 * p * r);
    setE (VSRC_1, u);
  }
  else {
    setE (VSRC_1, 0);
  }
}
Exemplo n.º 9
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)));
  }
}
Exemplo n.º 10
0
void mutual2::calcTR (nr_double_t) {
  nr_double_t k12 = getPropertyDouble ("k12");
  nr_double_t k13 = getPropertyDouble ("k13");
  nr_double_t k23 = getPropertyDouble ("k23");
  nr_double_t l1  = getPropertyDouble ("L1");
  nr_double_t l2  = getPropertyDouble ("L2");
  nr_double_t l3  = getPropertyDouble ("L3");
  nr_double_t M12 = k12 * sqrt (l1 * l2);
  nr_double_t M13 = k13 * sqrt (l1 * l3);
  nr_double_t M23 = k23 * sqrt (l2 * l3);
  nr_double_t r11, r12, r13, r21, r22, r23, r31, r32, r33;
  nr_double_t v11, v12, v13, v21, v22, v23, v31, v32, v33;
  nr_double_t i1 = real (getJ (VSRC_1));
  nr_double_t i2 = real (getJ (VSRC_2));
  nr_double_t i3 = real (getJ (VSRC_3));

  setState  (fState11, i1 * l1);
  integrate (fState11, l1, r11, v11);
  setState  (fState22, i2 * l2);
  integrate (fState22, l2, r22, v22);
  setState  (fState33, i3 * l3);
  integrate (fState33, l3, r33, v33);

  setState  (fState12, i2 * M12);
  integrate (fState12, M12, r12, v12);
  setState  (fState13, i3 * M13);
  integrate (fState13, M13, r13, v13);
  setState  (fState21, i1 * M12);
  integrate (fState21, M12, r21, v21);
  setState  (fState23, i3 * M23);
  integrate (fState23, M23, r23, v23);
  setState  (fState31, i1 * M13);
  integrate (fState31, M13, r31, v31);
  setState  (fState32, i2 * M23);
  integrate (fState32, M23, r32, v32);

  setD (VSRC_1, VSRC_1, -r11);
  setD (VSRC_1, VSRC_2, -r12);
  setD (VSRC_1, VSRC_3, -r13);
  setD (VSRC_2, VSRC_1, -r21);
  setD (VSRC_2, VSRC_2, -r22);
  setD (VSRC_2, VSRC_3, -r23);
  setD (VSRC_3, VSRC_1, -r31);
  setD (VSRC_3, VSRC_2, -r32);
  setD (VSRC_3, VSRC_3, -r33);
  setE (VSRC_1, v11 + v12 + v13);
  setE (VSRC_2, v21 + v22 + v23);
  setE (VSRC_3, v31 + v32 + v33);
}
Exemplo n.º 11
0
void Lcd::clear(){
	resetRS();
	setE();
	setBits(0x01);
	Timer::wait_ms(1);
	resetE();
	Timer::wait_ms(3);

	resetRS();
	setE();
	setBits(0x06);
	Timer::wait_ms(1);
	resetE();
	Timer::wait_ms(2);
}
LL_MNode newLL_MNode( double data[],int rows ){
	
	int i;
	
	if(rows <= 0){
		fprintf(stderr,"ERROR trying to initialize matrix_");	
		fprintf(stderr,"linklist node with no data\n");
		return NULL;	
	}

	LL_MNode node = (LL_MNode) malloc(sizeof(struct _LL_MNode));

	if(node==NULL){
		return NULL;
	}

	//Create Matrix
	node->data = newMatrix(rows,1);
	//Initialize the Matrix with the passed data
	for(i=0;i<rows;i++){
		setE(node->data,i+1,1,data[i]);
	}
	node->next = NULL;
	return node;
}
Exemplo n.º 13
0
int DivideEachElementCol(matrix * mtx, int col, double val){
	if(mtx==NULL){
		return -1;
	}
	//printf("DivideEachElementCol\n");	
	if(!(*mtx)){
		return -1;
	}

	if( col<1 || col>(*mtx)->cols){
		return -1;
	}


	int i;
	matrix mtxtemp = (*mtx);
	while(mtxtemp!=NULL){
		for(i=1;i<=mtxtemp->rows;i++){
			setE(mtxtemp,i,col,ELEM(mtxtemp,i,col)/val);	
		}
		mtxtemp=mtxtemp->Extra;
	}

	return 0;
}
bool RSAPrivateKey::deserialise(ByteString& serialised)
{
	ByteString dP = ByteString::chainDeserialise(serialised);
	ByteString dQ = ByteString::chainDeserialise(serialised);
	ByteString dPQ = ByteString::chainDeserialise(serialised);
	ByteString dDP1 = ByteString::chainDeserialise(serialised);
	ByteString dDQ1 = ByteString::chainDeserialise(serialised);
	ByteString dD = ByteString::chainDeserialise(serialised);
	ByteString dN = ByteString::chainDeserialise(serialised);
	ByteString dE = ByteString::chainDeserialise(serialised);

	if ((dD.size() == 0) ||
	    (dN.size() == 0) ||
	    (dE.size() == 0))
	{
		return false;
	}

	setP(dP);
	setQ(dQ);
	setPQ(dPQ);
	setDP1(dDP1);
	setDQ1(dDQ1);
	setD(dD);
	setN(dN);
	setE(dE);

	return true;
}
Exemplo n.º 15
0
void opamp::initDC (void) {
  allocMatrixMNA ();
  setB (NODE_INP, VSRC_1, 0);
  setB (NODE_OUT, VSRC_1, 1);
  setB (NODE_INM, VSRC_1, 0);
  setC (VSRC_1, NODE_OUT, -1); setD (VSRC_1, VSRC_1, 0); setE (VSRC_1, 0);
}
Exemplo n.º 16
0
void Lcd::printChar(const char c){
	setRS();
	setE();
	setBits(c);
	Timer::wait_ms(1);
	resetE();
	Timer::wait_ms(1);
}
Exemplo n.º 17
0
// Initialize constant MNA entries for DC analysis.
void digital::initDC (void) {
  initDigital ();
  allocMatrixMNA ();
  delay = false;
  setB (NODE_OUT, VSRC_1, +1);
  setC (VSRC_1, NODE_OUT, -1);
  setE (VSRC_1, 0);
}
Exemplo n.º 18
0
void vam::calcTR (nr_double_t t) {
  nr_double_t f = getPropertyDouble ("f");
  nr_double_t p = getPropertyDouble ("Phase");
  nr_double_t d = getPropertyDouble ("m");
  nr_double_t a = getPropertyDouble ("U");
  nr_double_t u = a * sin (2 * M_PI * f * t + rad (p));
  setE (VSRC_1, u);
  setC (VSRC_1, NODE_3, -u * d);
}
TransformationMatrix::TransformationMatrix(const CGAffineTransform& t)
{
    setA(t.a);
    setB(t.b);
    setC(t.c);
    setD(t.d);
    setE(t.tx);
    setF(t.ty);
}
Exemplo n.º 20
0
// Computes variable MNA entries during DC analysis.
void digital::calcDC (void) {
  calcOutput ();
  calcDerivatives ();
  for (i = 0, Veq = 0; i < getSize () - 1; i++) {
    setC (VSRC_1, NODE_IN1 + i, g[i]);
    Veq += g[i] * getVin (i);
  }
  setE (VSRC_1, Veq - Vout);
}
Exemplo n.º 21
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);
  }
}
Exemplo n.º 22
0
void circulator::initDC (void) {
  nr_double_t z1 = getPropertyDouble ("Z1");
  nr_double_t z2 = getPropertyDouble ("Z2");
  nr_double_t z3 = getPropertyDouble ("Z3");
  nr_double_t r1 = (z0 - z1) / (z0 + z1);
  nr_double_t r2 = (z0 - z2) / (z0 + z2);
  nr_double_t r3 = (z0 - z3) / (z0 + z3);
  nr_double_t d  = 1 - r1 * r2 * r3;

  nr_double_t s11 = (r2 * r3 - r1) / d;
  nr_double_t s22 = (r1 * r3 - r2) / d;
  nr_double_t s33 = (r1 * r2 - r3) / d;
  nr_double_t s12 = sqrt (z2/z1) * (z1+z0) / (z2+z0) * r3 * (1-r1*r1) / d;
  nr_double_t s23 = sqrt (z3/z2) * (z2+z0) / (z3+z0) * r1 * (1-r2*r2) / d;
  nr_double_t s31 = sqrt (z1/z3) * (z3+z0) / (z1+z0) * r2 * (1-r3*r3) / d;
  nr_double_t s21 = sqrt (z1/z2) * (z2+z0) / (z1+z0) * (1-r2*r2) / d;
  nr_double_t s13 = sqrt (z3/z1) * (z1+z0) / (z3+z0) * (1-r1*r1) / d;
  nr_double_t s32 = sqrt (z2/z3) * (z3+z0) / (z2+z0) * (1-r3*r3) / d;

  allocMatrixMNA ();

  setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
  setB (NODE_1, VSRC_3, +0.0);
  setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
  setB (NODE_2, VSRC_3, +0.0);
  setB (NODE_3, VSRC_1, +0.0); setB (NODE_3, VSRC_2, +0.0);
  setB (NODE_3, VSRC_3, +1.0);

  setC (VSRC_1, NODE_1, s11 - 1.0); setC (VSRC_1, NODE_2, s12);
  setC (VSRC_1, NODE_3, s13);
  setC (VSRC_2, NODE_1, s21); setC (VSRC_2, NODE_2, s22 - 1.0);
  setC (VSRC_2, NODE_3, s23);
  setC (VSRC_3, NODE_1, s31); setC (VSRC_3, NODE_2, s32);
  setC (VSRC_3, NODE_3, s33 - 1.0);

  setD (VSRC_1, VSRC_1, z0 * (s11 + 1.0)); setD (VSRC_1, VSRC_2, z0 * s12);
  setD (VSRC_1, VSRC_3, z0 * s13);
  setD (VSRC_2, VSRC_1, z0 * s21); setD (VSRC_2, VSRC_2, z0 * (s22 + 1.0));
  setD (VSRC_2, VSRC_3, z0 * s23);
  setD (VSRC_3, VSRC_1, z0 * s31); setD (VSRC_3, VSRC_2, z0 * s32);
  setD (VSRC_3, VSRC_3, z0 * (s33 + 1.0));

  setE (VSRC_1, +0.0); setE (VSRC_2, +0.0); setE (VSRC_3, +0.0);
}
int setMatrixLLValueAtRow(matrix_linklist LL, int R, double val){
  #ifdef _ERROR_CHECKING_ON_
  if(LL==NULL){
    #ifdef _ERROR_
    fprintf(stderr,"LL is NULL in setMatrixLLValueAtRow\n"); 
    #endif
    #ifdef _FORCE_HARD_CRASH_
     exit(1);
    #endif
    return -1;
  }
  if(LL->start==NULL){
    #ifdef _ERROR_
    fprintf(stderr,"ERROR getMatrixLLstartAtRow has error because ");
    fprintf(stderr,"LL->start is NULL\n");
    #endif
    #ifdef _FORCE_HARD_CRASH_
     exit(1);
    #endif
    return -1;
  }
  #endif
  int rows;
  rows = getRows(LL->start->data);
  #ifdef _ERROR_CHECKING_ON_
  if(R>rows){
    #ifdef _ERROR_
    fprintf(stderr,"ERROR getMatrixLLstartAtRow R value is larger ");
    fprintf(stderr,"than the number of rows\n");
    #endif
    #ifdef _FORCE_HARD_CRASH_
     exit(1);
    #endif
    return -1;
  }
  #endif
  setE(LL->start->data,R,1,val);
  LL_MNode temp = LL->start->next;
  while(temp!=NULL){
    setE(temp->data,R,1,val); 
    temp = temp->next;
  }
  return 0;
}
Exemplo n.º 24
0
void dcfeed::calcTR (nr_double_t) {
  nr_double_t l = getPropertyDouble ("L");
  nr_double_t r, v;
  nr_double_t i = real (getJ (VSRC_1));

  setState (fState, i * l);
  integrate (fState, l, r, v);
  setD (VSRC_1, VSRC_1, -r);
  setE (VSRC_1, v);
}
Exemplo n.º 25
0
void digisource::initDC (void) {
  char * init = getPropertyString ("init");
  nr_double_t v = getPropertyDouble ("V");
  bool lo = !strcmp (init, "low");
  allocMatrixMNA ();
  setC (VSRC_1, NODE_1, 1.0);
  setB (NODE_1, VSRC_1, 1.0);
  setD (VSRC_1, VSRC_1, 0.0);
  setE (VSRC_1, lo ? 0 : v);
}
Exemplo n.º 26
0
void vcvs::initDC (void) {
  nr_double_t g = getPropertyDouble ("G");
  allocMatrixMNA ();
  setC (VSRC_1, NODE_1, +g); setC (VSRC_1, NODE_2, -1.0);
  setC (VSRC_1, NODE_3, +1.0); setC (VSRC_1, NODE_4, -g);
  setB (NODE_1, VSRC_1, +0); setB (NODE_2, VSRC_1, -1.0);
  setB (NODE_3, VSRC_1, +1.0); setB (NODE_4, VSRC_1, +0);
  setD (VSRC_1, VSRC_1, 0.0);
  setE (VSRC_1, 0.0);
}
Exemplo n.º 27
0
// Computes MNA entries during transient analysis.
void digital::calcTR (nr_double_t t) {
  if (delay) {
    Tdelay = t - getPropertyDouble ("t");
    calcOutput ();
    setE (VSRC_1, Vout);
  }
  else {
    calcDC ();
  }
}
Exemplo n.º 28
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);
}
matrix getMatrixLLMatchAtRow(matrix_linklist LL, double match, int R,  int * numMatches){

  #ifdef _ERROR_CHECKING_ON_
  if(LL==NULL){
    #ifdef _ERROR_
    fprintf(stderr,"ERROR LL is NULL in getMatrixLLMatchAtRow\n");
    #endif
    #ifdef _FORCE_HARD_CRASH_
    exit(1);
    #endif
    return NULL;
  }
  #endif

  *numMatches =getMatrixLLNumberMatchAtRow( LL,(double)match,R);
 
  matrix matches; 
  #ifdef _ERROR_CHECKING_ON_
  if(*numMatches<0){
    matches=NULL;
    #ifdef _ERROR_
    fprintf(stderr,"numMatches in getMatrixLLMatchAtRow is less than 0\n");
    #endif
    #ifdef _FORCE_HARD_CRASH_
    exit(1);
    #endif
    return NULL;
  }
  #endif
  if(*numMatches==0){
    matches=NULL;
    return matches;
  }

  printf("LL print numMatches %d\n",*numMatches);
  matches = newMatrix(*numMatches,1);
  
  int index;
  int seq;
  seq = 1;
  index = 1;
  LL_MNode node = LL->start;
  while( node!=NULL){
    
    if(match==getE(node->data,R,1)){
      setE(matches,index,1,seq);
      printf("matchesRec %g\n",getE(matches,index,1));
      index++;
    }
    node=node->next;
    seq++;
  }
  
  return matches;
}
Exemplo n.º 30
0
void vac::calcTR (nr_double_t t) {
  nr_double_t f = getPropertyDouble ("f");
  nr_double_t p = getPropertyDouble ("Phase");
  nr_double_t d = getPropertyDouble ("Theta");
  nr_double_t a = getPropertyDouble ("U");
  nr_double_t s = getNet()->getSrcFactor ();
  nr_double_t o = 2 * M_PI * f;
  nr_double_t T = p / f / 360;
  nr_double_t u = s * a * exp (-(t + T) * d * f) * sin (o * t + rad (p));
  setE (VSRC_1, u);
}