Re call(A0& a0) const
 {
     return Re();
 }
/* Lambda formula: z(0)=p, lambda=const., z(n+1) = lambda*z(n)*(1 - z(n)). */
static ordinal_number_t calculate_lambda(lambda_t* handle, const complex_number_t* position)
{


	/* Lambda fractal constants. */
	real_number_t bailout_square;

	/* Three helper variables. */
	real_number_t    radius_square;
	real_number_t    help;
	real_number_t    help_two;
	ordinal_number_t step;
	
	/*
	 * Z stores the complex number during the iterations, Zn is the next iteration step.
	 */
	complex_number_t Z;
	complex_number_t Zn;

	/* These ones accelerate the calculation. */
	complex_number_t Z_square;
	real_number_t    ReZs_ImZs;
	real_number_t    ReZ_ImZ;

	/* Lambda parameter. */
	complex_number_t lambda;

	/* Init multiple precision vars. */
	mpf_set_default_prec(sizeof(char)*handle->prec);
	
	mpf_init(bailout_square);
	mpf_init(Re(lambda));
	mpf_init(Im(lambda));
	mpf_init(Re(Z_square));
	mpf_init(Im(Z_square));
	mpf_init(ReZs_ImZs);
	mpf_init(ReZ_ImZ);
	mpf_init(Re(Z));
	mpf_init(Im(Z));
	mpf_init(Re(Zn));
	mpf_init(Im(Zn));
	mpf_init(radius_square);
	mpf_init(help);
	mpf_init(help_two);

	/* Set the bailout square constant. */
	mpf_set_d(bailout_square,4);
	
	mpf_set(Re(lambda),Re(handle->lambda));
	mpf_set(Im(lambda),Im(handle->lambda));

	/* The calculation begins with the a point on the complex plane. */
	mpf_set(Re(Z),position->real_part);
	mpf_set(Im(Z),position->imaginary_part);

	//fprintf(stderr,"Hallo\n");
	/* Now do the iteration. */
	for (step=0;step<handle->iteration_steps;step++)
	{
		/* Calculate Z_square first, as we can use a faster formula then. */
		mpf_mul(Re(Z_square),Re(Z),Re(Z));
		mpf_mul(Im(Z_square),Im(Z),Im(Z));

		/* Calculate the radius from complex pane origin to Z. */
		mpf_add(radius_square,Re(Z_square),Im(Z_square));

 		/* Break the iteration if the mandelbrot bailout orbit is left. */
		if (mpf_cmp(radius_square,bailout_square)>0) break;

		/* Two other speed up variables. */
		mpf_sub(ReZs_ImZs,Re(Z_square),Im(Z_square));
		mpf_mul(ReZ_ImZ,Im(Z),Re(Z));

		/* Now calculate the lambda function. */
		mpf_mul(help,Re(lambda),Re(Z));
		mpf_mul(help_two,Im(lambda),Im(Z));
		mpf_sub(help,help,help_two);
		mpf_mul(help_two,Re(lambda),ReZs_ImZs);
		mpf_add(help,help,help_two);
		mpf_mul_ui(help_two,Im(lambda),2);
		mpf_mul(help_two,help_two,ReZ_ImZ);
		mpf_sub(Re(Zn),help,help_two);

		mpf_mul(help,Re(lambda),Im(Z));
		mpf_mul(help_two,Im(lambda),Re(Z));
		mpf_add(help,help,help_two);
		mpf_mul(help_two,Im(lambda),ReZs_ImZs);
		mpf_add(help,help,help_two);
		mpf_mul_ui(help_two,Re(lambda),2);
		mpf_mul(help_two,help_two,ReZ_ImZ);
		mpf_add(Im(Zn),help,help_two);

		/* Copy Zn to Z */
		mpf_set(Re(Z),Re(Zn));
		mpf_set(Im(Z),Im(Zn));
	}

	/* Clear multiple precision Variables. */
	mpf_clear(bailout_square);
	mpf_clear(radius_square);
	mpf_clear(help);
	mpf_clear(help_two);
	mpf_clear(Re(Z));
	mpf_clear(Im(Z));
	mpf_clear(Re(Zn));
	mpf_clear(Im(Zn));
	mpf_clear(Re(Z_square));
	mpf_clear(Im(Z_square));
	mpf_clear(ReZs_ImZs);
	mpf_clear(ReZ_ImZ);
	mpf_clear(Re(lambda));
	mpf_clear(Im(lambda));

	return step; /* Return the iteration step in which we reached the bailout radius. */
}
Esempio n. 3
0
int FSolver::HarmonicAxisymmetric(CBigComplexLinProb &L)
{
    int i,j,k,s,flag,sdi_iter,sdin,ww,Iter=0;
    int pctr;
    CComplex Mx[3][3],My[3][3],Mn[3][3],Me[3][3],be[3];		// element matrices;
    double l[3],p[3],q[3];		// element shape parameters;
    int n[3];					// numbers of nodes for a particular element;
    double a,r,t,x,y,B,w,res,lastres,ds,R,rn[3],g[3],a_hat,R_hat,vol,Cduct;
    CComplex K,mu,dv,B1,B2,v[3],mu1,mu2,lag,halflag,deg45,Jv; //u[3],
    CComplex **Mu,*V_sdi,*V_old;
    double c=PI*4.e-05;
    double units[]= {2.54,0.1,1.,100.,0.00254,1.e-04};
    CElement *El;
    int LinearFlag=TRUE;
    int SDIflag=FALSE;
    res=0;

// #ifndef NEWTON
    CComplex murel,muinc;
// #else
    CComplex Mnh[3][3];
    CComplex Mna[3][3];
    CComplex Mns[3][3];
// #endif

    extRo*=units[LengthUnits];
    extRi*=units[LengthUnits];
    extZo*=units[LengthUnits];

    deg45=1+I;
    w=Frequency*2.*PI;

    CComplex *CircInt1,*CircInt2,*CircInt3;


    // Can't handle LamType==1 or LamType==2 in AC problems.
    // Detect if this is being attempted.
    for(i=0; i<NumEls; i++)
    {
        if( (blockproplist[meshele[i].blk].LamType==1) ||
                (blockproplist[meshele[i].blk].LamType==2) )
        {
            WarnMessage("On-edge lamination not supported in AC analyses");
            return FALSE;
        }
    }

    // Go through and evaluate permeability for regions subject to prox effects
    for(i=0; i<NumBlockLabels; i++) GetFillFactor(i);

    V_old=(CComplex *) calloc(NumNodes+NumCircProps,sizeof(CComplex));

    // check to see if any circuits have been defined and process them;
    if (NumCircProps>0)
    {
        CircInt1=(CComplex *)calloc(NumCircProps,sizeof(CComplex));
        CircInt2=(CComplex *)calloc(NumCircProps,sizeof(CComplex));
        CircInt3=(CComplex *)calloc(NumCircProps,sizeof(CComplex));
        for(i=0; i<NumEls; i++)
        {
            if(meshele[i].lbl>=0)
                if(labellist[meshele[i].lbl].InCircuit!=-1)
                {
                    El=&meshele[i];

                    // get element area;
                    for(k=0; k<3; k++) n[k]=El->p[k];
                    p[0]=meshnode[n[1]].y - meshnode[n[2]].y;
                    p[1]=meshnode[n[2]].y - meshnode[n[0]].y;
                    p[2]=meshnode[n[0]].y - meshnode[n[1]].y;
                    q[0]=meshnode[n[2]].x - meshnode[n[1]].x;
                    q[1]=meshnode[n[0]].x - meshnode[n[2]].x;
                    q[2]=meshnode[n[1]].x - meshnode[n[0]].x;
                    a=(p[0]*q[1]-p[1]*q[0])/2.;
                    r=(meshnode[n[0]].x+meshnode[n[1]].x+meshnode[n[2]].x)/3.;

                    // if coils are wound, they act like they have
                    // a zero "bulk" conductivity...
                    Cduct=blockproplist[El->blk].Cduct;
                    if (labellist[El->lbl].bIsWound) Cduct=0;

                    // evaluate integrals;

                    // total cross-section of circuit;
                    CircInt1[labellist[El->lbl].InCircuit]+=a;

                    // integral of conductivity / R over the circuit;
                    CircInt2[labellist[El->lbl].InCircuit]+=a*Cduct/(0.01*r);

                    // integral of applied J over current;
                    CircInt3[labellist[El->lbl].InCircuit]+=
                        (blockproplist[El->blk].Jr+I*blockproplist[El->blk].Ji)*a*100.;
                }
        }

        for(i=0; i<NumCircProps; i++)
        {
            if (circproplist[i].CircType==0) // specified current
            {
                if(CircInt2[i]==0)  //circuit composed of zero cond. materials
                {
                    circproplist[i].Case=1;
                    if (CircInt1[i]==0.) circproplist[i].J=0.;
                    else circproplist[i].J=0.01*(
                                                   (circproplist[i].Amps_re+I*circproplist[i].Amps_im) -
                                                   CircInt3[i])/CircInt1[i];
                }
                else
                {
                    circproplist[i].Case=2; // need to include an extra
                    // entry in matrix to solve for
                    // voltage grad in the circuit
                }
            }
            else
            {
                // case where voltage gradient is specified a priori...
                circproplist[i].Case=0;
                circproplist[i].dV=circproplist[i].dVolts_re +
                                   I*circproplist[i].dVolts_im;
            }
        }
    }


    // check to see if there are any SDI boundaries...
    // lineproplist[ meshele[i].e[j] ].BdryFormat==0
    for(i=0; i<NumLineProps; i++)
        if(lineproplist[i].BdryFormat==3) SDIflag=TRUE;

    if(SDIflag==TRUE)
    {
        // there is an SDI boundary defined; check to see if it is in use
        SDIflag=FALSE;
        for(i=0; i<NumEls; i++)
            for(j=0; j<3; j++)
                if (lineproplist[meshele[i].e[j]].BdryFormat==3)
                {
                    SDIflag=TRUE;
                    printf("Problem has SDI boundaries\n");
                    i=NumEls;
                    j=3;
                }
    }

    if (SDIflag==TRUE)
    {
        V_sdi=(CComplex *) calloc(NumNodes+NumCircProps,sizeof(CComplex));
        sdin=2;
    }
    else sdin=1;


    // compute effective permeability for each block type;
    Mu=(CComplex **)calloc(NumBlockProps,sizeof(CComplex *));
    for(i=0; i<NumBlockProps; i++) Mu[i]=(CComplex *)calloc(2,sizeof(CComplex));

    for(k=0; k<NumBlockProps; k++)
    {

        if (blockproplist[k].LamType==0)
        {

            Mu[k][0]=blockproplist[k].mu_x*exp(-I*blockproplist[k].Theta_hx*PI/180.);
            Mu[k][1]=blockproplist[k].mu_y*exp(-I*blockproplist[k].Theta_hy*PI/180.);

            if(blockproplist[k].Lam_d!=0)
            {
                if (blockproplist[k].Cduct != 0)
                {
                    halflag=exp(-I*blockproplist[k].Theta_hx*PI/360.);
                    ds=sqrt(2./(0.4*PI*w*blockproplist[k].Cduct*blockproplist[k].mu_x));
                    K=halflag*deg45*blockproplist[k].Lam_d*0.001/(2.*ds);
                    Mu[k][0]=((Mu[k][0]*tanh(K))/K)*blockproplist[k].LamFill +
                             (1.-blockproplist[k].LamFill);

                    halflag=exp(-I*blockproplist[k].Theta_hy*PI/360.);
                    ds=sqrt(2./(0.4*PI*w*blockproplist[k].Cduct*blockproplist[k].mu_y));
                    K=halflag*deg45*blockproplist[k].Lam_d*0.001/(2.*ds);
                    Mu[k][1]=((Mu[k][1]*tanh(K))/K)*blockproplist[k].LamFill +
                             (1.-blockproplist[k].LamFill);
                }
                else
                {
                    Mu[k][0]=Mu[k][0]*blockproplist[k].LamFill +
                             (1.- blockproplist[k].LamFill);
                    Mu[k][1]=Mu[k][1]*blockproplist[k].LamFill +
                             (1. - blockproplist[k].LamFill);
                }

            }
        }
        else
        {
            Mu[k][0]=1;
            Mu[k][1]=1;
        }
    }


    do
    {
        for(sdi_iter=0; sdi_iter<sdin; sdi_iter++)
        {
//		TheView->SetDlgItemText(IDC_FRAME1,"Matrix Construction");
//		TheView->m_prog1.SetPos(0);
            printf("Matrix Construction\n");
            pctr=0;

            if (Iter>0) L.Wipe();

            // build element matrices using the matrices derived in Allaire's book.
            for(i=0; i<NumEls; i++)
            {

                // update ``building matrix'' progress bar...
                j=(i*20)/NumEls+1;
                if(j>pctr)
                {
                    j=pctr*5;
                    if (j>100) j=100;
//			TheView->m_prog1.SetPos(j);
                    pctr++;
                }

                // zero out Me, be;
                for(j=0; j<3; j++)
                {
                    for(k=0; k<3; k++)
                    {
                        Me[j][k]=0;
                        Mx[j][k]=0;
                        My[j][k]=0;
                        Mn[j][k]=0;
// #ifdef NEWTON
                        if (ACSolver==1)
                        {
                            Mnh[j][k]=0;
                            Mna[j][k]=0;
                            Mns[j][k]=0;
                        }
// #endif
                    }
                    be[j]=0;
                }

                // Determine shape parameters.
                // l == element side lengths;
                // p corresponds to the `b' parameter in Allaire
                // q corresponds to the `c' parameter in Allaire
                El=&meshele[i];

                for(k=0; k<3; k++)
                {
                    n[k]=El->p[k];
                    rn[k]=meshnode[n[k]].x;
                }

                p[0]=meshnode[n[1]].y - meshnode[n[2]].y;
                p[1]=meshnode[n[2]].y - meshnode[n[0]].y;
                p[2]=meshnode[n[0]].y - meshnode[n[1]].y;
                q[0]=meshnode[n[2]].x - meshnode[n[1]].x;
                q[1]=meshnode[n[0]].x - meshnode[n[2]].x;
                q[2]=meshnode[n[1]].x - meshnode[n[0]].x;
                g[0]=(meshnode[n[2]].x + meshnode[n[1]].x)/2.;
                g[1]=(meshnode[n[0]].x + meshnode[n[2]].x)/2.;
                g[2]=(meshnode[n[1]].x + meshnode[n[0]].x)/2.;

                for(j=0,k=1; j<3; k++,j++)
                {
                    if (k==3) k=0;
                    l[j]=sqrt( pow(meshnode[n[k]].x-meshnode[n[j]].x,2.) +
                               pow(meshnode[n[k]].y-meshnode[n[j]].y,2.) );
                }
                a=(p[0]*q[1]-p[1]*q[0])/2.;
                R=(meshnode[n[0]].x+meshnode[n[1]].x+meshnode[n[2]].x)/3.;

                for(j=0,a_hat=0; j<3; j++) a_hat+=(rn[j]*rn[j]*p[j]/(4.*R));
                vol=2.*R*a_hat;

                for(j=0,flag=0; j<3; j++) if(rn[j]<1.e-06) flag++;
                switch(flag)
                {
                case 2:
                    R_hat=R;

                    break;

                case 1:

                    if(rn[0]<1.e-06)
                    {
                        if (fabs(rn[1]-rn[2])<1.e-06) R_hat=rn[2]/2.;
                        else R_hat=(rn[1] - rn[2])/(2.*log(rn[1]) - 2.*log(rn[2]));
                    }
                    if(rn[1]<1.e-06)
                    {
                        if (fabs(rn[2]-rn[0])<1.e-06) R_hat=rn[0]/2.;
                        else R_hat=(rn[2] - rn[0])/(2.*log(rn[2]) - 2.*log(rn[0]));
                    }
                    if(rn[2]<1.e-06)
                    {
                        if (fabs(rn[0]-rn[1])<1.e-06) R_hat=rn[1]/2.;
                        else R_hat=(rn[0] - rn[1])/(2.*log(rn[0]) - 2.*log(rn[1]));
                    }

                    break;

                default:

                    if (fabs(q[0])<1.e-06)
                        R_hat=(q[1]*q[1])/(2.*(-q[1] + rn[0]*log(rn[0]/rn[2])));
                    else if (fabs(q[1])<1.e-06)
                        R_hat=(q[2]*q[2])/(2.*(-q[2] + rn[1]*log(rn[1]/rn[0])));
                    else if (fabs(q[2])<1.e-06)
                        R_hat=(q[0]*q[0])/(2.*(-q[0] + rn[2]*log(rn[2]/rn[1])));
                    else
                        R_hat=-(q[0]*q[1]*q[2])/
                              (2.*(q[0]*rn[0]*log(rn[0]) +
                                   q[1]*rn[1]*log(rn[1]) +
                                   q[2]*rn[2]*log(rn[2])));

                    break;
                }

                // Mr Contribution
                // Derived from flux formulation with c0 + c1 r^2 + c2 z
                // interpolation in the element.
                K=(-1./(2.*a_hat*R));
                for(j=0; j<3; j++)
                    for(k=j; k<3; k++)
                        Mx[j][k] += K*p[j]*rn[j]*p[k]*rn[k];

                // need this loop to avoid singularities.  This just puts something
                // on the main diagonal of nodes that are on the r=0 line.
                // The program later sets these nodes to zero, but it's good to
                // for scaling reasons to grab entries from the neighboring diagonals
                // rather than just setting these entries to 1 or something....
                for(j=0; j<3; j++)
                    if (rn[j]<1.e-06) Mx[j][j]+=Mx[0][0]+Mx[1][1]+Mx[2][2];

                // Mz Contribution;
                // Derived from flux formulation with c0 + c1 r^2 + c2 z
                // interpolation in the element.
                K=(-1./(2.*a_hat*R_hat));
                for(j=0; j<3; j++)
                    for(k=j; k<3; k++)
                        My[j][k] += K*(q[j]*rn[j])*(q[k]*rn[k])*
                                    (g[j]/R)*(g[k]/R);

                // Fill out rest of entries of Mx and My;
                Mx[1][0]=Mx[0][1];
                Mx[2][0]=Mx[0][2];
                Mx[2][1]=Mx[1][2];
                My[1][0]=My[0][1];
                My[2][0]=My[0][2];
                My[2][1]=My[1][2];

                // contribution from eddy currents;
                // induced current interpolated as constant (avg. of nodal values)
                // over the entire element;
                K = -I*R*a*w*blockproplist[meshele[i].blk].Cduct*c/6.;

                // radially laminated blocks appear to have no conductivity;
                // eddy currents are accounted for in these elements by their
                // frequency-dependent permeability.
                if((blockproplist[El->blk].LamType==0) &&
                        (blockproplist[El->blk].Lam_d>0)) K=0;

                // if this element is part of a wound coil,
                // it should have a zero "bulk" conductivity...
                if(labellist[El->lbl].bIsWound) K=0;

                for(j=0; j<3; j++)
                    for(k=0; k<3; k++)
                        Me[j][k]+=K*4./3.;

                // contributions to Me, be from derivative boundary conditions;
                for(j=0; j<3; j++)
                {
                    k=j+1;
                    if(k==3) k=0;
                    r=(meshnode[n[j]].x+meshnode[n[k]].x)/2.;
                    if (El->e[j] >= 0)
                    {

                        if (lineproplist[El->e[j]].BdryFormat==2)
                        {
                            // conversion factor is 10^(-4) (I think...)

                            K = -0.0001*c*2.*r*lineproplist[ El->e[j] ].c0*l[j]/6.;
                            Me[j][j]+=2*K;
                            Me[k][k]+=2*K;
                            Me[j][k]+=K;
                            Me[k][j]+=K;

                            K = (lineproplist[ El->e[j] ].c1*l[j]/2.)*2.*r*0.0001;
                            be[j]+=K;
                            be[k]+=K;
                        }

                        if (lineproplist[El->e[j]].BdryFormat==1)
                        {
                            ds=sqrt(2./(0.4*PI*w*lineproplist[El->e[j]].Sig*
                                        lineproplist[El->e[j]].Mu));
                            K=deg45/(-ds*lineproplist[El->e[j]].Mu*100.);
                            K*=(2.*r*l[j]/6.);
                            Me[j][j]+=2*K;
                            Me[k][k]+=2*K;
                            Me[j][k]+=K;
                            Me[k][j]+=K;
                        }

                    }
                }

                // contribution to be from current density in the block
                for(j=0; j<3; j++)
                {
                    Jv=0;
                    if(labellist[El->lbl].InCircuit>=0)
                    {
                        k=labellist[El->lbl].InCircuit;
                        if(circproplist[k].Case==1) Jv=circproplist[k].J;
                        if(circproplist[k].Case==0)
                            Jv=-100.*circproplist[k].dV*
                               blockproplist[El->blk].Cduct/R;
                    }

                    K=-2.*R*(blockproplist[El->blk].Jr+I*blockproplist[El->blk].Ji+Jv)*a/3.;
                    be[j]+=K;

                    if(labellist[El->lbl].InCircuit>=0)
                    {
                        k=labellist[El->lbl].InCircuit;
                        if(circproplist[k].Case==2)
                            L.b[NumNodes+k]+=K/R;
                    }
                }

                // do Case 2 circuit stuff for element
                if(labellist[El->lbl].InCircuit>=0)
                {
                    k=labellist[El->lbl].InCircuit;
                    if(circproplist[k].Case==2)
                    {
                        K=-2.*I*a*w*blockproplist[meshele[i].blk].Cduct*c;
                        for(j=0; j<3; j++)
                            L.Put(L.Get(n[j],NumNodes+k)+K/3.,n[j],NumNodes+k);
                        L.Put(L.Get(NumNodes+k,NumNodes+k)+K/R,NumNodes+k,NumNodes+k);
                    }
                }

/////////////////////////
//
//  Nonlinear Stuff
//
/////////////////////////

                // update permeability for the element;
                if (Iter==0)
                {
                    k=meshele[i].blk;
                    if (blockproplist[k].BHpoints != 0) LinearFlag=FALSE;
                    meshele[i].mu1=Mu[k][0];
                    meshele[i].mu2=Mu[k][1];
                }
                else
                {
                    k=meshele[i].blk;

                    if ((blockproplist[k].LamType==0) &&
                            (meshele[i].mu1==meshele[i].mu2)
                            &&(blockproplist[k].BHpoints>0))
                    {
                        //	Derive B directly from energy;
                        v[0]=0;
                        v[1]=0;
                        v[2]=0;
                        for(j=0; j<3; j++)
                            for(ww=0; ww<3; ww++)
                                v[j]+=(Mx[j][ww]+My[j][ww])*L.V[n[ww]];
                        for(j=0,dv=0; j<3; j++) dv+=conj(L.V[n[j]])*v[j];
                        dv*=(10000.*c*c/vol);
                        B=sqrt(abs(dv));

// #ifdef NEWTON
                        if (ACSolver==1)
                        {
                            // find out new mu from saturation curve;
                            blockproplist[k].GetBHProps(B,mu,dv);
                            mu=1./(muo*mu);
                            meshele[i].mu1=mu;
                            meshele[i].mu2=mu;
                            for(j=0; j<3; j++)
                            {
                                for(ww=0,v[j]=0; ww<3; ww++)
                                    v[j]+=(Mx[j][ww]+My[j][ww])*L.V[n[ww]];
                            }

                            // Newton iteration
                            K=-200.*c*c*c*dv/vol;
                            for(j=0; j<3; j++)
                                for(ww=0; ww<3; ww++)
                                {
                                    // Still compute Mn, the approximate N-R matrix used in
                                    // the complex-symmetric approx.  This will be useful
                                    // w.r.t. preconditioning.  However, subtract it off of Mnh and Mna
                                    // so that there is no net addition.
                                    Mn[j][ww] =K*Re(v[j]*conj(v[ww]));
                                    Mnh[j][ww]=  0.5*Re(K)*v[j]*conj(v[ww])-Re(Mn[j][ww]);
                                    Mna[j][ww]=I*0.5*Im(K)*v[j]*conj(v[ww])-I*Im(Mn[j][ww]);
                                    Mns[j][ww]=  0.5*K*v[j]*v[ww];
                                }
                        }
// #else
                        else
                        {
                            // find out new mu from saturation curve;
                            murel=1./(muo*blockproplist[k].Get_v(B));
                            muinc=1./(muo*blockproplist[k].GetdHdB(B));

                            // successive approximation;
                            //      K=muinc;                            // total incremental
                            //      K=murel;                            // total updated
                            K=2.*murel*muinc/(murel+muinc);     // averaged
                            meshele[i].mu1=K;
                            meshele[i].mu2=K;
                            K=-(1./murel - 1/K);
                            for(j=0; j<3; j++)
                                for(ww=0; ww<3; ww++)
                                    Mn[j][ww]=K*(Mx[j][ww]+My[j][ww]);
                        }
// #endif
                    }
                }

                // Apply correction for elements subject to prox effects
                if((blockproplist[meshele[i].blk].LamType>2) && (Iter==0) && (sdi_iter==0))
                {
                    meshele[i].mu1=labellist[meshele[i].lbl].ProximityMu;
                    meshele[i].mu2=labellist[meshele[i].lbl].ProximityMu;
                }

                // "Warp" the permeability of this element if part of
                // the conformally mapped external region
                if((labellist[meshele[i].lbl].IsExternal) && (Iter==0) && (sdi_iter==0))
                {
                    double Z=(meshnode[n[0]].y+meshnode[n[1]].y+meshnode[n[2]].y)/3. - extZo;
                    double kludge=(R*R+Z*Z)*extRi/(extRo*extRo*extRo);
                    meshele[i].mu1/=kludge;
                    meshele[i].mu2/=kludge;
                }

                // combine block matrices into global matrices;
                for(j=0; j<3; j++)
                    for(k=0; k<3; k++)
                    {
//#ifdef NEWTON
                        if (ACSolver==1)
                        {
                            Me[j][k]+= (Mx[j][k]/(El->mu2) + My[j][k]/(El->mu1) + Mn[j][k]);
                            be[j]+=(Mnh[j][k]+Mna[j][k]+Mn[j][k])*L.V[n[k]];
                            be[j]+=Mns[j][k]*L.V[n[k]].Conj();
                        }
//#else
                        else
                        {
                            Me[j][k]+= (Mx[j][k]/(El->mu2) + My[j][k]/(El->mu1));
                            be[j]+=Mn[j][k]*L.V[n[k]];
                        }
//#endif

                    }

                for (j=0; j<3; j++)
                {
                    for (k=j; k<3; k++)
                    {
                        L.Put(L.Get(n[j],n[k])+Me[j][k],n[j],n[k]);
//#ifdef NEWTON
                        if (ACSolver==1)
                        {
                            if (Mnh[j][k]!=0) L.Put(L.Get(n[j],n[k],1) + Mnh[j][k],n[j],n[k],1);
                            if (Mns[j][k]!=0) L.Put(L.Get(n[j],n[k],2) + Mns[j][k],n[j],n[k],2);
                            if (Mna[j][k]!=0) L.Put(L.Get(n[j],n[k],3) + Mna[j][k],n[j],n[k],3);
                        }
//#endif
                    }
                    L.b[n[j]]+=be[j];
                }

///////////////////////////////////////////////////

            }

            // add in contribution from point currents;
            for(i=0; i<NumNodes; i++)
                if(meshnode[i].bc>=0)
                {
                    r=meshnode[i].x;
                    K = (2.*r*0.01)*(nodeproplist[meshnode[i].bc].Jr +
                                     I*nodeproplist[meshnode[i].bc].Ji);
                    L.b[i]-=K;
                }

            // add in total current constraints for circuits;
            for(i=0; i<NumCircProps; i++)
                if (circproplist[i].Case==2)
                {
                    L.b[NumNodes+i]+=2.*0.01*(circproplist[i].Amps_re +
                                              I*circproplist[i].Amps_im);
                }

            // apply fixed boundary conditions at points;
            for(i=0; i<NumNodes; i++)
                if(meshnode[i].x<(units[LengthUnits]*1.e-06))
                {
                    K=0;
                    L.SetValue(i,K);
                }
                else if(meshnode[i].bc >=0)
                    if((nodeproplist[meshnode[i].bc].Jr==0) &&
                            (nodeproplist[meshnode[i].bc].Ji==0) && (sdi_iter==0))
                    {
                        K =  (nodeproplist[meshnode[i].bc].Ar
                              + I*nodeproplist[meshnode[i].bc].Ai) / c;
                        L.SetValue(i,K);
                    }

            // apply fixed boundary conditions along segments;
            for(i=0; i<NumEls; i++)
                for(j=0; j<3; j++)
                {
                    k=j+1;
                    if(k==3) k=0;
                    if(meshele[i].e[j]>=0)
                        if(lineproplist[ meshele[i].e[j] ].BdryFormat==0)
                        {
                            if(Coords==0)
                            {
                                // first point on the side;
                                x=meshnode[meshele[i].p[j]].x;
                                y=meshnode[meshele[i].p[j]].y;
                                x/=units[LengthUnits];
                                y/=units[LengthUnits];
                                s=meshele[i].e[j];
                                a=lineproplist[s].A0 + x*lineproplist[s].A1 +
                                  y*lineproplist[s].A2;
                                K=(a/c)*exp(I*lineproplist[s].phi*DEG);
                                L.SetValue(meshele[i].p[j],K);

                                // second point on the side;
                                x=meshnode[meshele[i].p[k]].x;
                                y=meshnode[meshele[i].p[k]].y;
                                x/=units[LengthUnits];
                                y/=units[LengthUnits];
                                s=meshele[i].e[j];
                                a=lineproplist[s].A0 + x*lineproplist[s].A1 +
                                  y*lineproplist[s].A2;
                                K=(a/c)*exp(I*lineproplist[s].phi*DEG);
                                L.SetValue(meshele[i].p[k],K);
                            }
                            else
                            {
                                // first point on the side;
                                x=meshnode[meshele[i].p[j]].x;
                                y=meshnode[meshele[i].p[j]].y;
                                r=sqrt(x*x+y*y);
                                if ((x==0) && (y==0)) t=0;
                                else t=atan2(y,x)/DEG;
                                r/=units[LengthUnits];
                                s=meshele[i].e[j];
                                a=lineproplist[s].A0 + r*lineproplist[s].A1 +
                                  t*lineproplist[s].A2;
                                K=(a/c)*exp(I*lineproplist[s].phi*DEG);
                                L.SetValue(meshele[i].p[j],K);

                                // second point on the side;
                                x=meshnode[meshele[i].p[k]].x;
                                y=meshnode[meshele[i].p[k]].y;
                                r=sqrt(x*x+y*y);
                                if((x==0) && (y==0)) t=0;
                                else t=atan2(y,x)/DEG;
                                r/=units[LengthUnits];
                                s=meshele[i].e[j];
                                a=lineproplist[s].A0 + r*lineproplist[s].A1 +
                                  t*lineproplist[s].A2;
                                K=(a/c)*exp(I*lineproplist[s].phi*DEG);
                                L.SetValue(meshele[i].p[k],K);
                            }

                        }
                }

            if ((SDIflag==TRUE) && (sdi_iter==1)) for(i=0; i<NumEls; i++)
                    for(j=0; j<3; j++)
                    {
                        k=j+1;
                        if(k==3) k=0;
                        if(meshele[i].e[j]>=0)
                            if(lineproplist[ meshele[i].e[j] ].BdryFormat==3)
                            {
                                L.SetValue(meshele[i].p[j],0.*I);
                                L.SetValue(meshele[i].p[k],0.*I);
                            }
                    }

            // "fix" diagonal entries associated with circuits that have
            // applied current or voltage that is known a priori
            // so that solver doesn't throw a "singular" flag
            for(j=0; j<NumCircProps; j++)
                if (circproplist[j].Case<2)	L.Put(L.Get(0,0),NumNodes+j,NumNodes+j);

            for(k=0; k<NumPBCs; k++)
            {
                if (pbclist[k].t==0) L.Periodicity(pbclist[k].x,pbclist[k].y);
                if (pbclist[k].t==1) L.AntiPeriodicity(pbclist[k].x,pbclist[k].y);
            }

            // solve the problem;
            if (SDIflag==FALSE) for(j=0; j<NumNodes+NumCircProps; j++) V_old[j]=L.V[j];
            else
            {
                if(sdi_iter==0)
                    for(j=0; j<NumNodes+NumCircProps; j++) V_sdi[j]=L.V[j];
                else
                    for(j=0; j<NumNodes+NumCircProps; j++)
                    {
                        V_old[j]=V_sdi[j];
                        V_sdi[j]=L.V[j];
                    }
            }

            if (L.bNewton)
            {
                L.Precision=std::min(1.e-4,0.001*res);
                if (L.Precision<Precision) L.Precision=Precision;
            }

            if (L.PBCGSolveMod(Iter+sdi_iter)==FALSE) return FALSE;

            if(sdi_iter==1)
                for(j=0; j<NumNodes+NumCircProps; j++) L.V[j]=(V_sdi[j]+L.V[j])/2.;

        } //end of SDI loop;

        if (LinearFlag==FALSE)
        {

            for(j=0,x=0,y=0; j<NumNodes; j++)
            {
                x+=Re((L.V[j]-V_old[j])*conj(L.V[j]-V_old[j]));
                y+=Re(L.V[j]*conj(L.V[j]));
            }
            if (y==0) LinearFlag=TRUE;
            else
            {
                lastres=res;
                res=sqrt(x/y);
            }

            // relaxation if we need it
            if(Iter>5)
            {
                if ((res>lastres) && (Relax>0.1)) Relax/=2.;
                else Relax+= 0.1 * (1. - Relax);

                for(j=0; j<NumNodes+NumCircProps; j++) L.V[j]=Relax*L.V[j]+(1.0-Relax)*V_old[j];
            }


            // report some results
            char outstr[256];
//#ifdef NEWTON
            if(ACSolver==1) sprintf(outstr,"Newton Iteration(%i) Relax=%.4g\n",Iter,Relax);
//#else
            else sprintf(outstr,"Successive Approx(%i) Relax=%.4g\n",Iter,Relax);
//#endif
//        TheView->SetDlgItemText(IDC_FRAME2,outstr);
            printf("%s\n", outstr);
            j=(int)  (100.*log10(res)/(log10(Precision)+2.));
            if (j>100) j=100;
//        TheView->m_prog2.SetPos(j);
        }

        // nonlinear iteration has to have a looser tolerance
        // than the linear solver--otherwise, things can't ever
        // converge.  Arbitrarily choose 100*tolerance.
        if((res<100.*Precision) && Iter>0) LinearFlag=TRUE;

        Iter++;

    }
    while(LinearFlag==FALSE);


    // convert answer back to webers
    for (i=0; i<NumNodes; i++) L.b[i]=L.V[i]*c*2.*PI*meshnode[i].x*0.01;
    for (i=0; i<NumCircProps; i++)
        L.b[NumNodes+i]=(I*w*c*0.01*L.V[NumNodes+i]);


    // free up space allocated in this routine
    for(k=0; k<NumBlockProps; k++) free(Mu[k]);
    free(Mu);
    free(V_old);
    if (SDIflag==TRUE) free(V_sdi);
    if(NumCircProps>0)
    {
        free(CircInt1);
        free(CircInt2);
        free(CircInt3);
    }
    return TRUE;
}
Esempio n. 4
0
Arbin Re(Arbin n){
  if(jeton=='+'){
    printf("Re->+TRe\n");
    AVANCER
    return construire('+',n,Re(T()));
  }
Esempio n. 5
0
void CbelaviewDoc::LineIntegral(int inttype, double *z)
{
// inttype	Integral
//		0	E.t
//		1	D.n 
//		2	Contour length 
//		3	Stress Tensor Force 
//		4	Stress Tensor Torque 

	// inttype==0 => E.t 
	if(inttype==0){ 
		CPointVals u;
		int k;

		k=(int) contour.GetSize();
		GetPointValues(contour[0].re,contour[0].im, u);
		z[0] = u.V;
		GetPointValues(contour[k-1].re,contour[k-1].im,u);
		z[0]-= u.V;
	}

	// inttype==1 => D.n
	if(inttype==1){
		CComplex n,t,pt;
		CPointVals v;
		double dz,u,d,Dn;
		int i,j,k,m,elm;
		int NumPlotPoints=d_LineIntegralPoints;
		BOOL flag;

		z[0]=0;
		z[1]=0;
		for(k=1;k<contour.GetSize();k++)
		{
			dz=abs(contour[k]-contour[k-1])/((double) NumPlotPoints);
			for(i=0,elm=-1;i<NumPlotPoints;i++)
			{
				u=(((double) i)+0.5)/((double) NumPlotPoints);
				pt=contour[k-1] + u*(contour[k] - contour[k-1]);
				t=contour[k]-contour[k-1];
				t/=abs(t);
				n=I*t;
				pt+=n*1.e-06;
			
				if (elm<0) elm=InTriangle(pt.re,pt.im);
				else if (InTriangleTest(pt.re,pt.im,elm)==FALSE)
				{
					flag=FALSE;
					for(j=0;j<3;j++)
						for(m=0;m<NumList[meshelem[elm].p[j]];m++)
						{
							elm=ConList[meshelem[elm].p[j]][m];
							if (InTriangleTest(pt.re,pt.im,elm)==TRUE)
							{
								flag=TRUE;
								m=100;
								j=3;
							}
						}
					if (flag==FALSE) elm=InTriangle(pt.re,pt.im);
				}
				if(elm>=0)
					flag=GetPointValues(pt.re,pt.im,elm,v);
				else flag=FALSE;

				if(flag==TRUE){
					Dn = Re(v.D/n);
					
					if (ProblemType==AXISYMMETRIC)
						d=2.*PI*pt.re*sq(LengthConv[LengthUnits]);
					else
						d=Depth*LengthConv[LengthUnits];

					z[0]+=(Dn*dz*d);
					z[1]+=dz*d;
				}
			}
		}
		z[1]=z[0]/z[1]; // Average D.n over the surface;
	}

	// inttype==2 => Contour Length
	if(inttype==2){
		int i,k;
		k=(int) contour.GetSize();
		for(i=0,z[0]=0;i<k-1;i++)
			z[0]+=abs(contour[i+1]-contour[i]);
		z[0]*=LengthConv[LengthUnits];

		if(ProblemType==1){
			for(i=0,z[1]=0;i<k-1;i++)
				z[1]+=(PI*(contour[i].re+contour[i+1].re)*
						abs(contour[i+1]-contour[i]));
			z[1]*=pow(LengthConv[LengthUnits],2.);
		}
		else{
			z[1]=z[0]*Depth;
		}
	}

	// inttype==3 => Stress Tensor Force
	if(inttype==3){
		CComplex n,t,pt;
		double Hn,Bn,BH,dF1,dF2;
		CPointVals v;
		double dz,dza,u;
		int i,j,k,m,elm;
		int NumPlotPoints=d_LineIntegralPoints;
		BOOL flag;

		for(i=0;i<4;i++) z[i]=0;

		for(k=1;k<contour.GetSize();k++)
		{
			dz=abs(contour[k]-contour[k-1])/((double) NumPlotPoints);
			for(i=0,elm=-1;i<NumPlotPoints;i++)
			{
				u=(((double) i)+0.5)/((double) NumPlotPoints);
				pt=contour[k-1] + u*(contour[k] - contour[k-1]);
				t=contour[k]-contour[k-1];
				t/=abs(t);
				n=I*t;
				pt+=n*1.e-06;
			
				if (elm<0) elm=InTriangle(pt.re,pt.im);
				else if (InTriangleTest(pt.re,pt.im,elm)==FALSE)
				{
					flag=FALSE;
					for(j=0;j<3;j++)
						for(m=0;m<NumList[meshelem[elm].p[j]];m++)
						{
							elm=ConList[meshelem[elm].p[j]][m];
							if (InTriangleTest(pt.re,pt.im,elm)==TRUE)
							{
								flag=TRUE;
								m=100;
								j=3;
							}
						}
					if (flag==FALSE) elm=InTriangle(pt.re,pt.im);
				}
				if(elm>=0)
					flag=GetPointValues(pt.re,pt.im,elm,v);
				else flag=FALSE;

				if(flag==TRUE)
				{
					Hn= Re(v.E/n);
					Bn= Re(v.D/n);
					BH= Re(v.D*conj(v.E));
					dF1=v.E.re*Bn + v.D.re*Hn - n.re*BH;
					dF2=v.E.im*Bn + v.D.im*Hn - n.im*BH;
					
					dza=dz*LengthConv[LengthUnits];
					if(ProblemType==1){
						dza*=2.*PI*pt.re*LengthConv[LengthUnits];
						dF1=0;
					}
					else dza*=Depth;
					
					z[0]+=(dF1*dza/2.);
					z[1]+=(dF2*dza/2.);
				}
			}
			
		}
	}

	// inttype==4 => Stress Tensor Torque
	if(inttype==4){
		CComplex n,t,pt;
		double Hn,Bn,BH,dF1,dF2,dT;
		CPointVals v;
		double dz,dza,u;
		int i,j,k,m,elm;
		int NumPlotPoints=d_LineIntegralPoints;
		BOOL flag;

		z[0]=z[1]=0;

		for(k=1;k<contour.GetSize();k++)
		{
			dz=abs(contour[k]-contour[k-1])/((double) NumPlotPoints);
			for(i=0,elm=-1;i<NumPlotPoints;i++)
			{
				u=(((double) i)+0.5)/((double) NumPlotPoints);
				pt=contour[k-1]+ u*(contour[k] - contour[k-1]);
				t=contour[k]-contour[k-1];
				t/=abs(t);
				n=I*t;
				pt+=n*1.e-6;
			
				if (elm<0) elm=InTriangle(pt.re,pt.im);
				else if (InTriangleTest(pt.re,pt.im,elm)==FALSE)
				{
					flag=FALSE;
					for(j=0;j<3;j++)
						for(m=0;m<NumList[meshelem[elm].p[j]];m++)
						{
							elm=ConList[meshelem[elm].p[j]][m];
							if (InTriangleTest(pt.re,pt.im,elm)==TRUE)
							{
								flag=TRUE;
								m=100;
								j=3;
							}
						}
					if (flag==FALSE) elm=InTriangle(pt.re,pt.im);
				}
				if(elm>=0)
					flag=GetPointValues(pt.re,pt.im,elm,v);
				else flag=FALSE;

				if(flag==TRUE)
				{
					Hn= Re(v.E/n);
					Bn= Re(v.D/n);
					BH= Re(v.D*conj(v.E));
					dF1=v.E.re*Bn + v.D.re*Hn - n.re*BH;
					dF2=v.E.im*Bn + v.D.im*Hn - n.im*BH;
					dT= pt.re*dF2 - dF1*pt.im;				
					dza=dz*LengthConv[LengthUnits]*LengthConv[LengthUnits];
							
					z[0]+=(dT*dza*Depth/2.);
				}
			}
		}
	
	}

	return;
}
void CNE6SSM_high_scale_constraint<Two_scale>::apply()
{
   assert(model && "Error: CNE6SSM_high_scale_constraint::apply():"
          " model pointer must not be zero");

   if (std::fabs(model->get_g1()) > 3.54491) {
#ifdef ENABLE_VERBOSE
      ERROR("CNE6SSM_high_scale_constraint: Non-perturbative gauge "
            "coupling g1 = " << model->get_g1());
#endif
      model->set_g1(3.54491);
   }
   if (std::fabs(model->get_g2()) > 3.54491) {
#ifdef ENABLE_VERBOSE
      ERROR("CNE6SSM_high_scale_constraint: Non-perturbative gauge "
            "coupling g2 = " << model->get_g2());
#endif
      model->set_g2(3.54491);
   }
   if (std::fabs(model->get_g3()) > 3.54491) {
#ifdef ENABLE_VERBOSE
      ERROR("CNE6SSM_high_scale_constraint: Non-perturbative gauge "
            "coupling g3 = " << model->get_g3());
#endif
      model->set_g3(3.54491);
   }

   update_scale();

   const auto MuPrInput = INPUTPARAMETER(MuPrInput);
   const auto BMuPrInput = INPUTPARAMETER(BMuPrInput);
   const auto MuPhiInput = INPUTPARAMETER(MuPhiInput);
   const auto BMuPhiInput = INPUTPARAMETER(BMuPhiInput);
   const auto SigmaLInput = INPUTPARAMETER(SigmaLInput);
   const auto KappaPrInput = INPUTPARAMETER(KappaPrInput);
   const auto SigmaxInput = INPUTPARAMETER(SigmaxInput);
   const auto gDInput = INPUTPARAMETER(gDInput);
   const auto hEInput = INPUTPARAMETER(hEInput);
   const auto KappaInput = INPUTPARAMETER(KappaInput);
   const auto Lambda12Input = INPUTPARAMETER(Lambda12Input);
   const auto fuInput = INPUTPARAMETER(fuInput);
   const auto fdInput = INPUTPARAMETER(fdInput);
   const auto Azero = INPUTPARAMETER(Azero);
   const auto m0 = INPUTPARAMETER(m0);
   const auto m12 = INPUTPARAMETER(m12);
   const auto g1 = MODELPARAMETER(g1);
   const auto Ye = MODELPARAMETER(Ye);
   const auto Yd = MODELPARAMETER(Yd);
   const auto Yu = MODELPARAMETER(Yu);
   const auto Lambdax = MODELPARAMETER(Lambdax);

   MODEL->set_g1p(Re(g1));
   MODEL->set_MuPr(Re(MuPrInput));
   MODEL->set_BMuPr(Re(BMuPrInput));
   MODEL->set_MuPhi(Re(MuPhiInput));
   MODEL->set_BMuPhi(Re(BMuPhiInput));
   MODEL->set_SigmaL(Re(SigmaLInput));
   MODEL->set_KappaPr(Re(KappaPrInput));
   MODEL->set_Sigmax(Re(SigmaxInput));
   MODEL->set_gD((gDInput).real());
   MODEL->set_hE((hEInput).real());
   MODEL->set_Kappa((KappaInput).real());
   MODEL->set_Lambda12((Lambda12Input).real());
   MODEL->set_fu((fuInput).real());
   MODEL->set_fd((fdInput).real());
   MODEL->set_TYe((Azero*Ye).real());
   MODEL->set_TYd((Azero*Yd).real());
   MODEL->set_TYu((Azero*Yu).real());
   MODEL->set_TKappaPr(Re(Azero*KappaPrInput));
   MODEL->set_TSigmax(Re(Azero*SigmaxInput));
   MODEL->set_ThE((Azero*hEInput).real());
   MODEL->set_TSigmaL(Re(Azero*SigmaLInput));
   MODEL->set_TgD((Azero*gDInput).real());
   MODEL->set_Tfu((Azero*fuInput).real());
   MODEL->set_Tfd((Azero*fdInput).real());
   MODEL->set_TKappa((Azero*KappaInput).real());
   MODEL->set_TLambda12((Azero*Lambda12Input).real());
   MODEL->set_TLambdax(Re(Azero*Lambdax));
   MODEL->set_mHd2(Re(Sqr(m0)));
   MODEL->set_mHu2(Re(Sqr(m0)));
   MODEL->set_ms2(Re(Sqr(m0)));
   MODEL->set_msbar2(Re(Sqr(m0)));
   MODEL->set_mphi2(Re(Sqr(m0)));
   MODEL->set_mHp2(Re(Sqr(m0)));
   MODEL->set_mHpbar2(Re(Sqr(m0)));
   MODEL->set_mH1I2((Sqr(m0)*UNITMATRIX(2)).real());
   MODEL->set_mH2I2((Sqr(m0)*UNITMATRIX(2)).real());
   MODEL->set_mSI2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_mq2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_ml2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_md2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_mu2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_me2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_mDx2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_mDxbar2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_MassB(Re(m12));
   MODEL->set_MassWB(Re(m12));
   MODEL->set_MassG(Re(m12));
   MODEL->set_MassBp(Re(m12));

   {
      const auto g1 = MODELPARAMETER(g1);
      const auto g2 = MODELPARAMETER(g2);
      const auto g3 = MODELPARAMETER(g3);
      const auto g1p = MODELPARAMETER(g1p);
      const auto Yd = MODELPARAMETER(Yd);
      const auto hE = MODELPARAMETER(hE);
      const auto Ye = MODELPARAMETER(Ye);
      const auto SigmaL = MODELPARAMETER(SigmaL);
      const auto KappaPr = MODELPARAMETER(KappaPr);
      const auto Sigmax = MODELPARAMETER(Sigmax);
      const auto gD = MODELPARAMETER(gD);
      const auto Kappa = MODELPARAMETER(Kappa);
      const auto Lambda12 = MODELPARAMETER(Lambda12);
      const auto Lambdax = MODELPARAMETER(Lambdax);
      const auto fu = MODELPARAMETER(fu);
      const auto fd = MODELPARAMETER(fd);
      const auto Yu = MODELPARAMETER(Yu);

      if (MaxAbsValue(g1) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("g1", MaxAbsValue(g1), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("g1");
      if (MaxAbsValue(g2) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("g2", MaxAbsValue(g2), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("g2");
      if (MaxAbsValue(g3) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("g3", MaxAbsValue(g3), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("g3");
      if (MaxAbsValue(g1p) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("g1p", MaxAbsValue(g1p), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("g1p");
      if (MaxAbsValue(Yd) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Yd", MaxAbsValue(Yd), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Yd");
      if (MaxAbsValue(hE) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("hE", MaxAbsValue(hE), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("hE");
      if (MaxAbsValue(Ye) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Ye", MaxAbsValue(Ye), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Ye");
      if (MaxAbsValue(SigmaL) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("SigmaL", MaxAbsValue(SigmaL), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("SigmaL");
      if (MaxAbsValue(KappaPr) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("KappaPr", MaxAbsValue(KappaPr), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("KappaPr");
      if (MaxAbsValue(Sigmax) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Sigmax", MaxAbsValue(Sigmax), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Sigmax");
      if (MaxAbsValue(gD) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("gD", MaxAbsValue(gD), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("gD");
      if (MaxAbsValue(Kappa) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Kappa", MaxAbsValue(Kappa), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Kappa");
      if (MaxAbsValue(Lambda12) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Lambda12", MaxAbsValue(Lambda12), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Lambda12");
      if (MaxAbsValue(Lambdax) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Lambdax", MaxAbsValue(Lambdax), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Lambdax");
      if (MaxAbsValue(fu) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("fu", MaxAbsValue(fu), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("fu");
      if (MaxAbsValue(fd) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("fd", MaxAbsValue(fd), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("fd");
      if (MaxAbsValue(Yu) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Yu", MaxAbsValue(Yu), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Yu");

   }
}
void CMSSM_high_scale_constraint<Two_scale>::apply()
{
   assert(model && "Error: CMSSM_high_scale_constraint::apply():"
          " model pointer must not be zero");

   if (std::fabs(model->get_g1()) > 3.54491) {
#ifdef ENABLE_VERBOSE
      ERROR("CMSSM_high_scale_constraint: Non-perturbative gauge "
            "coupling g1 = " << model->get_g1());
#endif
      model->set_g1(3.54491);
   }
   if (std::fabs(model->get_g2()) > 3.54491) {
#ifdef ENABLE_VERBOSE
      ERROR("CMSSM_high_scale_constraint: Non-perturbative gauge "
            "coupling g2 = " << model->get_g2());
#endif
      model->set_g2(3.54491);
   }
   if (std::fabs(model->get_g3()) > 3.54491) {
#ifdef ENABLE_VERBOSE
      ERROR("CMSSM_high_scale_constraint: Non-perturbative gauge "
            "coupling g3 = " << model->get_g3());
#endif
      model->set_g3(3.54491);
   }

   update_scale();

   const auto Azero = INPUTPARAMETER(Azero);
   const auto m0 = INPUTPARAMETER(m0);
   const auto m12 = INPUTPARAMETER(m12);
   const auto Ye = MODELPARAMETER(Ye);
   const auto Yd = MODELPARAMETER(Yd);
   const auto Yu = MODELPARAMETER(Yu);

   MODEL->set_TYe((Azero*Ye).real());
   MODEL->set_TYd((Azero*Yd).real());
   MODEL->set_TYu((Azero*Yu).real());
   MODEL->set_mHd2(Re(Sqr(m0)));
   MODEL->set_mHu2(Re(Sqr(m0)));
   MODEL->set_mq2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_ml2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_md2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_mu2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_me2((Sqr(m0)*UNITMATRIX(3)).real());
   MODEL->set_MassB(Re(m12));
   MODEL->set_MassWB(Re(m12));
   MODEL->set_MassG(Re(m12));

   {
      const auto g1 = MODELPARAMETER(g1);
      const auto g2 = MODELPARAMETER(g2);
      const auto g3 = MODELPARAMETER(g3);
      const auto Yd = MODELPARAMETER(Yd);
      const auto Ye = MODELPARAMETER(Ye);
      const auto Yu = MODELPARAMETER(Yu);

      if (MaxAbsValue(g1) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("g1", MaxAbsValue(g1), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("g1");
      if (MaxAbsValue(g2) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("g2", MaxAbsValue(g2), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("g2");
      if (MaxAbsValue(g3) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("g3", MaxAbsValue(g3), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("g3");
      if (MaxAbsValue(Yd) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Yd", MaxAbsValue(Yd), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Yd");
      if (MaxAbsValue(Ye) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Ye", MaxAbsValue(Ye), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Ye");
      if (MaxAbsValue(Yu) > 3.5449077018110318)
         model->get_problems().flag_non_perturbative_parameter("Yu", MaxAbsValue(Yu), model->get_scale(), 3.5449077018110318);
      else
         model->get_problems().unflag_non_perturbative_parameter("Yu");

   }
}
Esempio n. 8
0
void CbelaviewDoc::GetLineValues(CXYPlot &p,int PlotType,int NumPlotPoints)
{
	double *q,z,u,dz;
	CComplex pt,n,t;
	int i,j,k,m,elm;
	CPointVals v;
	BOOL flag;
	
	q=(double *)calloc(contour.GetSize(),sizeof(double));
	for(i=1,z=0.;i<contour.GetSize();i++)
	{
		z+=abs(contour[i]-contour[i-1]);
		q[i]=z;
	}
	dz=z/(NumPlotPoints-1);
	
	/*
		m_XYPlotType.AddString("Potential");
		m_XYPlotType.AddString("|B|        (Magnitude of flux density)");
		m_XYPlotType.AddString("B . n      (Normal flux density)");
		m_XYPlotType.AddString("B . t      (Tangential flux density)");
		m_XYPlotType.AddString("|H|        (Magnitude of field intensity)");
		m_XYPlotType.AddString("H . n      (Normal field intensity)");
		m_XYPlotType.AddString("H . t      (Tangential field intensity)");
		m_XYPlotType.AddString("J_eddy     
	*/


	switch (PlotType)
	{
		case 0:
			p.Create(NumPlotPoints,2);
			strcpy(p.lbls[1],"Potential, Volts");
			break;
		case 1:
			p.Create(NumPlotPoints,2);
			strcpy(p.lbls[1],"|D|, C/m^2");
			break;
		case 2:
			p.Create(NumPlotPoints,2);
			strcpy(p.lbls[1],"D.n, C/m^2");
			break;
		case 3:
			p.Create(NumPlotPoints,2);
			strcpy(p.lbls[1],"D.t, C/m^2");
			break;
		case 4:
			p.Create(NumPlotPoints,2);
			strcpy(p.lbls[1],"|E|, V/m");
			break;
		case 5:
			p.Create(NumPlotPoints,2);
			strcpy(p.lbls[1],"E.n, V/m");
			break;
		case 6:
			p.Create(NumPlotPoints,2);
			strcpy(p.lbls[1],"E.t, V/m");
			break;
		default:
			p.Create(NumPlotPoints,2);
			break;
	}


	
	switch(LengthUnits){
		case 1:
			strcpy(p.lbls[0],"Length, mm");
			break;
		case 2:
			strcpy(p.lbls[0],"Length, cm");
			break;
		case 3:
			strcpy(p.lbls[0],"Length, m");
			break;
		case 4:
			strcpy(p.lbls[0],"Length, mils");
			break;
		case 5:
			strcpy(p.lbls[0],"Length, um");
			break;
		default:
			strcpy(p.lbls[0],"Length, inches");
			break;
	}

	for(i=0,k=1,z=0,elm=-1;i<NumPlotPoints;i++,z+=dz)
	{
		while((z>q[k]) && (k<(contour.GetSize()-1))) k++;
		u=(z-q[k-1])/(q[k]-q[k-1]);
		pt=contour[k-1]+u*(contour[k]-contour[k-1]);
		t=contour[k]-contour[k-1];
		t/=abs(t);
		n = I*t;
		pt+=(n*1.e-06);
		
		if (elm<0) elm=InTriangle(pt.re,pt.im);
		else if (InTriangleTest(pt.re,pt.im,elm)==FALSE)
		{
			flag=FALSE;
			for(j=0;j<3;j++)
				for(m=0;m<NumList[meshelem[elm].p[j]];m++)
				{
					elm=ConList[meshelem[elm].p[j]][m];
					if (InTriangleTest(pt.re,pt.im,elm)==TRUE)
					{
						flag=TRUE;
						m=100;
						j=3;
					}
				}
			if (flag==FALSE) elm=InTriangle(pt.re,pt.im);
		}
		if(elm>=0)
			flag=GetPointValues(pt.re,pt.im,elm,v);
		else flag=FALSE;

		p.M[i][0]=z;
		if(flag!=FALSE)
		{
			switch (PlotType)
			{
				case 0:
					p.M[i][1]=v.V;
					break;
				case 1:
					p.M[i][1]=abs(v.D);
					break;
				case 2:
					p.M[i][1]=Re(v.D/n);
					break;
				case 3:
					p.M[i][1]=Re(v.D/t);
					break;
				case 4:
					p.M[i][1]=abs(v.E);
					break;
				case 5:
					p.M[i][1]=Re(v.E/n);
					break;
				case 6:
					p.M[i][1]=Re(v.E/t);
					break;
				default:
					p.M[i][1]=0;
					break;
			}
		}
	}
		
	free(q);
}
Esempio n. 9
0
// expose restart2 to python
void read_solution(char * filename, mcomplex * C_ptr)
{
    extern int qpts, dimR, dimQ, Nx, Nz;
    extern mcomplex ****U, ****C;
    extern mcomplex ****IU, ****IC;
    int x, y, z;
    hid_t file_id1, dataset_a, dataset_b;       /* file identifier */
    hid_t dataset_ia, dataset_ib;
    hid_t complex_id;

    /* define compound datatype for the complex number */
    typedef struct {
        double re;              /*real part */
        double im;              /*imaginary part */
    } complex_t;

    complex_id = H5Tcreate(H5T_COMPOUND, sizeof(complex_t));
    H5Tinsert(complex_id, "real", HOFFSET(complex_t, re),
              H5T_NATIVE_DOUBLE);
    H5Tinsert(complex_id, "imaginary", HOFFSET(complex_t, im),
              H5T_NATIVE_DOUBLE);

    /* define some temporal matrix to store the data to the hdf file */
    complex_t Matrix1[dimR][Nz][Nx / 2];
    complex_t Matrix2[dimR][Nz][Nx / 2];

    complex_t IMatrix1[dimR][Nz][Nx / 2];
    complex_t IMatrix2[dimR][Nz][Nx / 2];

    // open the file and dataset 
    file_id1 = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
    dataset_a = H5Dopen1(file_id1, "/data_alpha");
    dataset_b = H5Dopen1(file_id1, "/data_beta");

    dataset_ia = H5Dopen1(file_id1, "/data_ialpha");
    dataset_ib = H5Dopen1(file_id1, "/data_ibeta");

    assert(EXIT_SUCCESS ==
        H5Dread(dataset_a, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                Matrix1));
    assert(EXIT_SUCCESS ==
        H5Dread(dataset_b, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                Matrix2));

    assert(EXIT_SUCCESS ==
        H5Dread(dataset_ia, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                IMatrix1));
    assert(EXIT_SUCCESS ==
        H5Dread(dataset_ib, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT,
                IMatrix2));


    assert(EXIT_SUCCESS == H5Dclose(dataset_a));
    assert(EXIT_SUCCESS == H5Dclose(dataset_b));

    assert(EXIT_SUCCESS == H5Dclose(dataset_ia));
    assert(EXIT_SUCCESS == H5Dclose(dataset_ib));

    assert(EXIT_SUCCESS == H5Fclose(file_id1));

    for (y = 0; y < dimR; y++) {
        for (z = 0; z < Nz; ++z) {
            for (x = 0; x < Nx / 2; ++x) {
                Re(C[z][ALPHA][y][x]) = Matrix1[y][z][x].re;
                Im(C[z][ALPHA][y][x]) = Matrix1[y][z][x].im;
                Re(C[z][BETA][y][x]) = Matrix2[y][z][x].re;
                Im(C[z][BETA][y][x]) = Matrix2[y][z][x].im;

                Re(IC[z][ALPHA][y][x]) = IMatrix1[y][z][x].re;
                Im(IC[z][ALPHA][y][x]) = IMatrix1[y][z][x].im;
                Re(IC[z][BETA][y][x]) = IMatrix2[y][z][x].re;
                Im(IC[z][BETA][y][x]) = IMatrix2[y][z][x].im;
            }
        }
    }

    /* compute  ux hat, uy hat, uz hat given alpha, beta,. */
    initAlphaBeta2();

    /* compute the boundary condition for previous stage or time step, 
       result is stored in Uxb and Uzb */
    if (increBoundary() != NO_ERR) {
        printf("increBoundary failure\n");
    }


    /* compute iux, iuy, iuz given i-alpha, i-beta */

    incre_initAlphaBeta2();

    memset(U[Nz / 2][0][0], 0, 5 * qpts * (Nx / 2) * sizeof(mcomplex));
    memset(IU[Nz / 2][0][0], 0, 5 * qpts * (Nx / 2) * sizeof(mcomplex));

    memmove(C_ptr, C[0][0][0], Nz * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
}
Esempio n. 10
0
// expose write_data2 to python
void save_solution(char * filename, mcomplex * C_ptr)
{
    hid_t file_id1, dataset_a, dataset_b;       /* file identifier */
    hid_t fid1, dataset_ia, dataset_ib;
    hid_t fid2, dataset_Nx, dataset_Ny, dataset_Nz, dataset_dt, dataset_Re,
        dataset_mpg;
    hid_t complex_id;
    hsize_t fdim[] = { dimR, Nz, Nx / 2 };
    hsize_t fdim2[] = { 1 };

    extern mcomplex ****C, ****IC;
    extern int qpts, Nx, Nz, dimR, dimQ;
    extern double dt, re, mpg;
    int x, y, z;
    int Ny = qpts * 2 / 3;
    /* define compound datatype for the complex number */
    typedef struct {
        double re;              /*real part */
        double im;              /*imaginary part */
    } complex_t;

    memmove(C[0][0][0], C_ptr, Nz * 2 * dimR * (Nx / 2) * sizeof(mcomplex));

    /* Compute U from C */
    initAlphaBeta2();

    complex_id = H5Tcreate(H5T_COMPOUND, sizeof(complex_t));
    H5Tinsert(complex_id, "real", HOFFSET(complex_t, re),
              H5T_NATIVE_DOUBLE);
    H5Tinsert(complex_id, "imaginary", HOFFSET(complex_t, im),
              H5T_NATIVE_DOUBLE);

    /* define some temporal matrix to store the data to the hdf file */
    complex_t Matrix1[dimR][Nz][Nx / 2];
    complex_t Matrix2[dimR][Nz][Nx / 2];

    complex_t IMatrix1[dimR][Nz][Nx / 2];
    complex_t IMatrix2[dimR][Nz][Nx / 2];

    for (y = 0; y < dimR; y++) {
        for (z = 0; z < Nz; ++z) {
            for (x = 0; x < Nx / 2; ++x) {
                Matrix1[y][z][x].re = Re(C[z][ALPHA][y][x]);    /* storing solved solutions to Matrix */
                Matrix1[y][z][x].im = Im(C[z][ALPHA][y][x]);
                Matrix2[y][z][x].re = Re(C[z][BETA][y][x]);
                Matrix2[y][z][x].im = Im(C[z][BETA][y][x]);

                IMatrix1[y][z][x].re = Re(IC[z][ALPHA][y][x]);  /* storing solved solutions to Matrix */
                IMatrix1[y][z][x].im = Im(IC[z][ALPHA][y][x]);
                IMatrix2[y][z][x].re = Re(IC[z][BETA][y][x]);
                IMatrix2[y][z][x].im = Im(IC[z][BETA][y][x]);
            }
        }
    }

    /* create File data.h5 for three data sets */
    file_id1 =
        H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /* create the dataspace */
    fid1 = H5Screate_simple(3, fdim, NULL);
    fid2 = H5Screate_simple(1, fdim2, NULL);

    /* create datasets with name u v w */
    dataset_a =
        H5Dcreate1(file_id1, "/data_alpha", complex_id, fid1, H5P_DEFAULT);
    dataset_b =
        H5Dcreate1(file_id1, "/data_beta", complex_id, fid1, H5P_DEFAULT);

    dataset_ia =
        H5Dcreate1(file_id1, "/data_ialpha", complex_id, fid1,
                   H5P_DEFAULT);
    dataset_ib =
        H5Dcreate1(file_id1, "/data_ibeta", complex_id, fid1, H5P_DEFAULT);


    dataset_Nx =
        H5Dcreate1(file_id1, "data_Nx", H5T_STD_I32LE, fid2, H5P_DEFAULT);
    dataset_Ny =
        H5Dcreate1(file_id1, "data_Ny", H5T_STD_I32LE, fid2, H5P_DEFAULT);
    dataset_Nz =
        H5Dcreate1(file_id1, "data_Nz", H5T_STD_I32LE, fid2, H5P_DEFAULT);

    dataset_dt =
        H5Dcreate1(file_id1, "data_dt", H5T_IEEE_F64LE, fid2, H5P_DEFAULT);
    dataset_Re =
        H5Dcreate1(file_id1, "data_Re", H5T_IEEE_F64LE, fid2, H5P_DEFAULT);
    dataset_mpg =
        H5Dcreate1(file_id1, "data_mpg", H5T_IEEE_F64LE, fid2,
                   H5P_DEFAULT);

    /* write data to corresponding datasets */
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_a, complex_id, H5S_ALL, fid1, H5P_DEFAULT,
                 Matrix1));
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_b, complex_id, H5S_ALL, fid1, H5P_DEFAULT,
                 Matrix2));
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_ia, complex_id, H5S_ALL, fid1, H5P_DEFAULT,
                 IMatrix1));
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_ib, complex_id, H5S_ALL, fid1, H5P_DEFAULT,
                 IMatrix2));

    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_Nx, H5T_NATIVE_INT, H5S_ALL, fid2, H5P_DEFAULT,
                 &Nx));
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_Ny, H5T_NATIVE_INT, H5S_ALL, fid2, H5P_DEFAULT,
                 &Ny));
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_Nz, H5T_NATIVE_INT, H5S_ALL, fid2, H5P_DEFAULT,
                 &Nz));
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_dt, H5T_IEEE_F64LE, H5S_ALL, fid2, H5P_DEFAULT,
                 &dt));
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_Re, H5T_IEEE_F64LE, H5S_ALL, fid2, H5P_DEFAULT,
                 &re));
    assert(EXIT_SUCCESS ==
        H5Dwrite(dataset_mpg, H5T_IEEE_F64LE, H5S_ALL, fid2, H5P_DEFAULT,
                 &mpg));

    /* close datasets and file */
    assert(EXIT_SUCCESS == H5Dclose(dataset_a));
    assert(EXIT_SUCCESS == H5Dclose(dataset_b));
    assert(EXIT_SUCCESS == H5Dclose(dataset_ia));
    assert(EXIT_SUCCESS == H5Dclose(dataset_ib));
    assert(EXIT_SUCCESS == H5Dclose(dataset_Nx));
    assert(EXIT_SUCCESS == H5Dclose(dataset_Ny));
    assert(EXIT_SUCCESS == H5Dclose(dataset_Nz));
    assert(EXIT_SUCCESS == H5Dclose(dataset_dt));
    assert(EXIT_SUCCESS == H5Dclose(dataset_Re));
    assert(EXIT_SUCCESS == H5Dclose(dataset_mpg));

    assert(EXIT_SUCCESS == H5Sclose(fid1));
    assert(EXIT_SUCCESS == H5Sclose(fid2));
    assert(EXIT_SUCCESS == H5Fclose(file_id1));
}
Esempio n. 11
0
double ddt_project(int i_step, mcomplex * IC_given)
{

    mcomplex *dCdt;
    double *dudt; 
    double *v; 
    double num, den;
    int x, y, z, i;
    int XFLOW, YFLOW, ZFLOW;
    int len1 = (Nz * 2 * dimR * (Nx / 2));
    int len2 = (3 * 3 * (Nx / 2) * qpts * 3 * (Nz /2));
    int i_plus, i_minus;

    // Allocate memory
    dCdt = cVector(len1);
    dudt = dVector(len2);
    v = dVector(len2);
    memset(dCdt, 0,
           (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
    memset(dudt, 0,
           3 * (3 * Nx / 2) * qpts * (3 * Nz / 2) * sizeof(double));
    memset(v, 0,
           3 * (3 * Nx / 2) * qpts * (3 * Nz / 2) * sizeof(double));

    // compute time derivative with finite difference
    if (i_step == 0) {
        i_plus = 3*(i_step + 1);
        i_minus = 3*i_step;
    } else {
        i_plus = 3*i_step;
        i_minus = 3*(i_step - 1);   
    }

    for (z = 0; z < (Nz) * 2 * dimR * (Nx / 2); ++ z) {
        Re(dCdt[z]) = (1.0/dt) * (Re(MC[i_plus][0][0][0][z])-Re(MC[i_minus][0][0][0][z]));
        Im(dCdt[z]) = (1.0/dt) * (Im(MC[i_plus][0][0][0][z])-Im(MC[i_minus][0][0][0][z]));
    }
    // find physical derivative, sensitivity
    spec2phys(dCdt,dudt);
    spec2phys(IC_given,v);
    
    //compute numerator and denominator of projection
    num = 0.0;
    den = 0.0;
    XFLOW = 0 * (3 * Nx / 2) * qpts * (3 * Nz / 2);
    YFLOW = 1 * (3 * Nx / 2) * qpts * (3 * Nz / 2);
    ZFLOW = 2 * (3 * Nx / 2) * qpts * (3 * Nz / 2);
    
    for (y = 0; y < qpts; ++y){
        for (z = 0; z < (3 * Nz / 2); ++z){
            for (x = 0; x < (3 * Nx / 2); ++x){
                i = (x * qpts + y) * (3 * Nz / 2) + z;
                num += dudt[i + XFLOW] * v[i + XFLOW] * W[y];
                den += dudt[i + XFLOW] * dudt[i + XFLOW] * W[y];
                num += dudt[i + YFLOW] * v[i + YFLOW] * W[y];
                den += dudt[i + YFLOW] * dudt[i + YFLOW] * W[y];
                num += dudt[i + ZFLOW] * v[i + ZFLOW] * W[y];
                den += dudt[i + ZFLOW] * dudt[i + ZFLOW] * W[y];
            }
        }
    }
    
    // subtract component of IC_given that is parallel to dCdt


    for (z = 0; z < (Nz) * 2 * dimR * (Nx / 2); ++ z) {
        Re(IC_given[z]) -= (num/den) * Re(dCdt[z]);
        Im(IC_given[z]) -= (num/den) * Im(dCdt[z]);
    }


    // free memory
    freecVector(dCdt);
    freedVector(dudt);
    freedVector(v);
	return (num/den);
}
Esempio n. 12
0
void adjoint(int start_step, int end_step, mcomplex *AC_given, int inhomo,
             double strength)
{
    int n, dctr, count, z;
    mcomplex *ICtmp;
    int len1 = (Nz * 2 * dimR * (Nx / 2));
    ICtmp = cVector(len1); 
    /* retrieve solution */
    assert (end_step < start_step);
    assert (end_step >= 0);
    assert (start_step <= nsteps);
	assert (AC_given != 0);

    memmove(C[0][0][0], MC[start_step * 3][0][0][0],
            (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
    memmove(AC[0][0][0], AC_given,
            (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));


    
    /***************solving adjoint equations ****/

    adj_initAlphaBeta2();
    strength *= dt;

    /* time step for adjoint problem */
    for (n = start_step; n > end_step; --n) {

        count = n * 3;
        memmove(ICtmp, MIC[count][0][0][0],
                (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
        ddt_project(n, ICtmp);
        for (z = 0; z < (Nz) * 2 * dimR * (Nx / 2); ++ z) {
            Re(AC[0][0][0][z]) -= 0.5 * strength * Re(ICtmp[z]);
            Im(AC[0][0][0][z]) -= 0.5 * strength * Im(ICtmp[z]);
        }

        for (dctr = 0; dctr < 3; ++dctr) {    /* RK steps */

            count = n * 3 - dctr - 1;

            /*read data from memery */
            if (dctr < 2) {
                memmove(C[0][0][0], MC[count - 1][0][0][0],
                        (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));

                /* reconstruct the state and incremental state solution u,
                   iu from alpha and beta */
                initAlphaBeta2();

                if (pass2(dctr, n) != NO_ERR) {
                    printf("Pass2 failure\n");
                    n = -1;
                    break;
                }
                memmove(LU[0][0][0], U[0][0][0],
                        (Nz) * 5 * qpts * (Nx / 2) * sizeof(mcomplex));
            }
            /*read data from memery */
            memmove(C[0][0][0], MC[count][0][0][0],
                    (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));

            /*reconstruct the state and incremental state solution u,
              iu from alpha and beta */
            initAlphaBeta2();

            if (pass2(dctr, n) != NO_ERR) {
                printf("Pass2 failure\n");
                n = -1;
                break;
            }

            adjproject0(count, dctr, NULL);
            adjproject(count, dctr, 0, 1, NULL);
            for (z = 1; z < Nz; ++z) {
                if (z == Nz / 2) {
                    memset(AU[z][0][0], 0,
                           5 * qpts * (Nx / 2) * sizeof(mcomplex));
                    memset(AC[z][0][0], 0,
                           2 * dimR * (Nx / 2) * sizeof(mcomplex));
                    continue;
                }
                adjproject(count, dctr, z, 0, NULL);
            }
        }

        count = (n - 1) * 3;
        memmove(ICtmp, MIC[count][0][0][0],
                (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
        ddt_project(n-1, ICtmp);
        for (z = 0; z < (Nz) * 2 * dimR * (Nx / 2); ++ z) {
            Re(AC[0][0][0][z]) -= 0.5 * strength * Re(ICtmp[z]);
            Im(AC[0][0][0][z]) -= 0.5 * strength * Im(ICtmp[z]);
        }

	}

    memmove(AC_given, AC[0][0][0],
            (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
    freecVector( ICtmp );
}
Esempio n. 13
0
void primal(int ru_steps, mcomplex *C_given)
{
   int i, n, z, dctr, count;

    /******************restart check ******************************/
    if (C_given != 0) {
        memmove(C[0][0][0], C_given,
                (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
        initAlphaBeta2();
    }
    else            // provide laminar solution with perturbations
    {
        memset(U[0][0][0], 0, Nz * 5 * qpts * Nx / 2 * sizeof(mcomplex));
        for (i = 0; i < qpts; i++) {
            Re(U[0][XEL][i][0]) = (1.0 - Qy[i] * Qy[i]) * flux * 3./4;
            Im(U[0][XEL][i][0]) = 0.0;
        }
        // perturbation
        for (i = 0; i < qpts; i++) {
            Re(U[1][XEL][i][1]) = (rand() / (double)RAND_MAX - 0.5);
            Im(U[1][XEL][i][1]) = (rand() / (double)RAND_MAX - 0.5);
        }
        initAlphaBeta();
    }

    /**********************************end of restart **********************/

    /* store current Fourier coefficient into MC
       used for solving the adjoint system. */
    // destination // source
    memset(MC[0][0][0][0], 0, (nsteps * 3 + 1) *
           (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
    memmove(MC[0][0][0][0], C[0][0][0],
            (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));

    /***************solving state and incremental state equations ****/

    /* time step for forward problem */
    for (n = 0; n < nsteps + ru_steps; ++n) {
        if (n % 100 == 0) {
            printf("Step %d/%d\n", n, nsteps + ru_steps);
        }
        for (dctr = 0; dctr < 3; ++dctr) {    /* RK steps */

            /* do FFTs to get H_hats.  After this we have for each (Kx,y,Kz)
               Hx_hat   -->  U[z][HXEL][y][x]
               Hy_hat   -->  U[z][HYEL][y][x]
               Hz_hat   -->  U[z][HZEL][y][x]
             */
            if (pass1(dctr, n) != NO_ERR) {
                printf("Pass1 failure\n");
                n = nsteps + ru_steps;
                break;
            }

            count = (n - ru_steps) * 3 + dctr + 1;

            project0(count, dctr, NULL);    /* (kx, kz)=(0, 0),
                               solve for a, b */
            project(count, dctr, 0, 1, NULL);    /* (kx, kz)!=(0, 0),
                               solve for alpha, beta */
            for (z = 1; z < Nz; ++z) {
                if (z == Nz / 2) {
                    memset(U[z][0][0], 0,
                           5 * qpts * (Nx / 2) * sizeof(mcomplex));
                    memset(C[z][0][0], 0,
                           2 * dimR * (Nx / 2) * sizeof(mcomplex));
                    continue;
                }

                project(count, dctr, z, 0, NULL);
            }
        }        /* end for dctr... */
    }            /* end for n... */

    if (C_given != 0) {  /* copy the final solution back to given buffer */
        memmove(C_given, C[0][0][0],
                (Nz) * 2 * dimR * (Nx / 2) * sizeof(mcomplex));
    }
}
Esempio n. 14
0
Foam::tmp<Foam::volScalarField> Foam::phasePair::Ta() const
{
    return Re()*pow(Mo(), 0.23);
}
Esempio n. 15
0
void restart(int restart_flag)
{

  extern int    qpts, dimR, dimQ, Nx, Nz;
  extern mcomplex ****U, ****C;
  extern mcomplex ****IU, ****IC;

  int x, y, z, i;
  hid_t  file_id1, dataset_u, dataset_v,dataset_w;   /* file identifier */
  hid_t fid1,dataset_iu, dataset_iv,dataset_iw ;
  hid_t complex_id;
  hsize_t fdim[]={ qpts, Nz, Nx/2};
  herr_t  ret;
  char filename [50];

    /* define compound datatype for the complex number */
    typedef struct
    {
      double re;   /*real part*/
      double im;   /*imaginary part*/
    } complex_t;

    complex_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_t));
    H5Tinsert (complex_id, "real", HOFFSET(complex_t,re), H5T_NATIVE_DOUBLE);
    H5Tinsert (complex_id, "imaginary", HOFFSET(complex_t,im), H5T_NATIVE_DOUBLE);

    /* define some temporal matrix to store the data to the hdf file */
    complex_t Matrix1[qpts][Nz][Nx/2];
    complex_t Matrix2[qpts][Nz][Nx/2];
    complex_t Matrix3[qpts][Nz][Nx/2];

    complex_t IMatrix1[qpts][Nz][Nx/2];
    complex_t IMatrix2[qpts][Nz][Nx/2];
    complex_t IMatrix3[qpts][Nz][Nx/2];  // find the restart file 


      sprintf(filename, "data_t=%d", restart_flag);

      // open the file and dataset 
      file_id1 = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
      dataset_u = H5Dopen(file_id1,"/data_u");
      dataset_v = H5Dopen(file_id1,"/data_v");
      dataset_w = H5Dopen(file_id1,"/data_w");

      dataset_iu = H5Dopen(file_id1,"/data_iu");
       dataset_iv = H5Dopen(file_id1,"/data_iv");
      dataset_iw = H5Dopen(file_id1,"/data_iw");

      ret = H5Dread(dataset_u, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, Matrix1);
      ret = H5Dread(dataset_v, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, Matrix2);
      ret = H5Dread(dataset_w, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, Matrix3);
      ret = H5Dread(dataset_iu, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, IMatrix1);
      ret = H5Dread(dataset_iv, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, IMatrix2);
      ret = H5Dread(dataset_iw, complex_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, IMatrix3);

      ret=H5Dclose(dataset_u);
      ret=H5Dclose(dataset_v);
      ret=H5Dclose(dataset_w);
      ret=H5Dclose(dataset_iu);
      ret=H5Dclose(dataset_iv);
      ret=H5Dclose(dataset_iw);
      ret=H5Fclose(file_id1);

      for (y=0; y<qpts; y++)
	{
	  for (z=0; z<Nz; ++z)
	    {
	      for(x=0; x<Nx/2; ++x)
		{
		  Re(U[z][XEL][y][x])=Matrix1[y][z][x].re;  
		  Im(U[z][XEL][y][x])=Matrix1[y][z][x].im;
		  Re(U[z][YEL][y][x])=Matrix2[y][z][x].re;
		  Im(U[z][YEL][y][x])=Matrix2[y][z][x].im;
		  Re(U[z][ZEL][y][x])=Matrix3[y][z][x].re;
		  Im(U[z][ZEL][y][x])=Matrix3[y][z][x].im;

		  Re(IU[z][XEL][y][x])=IMatrix1[y][z][x].re; 
		  Im(IU[z][XEL][y][x])=IMatrix1[y][z][x].im;
		  Re(IU[z][YEL][y][x])=IMatrix2[y][z][x].re;
		  Im(IU[z][YEL][y][x])=IMatrix2[y][z][x].im;
		  Re(IU[z][ZEL][y][x])=IMatrix3[y][z][x].re;
		  Im(IU[z][ZEL][y][x])=IMatrix3[y][z][x].im;
		}
	    }
	} 

      /* compute inital coefficients in expansion  given the value of ux hat, uy hat, uz hat. */
      initAlphaBeta();
 
      /* compute the boundary condition for previous stage or time step, result is stored in Uxb and Uzb*/
      if (increBoundary()!= NO_ERR)
	{
	  printf("increBoundary failure\n");
	}

      /* compute initial coefficients for incremental state solver */ 

      incre_initAlphaBeta();
      printf(" restart computed coefficients!\n");
      for (i = 0; i < dimQ; ++i)
	{
	  for (z= 0; z < Nz; ++z)
	    {
	      for (x = 0; x < Nx/2; ++x)
		{
		  printf(" IC[%d][ALPHA][%d][%d]=%f+%fi\n", z, i, x,Re(IC[z][ALPHA][i][x]), Im(IC[z][ALPHA][i][x]));
		}
	    }
	}
      for (i = 0; i < dimR; ++i)
	{
	  for (z= 0; z < Nz; ++z)
	    {
	      for (x = 0; x < Nx/2; ++x)
		{
		  printf(" IC[%d][BETA][%d][%d]=%f+%fi\n", z, i, x,Re(IC[z][BETA][i][x]), Im(IC[z][BETA][i][x]));
		}
	    }
	}
      printf(" finish restart computing coefficients!\n\n");

}
Esempio n. 16
0
/*==============================================================================
* CALC_POTENTIAL: 
*
*    rho^ = FFT(rho)
*    Phi^ = G^ * rho^ ;     G^ = -1/k**2 (no adjustment for finite differences)
*    Phi  = FFT(Phi^) 
*
*    uses NR routine fourn.c for FFT's
*==============================================================================*/
void fft_potential(flouble *data, long l1dim)
{
   FILE         *fpout;
   double        Green, sf, sf2;
   double        FFTnorm;
   double        kx, ky, kz, ksquare, kf;
   double        sin2sfkz, sin2sfky;
   long          *k;
   long          k_dim, k_nyq;
   long          i, l, m, n;
   int           forward=1, backward=-1;
   unsigned long nn[NDIM];
   
   /* dimensions of grid */
   nn[0] = l1dim;
   nn[1] = l1dim; 
   nn[2] = l1dim;
   k_dim = l1dim;
   k_nyq = l1dim/2;
   
   /* this will help extracting information from data^ */
   k = (long*) calloc(l1dim,sizeof(long));
   for(i=0; i<l1dim; i++)
     {
      if(i <= k_nyq)
         k[i] = i;
      else
         k[i] = -(l1dim-i);
     }
   
   /* fourn normalisation factor */
   FFTnorm = (double)pow3(l1dim);
   
   /* fundamental wave in box units: kf = 2*pi */
   kf  = TWOPI;
   
   /* adjusting the 7-point-difference Green's function */
   sf  = PI/(double)l1dim/kf;
   sf2 = pow2(sf);
   
   
   /* forward FFT */
   fourn(data-1, nn-1, NDIM, forward);
   
  PkSpectrum.time -= time(NULL);
  PkSpectrum.time += time(NULL);
   
   /* calculation of gravitational potential */
   for(n = 0; n < k_dim; n++) 
     {
      kz       = kf * k[n];
      sin2sfkz = pow2(sin(sf*kz));
      
      for(m = 0; m < k_dim; m++)
        {
         ky       = kf * k[m];
         sin2sfky = pow2(sin(sf*ky));
         
         for(l = 0; l < k_dim; l++)
           {
            kx = kf * k[l];
            
            /* get k^2 => NOT needed for 7-point difference approximation to Green = -1.0 / ksquare */
            /* ksquare = kx * kx + ky * ky + kz * kz; */
            
            /* Green's function */
            if (k[l] == 0 &&  k[m]  == 0 && k[n] == 0)
              {
               Green = 0.0;
              }
            else
              {
               /* 7-point difference approximation to Green = -1.0 / ksquare */
               Green = -sf2/(pow2(sin(sf*kx))+sin2sfky+sin2sfkz);
              }
            
            data[Re(l,m,n,l1dim)] *= Green;
            data[Im(l,m,n,l1dim)] *= Green;
            
           }
        }
     }
   
   
   /* backward FFT */
   fourn(data-1, nn-1, NDIM, backward);
   
   /* normalize FFT output */
   for(i=0; i<2*l1dim*l1dim*l1dim; i++)
      data[i] /= FFTnorm;
   
   /* delete k-array again */
   free(k);
}
Esempio n. 17
0
/* Compute double precision LLR */
SPC_DECL void llr_d(const cArray   inputSignal,    /* input signal */
           const int_T    numElements,    /* number of input signal elements */
           const real_T  *noiseVariance,  /* noise variance */
           const int_T    M,              /* M            */
           const int_T    nBits,          /* number of bits in symbol (log2(M)) */
           const cArray   constellation,  /* signal constellation */
           const int32_T *S0,             /* symbols having 0 */
           const int32_T *S1,             /* symbols having 1 */
           real_T        *llr)            /* output values - LLR */
{
    int_T  elementIdx = 0;
    int_T  symbolIdx  = 0;
    int_T  bitIdx     = 0;
    real_T tempS0     = 0.0;
    real_T tempS1     = 0.0;
    real_T expSumS0   = 0.0;
    real_T expSumS1   = 0.0;

    for (elementIdx = 0; elementIdx < numElements; elementIdx++)
    {
        for (bitIdx = 0; bitIdx < nBits; bitIdx++)
        {
            expSumS0 = 0.0;
            expSumS1 = 0.0;

            for (symbolIdx = 0; symbolIdx < M/2; symbolIdx++)
            {
                /* tempS0 = (S0x - X)^2; (S0x, S0y) represet constellation symbols */
                /* with bit 0                         
                 */
                /* cr: precompute (bitIdx*M/2)+symbolIdx */
                tempS0 = (Re(constellation, S0[(bitIdx*M/2)+symbolIdx]) - 
                          Re(inputSignal, elementIdx)) * 
                    (Re(constellation, S0[(bitIdx*M/2)+symbolIdx]) - 
                     Re(inputSignal, elementIdx));

                /* tempS0 = (S0x - X)^2 + (S0y - Y)^2 */
                tempS0 +=  (Im(constellation, S0[(bitIdx*M/2)+symbolIdx]) - 
                            Im(inputSignal, elementIdx)) * 
                    (Im(constellation, S0[(bitIdx*M/2)+symbolIdx]) - 
                     Im(inputSignal, elementIdx));
                
                expSumS0 += exp(-1  * tempS0 / noiseVariance[0]);

                /* tempS1 = (S1x - X)^2; (S1x, S1y) represet constellation symbols */
                /* with bit 1                                                      */
                tempS1 = (Re(constellation, S1[(bitIdx*M/2)+symbolIdx]) - 
                          Re(inputSignal, elementIdx)) * 
                    (Re(constellation, S1[(bitIdx*M/2)+symbolIdx]) - 
                     Re(inputSignal, elementIdx));

                /* tempS1 = (S1x - X)^2 + (S1y - Y)^2 */
                tempS1 +=  (Im(constellation, S1[(bitIdx*M/2)+symbolIdx]) - 
                            Im(inputSignal, elementIdx)) * 
                    (Im(constellation, S1[(bitIdx*M/2)+symbolIdx]) - 
                     Im(inputSignal, elementIdx));
                
                expSumS1 += exp(-1  * tempS1 / noiseVariance[0]);
            }
            llr[(elementIdx * nBits) + bitIdx] = log(expSumS0 / expSumS1);
        }
    } /* end of "for (elementIdx = 0 ..." */
} /* end of llr_d() */
Esempio n. 18
0
CComplex CbelaviewDoc::BlockIntegral(int inttype)
{
	int i,k;
	double B1,B2,F1,F2,y;
	CComplex c,z;
	CComplex A[3],Jn[3],U[3],V[3];
	double a,R;
	double r[3];

	for(i=0,z=0;i<meshelem.GetSize();i++)
	{
		if((blocklist[meshelem[i].lbl].IsSelected==TRUE) && (inttype<5))
		{
			// compute some useful quantities employed by most integrals...
			a=ElmArea(i)*pow(LengthConv[LengthUnits],2.);
			if(ProblemType==1){
				for(k=0;k<3;k++) 
					r[k]=meshnode[meshelem[i].p[k]].x*LengthConv[LengthUnits];
				R=(r[0]+r[1]+r[2])/3.;
			}

			// now, compute the desired integral;
			switch(inttype)
			{
				case 0: // stored energy
					if(ProblemType==1) a*=(2.*PI*R); else a*=Depth;
					z+=a*Re(D(i)*conj(E(i)))/2.;
					break;

				case 1: // cross-section area
					z+=a;
					break;
					
				case 2: // volume
					if(ProblemType==1) a*=(2.*PI*R); else a*=Depth;
					z+=a;
					break;

				case 3: // D
					if(ProblemType==1) a*=(2.*PI*R); else a*=Depth;
					z+=a*D(i);
					break;

				case 4: // E
					if(ProblemType==1) a*=(2.*PI*R); else a*=Depth;
					z+=a*E(i);
					break;

				default:
					break;
			}
		  }

		// integrals that need to be evaluated over all elements, 
		// regardless of which elements are actually selected.
		if(inttype>4)
		{
			a=ElmArea(i)*pow(LengthConv[LengthUnits],2.);
			if(ProblemType==1){
				for(k=0;k<3;k++)
					r[k]=meshnode[meshelem[i].p[k]].x*LengthConv[LengthUnits];
				R=(r[0]+r[1]+r[2])/3.;
				a*=(2.*PI*R);
			}
			else a*=Depth;
		  
			switch(inttype){

				case 5: 
					B1=Re(D(i));
					B2=Im(D(i));
					c=HenrotteVector(i);
				
					// x (or r) direction Henrotte force, SS part.
					if(ProblemType==0){				
						y=(((B1*B1) - (B2*B2))*Re(c) + 2.*(B1*B2)*Im(c))/(2.*eo)*AECF(i);
						z.re += (a*y);
					}			
				
					// y (or z) direction Henrotte force, SS part
					y=(((B2*B2) - (B1*B1))*Im(c) + 2.*(B1*B2)*Re(c))/(2.*eo)*AECF(i);
					z.im += (a*y);

					break;

				case 6: // Henrotte torque, SS part.
					if(ProblemType!=0) break;
					B1=Re(D(i));
					B2=Im(D(i));
					c=HenrotteVector(i);

					F1 = (((B1*B1) - (B2*B2))*Re(c) + 
						 2.*(B1*B2)*Im(c))/(2.*eo);
					F2 = (((B2*B2) - (B1*B1))*Im(c) + 
						 2.*(B1*B2)*Re(c))/(2.*eo);
					
					for(c=0,k=0;k<3;k++)
						c+=meshnode[meshelem[i].p[k]].CC()*LengthConv[LengthUnits]/3.;
					
					y=Re(c)*F2 -Im(c)*F1;
					y*=AECF(i);
					z+=(a*y);

					break;
				
				default:
					break;
		  }
	  }
	}
	
	// Integrals 3 and 4 are averages over the selected volume;
	// Need to divide by the block volme to get the average.
	if((inttype==3) || (inttype==4)) z/=BlockIntegral(2);

	return z;
}
Esempio n. 19
0
/* project when (Kx,Kz) != (0,0) */
void increproject(int count, int k, int z, int x0,
                  func_force_tt force)
{

    /* External Variables */
    extern int qpts, dimR, dimQ, Nx;
    extern double dt, re;
    extern double *Kx, *Kz, **K2;
    extern mcomplex **IFa, **IFb, **ITM;
    extern double **Q, **Qp, **Qpp, **R, **Rp, **Qw, **Qpw, **Rw, **Qs,
        **Qps, **Qpps, **Rs, **Rps;
    extern double ***M;
    extern mcomplex ****IU, ****IC;
    extern mcomplex *****MIC;
    /* Local variables */
    int i, j, x;
    double s, t[2];

    /* static double a[3] = {29./96., -3./40.,   1./6.};
       static double b[3] = {37./160., 5./24.,   1./6.};
       static double c[3] = { 8./15.,  5./12.,   3./4.};
       static double d[3] = { 0.,    -17./60.,  -5./12.}; */

    static double a[3] = { 1. / 3., -1. / 2, 1. / 3. };
    static double b[3] = { 1. / 6, 2. / 3, 0. };
    static double c[3] = { 1. / 2, 1. / 3., 1., };
    static double d[3] = { 0., -1. / 6, -2. / 3 };

    /*static double e[4] = { 4. / 3., -4. / 15., -4. / 15., 4. / 35. };
    static double r[8] =
        { -16. / 15., 16. / 35., 32. / 105., -32. / 105., -16. / 315.,
16. / 231., 0., 0. };
    static double xx[8] =
        { 8. / 35., -8. / 315., -8. / 105., 8. / 385., 8. / 385.,
-8. / 1001., -8. / 3003., 8. / 6435. };*/
    //   static  double h[3] = { 0., 1./2., 2./3.};
    //   static  double h[3] = { 0., 8./15., 2./3.};

//    mcomplex tmp[Nx / 2][dimR], tmp2[Nx / 2][dimQ];
//
//    if (force != NULL) {
//        force(n, k, z, tmp[0], tmp2[0]);
//    }

    /* Apply Forcing */
 
    if ((force != NULL)&&(k==0)) {
        memset(IFa[0], 0, dimQ * (Nx / 2) * sizeof(mcomplex));
        memset(IFb[0], 0, dimR * (Nx / 2) * sizeof(mcomplex));
        force(count, k, z, IFa, IFb);
        
        /* form mass matrix, solve for forcing contribution to da/dt */
        /* Left hand side M = Mv */
        memset(M[0][0], 0, dimR * 9 * (Nx / 2) * sizeof(double));
        for (i = 0; i < dimQ; ++i) {
            for (j = 0; j < T_QSDIAG; ++j) {
                for (x = x0; x < Nx / 2; ++x) {
                    M[i][j][x] = -(K2[z][x] * Qs[i][j] + Qps[i][j]);      
                }
            }
        }
        bsolve(M, IFa, QSDIAG - 1, QSDIAG - 1, dimQ, Nx / 2, x0);

        /* form mass matrix, solve for forcing contribution to db/dt */
        /* Left hand side M = Mv */
        memset(M[0][0], 0, dimR * 9 * (Nx / 2) * sizeof(double));
        for (i = 0; i < dimR; ++i) {
            for (j = 0; j < T_RSDIAG; ++j) {
                for (x = x0; x < Nx / 2; ++x) {
                    M[i][j][x] = Rs[i][j];      
                }
            }
        }
        bsolve(M, IFb, RSDIAG - 1, RSDIAG - 1, dimR, Nx / 2, x0);
      
        for (x = x0; x < Nx / 2; ++x) {
             for (i = 0; i < dimQ; ++i) {
                Re(IC[z][ALPHA][i][x]) += dt * Re(IFa[i][x]);
                Im(IC[z][ALPHA][i][x]) += dt * Im(IFa[i][x]);
             }
            
             for (i = 0; i < dimR; ++i) {
                Re(IC[z][BETA][i][x]) += dt * Re(IFb[i][x]);
                Im(IC[z][BETA][i][x]) += dt * Im(IFb[i][x]);
             }
        }
    
    }

    memset(IFa[0], 0, dimQ * (Nx / 2) * sizeof(mcomplex));
    memset(IFb[0], 0, dimR * (Nx / 2) * sizeof(mcomplex));

    /* FIRST COMPUTE ALPHAS */
    /* Create matrices for solving linear system. 
       Right hand side of system:  If this is the first step in the Runge-Kutta
       scheme, compute 
       [Mv + (1/RE)a[k]dt*Dv]*C[z][ALPHA] + dt*c[k]Fv. 
       Otherwise, compute C[z][ALPHA] + dt*c[k]Fv. 
       Lhs matrix:  Mv - (1/RE)b[k]dt*Dv           */

    if (k == 0) {               /* first step */
        memset(M[0][0], 0, dimR * 9 * (Nx / 2) * sizeof(double));
        for (i = 0; i < dimQ; ++i) {    /* M = Mv + (1/RE)a[k]dt*Dv */
            for (j = 0; j < T_QSDIAG; ++j) {
                for (x = x0; x < Nx / 2; ++x) {
                    s = K2[z][x] * K2[z][x];
                    M[i][j][x] = -(K2[z][x] * Qs[i][j] + Qps[i][j]) +
                        re * a[0] * dt * (s * Qs[i][j] +
                                          2. * K2[z][x] * Qps[i][j] +
                                          Qpps[i][j]);
                }
            }
        }
        /* compute [Mv + (1/RE)a[k]dt*Dv]*IC[z][ALPHA] and store the result
           in TM.  Then transfer the result back to IC[z][ALPHA]. */
        smMult(M, IC[z][ALPHA], ITM, QSDIAG - 1, QSDIAG - 1, dimQ, Nx / 2,
               x0);
        for (i = 0; i < dimQ; ++i) {
            memcpy(&IC[z][ALPHA][i][x0], &ITM[i][x0],
                   (Nx / 2 - x0) * sizeof(mcomplex));
        }
    }

    /* Left hand side M = Mv - (1/RE)b[k]dt*Dv */
    memset(M[0][0], 0, dimR * 9 * (Nx / 2) * sizeof(double));
    for (i = 0; i < dimQ; ++i) {
        for (j = 0; j < T_QSDIAG; ++j) {
            for (x = x0; x < Nx / 2; ++x) {
                s = K2[z][x] * K2[z][x];
                M[i][j][x] = -(K2[z][x] * Qs[i][j] + Qps[i][j]) -
                    re * b[k] * dt * (s * Qs[i][j] +
                                      2. * K2[z][x] * Qps[i][j] +
                                      Qpps[i][j]);
            }
        }
    }

    /* Finish computing the right hand size */
    /* array IFa */
    //memset(IFa[0], 0, dimR * (Nx / 2) * sizeof(mcomplex));
    for (i = 0; i < dimQ; ++i) {
        for (j = 0; j < qpts; ++j) {
            for (x = x0; x < Nx / 2; ++x) {
                Re(IFa[i][x]) += (Qpw[i][j] *
                                  (-Kx[x] * Im(IU[z][HXEL][j][x]) -
                                   Kz[z] * Im(IU[z][HZEL][j][x])) -
                                  K2[z][x] * (Qw[i][j] *
                                              Re(IU[z][HYEL][j][x])));
                Im(IFa[i][x]) +=
                    (Qpw[i][j] *
                     (Kx[x] * Re(IU[z][HXEL][j][x]) +
                      Kz[z] * Re(IU[z][HZEL][j][x])) -
                     K2[z][x] * (Qw[i][j] * Im(IU[z][HYEL][j][x])));
            }
        }
    }

    //if (force != NULL) {
    //    for (x = x0; x < Nx / 2; ++x) {
    //        for (i = 0; i < dimQ; ++i) {
    //            Im(IFa[i][x]) += Im(tmp[x][i]);
    //            Re(IFa[i][x]) += Re(tmp[x][i]);
    //        }
    //    }
    //}

    for (i = 0; i < dimQ; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            Re(IC[z][ALPHA][i][x]) += dt * c[k] * Re(IFa[i][x]);
            Im(IC[z][ALPHA][i][x]) += dt * c[k] * Im(IFa[i][x]);
        }
    }

/* Boundary conditions enforced here (note presence of Uzbt */

/*    for (x = x0; x < Nx / 2; ++x) {
        for (i = 0; i < 8 && i < dimQ; ++i) {
            Re(IC[z][ALPHA][i][x]) +=
                (r[i] / 2. - K2[z][x] * xx[i]) * (Re(Uzbt[z][x]) -
                                                  Re(Uzb[z][x])) +
                dt * re * (a[k] * Re(Uzbt[z][x]) +
                           b[k] * Re(Uzb[z][x])) * (-K2[z][x] * r[i] +
                                                    K2[z][x] * K2[z][x] *
                                                    xx[i]);
            Im(IC[z][ALPHA][i][x]) +=
                (r[i] / 2. - K2[z][x] * xx[i]) * (Im(Uzbt[z][x]) -
                                                  Im(Uzb[z][x])) +
                dt * re * (a[k] * Im(Uzbt[z][x]) +
                           b[k] * Im(Uzb[z][x])) * (-K2[z][x] * r[i] +
                                                    K2[z][x] * K2[z][x] *
                                                    xx[i]);
        }

    }
*/

    /* Compute alphas */
    bsolve(M, IC[z][ALPHA], QSDIAG - 1, QSDIAG - 1, dimQ, Nx / 2, x0);

    /* NOW COMPUTE BETAS */
    /* Create matrices for solving linear system. 
       Right hand side of system:  If this is the first step in the Runge-Kutta
       scheme, compute 
       [Mg + (1/RE)a[k]dt*Dg]*C[z][BETA] + dt*c[k]Fg. 
       Otherwise, compute C[z][BETA] + dt*c[k]Fg. 
       Lhs matrix:  Mg - (1/RE)b[k]dt*Dg                                */

    if (k == 0) {               /* first step */
        /* M = Mg + (1/RE)a[k]dt*Dg */
        memset(M[0][0], 0, dimR * 9 * (Nx / 2) * sizeof(double));
        for (i = 0; i < dimR; ++i) {
            for (j = 0; j < T_RSDIAG; ++j) {
                for (x = x0; x < Nx / 2; ++x) {
                    M[i][j][x] = Rs[i][j] -
                        re * a[0] * dt * (Rps[i][j] + K2[z][x] * Rs[i][j]);
                }
            }
        }

        /* compute [Mv + (1/RE)a[k]dt*Dv]*IC[z][BETA] and store the result
           in TM.  Then transfer the result back to IC[z][ALPHA]. */
        smMult(M, IC[z][BETA], ITM, RSDIAG - 1, RSDIAG - 1, dimR, Nx / 2,
               x0);
        for (i = 0; i < dimR; ++i) {
            memcpy(&IC[z][BETA][i][x0], &ITM[i][x0],
                   (Nx / 2 - x0) * sizeof(mcomplex));
        }
    }

    /* left hand side M = Mg - (1/RE)b[k]dt*Dg */
    memset(M[0][0], 0, dimR * 9 * (Nx / 2) * sizeof(double));
    for (i = 0; i < dimR; ++i) {        /* M = Mg - (1/RE)b[k]dt*Dg */
        for (j = 0; j < T_RSDIAG; ++j) {
            for (x = x0; x < Nx / 2; ++x) {
                M[i][j][x] = Rs[i][j] +
                    re * b[k] * dt * (Rps[i][j] + K2[z][x] * Rs[i][j]);
            }
        }
    }

    /* Finish computing the right hand size */
    /* array Fb */
    //memset(IFb[0], 0, dimR * (Nx / 2) * sizeof(mcomplex));
    for (i = 0; i < dimR; ++i) {
        for (j = 0; j < qpts; ++j) {
            for (x = x0; x < Nx / 2; ++x) {
                Re(IFb[i][x]) += Rw[i][j] *
                    (-Kz[z] * Im(IU[z][HXEL][j][x]) +
                     Kx[x] * Im(IU[z][HZEL][j][x]));
                Im(IFb[i][x]) +=
                    Rw[i][j] * (Kz[z] * Re(IU[z][HXEL][j][x]) -
                                Kx[x] * Re(IU[z][HZEL][j][x]));
            }
        }
    }

//     if (force != NULL) {
//         for (x = x0; x < Nx / 2; ++x) {
//             for (i = 0; i < dimR; ++i) {
//                 Im(IFb[i][x]) += Im(tmp2[x][i]);
//                 Re(IFb[i][x]) += Re(tmp2[x][i]);
//             }
//         }
//     }
    for (i = 0; i < dimR; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            Re(IC[z][BETA][i][x]) += dt * c[k] * Re(IFb[i][x]);
            Im(IC[z][BETA][i][x]) += dt * c[k] * Im(IFb[i][x]);
        }
    }

    /* Boundary conditions here: */

/*    for (x = x0; x < Nx / 2; ++x) {
        for (i = 0; i < 4 && i < dimR; ++i) {
            Re(IC[z][BETA][i][x]) +=
                e[i] / 2. * (Re(Uxbt[z][x]) - Re(Uxb[z][x])) +
                dt * re * (a[k] * Re(Uxbt[z][x]) +
                           b[k] * Re(Uxb[z][x])) * (-K2[z][x] * e[i] / 2.);
            Im(IC[z][BETA][i][x]) +=
                e[i] / 2. * (Im(Uxbt[z][x]) - Im(Uxb[z][x])) +
                dt * re * (a[k] * Im(Uxbt[z][x]) +
                           b[k] * Im(Uxb[z][x])) * (-K2[z][x] * e[i] / 2.);
        }
    }
*/

    /* Compute betas */
    bsolve(M, IC[z][BETA], RSDIAG - 1, RSDIAG - 1, dimR, Nx / 2, x0);

    /* NOW COMPUTE IU HATS */
    /* v = uy_hat+c2/4*(1-y)^2*(1+y). */
    for (i = 0; i < qpts; ++i) {
        memset(&IU[z][YEL][i][x0], 0, (Nx / 2 - x0) * sizeof(mcomplex));
    }
    for (i = 0; i < qpts; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            for (j = 0; j < dimQ; ++j) {
                Re(IU[z][YEL][i][x]) += Q[i][j] * Re(IC[z][ALPHA][j][x]);
                Im(IU[z][YEL][i][x]) += Q[i][j] * Im(IC[z][ALPHA][j][x]);
            }
            //Re(IU[z][YEL][i][x]) += Re(Uzb[z][x]) * Vadd[i] / 4.;
            //Im(IU[z][YEL][i][x]) += Im(Uzb[z][x]) * Vadd[i] / 4.;
        }
    }


    /* f = -dv/dy and store temporarily in XEL position of array U. */
    /*f=-dv/dy-c2/4*(3y^2-2y-1) */
    for (i = 0; i < qpts; ++i) {
        memset(&IU[z][XEL][i][x0], 0, (Nx / 2 - x0) * sizeof(mcomplex));
    }
    for (i = 0; i < qpts; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            for (j = 0; j < dimQ; ++j) {
                Re(IU[z][XEL][i][x]) -= Qp[i][j] * Re(IC[z][ALPHA][j][x]);
                Im(IU[z][XEL][i][x]) -= Qp[i][j] * Im(IC[z][ALPHA][j][x]);
            }
            //Re(IU[z][XEL][i][x]) -= Re(Uzb[z][x]) * Vpadd[i] / 4.;
            //Im(IU[z][XEL][i][x]) -= Im(Uzb[z][x]) * Vpadd[i] / 4.;
        }
    }

    /* sum(Q''alpha) and store in DXEL position. */
    /*df/dy=d^2 v/dy^2+c2/4*(6y-2)=d^2 v/dy^2+c2/2*(-3+3y+2) */
    for (i = 0; i < qpts; ++i) {
        memset(&IU[z][DXEL][i][x0], 0, (Nx / 2 - x0) * sizeof(mcomplex));
    }
    for (i = 0; i < qpts; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            for (j = 0; j < dimQ; ++j) {
                Re(IU[z][DXEL][i][x]) +=
                    Qpp[i][j] * Re(IC[z][ALPHA][j][x]);
                Im(IU[z][DXEL][i][x]) +=
                    Qpp[i][j] * Im(IC[z][ALPHA][j][x]);
            }
            //Re(IU[z][DXEL][i][x]) +=
            //    Re(Uzb[z][x]) * (-3 * Uadd[i] + 2) / 2.;
            //Im(IU[z][DXEL][i][x]) +=
            //    Im(Uzb[z][x]) * (-3 * Uadd[i] + 2) / 2.;
        }
    }

    /* Compute g = sum(beta*R) and store temporarily in ZEL position of 
       array U. */
    for (i = 0; i < qpts; ++i) {
        memset(&IU[z][ZEL][i][x0], 0, (Nx / 2 - x0) * sizeof(mcomplex));
    }
    for (i = 0; i < qpts; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            for (j = 0; j < dimR; ++j) {
                Re(IU[z][ZEL][i][x]) += R[i][j] * Re(IC[z][BETA][j][x]);
                Im(IU[z][ZEL][i][x]) += R[i][j] * Im(IC[z][BETA][j][x]);
            }

            //Re(IU[z][ZEL][i][x]) += Re(Uxb[z][x]) * Uadd[i] / 2.;
            //Im(IU[z][ZEL][i][x]) += Im(Uxb[z][x]) * Uadd[i] / 2.;
        }
    }


    /* Compute sum(beta*R') and store temporarily in DZEL position of
       array IU. */
    for (i = 0; i < qpts; ++i) {
        memset(&IU[z][DZEL][i][x0], 0, (Nx / 2 - x0) * sizeof(mcomplex));
    }
    for (i = 0; i < qpts; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            for (j = 0; j < dimR; ++j) {
                Re(IU[z][DZEL][i][x]) += Rp[i][j] * Re(IC[z][BETA][j][x]);
                Im(IU[z][DZEL][i][x]) += Rp[i][j] * Im(IC[z][BETA][j][x]);
            }
            //Re(IU[z][DZEL][i][x]) += -Re(Uxb[z][x]) / 2.;
            //Im(IU[z][DZEL][i][x]) += -Im(Uxb[z][x]) / 2.;
        }
    }

    /* now compute Iux hat, Iuz hat */
    for (i = 0; i < qpts; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            t[0] = Re(IU[z][XEL][i][x]);        /* real part of f */
            t[1] = Re(IU[z][ZEL][i][x]);        /* real part of g */

            Re(IU[z][XEL][i][x]) = (Kx[x] * Im(IU[z][XEL][i][x]) +
                                    Kz[z] * Im(IU[z][ZEL][i][x])) / K2[z][x];
            Re(IU[z][ZEL][i][x]) = (-Kx[x] * Im(IU[z][ZEL][i][x]) +
                                    Kz[z] * Im(IU[z][XEL][i][x])) / K2[z][x];
            Im(IU[z][XEL][i][x]) =
                -(Kx[x] * t[0] + Kz[z] * t[1]) / K2[z][x];
            Im(IU[z][ZEL][i][x]) =
                (Kx[x] * t[1] - Kz[z] * t[0]) / K2[z][x];
        }
    }

    /* dux hat, duz hat */
    for (i = 0; i < qpts; ++i) {
        for (x = x0; x < Nx / 2; ++x) {
            t[0] = Re(IU[z][DXEL][i][x]);       /* real part of Q''alpha */
            t[1] = Re(IU[z][DZEL][i][x]);       /* real part of R'beta */

            Re(IU[z][DXEL][i][x]) = (-Kx[x] * Im(IU[z][DXEL][i][x]) +
                                     Kz[z] * Im(IU[z][DZEL][i][x])) /
                K2[z][x];
            Re(IU[z][DZEL][i][x]) =
                -(Kx[x] * Im(IU[z][DZEL][i][x]) +
                  Kz[z] * Im(IU[z][DXEL][i][x])) / K2[z][x];
            Im(IU[z][DXEL][i][x]) =
                (Kx[x] * t[0] - Kz[z] * t[1]) / K2[z][x];
            Im(IU[z][DZEL][i][x]) =
                (Kx[x] * t[1] + Kz[z] * t[0]) / K2[z][x];
        }
    }

    if (count >= 0) {
        for (i = 0; i < dimR; i++) {
            for (x = x0; x < Nx / 2; x++) {
                Re(MIC[count][z][ALPHA][i][x]) = Re(IC[z][ALPHA][i][x]);
                Im(MIC[count][z][ALPHA][i][x]) = Im(IC[z][ALPHA][i][x]);
            }
        }
        for (i = 0; i < dimR; i++) {
            for (x = x0; x < Nx / 2; x++) {
                Re(MIC[count][z][BETA][i][x]) = Re(IC[z][BETA][i][x]);
                Im(MIC[count][z][BETA][i][x]) = Im(IC[z][BETA][i][x]);
            }
        }
    }

    /* UPDATE RHS FOR NEXT TIME */
    if (k != 2) {               /* not last step */
        /* first alphas */
        memset(M[0][0], 0, dimR * 9 * (Nx / 2) * sizeof(double));
        for (i = 0; i < dimQ; ++i) {    /* M = Mv + (1/RE)a[k+1]dt*Dv */
            for (j = 0; j < T_QSDIAG; ++j) {
                for (x = x0; x < Nx / 2; ++x) {
                    s = K2[z][x] * K2[z][x];
                    M[i][j][x] = -(K2[z][x] * Qs[i][j] + Qps[i][j]) +
                        re * a[k + 1] * dt * (s * Qs[i][j] +
                                              2. * K2[z][x] * Qps[i][j] +
                                              Qpps[i][j]);
                }
            }
        }

        /* compute [Mv + (1/RE)a[k]dt*Dv]*C[z][ALPHA].  Then update
           C[z][ALPHA] */
        smMult(M, IC[z][ALPHA], ITM, QSDIAG - 1, QSDIAG - 1, dimQ, Nx / 2,
               x0);
        for (i = 0; i < dimQ; ++i) {
            for (x = x0; x < Nx / 2; ++x) {
                Re(IC[z][ALPHA][i][x]) =
                    Re(ITM[i][x]) + dt * d[k + 1] * Re(IFa[i][x]);
                Im(IC[z][ALPHA][i][x]) =
                    Im(ITM[i][x]) + dt * d[k + 1] * Im(IFa[i][x]);
            }
        }

        /* now betas */
        memset(M[0][0], 0, dimR * 9 * (Nx / 2) * sizeof(double));
        for (i = 0; i < dimR; ++i) {    /* M = Mg + (1/RE)a[k+1]dt*Dg */
            for (j = 0; j < T_RSDIAG; ++j) {
                for (x = x0; x < Nx / 2; ++x) {
                    M[i][j][x] = Rs[i][j] -
                        re * a[k + 1] * dt * (Rps[i][j] +
                                              K2[z][x] * Rs[i][j]);
                }
            }
        }

        /* compute [Mg + (1/RE)a[k+1]dt*Dg]*C[z][BETA] and then
           update C[z][BETA] */
        smMult(M, IC[z][BETA], ITM, RSDIAG - 1, RSDIAG - 1, dimR, Nx / 2,
               x0);
        for (i = 0; i < dimR; ++i) {
            for (x = x0; x < Nx / 2; ++x) {
                Re(IC[z][BETA][i][x]) =
                    Re(ITM[i][x]) + dt * d[k + 1] * Re(IFb[i][x]);
                Im(IC[z][BETA][i][x]) =
                    Im(ITM[i][x]) + dt * d[k + 1] * Im(IFb[i][x]);
            }
        }
    }

}
Esempio n. 20
0
std::ostream & operator<<(std::ostream & out, const Complex & c)
{
	out << "(" << Re(c) << ", " << Im(c) << "i)" << endl;
	return out;
}
Esempio n. 21
0
 //! Constructor of class cdotprecision
 explicit inline cdotprecision(const complex      &c)   : re(Re(c)),im(Im(c)) { }
Esempio n. 22
0
void CiSi( double x, double *ci, double *si )
{
	int			i, k, odd;
	double		a, err, fact, sign, sum, sumc, sums, t, term;
	Complex	h, b, c, d, del;

	t = fabs(x);
	if( t == 0.0 )
	{
		*si = 0.0;
		*ci = -1.0 / FPMIN;
		return;
	}
	if( t > TMIN )
	{
		b = Complex(1.0, t);
		c = Complex(1.0/FPMIN, 0.0);
		d = h = ONE / b;
		for( i=2; i<=MAXIT; i++ )
		{
			a = -(i-1) * ( i-1);
			b += Complex(2.0, 0.0);
			d = ONE / ( a * d + b );
			c = b + (Complex(a, 0.0) / c);
			del = c * d;
			h *= del;
			if( fabs(Re(del) - 1.0) + fabs(Im(del)) < EPS)
				break;
		}
		if( i > MAXIT )
		{
			printf("cf failed u CiSi");
			assert(0);
		}
		h *= Complex(cos(t),sin(t));
		*ci = -Re(h);
		*si = PIBY2 + Im(h);
	}
	else
	{
		if( t < sqrt(FPMIN) )
		{
			sumc = 0.0;
			sums = t;
		}
		else
		{
			sum = sumc = sums = 0.0;
			sign = fact = 1.0;
			odd = TRUE;
			for( k=1; k<=MAXIT; k++ )
			{
				fact *= t / k;
				term = fact / k;
				sum += sign*term;
				err = term/fabs(sum);
				if( odd)
				{
					sign = -sign;
					sums = sum;
					sum = sumc;
				}
				else
				{
					sumc = sum;
					sum = sums;
				}
				if( err < EPS )
					break;
				odd = !odd;
			}
			if( k > MAXIT )
			{
				printf("Maxits exceeded ");
				assert(0);
			}
		}
		*si = sums;
		*ci = sumc + log(t) + EULER;
	}

	if( x < 0.0 )
		*si = -(*si);
}
Esempio n. 23
0
 //! Implementation of standard assigning operator
 inline cdotprecision& operator= (const complex & a) 
                                 { re=Re(a),im=Im(a); return *this; }
Esempio n. 24
0
Arbin E(){
  printf("E->TRe\n");
  return Re(T());
}
Esempio n. 25
0
int comp_stat(int n)
{
 /* External Variables */
  extern int Nx, Nz, qpts, nums;
  extern mcomplex ****U,****IU, **GUxb,**GUzb, ishear;
  extern double **uu, **us, *W;
  extern FILE *fp, *fp2, *fp3, *fp4, *fp5, *fp6, *fp7, *fp8, *fp9, *fp10, *fp11;
    extern fftw_complex ***CT;
    extern fftw_plan pf1, pf2;
    extern fftw_plan Ipf1, Ipf2;
    extern rfftwnd_plan pr1, pr2;
    extern double *Kx, *Kz, **K2;
    extern double re, dt, tau, itau;
    int  x,i,j,y, z, idx;
    fftw_real *RT;     /* real to complex transform */
    fftw_complex *fout = NULL;
    fftw_real *rout = NULL;
    extern mcomplex ****U,****IU;
    double norm; 
   

    idx = (3*Nz/2)*(3*Nx/2+2);
    RT = (fftw_real *)CT[0][0];
    norm = 1.0 / ((3.*Nx/2.)*(3.*Nz/2.));
    double u1, u2, u3, u1u2, u1u3, u2u3, u1y;
    double iu1, iu2, iu3, iu1u2, iu1u3, iu2u3, u1u1, u2u2, u3u3, iu1u1, iu2u2, iu3u3;
    double au1, au2, au3, au1u2, au1u3, au2u3, au1u1, au2u2, au3u3;
    double iau1, iau2, iau3, iau1u2, iau1u3, iau2u3, iau1u1, iau2u2, iau3u3;

    tau+=Re(GUxb[0][0]);
    itau+=Re(ishear);
    /* for(j=0; j< qpts; j++)
      {
	uu[0][j] += Re(U[0][XEL][j][0]);
	uu[1][j] += Re(U[0][YEL][j][0]);
	uu[2][j] += Re(U[0][ZEL][j][0]);


	uu[3][j] += Re(IU[0][XEL][j][0]);
	uu[4][j] += Re(IU[0][YEL][j][0]);
	uu[5][j] += Re(IU[0][ZEL][j][0]);
	}*/

    if( (n+1) % 100 ==0)
      {
	/* record wall shear stress for state and incremental state */
	fprintf(fp7, "%f\n", tau/100.);
	tau=0;
	fprintf(fp8, "%f\n", itau/100.);
	itau=0;

	au1=0; au2=0; au3=0; au1u2=0; au2u3=0; au1u3=0; au1u1=0; au2u2=0; au3u3=0;
	iau1=0; iau2=0; iau3=0; iau1u2=0; iau2u3=0; iau1u3=0; iau1u1=0; iau2u2=0; iau3u3=0;

		nums=nums+1;
		/*fprintf(fp, "the time averge %d, %d\n", (n+1)-50, (n+1));
	for(j=0; j< qpts; j++)
	  {
	    fprintf(fp, "%d, %f %f %f  \n", j, uu[0][j]/50., uu[1][j]/50., uu[2][j]/50.);
	  }

	fprintf(fp2, "the time averge %d, %d\n", (n+1)-50, (n+1));
	for(j=0; j< qpts; j++)
	  {
	    fprintf(fp2, "%d, %f %f %f  \n", j, uu[3][j]/50., uu[4][j]/50., uu[5][j]/50.);
	    }

	    memset(uu[0], 0, 6*(qpts)*sizeof(double));*/

	memset(CT[0][0], 0,  MAXTT*(3*Nz/2)*(3*Nx/4+1)*sizeof(fftw_complex));
	for (z = 0; z < Nz/2; ++z)
	  {
	    memcpy(CT[0][z], GUxb[z], (Nx/2)*sizeof(fftw_complex));
	    memcpy(CT[1][z], GUzb[z], (Nx/2)*sizeof(fftw_complex));
	  }
	for (z = Nz/2+1; z < Nz; ++z)
	  {
	    memcpy(CT[0][z+Nz/2], GUxb[z], (Nx/2)*sizeof(fftw_complex));
	    memcpy(CT[1][z+Nz/2], GUzb[z], (Nx/2)*sizeof(fftw_complex));
	  }

	for (i = 0; i < 2; ++i)
	      {
		/* Each column of CT[i] */
		fftw(pf1, Nx/2, CT[i][0], 3*Nx/4+1, 1, fout, -1, -1);

		/* Each row of CT[i] */
		rfftwnd_complex_to_real(pr1, 3*Nz/2, CT[i][0], 1, 3*Nx/4+1, 
					rout, -1, -1);
	      }
	z=5;
	for(x=0; x< Nx/2; x++)
	  {
	    fprintf(fp2, "  %f  %f \n", RT[(z*(3*Nx/2+2)+x)], RT[idx+(z*(3*Nx/2+2)+x)]);
	  }

	z=20;
	for(x=0; x< Nx/2; x++)
	  {
	    fprintf(fp11, "  %f  %f \n", RT[(z*(3*Nx/2+2)+x)], RT[idx+(z*(3*Nx/2+2)+x)]);
	  }

	for (y = 0; y < qpts; ++y)
	  {
	    memset(CT[0][0], 0, MAXTT*(3*Nz/2)*(3*Nx/4+1)*sizeof(fftw_complex));

	    for (i = 0; i < 3; ++i)
	      {
		for (z = 0; z < Nz/2; ++z)
		  {
		    memcpy(CT[i][z], U[z][i][y], (Nx/2)*sizeof(fftw_complex));
		    memcpy(CT[i+3][z], IU[z][i][y], (Nx/2)*sizeof(fftw_complex));
		  }
		for (z = Nz/2+1; z < Nz; ++z)
		  {
		    memcpy(CT[i][z+Nz/2], U[z][i][y], (Nx/2)*sizeof(fftw_complex));
		    memcpy(CT[i+3][z+Nz/2], IU[z][i][y], (Nx/2)*sizeof(fftw_complex));
		  }
	      }
	    for (z = 0; z < Nz/2; ++z)
		  {
		    memcpy(CT[6][z], U[z][DXEL][y], (Nx/2)*sizeof(fftw_complex));
		  }
		for (z = Nz/2+1; z < Nz; ++z)
		  {
		    memcpy(CT[6][z+Nz/2], U[z][DXEL][y], (Nx/2)*sizeof(fftw_complex));
		  }
	    for (i = 0; i < 7; ++i)
	      {
		/* Each column of CT[i] */
		fftw(pf1, Nx/2, CT[i][0], 3*Nx/4+1, 1, fout, -1, -1);

		/* Each row of CT[i] */
		rfftwnd_complex_to_real(pr1, 3*Nz/2, CT[i][0], 1, 3*Nx/4+1, 
					rout, -1, -1);
	      }

	    u1=0;
	    u2=0;
	    u3=0;
	    u1y=0;
	    u1u2=0;
	    u1u3=0;
	    u2u3=0;
	    u1u1=0;
	    u2u2=0;
	    u3u3=0;
	    for (z = 0; z < (3*Nz/2); ++z)
	      {
		for (x = 0; x < 3*Nx/2; ++x)
		  {
		    u1 += RT[XEL*idx+(z*(3*Nx/2+2)+x)];
		    u2 += RT[YEL*idx+(z*(3*Nx/2+2)+x)];
		    u3 += RT[ZEL*idx+(z*(3*Nx/2+2)+x)];
		    u1y+=RT[6*idx+(z*(3*Nx/2+2)+x)];
		    u1u2 += RT[XEL*idx+(z*(3*Nx/2+2)+x)]* RT[YEL*idx+(z*(3*Nx/2+2)+x)];
		    u1u3 += RT[XEL*idx+(z*(3*Nx/2+2)+x)]* RT[ZEL*idx+(z*(3*Nx/2+2)+x)];
		    u2u3 += RT[YEL*idx+(z*(3*Nx/2+2)+x)]* RT[ZEL*idx+(z*(3*Nx/2+2)+x)];
		    u1u1 += RT[XEL*idx+(z*(3*Nx/2+2)+x)]* RT[XEL*idx+(z*(3*Nx/2+2)+x)];
		    u2u2 += RT[YEL*idx+(z*(3*Nx/2+2)+x)]* RT[YEL*idx+(z*(3*Nx/2+2)+x)];
		    u3u3 += RT[ZEL*idx+(z*(3*Nx/2+2)+x)]* RT[ZEL*idx+(z*(3*Nx/2+2)+x)];
		  }
	      }

	    u1=u1/(3*Nz/2)/(3*Nx/2);
	    u2=u2/(3*Nz/2)/(3*Nx/2);
	    u3=u3/(3*Nz/2)/(3*Nx/2);
	    u1y=u1y/(3*Nz/2)/(3*Nx/2);
	    u1u2=u1u2/(3*Nz/2)/(3*Nx/2);
	    u1u3=u1u3/(3*Nz/2)/(3*Nx/2);
	    u2u3=u2u3/(3*Nz/2)/(3*Nx/2);
	    u1u1=u1u1/(3*Nz/2)/(3*Nx/2);
	    u2u2=u2u2/(3*Nz/2)/(3*Nx/2);
	    u3u3=u3u3/(3*Nz/2)/(3*Nx/2);

	    us[0][y]+=u1;
	    us[1][y]+=u2;
	    us[2][y]+=u3;
	    us[3][y]+=u1u2;
	    us[4][y]+=u1u3;
	    us[5][y]+=u2u3;
	    us[12][y]+=u1u1;
	    us[13][y]+=u2u2;
	    us[14][y]+=u3u3;
	    us[18][y]+=u1y;
	    // fprintf(fp, "%d, %f %f %f  %f %f  %f %f %f %f\n", y, u1, u2, u3, u1u2, u1u3, u2u3, u1u1, u2u2, u3u3);

	     if(y==5)
	      {
		fprintf(fp3, " %f %f %f  %f %f  %f  %f  %f  %f %f\n", u1, u2, u3, u1u2, u1u3, u2u3, u1u1, u2u2, u3u3, 0.5*(u1u1+u2u2+u3u3));
	      }

	    if(y==40)
	      {
		fprintf(fp4, " %f %f %f  %f %f  %f  %f  %f  %f %f \n", u1, u2, u3, u1u2, u1u3, u2u3, u1u1, u2u2, u3u3, 0.5*(u1u1+u2u2+u3u3));
		}

	    iu1=0;
	    iu2=0;
	    iu3=0;
	    iu1u2=0;
	    iu1u3=0;
	    iu2u3=0;
	    iu1u1=0;
	    iu2u2=0;
	    iu3u3=0;
	    for (z = 0; z < (3*Nz/2); ++z)
	      {
		for (x = 0; x < 3*Nx/2; ++x)
		  {
		    iu1 += RT[(XEL+3)*idx+(z*(3*Nx/2+2)+x)];
		    iu2 += RT[(YEL+3)*idx+(z*(3*Nx/2+2)+x)];
		    iu3 += RT[(ZEL+3)*idx+(z*(3*Nx/2+2)+x)];
		    iu1u2 += RT[(XEL+3)*idx+(z*(3*Nx/2+2)+x)]* RT[(YEL+3)*idx+(z*(3*Nx/2+2)+x)];
		    iu1u3 += RT[(XEL+3)*idx+(z*(3*Nx/2+2)+x)]* RT[(ZEL+3)*idx+(z*(3*Nx/2+2)+x)];
		    iu2u3 += RT[(YEL+3)*idx+(z*(3*Nx/2+2)+x)]* RT[(ZEL+3)*idx+(z*(3*Nx/2+2)+x)];
		    iu1u1 += RT[(XEL+3)*idx+(z*(3*Nx/2+2)+x)]* RT[(XEL+3)*idx+(z*(3*Nx/2+2)+x)];
		    iu2u2 += RT[(YEL+3)*idx+(z*(3*Nx/2+2)+x)]* RT[(YEL+3)*idx+(z*(3*Nx/2+2)+x)];
		    iu3u3 += RT[(ZEL+3)*idx+(z*(3*Nx/2+2)+x)]* RT[(ZEL+3)*idx+(z*(3*Nx/2+2)+x)];
		  }
	      }

	    iu1=iu1/(3*Nz/2)/(3*Nx/2);
	    iu2=iu2/(3*Nz/2)/(3*Nx/2);
	    iu3=iu3/(3*Nz/2)/(3*Nx/2);
	    iu1u2=iu1u2/(3*Nz/2)/(3*Nx/2);
	    iu1u3=iu1u3/(3*Nz/2)/(3*Nx/2);
	    iu2u3=iu2u3/(3*Nz/2)/(3*Nx/2);
	    iu1u1=iu1u1/(3*Nz/2)/(3*Nx/2);
	    iu2u2=iu2u2/(3*Nz/2)/(3*Nx/2);
	    iu3u3=iu3u3/(3*Nz/2)/(3*Nx/2);

	    us[6][y]+=iu1;
	    us[7][y]+=iu2;
	    us[8][y]+=iu3;
	    us[9][y]+=iu1u2;
	    us[10][y]+=iu1u3;
	    us[11][y]+=iu2u3;
	    us[15][y]+=iu1u1;
	    us[16][y]+=iu2u2;
	    us[17][y]+=iu3u3;
	    //fprintf(fp2, "%d, %f %f %f  %f %f  %f %f  %f  %f \n", y, iu1, iu2, iu3, iu1u2, iu1u3, iu2u3, iu1u1, iu2u2, iu3u3);

	     if(y==5)
	      {
		fprintf(fp5, " %f %f %f  %f %f  %f %f  %f  %f  %f \n", iu1, iu2, iu3, iu1u2, iu1u3, iu2u3, iu1u1, iu2u2, iu3u3, 0.5*(iu1u1+iu2u2+iu3u3));
	      }
	    if(y==40)
	      {
		fprintf(fp6, " %f %f %f  %f %f  %f %f  %f  %f  %f\n", iu1, iu2, iu3, iu1u2, iu1u3, iu2u3, iu1u1, iu2u2, iu3u3,0.5*(iu1u1+iu2u2+iu3u3) );
		}

	    au1+=u1*W[y];     au2+=u2*W[y]; 	    au3+=u3*W[y];
	    au1u2+=u1u2*W[y];  au2u3+=u2u3*W[y];  au1u3+=u1u3*W[y];
	    au1u1+=u1u1*W[y];  au2u2+=u2u2*W[y];  au3u3+=u3u3*W[y];

	    iau1+=iu1*W[y];     iau2+=iu2*W[y]; 	    iau3+=iu3*W[y];
	    iau1u2+=iu1u2*W[y];  iau2u3+=iu2u3*W[y];  iau1u3+=iu1u3*W[y];
	    iau1u1+=iu1u1*W[y];  iau2u2+=iu2u2*W[y];  iau3u3+=iu3u3*W[y];
	  }
	fprintf(fp9, " %f %f %f  %f %f  %f  %f  %f  %f \n", au1, au2, au3, au1u2, au1u3, au2u3, au1u1, au2u2, au3u3);
	fprintf(fp10, " %f %f %f  %f %f  %f %f  %f  %f \n",  iau1, iau2, iau3, iau1u2, iau1u3, iau2u3, iau1u1, iau2u2, iau3u3);
      }

 return(NO_ERR);
}
void parcel::setRelaxationTimes
(
    label celli,
    scalar& tauMomentum,
    scalarField& tauEvaporation,
    scalar& tauHeatTransfer,
    scalarField& tauBoiling,
    const spray& sDB,
    const scalar rho,
    const vector& Up,
    const scalar temperature,
    const scalar pressure,
    const scalarField& Yfg,
    const scalarField& m0,
    const scalar dt
)
{

    const liquidMixture& fuels = sDB.fuels();

    scalar mCell = rho*sDB.mesh().V()[cell()];
    scalarField mfg(Yfg*mCell);

    label Ns = sDB.composition().Y().size();
    label Nf = fuels.components().size();

    // Tf is based on the 1/3 rule
    scalar Tf  = T() + (temperature - T())/3.0;

    // calculate mixture properties
    scalar W = 0.0;
    scalar kMixture = 0.0;
    scalar cpMixture = 0.0;
    scalar muf = 0.0;

    for(label i=0; i<Ns; i++)
    {
        scalar Y = sDB.composition().Y()[i][celli];
        W += Y/sDB.gasProperties()[i].W();
        // Using mass-fractions to average...
        kMixture += Y*sDB.gasProperties()[i].kappa(Tf);
        cpMixture += Y*sDB.gasProperties()[i].Cp(Tf);
        muf += Y*sDB.gasProperties()[i].mu(Tf);
    }
    W = 1.0/W;

    scalarField Xf(Nf, 0.0);
    scalarField Yf(Nf, 0.0);
    scalarField psat(Nf, 0.0);
    scalarField msat(Nf, 0.0);

    for(label i=0; i<Nf; i++)
    {
        label j = sDB.liquidToGasIndex()[i];
        scalar Y = sDB.composition().Y()[j][celli];
        scalar Wi = sDB.gasProperties()[j].W();
        Yf[i] = Y;
        Xf[i] = Y*W/Wi;
        psat[i] = fuels.properties()[i].pv(pressure, temperature);
        msat[i] = min(1.0, psat[i]/pressure)*Wi/W;
    }

    scalar nuf = muf/rho;

    scalar liquidDensity = fuels.rho(pressure, T(), X());
    scalar liquidcL = fuels.cp(pressure, T(), X());
    scalar heatOfVapour = fuels.hl(pressure, T(), X());

    // calculate the partial rho of the fuel vapour
    // alternative is to use the mass fraction
    // however, if rhoFuelVap is small (zero)
    // d(mass)/dt = 0 => no evaporation... hmmm... is that good? NO!

    // Assume equilibrium at drop-surface => pressure @ surface
    // = vapour pressure to calculate fuel-vapour density @ surface
    scalar pressureAtSurface = fuels.pv(pressure, T(), X());
    scalar rhoFuelVap = pressureAtSurface*fuels.W(X())/(specie::RR()*Tf);

    scalarField Xs(sDB.fuels().Xs(pressure, temperature, T(), Xf, X()));
    scalarField Ys(Nf, 0.0);
    scalar Wliq = 0.0;

    for(label i=0; i<Nf; i++)
    {
        label j = sDB.liquidToGasIndex()[i];
        scalar Wi = sDB.gasProperties()[j].W();
        Wliq += Xs[i]*Wi;
    }

    for(label i=0; i<Nf; i++)
    {
        label j = sDB.liquidToGasIndex()[i];
        scalar Wi = sDB.gasProperties()[j].W();
        Ys[i] = Xs[i]*Wi/Wliq;
    }

    scalar Reynolds = Re(Up, nuf);
    scalar Prandtl = Pr(cpMixture, muf, kMixture);

    // calculate the characteritic times

    if(liquidCore_> 0.5)
    {
//      no drag for parcels in the liquid core..
        tauMomentum = GREAT;
    }
    else
    {
        tauMomentum = sDB.drag().relaxationTime
        (
            Urel(Up),
            d(),
            rho,
            liquidDensity,
            nuf,
            dev()
        );
    }

    // store the relaxationTime since it is needed in some breakup models.
    tMom_ = tauMomentum;

    tauHeatTransfer = sDB.heatTransfer().relaxationTime
    (
        liquidDensity,
        d(),
        liquidcL,
        kMixture,
        Reynolds,
        Prandtl
    );

    // evaporation-properties are evaluated at averaged temperature
    // set the boiling conditions true if pressure @ surface is 99.9%
    // of the pressure
    // this is mainly to put a limit on the evaporation time,
    // since tauEvaporation is very very small close to the boiling point.

    for(label i=0; i<Nf; i++)
    {
        scalar Td = min(T(), 0.999*fuels.properties()[i].Tc());
        bool boiling = fuels.properties()[i].pv(pressure, Td)
            >= 0.999*pressure;

        scalar Di = fuels.properties()[i].D(pressure, Td);
        scalar Schmidt = Sc(nuf, Di);

        scalar partialPressure = Xf[i]*pressure;

//      saturated vapour
        if(partialPressure > psat[i])
        {
            tauEvaporation[i] = GREAT;
        }
//      not saturated vapour
        else
        {
            if (!boiling)
            {
                // For saturation evaporation, only use 99.99% for
                // numerical robustness
                scalar dm = max(SMALL, 0.9999*msat[i] - mfg[i]);

                tauEvaporation[i] = sDB.evaporation().relaxationTime
                (
                    d(),
                    fuels.properties()[i].rho(pressure, Td),
                    rhoFuelVap,
                    Di,
                    Reynolds,
                    Schmidt,
                    Xs[i],
                    Xf[i],
                    m0[i],
                    dm,
                    dt
                );
            }
            else
            {
                scalar Nusselt =
                    sDB.heatTransfer().Nu(Reynolds, Prandtl);

//              calculating the boiling temperature of the liquid at ambient pressure
                scalar tBoilingSurface = Td;

                label Niter = 0;
                scalar deltaT = 10.0;
                scalar dp0 = fuels.properties()[i].pv(pressure, tBoilingSurface) - pressure;
                while ((Niter < 200) && (mag(deltaT) > 1.0e-3))
                {
                    Niter++;
                    scalar pBoil = fuels.properties()[i].pv(pressure, tBoilingSurface);
                    scalar dp = pBoil - pressure;
                    if ( (dp > 0.0) && (dp0 > 0.0) )
                    {
                        tBoilingSurface -= deltaT;
                    }
                    else
                    {
                        if ( (dp < 0.0) && (dp0 < 0.0) )
                        {
                            tBoilingSurface += deltaT;
                        }
                        else
                        {
                            deltaT *= 0.5;
                            if ( (dp > 0.0) && (dp0 < 0.0) )
                            {
                                tBoilingSurface -= deltaT;
                            }
                            else
                            {
                                tBoilingSurface += deltaT;
                            }
                        }
                    }
                    dp0 = dp;
                }

                scalar vapourSurfaceEnthalpy = 0.0;
                scalar vapourFarEnthalpy = 0.0;

                for(label k = 0; k < sDB.gasProperties().size(); k++)
                {
                    vapourSurfaceEnthalpy += sDB.composition().Y()[k][celli]*sDB.gasProperties()[k].H(tBoilingSurface);
                    vapourFarEnthalpy += sDB.composition().Y()[k][celli]*sDB.gasProperties()[k].H(temperature);
                }

                scalar kLiquid = fuels.properties()[i].K(pressure, 0.5*(tBoilingSurface+T()));

                tauBoiling[i] = sDB.evaporation().boilingTime
                (
                    fuels.properties()[i].rho(pressure, Td),
                    fuels.properties()[i].cp(pressure, Td),
                    heatOfVapour,
                    kMixture,
                    Nusselt,
                    temperature - T(),
                    d(),
                    liquidCore(),
                    sDB.runTime().value() - ct(),
                    Td,
                    tBoilingSurface,
                    vapourSurfaceEnthalpy,
                    vapourFarEnthalpy,
                    cpMixture,
                    temperature,
                    kLiquid
                );
            }

        }
    }
}
complex COMPLEXmult(complex a, complex b)
{
  return COMPLEXinit(Re(a)*Re(b) - Im(a)*Im(b),
		     Re(a)*Im(b) + Im(a)*Re(b));
}
 Re call(A0 const&) const
 {
     return Re();
 }
Esempio n. 29
0
static void destructor_lambda(lambda_t* handle)
{
	mpf_clear(Re(handle->lambda));
	mpf_clear(Im(handle->lambda));
	free(handle);
}