CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

how to extract vector from tensor ?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   March 2, 2011, 14:01
Default how to extract vector from tensor ?
  #1
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 229
Rep Power: 9
Cyp is on a distinguished road
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
Cyp is offline   Reply With Quote

Old   March 2, 2011, 16:11
Default
  #2
Senior Member
 
Steven van Haren
Join Date: Aug 2010
Location: The Netherlands
Posts: 149
Rep Power: 6
stevenvanharen is on a distinguished road
Take a look at this util:

Cannot convert rms velocity fluctuations by foamToFieldview9 utility

You should be able to edit this utility to output the first column of your tensor.
stevenvanharen is offline   Reply With Quote

Old   March 2, 2011, 18:03
Default
  #3
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 229
Rep Power: 9
Cyp is on a distinguished road
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
Cyp is offline   Reply With Quote

Old   March 3, 2011, 05:14
Default
  #4
Senior Member
 
Steven van Haren
Join Date: Aug 2010
Location: The Netherlands
Posts: 149
Rep Power: 6
stevenvanharen is on a distinguished road
Hard to say like this.

Can you post the entire code?
stevenvanharen is offline   Reply With Quote

Old   March 3, 2011, 06:25
Default
  #5
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 229
Rep Power: 9
Cyp is on a distinguished road
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)
    );
Cyp is offline   Reply With Quote

Old   March 3, 2011, 06:57
Default
  #6
Senior Member
 
Steven van Haren
Join Date: Aug 2010
Location: The Netherlands
Posts: 149
Rep Power: 6
stevenvanharen is on a distinguished road
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
stevenvanharen is offline   Reply With Quote

Old   March 3, 2011, 08:47
Default
  #7
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 229
Rep Power: 9
Cyp is on a distinguished road
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....
Cyp is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
extract information from sample during simulation for use duongquaphim OpenFOAM Programming & Development 0 January 10, 2011 14:51
How to modify the stress tensor of momentum eqns. Jason FLUENT 1 November 26, 2010 06:20
curvature correction term, material derivative of a tensor volker OpenFOAM Programming & Development 7 June 3, 2010 08:08
About deformation gradient tensor ZHANG Main CFD Forum 0 June 18, 2007 12:51
second invariant of rate-of-strain tensor Chun Min Chew Main CFD Forum 3 December 10, 2003 12:34


All times are GMT -4. The time now is 09:44.