Ejemplo n.º 1
0
int EVqrShifted(MAT &A,double mu,double tol,int maxiter){
    int iter = 0 ;
    MAT T(A);
    MAT R(A.dim()), Q(A.dim()),muI(A.dim());
    
    //since we are not able to access column of a matrix easily, so we access row of matrices as substitute.
    for (int i =0 ; i < A.dim(); i++)
		muI[i][i] = mu;

    do{
	for(int i=0;i<A.dim();i++){           //subtract mu*I before QR factorization
		T[i][i] = T[i][i] - mu;
	}
	
	//QR decomposition
	QRDecomp(T,Q,R);	
	T = R * Q;
	//QR decomposition ends		
	for(int i=0;i<A.dim();i++){           //add mu*I back
		T[i][i] = T[i][i] + mu;
    }

	iter++;	
	
    }while(  (iter < maxiter) && (QRerror(T) > tol)  );
        
    printf("Largest 3 eigenvalues: ");
    for (int i = 0; i < 3; i++)
	printf(" %lf;",T[i][i]);
    printf("\nSmallest 3 eigenvalues: ");
    for (int i = A.dim()-1; i > A.dim()-4; i--)
	printf(" %lf;",T[i][i]);
    //printf("\niter %d\nerror: %E\n",iter,QRerror(A_k));
    return iter;

}
Ejemplo n.º 2
0
Foam::tmp<Foam::volScalarField> Foam::dragModels::segregated::K() const
{
    const fvMesh& mesh(pair_.phase1().mesh());

    const volScalarField& alpha1(pair_.phase1());
    const volScalarField& alpha2(pair_.phase2());

    const volScalarField& rho1(pair_.phase1().rho());
    const volScalarField& rho2(pair_.phase2().rho());

    tmp<volScalarField> tnu1(pair_.phase1().nu());
    tmp<volScalarField> tnu2(pair_.phase2().nu());

    const volScalarField& nu1(tnu1());
    const volScalarField& nu2(tnu2());

    volScalarField L
    (
        IOobject
        (
            "L",
            mesh.time().timeName(),
            mesh
        ),
        mesh,
        dimensionedScalar("L", dimLength, 0),
        zeroGradientFvPatchField<scalar>::typeName
    );
    L.internalField() = cbrt(mesh.V());
    L.correctBoundaryConditions();

    volScalarField I
    (
        alpha1
       /max
        (
            alpha1 + alpha2,
            residualAlpha_
        )
    );
    volScalarField magGradI
    (
        max
        (
            mag(fvc::grad(I)),
            residualAlpha_/L
        )
    );

    volScalarField muI
    (
        rho1*nu1*rho2*nu2
       /(rho1*nu1 + rho2*nu2)
    );
    volScalarField muAlphaI
    (
        alpha1*rho1*nu1*alpha2*rho2*nu2
       /(alpha1*rho1*nu1 + alpha2*rho2*nu2)
    );

    volScalarField ReI
    (
        pair_.rho()
       *pair_.magUr()
       /(
           magGradI
          *max(alpha1*alpha2, sqr(residualAlpha_))
          *muI
        )
    );

    volScalarField lambda(m_*ReI + n_*muAlphaI/muI);

    return lambda*sqr(magGradI)*muI;
}