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/)
-   -   PtrList<PtrList<dimesionedScalar> > (http://www.cfd-online.com/Forums/openfoam-programming-development/110694-ptrlist-ptrlist-dimesionedscalar.html)

Moslem December 18, 2012 10:04

PtrList<PtrList<dimesionedScalar> >
 
I want to define binary interaction parameters in a mixture. For example I need to determine the interaction diameter as a matrix-like variable, d_ij.
It seems that a variable of type PtrList<PtrList<dimesionedScalar> > is suitable. But I don't know how to apply a relation like :
d_ij[i][j]=(d[i]+d[j])/2
to initialize that.
Can anybody help me on this or refer to part of O.F. code for something similar?
Thanks.

niklas December 19, 2012 05:17

Would this do it

Code:

   
    typedef Vector2D<scalar> matrix;
    typedef Field<matrix> matrixField;

    matrix zeroMatrix(0,0);
    matrixField dij(U.size(), zeroMatrix);

    forAll(dij, celli)
    {
        dij[celli].x() = 1.0;
        dij[celli].y() = 12.0;
    }


niklas December 19, 2012 05:19

I just realized, no it wont...

Moslem December 19, 2012 09:26

Thanks,
I managed it in a different way. I used a PtrList<dimensionedScalar> of size N^2 insted of a N*N matrix.
Something like this:

PtrList<dimensionedScalar> d(specieName.size());
forAll(specieName, i)
{
d[i]= .... ;
}
PtrList<dimensionedScalar> d_ij(specieName.size()*specieName.size());
forAll(specieName, i)
{
forAll(specieName, j)
{
label k=i*specieName.size()+j;
d_ij[k]=(d[i]+d[j])/2;
}
}

Hisham January 10, 2013 11:21

Hi

You can also use List< List < scalar > >
Code:

typedef List< List < scalar > > myMatrix;

myMatrix myZeroMatrix(label x, label y)
{
myMatrix newMyMatrix(x);

forAll(newMyMatrix, i)
{
newMyMatrix[i].setSize(y,0);
}

return newMyMatrix;

}

To initiate your matrix
Code:

myMatrix d_ij;
d_ij = myZeroMatrix (6,6);

to modify elements:
Code:

d_ij[0][3] = 6;
Best regards
Hisham


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