Exemple #1
0
CByteMatrix CByteMatrix::Inv() const
{
	if (m!=n)
	{
		pErrorProc((void*)this,MATERR_DIMENSION,dwData);
		return *this;
	}
	else
	{
		switch (m)
		{
		case 1:
			if (GetModulo256Inv(pMatrix[0])==0)
			{
				pErrorProc((void*)this,MATERR_NOINVERSE,dwData);
				return *this;
			}
			return CByteMatrix(1,1,GetModulo256Inv(pMatrix[0]));
		case 2:
			{
				BYTE nInvDet=GetModulo256Inv(det2(*this));
				if (nInvDet==0)
				{
					pErrorProc((void*)this,MATERR_NOINVERSE,dwData);
					return *this;
				}
				return CByteMatrix(2,2,nInvDet*e(2,2),-nInvDet*e(1,2),-nInvDet*e(2,1),nInvDet*e(1,1));
			}
		case 3:
			{
				BYTE nInvDet=GetModulo256Inv(det3(*this));
				if (nInvDet==0)
				{
					pErrorProc((void*)this,MATERR_NOINVERSE,dwData);
					return *this;
				}
				CByteMatrix inv;
				inv.SetErrorProc(pErrorProc,dwData);
				inv.m=inv.n=3;
				inv.pMatrix=new BYTE[9];
				for (UINT i=1;i<=3;i++)
				{
					for (UINT j=1;j<=3;j++)
					{
						me(inv,j,i)=nInvDet*Cof(i,j);
					}
				}
				return inv;
			}
		default:
			{
				BYTE nInvDet=GetModulo256Inv(det(*this));
				if (nInvDet==0)
				{
					pErrorProc((void*)this,MATERR_NOINVERSE,dwData);
					return *this;
				}
				CByteMatrix inv;
				inv.SetErrorProc(pErrorProc,dwData);
				inv.m=inv.n=m;
				inv.pMatrix=new BYTE[inv.m*inv.m];
				for (UINT i=1;i<=inv.m;i++)
				{
					for (UINT j=1;j<=inv.n;j++)
					{
						me(inv,j,i)=nInvDet*Cof(i,j);
					}
				}
				return inv;
			}
		}
	}
	pErrorProc((void*)this,MATERR_NOINVERSE,dwData);
	return *this;
}
void Foam::MULES::implicitSolve
(
    const RhoType& rho,
    volScalarField& psi,
    const surfaceScalarField& phi,
    surfaceScalarField& phiPsi,
    const SpType& Sp,
    const SuType& Su,
    const scalar psiMax,
    const scalar psiMin
)
{
    const fvMesh& mesh = psi.mesh();

    const dictionary& MULEScontrols = mesh.solverDict(psi.name());

    label maxIter
    (
        readLabel(MULEScontrols.lookup("maxIter"))
    );

    label nLimiterIter
    (
        readLabel(MULEScontrols.lookup("nLimiterIter"))
    );

    scalar maxUnboundedness
    (
        readScalar(MULEScontrols.lookup("maxUnboundedness"))
    );

    scalar CoCoeff
    (
        readScalar(MULEScontrols.lookup("CoCoeff"))
    );

    scalarField allCoLambda(mesh.nFaces());

    {
        surfaceScalarField Cof
        (
            mesh.time().deltaT()*mesh.surfaceInterpolation::deltaCoeffs()
           *mag(phi)/mesh.magSf()
        );

        slicedSurfaceScalarField CoLambda
        (
            IOobject
            (
                "CoLambda",
                mesh.time().timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE,
                false
            ),
            mesh,
            dimless,
            allCoLambda,
            false   // Use slices for the couples
        );

        CoLambda == 1.0/max(CoCoeff*Cof, scalar(1));
    }

    scalarField allLambda(allCoLambda);
    //scalarField allLambda(mesh.nFaces(), 1.0);

    slicedSurfaceScalarField lambda
    (
        IOobject
        (
            "lambda",
            mesh.time().timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE,
            false
        ),
        mesh,
        dimless,
        allLambda,
        false   // Use slices for the couples
    );

    linear<scalar> CDs(mesh);
    upwind<scalar> UDs(mesh, phi);
    //fv::uncorrectedSnGrad<scalar> snGrads(mesh);

    fvScalarMatrix psiConvectionDiffusion
    (
        fvm::ddt(rho, psi)
      + fv::gaussConvectionScheme<scalar>(mesh, phi, UDs).fvmDiv(phi, psi)
        //- fv::gaussLaplacianScheme<scalar, scalar>(mesh, CDs, snGrads)
        //.fvmLaplacian(Dpsif, psi)
      - fvm::Sp(Sp, psi)
      - Su
    );

    surfaceScalarField phiBD(psiConvectionDiffusion.flux());

    surfaceScalarField& phiCorr = phiPsi;
    phiCorr -= phiBD;

    for (label i=0; i<maxIter; i++)
    {
        if (i != 0 && i < 4)
        {
            allLambda = allCoLambda;
        }

        limiter
        (
            allLambda,
            rho,
            psi,
            phiBD,
            phiCorr,
            Sp.field(),
            Su.field(),
            psiMax,
            psiMin,
            nLimiterIter
        );

        solve
        (
            psiConvectionDiffusion + fvc::div(lambda*phiCorr),
            MULEScontrols
        );

        scalar maxPsiM1 = gMax(psi.internalField()) - 1.0;
        scalar minPsi = gMin(psi.internalField());

        scalar unboundedness = max(max(maxPsiM1, 0.0), -min(minPsi, 0.0));

        if (unboundedness < maxUnboundedness)
        {
            break;
        }
        else
        {
            Info<< "MULES: max(" << psi.name() << " - 1) = " << maxPsiM1
                << " min(" << psi.name() << ") = " << minPsi << endl;

            phiBD = psiConvectionDiffusion.flux();

            /*
            word gammaScheme("div(phi,gamma)");
            word gammarScheme("div(phirb,gamma)");

            const surfaceScalarField& phir =
                mesh.lookupObject<surfaceScalarField>("phir");

            phiCorr =
                fvc::flux
                (
                    phi,
                    psi,
                    gammaScheme
                )
              + fvc::flux
                (
                    -fvc::flux(-phir, scalar(1) - psi, gammarScheme),
                    psi,
                    gammarScheme
                )
                - phiBD;
            */
        }
    }

    phiPsi = psiConvectionDiffusion.flux() + lambda*phiCorr;
}