Exemple #1
0
void TensorDerivative(Mode m, Mode mj, Geometry geo, Vec df, Vec vpsibra, Vec vIpsi, int ih){
	double mjc = get_c(mj);
	dcomp mw = get_w(m), yw = gamma_w(m, geo) ;

	Vecfun f, H, psibra;
	CreateVecfun(&f, geo->vf);
	CreateVecfun(&H, geo->vH);
	CreateVecfun(&psibra, vpsibra);

	Complexfun psi;
	CreateComplexfun(&psi, m->vpsi, vIpsi);

	int i;
	for(i=f.ns; i<f.ne; i++){
		if( valr(&f, i) == 0.0) continue;		
		dcomp ket_term = -csqr(mw ) * sqr(mjc) * 2.0
			* sqr(valr(&H, i) ) * geo->D * valr(&f, i) * yw * valc(&psi, i);	
		double val = valr(&psibra, i) * (ir(geo, i)? cimag(ket_term) : creal(ket_term) );
	
		VecSetValue(df, i+offset(geo, ih), val, INSERT_VALUES);
		// df is assembled in SetJacobian
	}
	DestroyVecfun(&f);
	DestroyVecfun(&H);
	DestroyVecfun(&psibra);
	DestroyComplexfun(&psi);
}
Exemple #2
0
void ColumnDerivative(Mode m, Mode mj, Geometry geo, Vec dfR, Vec dfI, Vec vIpsi, Vec vpsisq, int ih){
	// vIpsi is for m, vpsisq is for mj
	// use pointers so can check whether ih = jh


	// purposely don't set df = 0 here to allow multiple ih's
	double mjc = get_c(mj);
	dcomp mw = get_w(m), yw = gamma_w(m, geo);

	Complexfun psi, eps;
	CreateComplexfun(&psi,m->vpsi, vIpsi);
	CreateComplexfun(&eps,geo->veps, geo->vIeps);

	Vecfun f,H, psisq;
	CreateVecfun(&f, geo->vf);
	CreateVecfun(&H, geo->vH);
	CreateVecfun(&psisq, vpsisq);


	int i;
	for(i=psi.ns; i<psi.ne; i++){
		dcomp dfdk = 0.0, dfdc = 0.0, 
			DfywHpsi = geo->D * valr(&f, i) * yw * valr(&H, i) * valc(&psi, i);

		if(m == mj)
			dfdk += ( -csqr(mw)*yw / geo->y +2.0*mw ) * DfywHpsi + 2.0*mw* valc(&eps, i)*valc(&psi, i);
		// note: adding dcomp to a double ignores the imaginary part

		if(m->lasing && valr(&f, i) != 0.0){
		
			// dHdk removed; field simply rescaled -DL 6/15/14

			dfdc = csqr(mw) * DfywHpsi * valr(&H, i);
			dfdc *= (-2.0*mjc)*valr(&psisq, i);
		}
	
		if( !m->lasing)
			VecSetComplex(dfR, dfI, i+offset(geo, ih), ir(geo, i), dfdk, INSERT_VALUES);
		else{
			VecSetValue(dfR, i+offset(geo, ih), ir(geo, i)? cimag(dfdk) : creal(dfdk), INSERT_VALUES );
			VecSetValue(dfI, i+offset(geo, ih), ir(geo, i)? cimag(dfdc) : creal(dfdc), INSERT_VALUES );
		// df is assembled in SetJacobian
		}
	}


	DestroyComplexfun(&eps);
	DestroyComplexfun(&psi);
	DestroyVecfun(&f);
	DestroyVecfun(&H);
	DestroyVecfun(&psisq);
}
Exemple #3
0
void CollectVec(Geometry geo, Vec vN, Vec vM){
	VecSet(vM, 0.0);

	Vecfun f;
	CreateVecfun(&f, geo->vf);

	const double *vals;
	VecGetArrayRead(vN, &vals);
	int ns, ne;
	VecGetOwnershipRange(vN, &ns, &ne);
	if( ne > Nxyzcr(geo)-2) ne = Nxyzcr(geo)-2;

	int i;
	for(i=ns; i<ne; i++){
		if( valr(&f, i) == 0.0) continue;
		// skip if gain profile zero here

		Point p;
		CreatePoint_i(&p, i, &geo->gN);
		if( projectmedium(&p, &geo->gM, geo->LowerPML) )
			VecSetValue(vM, xyz(&p), vals[i-ns], ADD_VALUES);
	}

	VecRestoreArrayRead(vN, &vals);
	DestroyVecfun(&f);
	AssembleVec(vM);
}
Exemple #4
0
void ComputeGain(Geometry geo, Mode *ms, int Nh){	

	VecSet(geo->vH, 0.0);
	Vecfun H, f;
	CreateVecfun(&H, geo->vH);
	CreateVecfun(&f, geo->vf);
	int i, ih;
	for(ih=0; ih<Nh; ih++){
		Mode m = ms[ih];
		double mc = get_c(m);

		// do not change this from vscratch[3], or the hack below for single mode Column derivative will fail!
		VecDotMedium(geo, m->vpsi, m->vpsi, geo->vscratch[3], geo->vMscratch[0]);

		Vecfun psisq;
		CreateVecfun(&psisq ,geo->vscratch[3]);
		for(i=H.ns; i<H.ne; i++){
			if(valr(&f, i) == 0.0) continue;
			setr(&H, i, valr(&H, i) + sqr(mc) * valr(&psisq, i) ) ;
		}
		DestroyVecfun(&psisq);
	}
	
	if(geo->interference != 0.0 && Nh == 2){
		// does not affect single mode case
		VecDotMedium(geo, ms[0]->vpsi, ms[1]->vpsi, geo->vscratch[3], geo->vMscratch[0]);

		Vec Ipsi = geo->vscratch[5];
		TimesI( geo, ms[0]->vpsi, Ipsi);
		VecDotMedium(geo, ms[1]->vpsi, Ipsi, geo->vscratch[6], geo->vMscratch[0]);

		// 2 c1 c2 Re[ exp(i thet) psi1* x psi2) ]
		// term in square bracket is (cos thet + i sin thet ) x 
		// ( E1R . E2R + E1I . E2I ) + i ( E1R . E2I - E1I . E2R )
		
		// vscratch[3] and vscratch[6] are the real and imaginary parts of this last line
		double costh = cos(geo->interference), sinth = sin(geo->interference);
		VecScale(geo->vscratch[6], -sinth);
		VecAXPY( geo->vscratch[6], costh, geo->vscratch[3]);
		// now vscratch[6] = Re[ ... ]

		double mc[2] = {get_c(ms[0]), get_c(ms[1]) };
		Vecfun psi_int;
		CreateVecfun(&psi_int ,geo->vscratch[6]);

		for(i=H.ns; i<H.ne; i++){
			if(valr(&f, i) == 0.0) continue;
			setr(&H, i, valr(&H, i) + 2.0*mc[0]*mc[1] * valr(&psi_int, i) ) ;
		}
		DestroyVecfun(&psi_int);
	}

	for(i=H.ns; i<H.ne; i++)
		setr(&H, i, 1.0 / (1.0 + valr(&H, i) ) );
	// for plotting purposes, don't check if valr(&f, i)==0 here
	DestroyVecfun(&H);
	DestroyVecfun(&f);

}
Exemple #5
0
void LinearDerivative(Mode m, Geometry geo, Vec dfR, Vec dfI, int ih){

	Complexfun eps;
	CreateComplexfun(&eps, geo->veps, geo->vIeps);
	Vecfun f, H;
	CreateVecfun(&f, geo->vf);
	CreateVecfun(&H, geo->vH);

	dcomp mw = get_w(m), yw = gamma_w(m, geo);

	int i;
	for(i=eps.ns; i<eps.ne; i++){
		dcomp val = csqr(mw) * (valc(&eps, i) + geo->D * yw * valr(&f, i) * valr(&H, i) );
		VecSetComplex(dfR, dfI, i+offset(geo, ih), ir(geo, i), val, INSERT_VALUES);
		// df is assembled in SetJacobian
	}

	DestroyVecfun(&f);
	DestroyVecfun(&H);
	DestroyComplexfun(&eps);

}
QString PutHandler::handle(QByteArray t)
{
    QXmlStreamReader* reader = new QXmlStreamReader(t);
    QXmlStreamReader::TokenType token;

    QString pin;
    QString id;
    QString val;

    QRegExp pinr("(\\d{4,4})");
    QRegExp idr("(\\d{5,10})");
    QRegExp valr("(\\d{1,5})");

    while(!reader->atEnd() && !reader->hasError())
    {
        token = reader->readNext();
        if(token == QXmlStreamReader::StartDocument) {
            continue;
        }

        if(token == QXmlStreamReader::StartElement) {
            if(reader->name() == "putMoney")
            {
                continue;
            }
            else if(reader->name() == "pin")
            {
                reader->readNext();
                pin = reader->text().toString();
                continue;
            }
            else if(reader->name() == "id")
            {
                reader->readNext();
                id = reader->text().toString();
                continue;
            }
            else if(reader->name() == "val")
            {
                reader->readNext();
                val = reader->text().toString();
                continue;
            }
            else
            {
                return THandler::handle(t);
            }
        }
    }
    if(reader->hasError()) {
        return "Помилка в транзакції перевірки стану рахунку.";
    }

    //Перевірка валідності полів
    if(!pinr.exactMatch(pin)){
        return "Помилка запису пін коду";
    }
    if(!idr.exactMatch(id)){
        return "Помилка запису id рахунку";
    }
    if(!valr.exactMatch(val)){
        return "Помилка запису кількості грошей";
    }
    if(val.toUInt() == 0 ){
        return "Неправильна кількість грошей";
    }

    return accountManager->getMoney(id,pin,val);
}