CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Diagonal Form of a Symmetric Tensor (https://www.cfd-online.com/Forums/openfoam-programming-development/157528-diagonal-form-symmetric-tensor.html)

pablitobass July 31, 2015 11:48

Diagonal Form of a Symmetric Tensor
 
Hello everyone,

I'm trying to calculate the diagonal of a symmetric tensor, but without success. The part of code I wrote is this one:
Code:

Foam::symmTensor
Foam::ConfOldroyd_B::D() const
{
  return diag(a_);
}

Since the tensor a_ is symmetric, the diagonal form must exist.

Furthermore I have extracted the tensor a_ from the symmTensorField

Code:

    A_
    (
            IOobject
            (
            "A",
            U.time().timeName(),
            U.mesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
            ),
            U.mesh()
    )

using a forAll loop
Code:

Foam::symmTensor
Foam::ConfOldroyd_B::a() const
{
   
    forAll(A_,celli)
    {
      A_[celli];
    }
       
    return a_;             

}

If I did everything in the right way, the loop should give me an array whose element are symmetric tensors associated whit each celli. Is that right?

This is the error message I get when I compile

Quote:

error: could not convert ‘Foam::diag(const Foam::SymmTensor<Cmpt>&) [with Cmpt = double]()’ from ‘Foam::DiagTensor<double>’ to ‘Foam::symmTensor {aka Foam::SymmTensor<double>}
p.s I have tried all the operation "exclusive to tensors of rank 2" I found on the user manual. All of them work fine except the "diag(T)" one.

Does anyone have an idea about what might be the problem?

Many thanks in advantage.

Regards,
Paolo

pablitobass July 31, 2015 19:35

I have just found another thread about the same topic.

It seems that the problem can be solved by using DiagTensor instead of diag().

However, I had a look into the file DiagTensor.H and it seems that it returns a tensor whose elements are only the diagonal of the original tensor. In other words, the result is a tensor whose out diagonal elements have been deleted.

In my case, I need the diagonal form of the tensor as a solution of the eigenvalues problem, therefore the previous method does not work for me.

Sorry for the useless question.

Regards,
Paolo

pablitobass August 5, 2015 11:22

I hope I found a way to get the tensor I was looking for. I also used it to calculate the logartihm of the tensor A_. The code I wrote is this one
Code:

Foam::tensor
Foam::Oldroyd_B_Conform::teta() const
{
   
    forAll(A_, cellI)
    {

        tensor a_ = A_[cellI];


        tensor Omega_ = eigenVectors(a_);
        tensor OmegaT_ = eigenVectors(a_).T();

        OmegaT_ & a_ & Omega_ =  D_ ;

        scalar log_d_x = log(D_.xx());
        scalar log_d_y = log(D_.yy());
        scalar log_d_z = log(D_.zz());

        tensor (

          log_d_x,    0,      0,
              0,  log_d_y,    0,
              0,      0,  log_d_z

          ) = log_D_;

          Omega_ & log_D_ & OmegaT_ =  teta_;

    }

    return teta_;

}

I tried to output the tensor and at least something has bee calculated; I still do not know whether is right or not.

However, I have a couple of (more) doubts:

1. Is it normal that the code prints on screen just one tensor teta_? I expected it to be an array of tensors.

2. Since I have to solve a trasport equation for teta_, does anyone know how to re-create a volTensorField from the teta_ tensors?

Thanks

Paolo


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