CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to extract vector from tensor ? (http://www.cfd-online.com/Forums/openfoam-programming-development/85620-how-extract-vector-tensor.html)

Cyp March 2, 2011 14:01

how to extract vector from tensor ?
 
Hi!

I would like to extract a vector from a tensor. I know one can recover a scalar from a tensor using T.xx() ; T.xy() ...

Do you know what can I do to recover the first column of my tensor ?


Best,
Cyp

stevenvanharen March 2, 2011 16:11

Take a look at this util:

http://www.cfd-online.com/Forums/ope...9-utility.html

You should be able to edit this utility to output the first column of your tensor.

Cyp March 2, 2011 18:03

Hi Steve!

Thank you for your answer. I had a look at your code.

I tried this snippet :
Code:

        D1.component(tensor::XX) = U1x.component(vector::X);
        D1.component(tensor::YX) = U1x.component(vector::Y);
        D1.component(tensor::ZX) = U1x.component(vector::Z);

It compiles but my tensor D1 is not update with the U1x values.. Do you why I am wrong ?

Regards,
Cyp

stevenvanharen March 3, 2011 05:14

Hard to say like this.

Can you post the entire code?

Cyp March 3, 2011 06:25

Hi Steven!

Actually, this the piece of code

Code:

        fvVectorMatrix U1xEqn
        (
            fvm::ddt(U1x)
          - fvm::laplacian(nu, U1x)
          + unitE*alpha*vector(1,0,0)
        );

        solve(U1xEqn == -fvc::grad(p1x));

        // --- PISO loop

        for (int corr=0; corr<nCorr; corr++)
        {
            volScalarField rU1xA = 1.0/U1xEqn.A();
//            rUA = 1.0/UEqn.A();

            U1x    = rU1xA*U1xEqn.H();
            phi_1x = (fvc::interpolate(U1x) & mesh.Sf())
                  + fvc::ddtPhiCorr(rU1xA, U1x, phi_1x);

            adjustPhi(phi_1x, U1x, p1x);

            for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
            {
                fvScalarMatrix p1xEqn
                (
                    fvm::laplacian(rU1xA, p1x) == fvc::div(phi_1x)
                );

                p1xEqn.setReference(pRefCell, pRefValue);
                p1xEqn.solve();

                if (nonOrth == nNonOrthCorr)
                {
                    phi_1x -= p1xEqn.flux();
                }
            }

            #include "continuityErrs.H"

            U1x -= rU1xA*fvc::grad(p1x);
            U1x.correctBoundaryConditions();
        }

        D1.component(tensor::XX) = U1x.component(vector::X);
        D1.component(tensor::YX) = U1x.component(vector::Y);
        D1.component(tensor::ZX) = U1x.component(vector::Z);

Where D1 is a volTensorField defined as:
Code:

    volTensorField D1
    (
        IOobject
        (
            "D1",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        dimensionedTensor("D1",dimensionSet(0,2,0,0,0),tensor::zero)
    );


stevenvanharen March 3, 2011 06:57

like this it works:

Code:

D1= tensor(1,0,0,0,0,0,0,0,0)*U1x.component(vector::X);
I know it looks a bit strange but at least it works :)

Cyp March 3, 2011 08:47

Thank you for your answer..

in fact, it not really worked since when you write :
Code:

D1= tensor(1,0,0,0,0,0,0,0,0)*U1x.component(vector::X);
D1= tensor(0,0,0,1,0,0,0,0,0)*U1x.component(vector::Y);

The first instruction is not accounted for...

So, indeed I could do :
Code:

D1=
tensor(1,0,0,0,0,0,0,0,0)*U1x.component(vector::X) +
 tensor(0,0,0,1,0,0,0,0,0)*U1x.component(vector::Y);

but it's not what I looked for....


All times are GMT -4. The time now is 05:56.